Skip to content

Bug sweep 1: exit codes, loopback daemons, attach logs, misc fixes - #376

Merged
scott-cotton merged 13 commits into
mainfrom
scott/bug-sweep
Oct 2, 2026
Merged

scott-cotton merged 13 commits into
mainfrom
scott/bug-sweep

Conversation

@scott-cotton

Copy link
Copy Markdown
Member

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 --attach now exits non-zero on canceled jobs (like --wait); smart-test run exits non-zero when any execution failed or was canceled (unless --no-wait), in default and -o json/yaml modes.
  • fix(locald) — H1/H2: sandbox manager (:6666), root manager (:6667) and control-plane proxy (:0) now bind 127.0.0.1 instead of all interfaces. They were unauthenticated and exposed Status (connect config incl. env, apiKey), GetResourceOutputs, Shutdown, and a SOCKS5 path into the cluster to network peers. All clients already dial 127.0.0.1, so old/new CLI/daemon mixes keep working.
  • fix(repoconfig) — open repos with EnableDotGitCommonDir (linked worktrees failed with "reference not found"); pick origin (else first by name) instead of map-ordered remotes[0]; skip remotes with no URL instead of panicking.
  • fix: smart-test labels… — --set-label nil-map panic; port2Int no longer converts port keys inside labels / resources[].params; traffic record reports middleware-removal errors (named return).
  • fix(jobs) — --attach log 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, --timeout bounds streaming.

Behavior change (release note)

smart-test run now fails the process when tests fail/cancel. CI steps that ran it bare and relied on exit 0 will start failing.

Testing

  • New unit tests for each fix (verified failing without the fix for H3, port2Int, attach logs); first httptest-based fake API in the repo (internal/command/jobs/printers_test.go).
  • go vet ./..., go test ./... clean.
  • go test -race ./internal/command/jobs still reports a benign pre-existing race in go-sdk createAPITransport → go-openapi SetDebug (package global) when two log streams start concurrently; to fix in go-sdk.
  • Not yet exercised live: local connect (port-forward and control-plane-proxy links) and a real job submit --attach.

Refs ENG-1248.

🤖 Generated with Claude Code

scott-cotton and others added 5 commits September 29, 2026 02:03
… 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]>
cursor[bot]
cursor Bot previously approved these changes Sep 29, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: medium. Approved; Bugbot and Security Agent were not running after the first poll, so those signals were skipped, and no approval policy required human review. Reviewers were not assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

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 davixcky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..15 produced 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 attempt from the final drain.
  • LocalAddress for the proxy is still reported as ":<port>" (sandbox_server.go:197,210), not 127.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.

scott-cotton and others added 2 commits October 2, 2026 00:39
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]>
scott-cotton added a commit that referenced this pull request Oct 1, 2026
Brings in the --attach and locald address fixes from #376's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scott-cotton added a commit that referenced this pull request Oct 1, 2026
Brings in the --attach and locald address fixes from #376's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scott-cotton added a commit that referenced this pull request Oct 1, 2026
Brings in the --attach and locald address fixes from #376's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scott-cotton added a commit that referenced this pull request Oct 1, 2026
Brings in the --attach and locald address fixes from #376's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scott-cotton

Copy link
Copy Markdown
Member Author

@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:

  • Logs printed twice: the final drain no longer asks for a stream the server has already ended, so a finished job doesn't get the RESTART replay.
  • Hang on a stream with no output: once one stream ends, the other is let go after 3s without output, and the drain does the same. The idle timer resets on every line, so a long tail isn't cut short.
  • Canceled job: no drain, so no 400 Bad Request: canceled job attempt.
  • Timeout during the final drain: now an error ("timed out waiting for the logs…; output may be incomplete") instead of exit 0.
  • LocalAddress: reports 127.0.0.1:<port> for the control-plane proxy and localhost:<port> for the port-forward, which is what each binds.

New tests in internal/command/jobs cover each case against a fake server that behaves like the one you saw: a RESTART replay when resuming from a cursor, a silent stream that never closes, and a 400 for a canceled attempt. They fail on the code you reviewed and pass now. I haven't re-run against staging, so your re-test is the real check.

Not addressed here:

  • If a stream dies partway (a 504, say) and the job then finishes, the drain resumes from a cursor and can still get the replay. Fixing that needs a cursor comparison or a server change.
  • CI still doesn't run go test.

@cursor
cursor Bot dismissed their stale review October 1, 2026 22:42

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.

@davixcky
davixcky self-requested a review October 1, 2026 23:12

@davixcky davixcky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

scott-cotton and others added 5 commits October 2, 2026 10:47
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]>
@scott-cotton
scott-cotton merged commit 0e41957 into main Oct 2, 2026
1 check passed
@scott-cotton
scott-cotton deleted the scott/bug-sweep branch October 2, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants