Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(cli): add daemon signal check to prevent silent PAT fallback

Willow Lopez33967611b2f2
diff --git a/server/cmd/multica/cmd_agent_test.go b/server/cmd/multica/cmd_agent_test.go
index 8a5475a302..2e67e1c4b7 100644
--- a/server/cmd/multica/cmd_agent_test.go
+++ b/server/cmd/multica/cmd_agent_test.go
@@ -119,6 +119,7 @@ func TestResolveToken_AgentContextSkipsConfig(t *testing.T) {
t.Setenv("MULTICA_AGENT_ID", "")
t.Setenv("MULTICA_TASK_ID", "")
t.Setenv("MULTICA_TOKEN", "")
+ t.Setenv("MULTICA_DAEMON_PORT", "")
if got := resolveToken(testCmd()); got != "mul_profile_token" {
t.Fatalf("resolveToken() = %q, want profile token", got)
@@ -144,6 +145,59 @@ func TestResolveToken_AgentContextSkipsConfig(t *testing.T) {
t.Fatalf("resolveToken() = %q, want MULTICA_TOKEN", got)
}
})
+
+ t.Run("daemon port set without agent context avoids config fallback", func(t *testing.T) {
+ t.Setenv("MULTICA_AGENT_ID", "")
+ t.Setenv("MULTICA_TASK_ID", "")
+ t.Setenv("MULTICA_TOKEN", "")
+ t.Setenv("MULTICA_DAEMON_PORT", "19514")
+
+ if got := resolveToken(testCmd()); got != "" {
+ t.Fatalf("resolveToken() = %q, want empty (daemon port set, fail closed)", got)
+ }
+ })
+
+ t.Run("daemon port set with explicit task token uses task token", func(t *testing.T) {
+ t.Setenv("MULTICA_AGENT_ID", "")
+ t.Setenv("MULTICA_TASK_ID", "")
+ t.Setenv("MULTICA_TOKEN", "mat_task_token")
+ t.Setenv("MULTICA_DAEMON_PORT", "19514")
+
+ if got := resolveToken(testCmd()); got != "mat_task_token" {
+ t.Fatalf("resolveToken() = %q, want MULTICA_TOKEN (task token wins over daemon signal)", got)
+ }
+ })
+
+ // MULTICA_SERVER_URL is a user-facing env var that may be set in a
+ // normal shell. It is NOT a daemon identity signal — only
+ // MULTICA_DAEMON_PORT is. The config fallback must still work when
+ // SERVER_URL is set but no daemon signal is present.
+ t.Run("MULTICA_SERVER_URL alone does not block config fallback", func(t *testing.T) {
+ t.Setenv("MULTICA_AGENT_ID", "")
+ t.Setenv("MULTICA_TASK_ID", "")
+ t.Setenv("MULTICA_TOKEN", "")
+ t.Setenv("MULTICA_DAEMON_PORT", "")
+ t.Setenv("MULTICA_SERVER_URL", "https://api.multica.ai")
+
+ if got := resolveToken(testCmd()); got != "mul_profile_token" {
+ t.Fatalf("resolveToken() = %q, want profile token (SERVER_URL is not a daemon identity signal)", got)
+ }
+ })
+
+ // Normal CLI usage: no daemon signals whatsoever. The user-global
+ // config token must be reachable. This is the most basic path and
+ // must not be broken by any daemon-signal guard expansion.
+ t.Run("no daemon signals, normal CLI reads config token", func(t *testing.T) {
+ t.Setenv("MULTICA_AGENT_ID", "")
+ t.Setenv("MULTICA_TASK_ID", "")
+ t.Setenv("MULTICA_TOKEN", "")
+ t.Setenv("MULTICA_DAEMON_PORT", "")
+ t.Setenv("MULTICA_SERVER_URL", "")
+
+ if got := resolveToken(testCmd()); got != "mul_profile_token" {
+ t.Fatalf("resolveToken() = %q, want profile token (normal CLI flow)", got)
+ }
+ })
}
func TestNewAPIClient_AgentContextRequiresTaskToken(t *testing.T) {
diff --git a/server/cmd/multica/cmd_auth.go b/server/cmd/multica/cmd_auth.go
index 02c6a88ba6..9777f600aa 100644
--- a/server/cmd/multica/cmd_auth.go
+++ b/server/cmd/multica/cmd_auth.go
@@ -77,6 +77,15 @@ func resolveToken(cmd *cobra.Command) string {
if inAgentExecutionContext() {
return ""
}
+ // A daemon-managed agent process may lose MULTICA_AGENT_ID /
+ // MULTICA_TASK_ID in child subprocesses (the runtime may not forward
+ // them), but MULTICA_DAEMON_PORT persists. When we detect the daemon
+ // signal we fail closed — never silently fall back to the user-global
+ // config token, because that fallback is how agent operations land as
+ // the wrong actor.
+ if os.Getenv("MULTICA_DAEMON_PORT") != "" {
+ return ""
+ }
profile := resolveProfile(cmd)
cfg, _ := cli.LoadCLIConfigForProfile(profile)
return cfg.Token