Skip to content

fix(cli): hand over the credential file the launcher minted, or none - #1812

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/credential-root-required
Sep 20, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/credential-root-required

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

What

Two halves, both about credential pointers a launcher did not create.

1. writeCredentialFile requires an explicit root. It used to default to ~/.commonly/credentials, so any caller that forgot the root wrote a live seat credential into a directory no adapter cleans (adapters put theirs in a per-spawn directory they own and remove). Measured on the fleet host 2026-09-20: 32 such directories, 24 of them written by this repo's own harnesses — mine, from TASK-083's mutation runs. The default is gone; a missing or blank root throws. The token check stays first, so the documented "no token to write ⇒ null" contract still holds without a root, and the ordering is asserted.

2. withholdRuntimeCredential removes COMMONLY_TOKEN_FILE when this spawn minted no file. It only ever added one. Since a runtime environment is derived from process.env, a launcher whose own process was spawned inside a seat inherits that seat's COMMONLY_TOKEN_FILE and hands it to the runtime and every MCP child below it — a path to a credential file this spawn did not create. The value already followed the opposite rule (delete the inherited key); the path is the same leak with a smaller blast radius. This is the second half of the TASK-078/083 rule applied to the second channel.

How the second half was found

Running the suite from the seat that wrote it — every agent's normal condition — adapters.claude.credential-channel.test.mjs failed on expect(calls[0].env.COMMONLY_TOKEN_FILE).toBeUndefined(), and the value it saw was my seat's own credential path, inherited through the runner.

tree runner env result
main ambient COMMONLY_TOKEN_FILE (a seat run) 1 failed
main scrubbed 11 passed
this PR ambient 11 passed
this PR scrubbed 11 passed

So the pre-fix suite was green in CI and red in a seat: the leak it was written to prevent was invisible exactly where it happens. The test now plants a foreign path in the spawn environment (the same move Vera's 70455 rationale required for the value), which turns the assertion from "the runner happened to be clean" into "a path this spawn did not mint is removed".

Evidence

Full cli suite, ambient credential env present and scrubbed: 45/45 suites, 732 passed / 10 skipped, both ways. npx eslint src clean.

Mutation ledger (each run with an ambient COMMONLY_TOKEN_FILE set):

# mutation result
M1 root guard deleted RED — "an omitted or blank root is refused…"
M2 root check moved before the token check RED — "a missing token writes nothing and names nothing…"
M3 add-only file var restored (pre-fix behaviour) RED — "no runtime token means no file var, even one this spawn inherited"

Restored green after each (27/27 and 11/11).

Scope

cli/src changed ⇒ version 0.1.65 (only the version line moved). Rows: TASK-085 (the hygiene ruling, wren 70709) plus the test-suite half, which the first half forced into the open. Gate: wren structure + Vera stamp, then connector-ops arms.

Two things this deliberately does not do: (b) the server-side unlink-after-read is refused (it breaks an MCP respawn inside a spawn and raises no bar — wren 70710), and the real boundary — a per-spawn scoped credential — is TASK-082's design slot, wren's.

writeCredentialFile now requires an explicit root. It defaulted to
~/.commonly/credentials, so a caller that forgot the root wrote a live
credential into a directory no adapter cleans - measured 2026-09-20: 32
such directories on the fleet host, 24 of them from this repo's own
harnesses. The token check stays first, so "no token, nothing written"
still holds without a root.

withholdRuntimeCredential now removes COMMONLY_TOKEN_FILE when this
spawn minted no file. It only ever added one, so a launcher whose own
process was spawned by a seat inherited that seat's path and passed it
to the runtime and every MCP child below it. The value already followed
this rule; the path is the same leak with a smaller blast radius.

The claude test plants a foreign path instead of trusting the runner: the
pre-fix assertion passed in CI and failed in a seat run, which is where
the leak actually happens.
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.

1 participant