{"record":{"id":"09218beb646fa42e","repo":"multica-ai/multica","slug":"connect-to-daemon-w","errorCode":null,"errorMessage":"connect to daemon: %w","messagePattern":"connect to daemon: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/cmd/multica/cmd_repo.go","lineNumber":386,"sourceCode":"\n\tparentCtx := cmd.Context()\n\tif parentCtx == nil {\n\t\tparentCtx = context.Background()\n\t}\n\tctx, cancel := context.WithTimeout(parentCtx, 5*time.Minute)\n\tdefer cancel()\n\tclient := &http.Client{}\n\tcheckoutURL := fmt.Sprintf(\"http://127.0.0.1:%s/repo/checkout\", daemonPort)\n\tvar body []byte\n\tfor {\n\t\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, checkoutURL, bytes.NewReader(data))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"create daemon checkout request: %w\", err)\n\t\t}\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t\tresp, err := client.Do(req)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"connect to daemon: %w\", err)\n\t\t}\n\t\tbody, err = io.ReadAll(resp.Body)\n\t\tcloseErr := resp.Body.Close()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"read daemon checkout response: %w\", err)\n\t\t}\n\t\tif closeErr != nil {\n\t\t\treturn fmt.Errorf(\"close daemon checkout response: %w\", closeErr)\n\t\t}\n\t\tif resp.StatusCode == http.StatusServiceUnavailable && resp.Header.Get(\"X-Multica-Retryable\") == \"repo-busy\" {\n\t\t\tdelay := repoCheckoutRetryDelay(resp.Header.Get(\"Retry-After\"), time.Now())\n\t\t\ttimer := time.NewTimer(delay)\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\ttimer.Stop()\n\t\t\t\treturn fmt.Errorf(\"connect to daemon: %w\", context.Cause(ctx))\n\t\t\tcase <-timer.C:\n\t\t\t\tcontinue","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/multica-ai/multica/blob/2c0912b6ec764b373d44eeea1e80f0d9f11ab417/server/cmd/multica/cmd_repo.go#L368-L404","documentation":"The first \"connect to daemon\" error site: client.Do(req) failed while POSTing to http://127.0.0.1:$MULTICA_DAEMON_PORT/repo/checkout. This is a transport-level failure — connection refused, no route, or the context deadline (5 minutes) expiring during the request itself. The retry loop only re-issues on HTTP 503 with X-Multica-Retryable: repo-busy, so transport errors abort immediately.","triggerScenarios":"Nothing listening on 127.0.0.1:$MULTICA_DAEMON_PORT (daemon not running or different port); daemon crashed between env injection and the call; wrong port value; the 5-minute ctx timeout elapsing while the request is in flight.","commonSituations":"Agent outlives its daemon (daemon restarted, old port captured in env); port mismatch after daemon reconfig; localhost unreachable in a network-namespace-restricted sandbox; very slow checkouts exceeding the 5-minute budget.","solutions":["Confirm the daemon is up and listening on the expected port: ss -ltnp | grep <port> or curl http://127.0.0.1:<port>/health.","If the daemon restarted with a new port, re-run the command in a fresh daemon task so MULTICA_DAEMON_PORT is re-injected.","If checkouts legitimately take >5 min, raise the context timeout in the CLI or reduce the checkout scope (smaller repo/ref) — note the timeout is hardcoded to 5*time.Minute.","Check the message chain: \"connection refused\" means no listener; \"context deadline exceeded\" means timeout."],"exampleFix":"# before: stale port from an old daemon\nMULTICA_DAEMON_PORT=8123 multica repo checkout URL   # connection refused\n\n# after: verify listener, re-run inside a live daemon task\nss -ltnp | grep 8123   # nothing? restart daemon / rerun task","handlingStrategy":"retry","validationCode":"# fail fast if nothing listens on the daemon port before the long command\nnc -z 127.0.0.1 \"$MULTICA_DAEMON_PORT\" || { echo 'daemon not listening' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"resp, err := client.Do(req)\nif err != nil {\n\tif errors.Is(err, context.DeadlineExceeded) {\n\t\t// 5-min budget exhausted mid-request: retry with a fresh context or bail\n\t}\n\treturn fmt.Errorf(\"connect to daemon: %w\", err)\n}","preventionTips":["Health-check the daemon port before invoking checkout.","Re-run commands inside fresh daemon tasks after daemon restarts so env stays correct.","Keep checkouts under the hardcoded 5-minute context budget or shrink the clone."],"tags":["go","http","network","daemon","connection-refused","timeout"],"backgroundTag":null,"analyzedSha":"2c0912b6ec764b373d44eeea1e80f0d9f11ab417","analyzedAt":"2026-08-15T13:25:18.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}