Skip to content

Bug sweep 2: auth storage/refresh and MCP session fixes - #377

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

scott-cotton merged 6 commits into
scott/bug-sweepfrom
scott/bug-sweep-2

Conversation

@scott-cotton

Copy link
Copy Markdown
Member

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

scott-cotton and others added 3 commits September 29, 2026 10:17
… plaintext tokens

- auth login stores credentials exclusively: after storing in one store
  it removes credentials from the other, so the new login is the one
  used (ResolveAuth prefers the keyring). Previously a keyring login
  followed by `login --insecure-storage` kept using the keyring org.
- auth logout deletes from both stores, so logging out can't make
  stale plaintext credentials active.
- Expired bearer tokens in the plaintext store are refreshed like
  keyring ones instead of failing immediately with ErrAuthExpired
  (headless Linux/containers without a keyring).
- Keep the current refresh token when the refresh response has none
  (CLI and locald refresh paths).

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The remote MCP session, and the credentials captured in its transport,
were created once and reused until the process exited. After
`auth logout` + `auth login` as another org, AI-agent tool calls kept
executing as the previous org (and bearer tokens went stale). Session()
now resolves auth on every call and recreates the session when the
credentials differ from those it was created with.

Also don't panic on a remote error result with empty or non-text content.

Refs ENG-1248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`signadot mcp` waited for a successful fetch of the hosted MCP's /meta
before serving stdio, retrying every 30s forever. Offline, behind a
proxy, or during a hosted-MCP outage it never answered `initialize`
(not even local tools like get_authentication_status) and never exited
after the client left. Now it waits only for the first fetch attempt;
remote tools are added (tools/list_changed) once a later fetch succeeds.

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; this automation did not approve because the auth storage, token refresh, and MCP session changes exceed the medium approval threshold. Human review is needed; 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.

LGTM. I built it locally (merged with the rest of the sweep) and compared it with main against staging. With mcp_url pointing at a dead port, signadot mcp on main never answers initialize; this branch answers in under 2s.

Non-blocking nits:

  1. A token refresh now rebuilds the MCP session (internal/mcp/remote/remote.go). The session key includes BearerToken, so every refresh counts as a credential change and closes the old session, even while a CallTool on it is still running. The retry in tools.go can then run a non-idempotent call (like a sandbox create) twice. Maybe have authTransport read the current headers on each request, and key the session only on org plus user or API key.
  2. Closing the old session can hang tool calls and leaks a connection (remote.go:138). It runs under r.mu, and the go-sdk's Close sends a DELETE with no timeout, so a remote that hangs blocks every tool call. It also drops the response body unclosed. Maybe close it outside the lock, in a goroutine.
  3. StoreExclusive ignores errors deleting the other store (internal/auth/storage.go:75). If deleting from the keyring fails, the old keyring login still wins. Maybe check it the way DeleteAll does.
  4. The plaintext credentials file is rewritten non-atomically, and now more often. #379 fixes this, so the two PRs need to land together.
  5. No tests for the empty-error-result panic fix or the locald refresh-token change.

Brings in origin/main via the updated base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scott-cotton and others added 2 commits October 2, 2026 00:40
Brings in the --attach and locald address fixes from #376's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in origin/main via the updated base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scott-cotton
scott-cotton merged commit 30cace9 into scott/bug-sweep Oct 2, 2026
1 check passed
@scott-cotton
scott-cotton deleted the scott/bug-sweep-2 branch October 2, 2026 09:02
scott-cotton added a commit that referenced this pull request Oct 2, 2026
Brings in #377, merged into the base.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scott-cotton added a commit that referenced this pull request Oct 2, 2026
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]>
scott-cotton added a commit that referenced this pull request Oct 2, 2026
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]>
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