{"record":{"id":"ff16f5524707f062","repo":"multica-ai/multica","slug":"agent-execution-context-requires-multica-token-to","errorCode":null,"errorMessage":"agent execution context requires MULTICA_TOKEN to be a task-scoped mat_ token%s","messagePattern":"agent execution context requires MULTICA_TOKEN to be a task-scoped mat_ token(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_agent.go","lineNumber":265,"sourceCode":"\n// resolveProfile returns the --profile flag value (empty string means default profile).\nfunc resolveProfile(cmd *cobra.Command) string {\n\tval, _ := cmd.Flags().GetString(\"profile\")\n\treturn val\n}\n\nfunc newAPIClient(cmd *cobra.Command) (*cli.APIClient, error) {\n\ttaskContext := inDaemonManagedExecutionContext()\n\ttoken := resolveToken(cmd)\n\tif taskContext && !strings.HasPrefix(token, \"mat_\") {\n\t\t// When the ONLY daemon signal is a workdir marker (no MULTICA_AGENT_ID /\n\t\t// MULTICA_TASK_ID / MULTICA_DAEMON_PORT), the likeliest cause outside a\n\t\t// real task is a leftover marker from a crashed daemon task in a\n\t\t// local_directory. Name the exact file so a normal user can recover\n\t\t// instead of hitting an opaque \"requires mat_ token\" error. Shares its\n\t\t// wording with requireHumanLocalCommand: same cause, same remedy.\n\t\tif markerPath := leftoverDaemonTaskMarkerPath(); markerPath != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"agent execution context requires MULTICA_TOKEN to be a task-scoped mat_ token%s\", leftoverMarkerSuffix(markerPath))\n\t\t}\n\t\treturn nil, fmt.Errorf(\"agent execution context requires MULTICA_TOKEN to be a task-scoped mat_ token%s\", daemonPortOnlyContextHint())\n\t}\n\n\tserverURL := resolveServerURL(cmd)\n\tworkspaceID := resolveWorkspaceID(cmd)\n\tif serverURL == \"\" {\n\t\treturn nil, fmt.Errorf(\"server URL not set: use --server-url flag, MULTICA_SERVER_URL env, or 'multica config set server_url <url>'\")\n\t}\n\n\tclient := cli.NewAPIClient(serverURL, workspaceID, token)\n\t// When running inside a daemon task, attribute actions to the agent.\n\tif agentID := os.Getenv(\"MULTICA_AGENT_ID\"); agentID != \"\" {\n\t\tclient.AgentID = agentID\n\t}\n\tif taskID := os.Getenv(\"MULTICA_TASK_ID\"); taskID != \"\" {\n\t\tclient.TaskID = taskID\n\t}","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_agent.go#L247-L283","documentation":"newAPIClient refuses to build a client in a daemon-managed execution context unless the token is a task-scoped mat_ token. When the only daemon signal is a leftover workdir marker (no MULTICA_AGENT_ID/MULTICA_TASK_ID/MULTICA_DAEMON_PORT), the message appends the exact marker file path so the user can recover instead of hitting an opaque refusal.","triggerScenarios":"inDaemonManagedExecutionContext() is true (marker file found walking up from cwd, or daemon env vars present), resolveToken returned a non-mat_ token (e.g. the human user's token), and leftoverDaemonTaskMarkerPath() found a stale marker file.","commonSituations":"A daemon task ran in a local_directory, crashed without cleanup, and left its marker file in the user's repository (MUL-6132); every later multica command in that directory tree is then treated as agent-context while the user authenticates as a human.","solutions":["Delete the marker file named in the error's appended suffix (the message gives the exact path).","Re-run the command from a directory outside the stale marker's tree, or from the repository root above it, to confirm it was directory-scoped.","If this recurs, check why daemon tasks in local_directory workdirs are not cleaning up their markers on failure, and report/fix the cleanup path."],"exampleFix":"# before: error in a repo where a daemon task crashed\nmultica agent list\n# -> agent execution context requires MULTICA_TOKEN to be a task-scoped mat_ token ...\n\n# after: remove the stale marker named in the message\nrm /path/to/repo/.multica/daemon-task-marker.json\nmultica agent list","handlingStrategy":"validation","validationCode":"# Before running multica in a repo, check for a stale daemon marker and remove it.\nfind . -name daemon-task-marker.json -path '*/.multica/*' \\\n  -exec sh -c 'echo \"removing stale marker: $1\"; rm \"$1\"' _ {} \\;","typeGuard":null,"tryCatchPattern":"// In Go code shelling out to multica:\nout, err := cmd.CombinedOutput()\nif err != nil && strings.Contains(string(out), \"task-scoped mat_ token\") {\n    if i := strings.Index(string(out), \"marker\"); i >= 0 {\n        return fmt.Errorf(\"stale daemon marker detected; delete the file named in: %s\", string(out))\n    }\n}","preventionTips":["Add stale-marker cleanup (or at least detection) to post-task teardown for local_directory runs.","When a daemon task crashes, check its workdir for the marker before reuse.","Keep human shells out of directories used as daemon task workdirs."],"tags":["go","cli","authentication","daemon","environment"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}