Skip to content

Bug sweep 4: data loss and crashes in everyday commands - #379

Merged
scott-cotton merged 15 commits into
scott/bug-sweepfrom
scott/bug-sweep-4
Oct 2, 2026
Merged

scott-cotton merged 15 commits into
scott/bug-sweepfrom
scott/bug-sweep-4

Conversation

@scott-cotton

Copy link
Copy Markdown
Member

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

scott-cotton and others added 9 commits September 29, 2026 10:58
…t large ones

- Download to a temp file in the output directory and rename it into
  place on success. Previously the output file was truncated before the
  request, so e.g. `artifact download -j wrongjob report.xml` zeroed an
  existing report.xml on a 404/401, and failures left partial files.
- The 4 minute timeout covered the whole streamed body, so artifacts
  taking longer to download always failed. It now only bounds the time
  until the download starts.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…default dir

With the default output directory, get-files removed the directory
before the --no-clobber check, so local edits were deleted anyway.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A sandbox file without `spec` (typo, empty, templated away) panicked
  on req.Spec.Cluster; it now returns an error.
- If --wait failed before any successful GET (cancel, API down for the
  whole timeout), the nil sandbox was passed to writeOutput and
  panicked; the applied sandbox is output instead.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iven

The server's update replaces the description, so
`secret update NAME --value-file f` without --description wiped the
stored one. The CLI now sends the current description unless
--description was given (an explicit empty value still clears it).
With -f the file remains the whole secret.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`devbox register` wrote ~/.signadot/.devbox-id without creating the
directory, so with auth only from the environment the devbox was
registered server-side and then saving its ID failed with ENOENT.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
run (on a fatal error) and Stop both did an unsynchronised
check-then-close of done, so e.g. Ctrl-C during `local override` could
panic with "close of closed channel" before the deferred undo, leaving
the override middleware on the shared sandbox. Close done via sync.Once.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The log server listened on all interfaces although the sandbox forward
delivers logs to localhost, so network peers could POST /api/logs and
print spoofed entries or escape sequences to the user's terminal.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on read errors

Credentials were written with a non-atomic os.WriteFile, and a reader
that failed to parse the file deleted it. A concurrent read during
login or token refresh (CLI, MCP server, locald) could therefore see a
partial file and delete freshly written credentials. Write via a temp
file + rename, and report an unparsable file instead of deleting it.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BugConfig embedded *config.API, whose MarshalJSON was promoted, so the
output was only the API config and dropped BuildInfo and Error, the CLI
version and init error the command exists to report (the error was
also an interface, marshalled as {}). Use named fields and a string
error.

Refs ENG-1248.

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

@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: high. Left a non-blocking comment and did not approve: this PR changes auth credential persistence, secret updates, and multiple data-loss paths, which is above the medium approval threshold. Human review is needed; no reviewer assignment tool is available, so no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

Brings in origin/main via the updated base. Resolves the two places
main's #362 (sandbox apply --dry-run) met this branch:

- apply.go: both added a nil-spec check; keeps main's wording,
  "sandbox must specify a spec" (TestApplyMissingSpec checks only "spec").
- apply_test.go: both created the file; keeps main's dry-run tests and
  this branch's apply tests side by side, imports merged.

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

@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: high. Left a non-blocking comment and did not approve: this PR changes auth credential persistence, secret updates, and multiple data-loss paths, which is above the medium approval threshold. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@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 (#376–#381), and compared it with main against staging. Most fixes work:

  • artifact download -j <missing job> over an existing report.xml now keeps the file. On main it was emptied to 0 bytes.
  • secret update NAME --value-file f now keeps the description. On main it was wiped.
  • sandbox apply on a file without spec returns sandbox file must specify spec. On main it was a SIGSEGV.
  • signadot bug now includes build info.

Requesting changes for the artifact download regressions. writeFileAtomic creates a temp file next to the target and renames it into place. That breaks any -o that isn't a regular file in a directory you can write to. I tested with a real artifact from a job:

-o target main this PR
regular file ✅ ✅
/dev/stdout (piped) ✅ works ❌ open /dev/.stdout.tmp-…: permission denied, exit 1
symlink → real.xml ✅ writes through the link ❌ link replaced by a regular file; real.xml keeps its old contents
new file under umask 077 600 644 (the fixed Chmod ignores the umask)

Run as root (common in CI containers), the /dev/stdout case renames a regular file over the /dev/stdout symlink instead of failing. Suggested fix: Lstat the target, and if it exists and isn't a regular file, write to it directly as before. For a new file, skip the Chmod, or apply the umask.

Also, not blocking:

  • A stalled download now hangs forever. The start timer is stopped on the first write and nothing replaces it. Calling Reset(timeout) on every write would make it an idle timeout.
  • A corrupt plaintext credentials file blocks auth logout and auth status. Logout fails with could not resolve auth: invalid credentials file …, so it can't clear the file. I confirmed this live. Maybe let logout delete the file on that error. There's also no tmp.Sync() before the rename.
  • Mismatched hosts for the override log server. It now listens on 127.0.0.1, but ToLocal in builder/sandbox_override.go:66 is still localhost:<port>, which breaks on hosts where localhost resolves only to ::1.

Brings in the --attach and locald address fixes from #376's review.

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

@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: high. Left a non-blocking comment and did not approve: this PR changes auth credential persistence, secret updates, and multiple data-loss paths, which is above the medium approval threshold. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

scott-cotton and others added 3 commits October 2, 2026 09:00
40ec067 wrote the download to a temp file beside -o and renamed it over,
which is not writing to -o: /dev/stdout failed (and as root was replaced
by a regular file), a symlink was replaced rather than written through,
and a new file ignored the umask. The output is now os.Create on the -o
name, as on main, opened when the first byte arrives — so a request that
fails before any data still leaves an existing file as it was, which is
what the temp file was for. An empty artifact still makes an empty file.

The start timeout is now an idle timeout, reset by every write, so a
download that stalls partway is an error rather than a hang.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An unreadable plain-text credentials file is kept rather than deleted on
read, but that made `auth logout` fail resolving it, so the one command
that clears it could not. Logout now removes it. The file is also synced
before it is renamed into place.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The override log server listens on 127.0.0.1, but the sandbox forward
named localhost:<port>, which breaks where localhost resolves only to ::1.

Refs ENG-1248.

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

@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: high. Left a non-blocking comment and did not approve: this PR changes auth credential persistence, secret updates, and multiple data-loss paths, which is above the medium approval threshold. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

Brings in origin/main via the updated base.

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

@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: high. Left a non-blocking comment and did not approve: this PR changes auth credential persistence, secret updates, and multiple data-loss paths, which is above the medium approval threshold. Human review is needed and no reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@scott-cotton
scott-cotton merged commit 580adf6 into scott/bug-sweep Oct 2, 2026
1 check passed
@scott-cotton
scott-cotton deleted the scott/bug-sweep-4 branch October 2, 2026 10:01
scott-cotton added a commit that referenced this pull request Oct 2, 2026
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]>
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