Repository navigation
Bug sweep 1: exit codes, loopback daemons, attach logs, misc fixes - #376
Conversation
… tests - `job submit --attach` returned nil when the job was canceled (including when the phase flips to canceled while streaming logs), unlike --wait. - `smart-test run` returned nil regardless of test outcomes; it now returns an error when any execution failed or was canceled (unless --no-wait), in both default and structured output modes. Refs ENG-1248 (H3, H4). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The sandbox manager (:6666), root manager (:6667) and control-plane proxy (:0) listened on all interfaces with no authentication, exposing Status (connect config incl. API key and env), GetResourceOutputs, Shutdown and a SOCKS5 path into the cluster to network peers. All clients already dial 127.0.0.1. Refs ENG-1248 (H1, H2). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nistically - Open repos with EnableDotGitCommonDir so HEAD/refs resolve in linked worktrees (previously "reference not found"). - Pick "origin" (else the first remote by name) instead of remotes[0], which go-git returns in map order, so repo identity/test names were unstable with multiple remotes. - Skip remotes without URLs instead of panicking on URLs[0]. Refs ENG-1248. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rrors - smart-test run: --set-label on a test file with no labels (stdin, or outside a git repo) panicked assigning to a nil map; labels are now copied, which also stops mutating the shared per-directory cache. - sandbox apply: port2Int no longer converts "port" keys inside map[string]string fields (labels, resources[].params), which made valid specs fail to unmarshal. - traffic record: use a named return so errors from removing the traffic-watch middleware are reported instead of silently dropped. Refs ENG-1248. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Stream logs when a terminal phase is observed (from the saved cursors), so jobs that finish between polls, or whose streams stopped early, still show their (remaining) logs. - Stream stdout and stderr independently: one ending no longer cancels the other and drops its output. - Save each stream's cursor even on error, so re-streaming resumes instead of duplicating output; only clear the previous line when it is the "Queued" status line. - Bound log streaming by --timeout, not only the polling loop. Refs ENG-1248. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolves internal/command/sandbox/subst.go: main's #362 landed the same fix this branch carried (labels and params keep a "port" key as a string), as freeFormMaps; this takes main's spelling and drops port2IntSkipFields. Co-Authored-By: Claude Opus 5.5 <[email protected]>
davixcky
left a comment
There was a problem hiding this comment.
I built this locally, merged with the rest of the sweep (#377–#381), and compared it with main against staging, using small jobs on signadot-e2e-runner. Most fixes work. --attach on a canceled job now exits 1 (it was 0), the first log line after "Queued" is no longer lost, the daemons listen on 127.0.0.1 only (they were on *:6666 and *:<proxy port>), and smart-test list works in a linked worktree.
Requesting changes for two --attach regressions I hit live:
1. Every job that's seen running prints its logs twice.
In waitForJob, the running branch streams to the end, then finish() calls ls.stream(ctx) again with the saved cursors. For a finished job the server doesn't resume from that cursor. It sends a RESTART signal and replays the whole log, which ParseSSEStream prints after WARNING: The execution has been restarted.... The job had only one attempt.
- A job printing
out 1..15/err 1..15produced 30 stdout and 30 stderr lines. - A 120-tick job printed 119 of the ticks twice.
2. --attach hangs about 60s after the job ends when a stream has no output.
stream() now waits for both stdout and stderr, but the server doesn't seem to close a stream that had no output. With a stdout-only job, all 120 ticks arrived, then the command sat until staging's gateway returned Error getting logs: 504 Gateway Timeout, and then did the duplicate replay from (1). On main this was hidden because stdout ending cancelled stderr.
Possible fixes: skip the final drain when the running stream already ended with EOF, or ignore a RESTART replay when resuming with a cursor; and add a short grace deadline for the other stream once one has ended or the phase is terminal. Or make the server close idle streams and honor the cursor for finished jobs.
Smaller things from the same run:
- A canceled job now prints
400 Bad Request: canceled job attemptfrom the final drain. LocalAddressfor the proxy is still reported as":<port>"(sandbox_server.go:197,210), not127.0.0.1:<port>.- A timeout during the final drain exits 0 with truncated output and no message.
- CI doesn't seem to run
go test, so none of the new tests gate merges.
Two regressions from 063f169, found in review against staging: - A job seen running had its logs printed twice: the running branch streamed both to the end, then the terminal-phase drain asked again from the saved cursors, and for a finished job the server ignores the cursor and replays the whole log after a RESTART. The drain now reads only the streams the server has not ended. - Waiting for both streams hung when one had no output, since the server does not end such a stream: a stdout-only job sat until the gateway's 504. Once one stream ends the other is let go after 3s without output, and the drain lets go of each the same way (an idle grace, reset by each line, so a long tail is not cut short). Also from the same review: - A canceled attempt's logs are not drained: the server refuses them ("400 Bad Request: canceled job attempt"). - --timeout running out during the final drain is an error, not exit 0 with the output cut short. Refs ENG-1248. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The control-plane proxy has listened on 127.0.0.1 since 0ba72ce, and the port-forward on client-go's "localhost", but status still reported both as ":<port>", which reads as every interface. They now say 127.0.0.1:<port> and localhost:<port>. Refs ENG-1248. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the --attach and locald address fixes from #376's review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the --attach and locald address fixes from #376's review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the --attach and locald address fixes from #376's review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the --attach and locald address fixes from #376's review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@davixcky thanks for running it live. Both regressions and the smaller items are addressed in 802abef and 7164433 on this branch, and #377–#380 are merged up on top of them:
New tests in Not addressed here:
|
Risk: medium. Dismissed this automation’s prior approval because existing review state still requires human review after later commits. Bugbot and Security Agent were not running after the first poll, so those signals were skipped. Human review is needed and no reviewers were assigned.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Second batch of CLI bug-sweep fixes (ENG-1248). **Stacked on #376** — base is `scott/bug-sweep`; review only the 3 commits here. ## Commits - **`fix(auth)`** — keep keyring and plaintext credentials consistent: - `auth login` stores exclusively (`auth.StoreExclusive`): after writing one store it removes the other, so the new login is actually used (`ResolveAuth` prefers the keyring). Before: keyring login as org A, then `login --insecure-storage` as org B → success printed, org A still used. - `auth logout` deletes from both stores (`auth.DeleteAll`). Before: logout removed the keyring entry and silently activated stale plaintext credentials. - Expired bearer tokens in the plaintext store are refreshed like keyring ones instead of immediately failing with `ErrAuthExpired` (headless Linux / containers without a keyring had to re-login every token lifetime). - Keep the current refresh token when the refresh response has none (CLI and locald refresh paths). - **`fix(mcp)` session** — the remote MCP session (and credentials captured in its transport) was created once per process. After re-login as another org, agent tool calls (create/update sandbox, …) kept executing as the old org. `Session()` now resolves auth each call and recreates the session when credentials change. Also: no panic on a remote error result with empty/non-text content. - **`fix(mcp)` startup** — `signadot mcp` blocked serving stdio until a *successful* `/meta` fetch (retried every 30s forever), so offline / behind a proxy / during a hosted-MCP outage it never answered `initialize`. Now it waits only for the first attempt; remote tools arrive via `tools/list_changed` once a later fetch succeeds. ## Not addressed (still open in ENG-1248) - Cross-process refresh-token coordination (MCP monitor, locald, CLI refreshing concurrently) — needs a file lock / design; depends on Auth0 rotation settings. - Single credential store across environments (`api_url` / `--config`) — design question. ## Testing - New tests with mock keyring + temp `HOME`: login/logout store consistency, plaintext refresh (fake refresh endpoint), MCP session recreation on re-login (fake streamable MCP server), first-fetch-on-failure. Each verified failing without its fix. - `go vet ./...`, `go test ./...` clean; `-race` clean for `auth`, `config`, `mcp/...`. Refs ENG-1248. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Fourth batch of CLI bug-sweep fixes (ENG-1248). **Stacked on #376.** It is independent of #377 and #378, and merges cleanly with both. There is one commit per fix; review only the 9 commits here. ## Commits - **`fix(artifact)`**: download to a temp file and rename it into place on success. Before, `artifact download -j wrongjob report.xml` emptied an existing `report.xml` on a 404/401, and failed downloads left partial files. The 4-minute timeout now only limits how long the download takes to start; before, it covered the whole body, so any artifact taking longer than 4 minutes to download failed. - **`fix(sandbox)` get-files**: with the default output directory, `--no-clobber` no longer deletes the directory, and the local edits in it, before the check. - **`fix(sandbox)` apply**: no panic on a file without `spec`, which now returns an error. No panic when `--wait` fails before any successful GET; the applied sandbox is printed instead. - **`fix(secret)`**: the server's update replaces the description (confirmed in `sandboxes/internal/control/secret/update.go` and `appdb.UpdateSecret`), so `secret update NAME --value-file f` wiped it. The CLI now sends the current description unless `--description` is given; an explicit empty value still clears it. With `-f`, the file is still the whole secret. - **`fix(devbox)`**: create `~/.signadot` before `devbox register`. Before, when auth came only from the environment, the devbox was registered on the server and then saving its ID failed with ENOENT. - **`fix(poll)`**: `Readiness.Stop` racing a fatal error could panic with "close of closed channel", e.g. on Ctrl-C during `local override`, before the undo ran, leaving the override middleware on a shared sandbox. `done` is now closed via `sync.Once`. - **`fix(override)`**: the override log server now listens on loopback only. It listened on all interfaces, so anyone on the network could POST `/api/logs` and print spoofed entries to the user's terminal. - **`fix(auth)`**: plaintext credentials are written atomically (temp file + rename), and a file that fails to parse is reported instead of deleted. Before, a read concurrent with login or token refresh could see a partial file and delete the fresh credentials. - **`fix(bug)`**: `signadot bug` printed only the API config, because the embedded `*config.API`'s `MarshalJSON` was promoted. It dropped `BuildInfo` and `Error`, which are what the command is for. The error was also an interface, which marshals as `{}`. **Output shape change:** the API config is now nested under `config`. ## Testing - Each fix has a test. The ones for the artifact download, `sandbox apply` (missing spec), devbox, `poll` (reproduces "close of closed channel") and plaintext credentials were checked to fail without their fixes. Tests use fake API servers where needed. - `go vet ./...` and `go test ./...` pass; `-race` passes for `internal/auth` and `internal/poll`. Refs ENG-1248. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Third batch of CLI bug-sweep fixes (ENG-1248), for `local connect`. **Stacked on #376** (independent of #377); review only the 4 commits here. Design invariants (see the triage comment on ENG-1248): at most one connect per machine, enforced by the locald pidfiles; disconnect has deliberately no deadline, since giving up part way could leave the machine's networking corrupted. ## Commits - **`fix(local): refuse connect when either local daemon is running`**: the pre-check only looked at the pidfile for the mode being started. With an unprivileged connect to cluster A running, a privileged `local connect --cluster B` started a root manager. Its sandbox-manager child failed to take the lock, and the root manager then monitored, and wired root networking to, A's sandbox manager. Connect still exited 0. - **`fix(locald): don't hang root manager shutdown after sbmgr monitor exits`**: if the sandbox manager command couldn't be formulated (e.g. the binary was moved or upgraded while connected), `sbmgrMonitor.run` returned without closing `doneAck`. `stop()` then blocked forever and disconnect never restored hosts, routes/pf or the resolver. - **`fix(local): report what disconnect is waiting on`**: no deadline added. After 5s, then every 30s, disconnect prints how long it has waited, the last shutdown error and the pidfiles/PIDs it is waiting on. Previously it retried silently forever, e.g. on a stale pidfile whose PID was reused after a hard power-off (`IsPIDRunning` treats EPERM as running). Proper staleness detection belongs in libconnect `processes`. - **`fix(locald): handle a missing tunnel API client in the sandbox manager`**: `GetResourceOutputs` (`sandbox get-env`/`get-files`) before the link was healthy called a nil client and crashed the sandbox manager; it now returns `Unavailable`. When the link never became healthy, the sandboxes watcher panicked on the nil client before the devbox session was released; the watcher now doesn't start without a client. The client is now guarded by the watcher mutex. ## Testing - New tests: either-pidfile pre-check, `stop()` after a fatal `run()` exit, disconnect wait report, and a nil tunnel client (GetResourceOutputs and watcher). The `doneAck` and tunnel-client tests fail without their fixes (timeout / nil-pointer panic). - `go vet ./...` and `go test ./...` pass; `-race` passes for `internal/locald/...` and `internal/command/local`. - Not yet run against a real cluster. Refs ENG-1248. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Fifth batch of CLI bug-sweep fixes (ENG-1248), for plans. **Stacked on #376.** It is independent of #377, #378 and #379, and merges cleanly with each. There is one commit per fix; review only the 5 commits here. ## Commits - **`fix(plan): resume live plan logs`**: `plan run --attach` and `plan x logs -f` opened the live stream once and discarded its errors. That caused three problems: - A stream requested before dispatch got a 404 (`execution not yet dispatched to a runner`) and the run showed no logs. - After the server's 5-minute idle cut (`planexecution/logproxy.go`, e.g. a silent step), all later logs were lost. - `--attach` cancelled the stream as soon as a terminal phase was seen, dropping trailing lines. The new `planexec.FollowLiveLogs` reconnects from the last cursor on a 404 before the execution finishes, on 5xx, and on connection/SSE errors. It stops when the stream ends or the execution is finished (the runner no longer holds live logs). `--attach` now gives the stream up to 10s after the execution finishes to deliver the rest. - **`fix(plan): don't truncate --output-dir exports`**: the export used go-openapi's 30s default request timeout, which covers the whole streamed body. Large or slow outputs were truncated, the remaining outputs skipped, and the run still exited 0 with only a warning. Downloads now have no request timeout (the command's context bounds them) and are written atomically. A failed export makes `plan run` exit non-zero after the result is reported. - **`fix(plan): allow compile/recompile to take longer than 30s`**: the server compiles synchronously with an LLM, bounded only by the request context. After 30s the CLI hit its deadline, the server cancelled the compile, and no plan was created. The timeout is now 5 minutes. - **`fix(planexec): dedup step outputs`**: plan outputs were keyed by `<step>/<plan output name>` instead of `<step>/<StepRef.OutputName>`. `plan x outputs` and `get-output --all` listed referenced step outputs twice when the names differed, and hid unrelated step outputs that happened to share the plan output's name. - **`fix(plan): send --param values of string-typed params as strings`**: `python_version=3.10` was sent as a JSON number and reached the plan as `3.1`. If the plan declares the param's JSON Schema `type: string`, the value is now sent as given. Untyped params keep the existing JSON inference, so an untyped `3.10` is still sent as a number; plan authors can type the param to avoid that. ## Testing - `FollowLiveLogs` is tested against a fake server: 404 before dispatch, then a stream cut by an SSE error, then a resume, checking the output and the cursors sent. A separate test checks that it stops with the error once the execution is finished. There are also tests for export (partial failure, no leftover files), output dedup (fails without the fix) and string-schema params. - `go vet ./...` and `go test ./...` pass; `-race` passes for `plan` and `planexec`. - Not yet run against a real plan execution. Refs ENG-1248. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>


First batch of fixes from the CLI bug sweep (ENG-1248). One commit per theme; reviewing commit-by-commit is easiest.
Commits
fix(jobs,smart-test)— H3/H4:job submit --attachnow exits non-zero on canceled jobs (like--wait);smart-test runexits non-zero when any execution failed or was canceled (unless--no-wait), in default and-o json/yamlmodes.fix(locald)— H1/H2: sandbox manager (:6666), root manager (:6667) and control-plane proxy (:0) now bind127.0.0.1instead of all interfaces. They were unauthenticated and exposedStatus(connect config incl.env,apiKey),GetResourceOutputs,Shutdown, and a SOCKS5 path into the cluster to network peers. All clients already dial127.0.0.1, so old/new CLI/daemon mixes keep working.fix(repoconfig)— open repos withEnableDotGitCommonDir(linked worktrees failed with "reference not found"); pickorigin(else first by name) instead of map-orderedremotes[0]; skip remotes with no URL instead of panicking.fix: smart-test labels…—--set-labelnil-map panic;port2Intno longer convertsportkeys insidelabels/resources[].params;traffic recordreports middleware-removal errors (named return).fix(jobs)—--attachlog streaming: logs shown when the job is first observed already terminal, remaining logs drained at the end, stdout/stderr no longer cancel each other, cursors kept on error (no duplicates), only the "Queued" line is cleared,--timeoutbounds streaming.Behavior change (release note)
smart-test runnow fails the process when tests fail/cancel. CI steps that ran it bare and relied on exit 0 will start failing.Testing
httptest-based fake API in the repo (internal/command/jobs/printers_test.go).go vet ./...,go test ./...clean.go test -race ./internal/command/jobsstill reports a benign pre-existing race in go-sdkcreateAPITransport→ go-openapiSetDebug(package global) when two log streams start concurrently; to fix in go-sdk.local connect(port-forward and control-plane-proxy links) and a realjob submit --attach.Refs ENG-1248.
🤖 Generated with Claude Code