{"record":{"id":"438d9662450f2e69","repo":"multica-ai/multica","slug":"archive-agent-w","errorCode":null,"errorMessage":"archive agent: %w","messagePattern":"archive agent: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_agent.go","lineNumber":836,"sourceCode":"\t\treturn cli.PrintJSON(os.Stdout, result)\n\t}\n\n\tfmt.Printf(\"Agent updated: %s (%s)\\n\", strVal(result, \"name\"), strVal(result, \"id\"))\n\treturn nil\n}\n\nfunc runAgentArchive(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx, cancel := cli.APIContext(context.Background())\n\tdefer cancel()\n\n\tvar result map[string]any\n\tif err := client.PostJSON(ctx, \"/api/agents/\"+args[0]+\"/archive\", nil, &result); err != nil {\n\t\treturn fmt.Errorf(\"archive agent: %w\", err)\n\t}\n\n\toutput, _ := cmd.Flags().GetString(\"output\")\n\tif output == \"json\" {\n\t\treturn cli.PrintJSON(os.Stdout, result)\n\t}\n\n\tfmt.Printf(\"Agent archived: %s (%s)\\n\", strVal(result, \"name\"), strVal(result, \"id\"))\n\treturn nil\n}\n\nfunc runAgentRestore(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tctx, cancel := cli.APIContext(context.Background())","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_agent.go#L818-L854","documentation":"Wrapped error returned when `multica agent archive <id>` fails to POST to `/api/agents/{id}/archive`. Archiving is a soft-delete/lifecycle transition; the wrapped cause is typically 404 (unknown agent), 409/400 (agent already archived or in a state that cannot be archived), auth failure, or a connectivity error.","triggerScenarios":"`multica agent archive <id>` on a deleted or mistyped id, archiving an already-archived agent, or when the server/auth is unreachable.","commonSituations":"Script archives agents in a loop and one id was already archived in a prior run; id copied with a trailing space; token expired mid-script.","solutions":["Verify the agent id and its current status: `multica agent get <id>`","If already archived, treat the outcome as success in scripts (idempotency check) rather than retrying","Fix connectivity/auth if the wrapped error is a connection or 401/403 error","Re-run once the state or environment is corrected"],"exampleFix":"# before\nmultica agent archive agt_1   # already archived\n# Error: archive agent: 400: agent already archived\n\n# after\nmultica agent get agt_1        # confirm status=archived; nothing to do","handlingStrategy":"try-catch","validationCode":"status=$(multica agent get \"$AGENT_ID\" --output json | jq -r .status)\n[ \"$status\" = \"archived\" ] || multica agent archive \"$AGENT_ID\"","typeGuard":null,"tryCatchPattern":"if err := runAgentArchive(cmd, args); err != nil {\n\tif strings.Contains(err.Error(), \"already archived\") { return nil } // idempotent scripts\n\treturn fmt.Errorf(\"archive agent: %w\", err)\n}","preventionTips":["Check current status before archiving to keep scripts idempotent","Treat 'already archived' as success in automation","Verify ids via `agent list` before lifecycle operations"],"tags":["cli","api","lifecycle","agent"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}