{"record":{"id":"ec8e263a34300eb2","repo":"multica-ai/multica","slug":"no-chat-task-in-context-run-inside-a-chat-task-m","errorCode":null,"errorMessage":"no chat task in context: run inside a chat task (MULTICA_TASK_ID set) or pass --task <id>","messagePattern":"no chat task in context: run inside a chat task \\(MULTICA_TASK_ID set\\) or pass --task <id>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_attachment.go","lineNumber":74,"sourceCode":"\tattachmentCmd.AddCommand(attachmentDownloadCmd)\n\tattachmentCmd.AddCommand(attachmentUploadCmd)\n\n\tattachmentDownloadCmd.Flags().StringP(\"output-dir\", \"o\", \".\", \"Directory to save the downloaded file\")\n\tattachmentUploadCmd.Flags().String(\"task\", \"\", \"Chat task id to attach to (defaults to MULTICA_TASK_ID)\")\n}\n\nfunc runAttachmentUpload(cmd *cobra.Command, args []string) error {\n\tclient, err := newAPIClient(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttaskID, _ := cmd.Flags().GetString(\"task\")\n\tif taskID == \"\" {\n\t\ttaskID = client.TaskID\n\t}\n\tif taskID == \"\" {\n\t\treturn fmt.Errorf(\"no chat task in context: run inside a chat task (MULTICA_TASK_ID set) or pass --task <id>\")\n\t}\n\n\tpath := args[0]\n\tif isHTTPURL(path) {\n\t\treturn fmt.Errorf(\"upload accepts a local file path, not a URL: %s\", path)\n\t}\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read file %s: %w\", path, err)\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), cli.AtLeastAPITimeout(60*time.Second))\n\tdefer cancel()\n\n\tatt, err := client.UploadChatAttachment(ctx, data, path, taskID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"upload attachment: %w\", err)\n\t}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_attachment.go#L56-L92","documentation":"The `attachment upload` CLI command needs to know which chat task owns the attachment. It first checks the --task flag, then falls back to client.TaskID (populated from the MULTICA_TASK_ID environment variable). When both are empty the command refuses to run because an attachment cannot be associated with any chat.","triggerScenarios":"Running `multica attachment upload <file>` outside a daemon-managed chat task with no --task flag and no MULTICA_TASK_ID in the environment (e.g. from a plain shell, CI, or a script that does not source the task env).","commonSituations":"Agent/automation scripts that reuse a snippet from a chat task but run it in a fresh terminal; users testing the CLI locally after reading docs that assume a chat-task context; MULTICA_TASK_ID lost because the command runs through sudo or a wrapper that scrubs env.","solutions":["Pass the task explicitly: `multica attachment upload --task <task-id> <file>`","Export MULTICA_TASK_ID=<task-id> before running the command","Run the command from inside a chat task session so the daemon injects MULTICA_TASK_ID","If scripting, fetch a task id first (e.g. `multica task list`) and feed it to --task"],"exampleFix":"# before\nmultica attachment upload ./report.pdf\n# -> no chat task in context...\n\n# after\nmultica attachment upload --task 42 ./report.pdf\n# or\nMULTICA_TASK_ID=42 multica attachment upload ./report.pdf","handlingStrategy":"validation","validationCode":"# shell: fail fast before calling upload\n: \"${MULTICA_TASK_ID:?no chat task in context: set MULTICA_TASK_ID or pass --task <id>}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scripts that upload attachments should always pass --task explicitly instead of relying on ambient env","At script start, assert MULTICA_TASK_ID is set when running inside chat-task automation"],"tags":["cli","attachment","configuration","task-context"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}