Skip to content

fix: redact known session credentials from records and errors - #286

Merged
xxchan merged 3 commits into
mainfrom
fix/session-credential-redaction
Oct 9, 2026
Merged

xxchan merged 3 commits into
mainfrom
fix/session-credential-redaction

Conversation

@xxchan

@xxchan xxchan commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Runtime errors and native frames can echo credentials into retained records, derived turn failures, and thrown errors. This change removes known credential values before record retention and delivery, and from opening and later adapter errors. Original runtime input and configuration stay unchanged.

The shared selection rules cover explicit session env, MCP env and credential headers, password-bearing connection URLs, and the selected Pi model's key resolved through its native SDK. Names, minimum lengths, path exclusions, encoded/decoded URL passwords and Authorization scheme handling are documented in the record-stream spec. Ordinary metadata and short local-provider placeholders stay readable. Pi refreshes its known keys on model changes without scanning credential files. Error classes, stack text and structured causes are preserved.

Records without known credentials skip traversal. With known values, a read-only scan preserves the original object unless a string matches. A local 5 MiB frame benchmark measured about 0.02 ms without known keys, 0.60 ms for a known-key miss (1,000 iterations each, zero copies), and 11.5 ms on a hit (30 iterations). These are rough local measurements while tests ran.

Validation:

  • Final CI=1 pnpm run check: 1400 tests passed; all five behavior backends passed.
  • Full Pi vendor suite: 33 passed. Full Claude vendor suite: 37 passed. Package build passed before review; final CI rebuilds both packages.
  • Real Claude and Pi with local providers reproduce reflected auth-header leaks before the fix and redact them afterward. Pi covers native model changes and the ollama placeholder. No real account is used.
  • A real Pi/MCP tool output preserves DEBUG/LOG_LEVEL/NODE_ENV and Content-Type while redacting full/bare Authorization, PostgreSQL/MongoDB connection URLs and encoded/decoded passwords. Unit tests also cover Redis, short passwords, identity preservation, unchanged outbound input, error class/stack/cause, live records and replay.

Limits: replacement happens within a string in one record. Model echoes split across text deltas can still reconstruct the original key in SessionView and coalesced events; this change does not buffer the stream. Unknown native subprocess credentials and previously stored host records are also outside this value-based protection. The spec and SessionOptions.env comment state these limits.

Closes #283.

@xxchan
xxchan merged commit 0352aa4 into main Oct 9, 2026
17 checks passed
@xxchan
xxchan deleted the fix/session-credential-redaction branch October 9, 2026 18:00
xxchan added a commit that referenced this pull request Oct 9, 2026
Resuming a missing Claude session previously returned a `Session` that
immediately exited, leaving the host to discover the failure on its
first prompt. Resumes now wait for the native `initialize` response
within the existing 30-second readback bound. A native
`result/error_during_execution`, control refusal, exit, or deadline
rejects the opening call and releases the process. Native failures
retain the redacted error text and `cause: { method: "initialize",
native }`.

Requested service tier uses the same initialization response; effort
readback follows it. Fresh opens without settings readback keep the
existing immediate path. Initialization and settings readbacks are
private: their replies never enter records, including duplicate replies
after opening, and successful answers are never attached to errors. This
also fixes the existing service-tier opening path exposing account
email, organization, subscription, process ID and home-directory
information.

Consumer impact: opening still confirms the requested service tier, but
no longer emits a `service_tier` event from the private initialization
answer. Claude's `Session.serviceTier()` is null until a native
`system/init` or `result` reports it during a turn. The runtime page and
record-stream specification document this behavior and distinguish
initialization readiness from restored-history continuity.

Validation:

- Recorded-frame regressions cover early failure, a matching
initialization response, unrelated responses, native refusal, exit,
deadline, combined settings, and the fresh-open path. An initialization
fixture based on Claude 2.1.295, with synthetic account details,
verifies that resume, service-tier opens, replay and opening errors
never expose those fields.
- Real Claude 2.1.295 with a local scripted provider: missing-ID resume
fails before any model request; valid resume initializes and can run
another turn. The full Claude vendor suite and behavior suite pass. No
real account was used.
- Full `CI=1 pnpm run check` and package builds pass on the code
combined with the credential-redaction change in #286.

Closes #285.

---------

Co-authored-by: Otter <[email protected]>
@xxchan xxchan mentioned this pull request Oct 9, 2026
xxchan added a commit that referenced this pull request Oct 9, 2026
Release OAR and CLI 0.50.0. This PR changes only the two package version
fields.

**Breaking: a failed turn is a union tagged by `failure`** (#280)
- `TurnOutcome` `failed` is now `FailedTurn`, exported: `credential`
exists only on `failure: "auth"`, `resetsAt` only on `failure: "quota"`,
`status` on every class. A host that reads `outcome.credential` must
check `failure === "auth"` first, or it no longer compiles.

**Added**
- **`resetsAt` on a quota failure** (#280): when the limit that refused
the turn resets, where the runtime reports it. Only claude does: a
`rate_limit` failure while claude's latest `rate_limit_event` says a
subscription limit is `rejected`, overage does not take the requests,
and a reset is named. It is the runtime's last report; a time already
past means unknown. Codex's reset time exists only in its prose and is
not parsed.
- **Claude token totals include subagents and compaction** (#282, #292):
`usage().total` is claude's own running total (`result.modelUsage`),
which counts the main loop, Task subagents, sidechains and compaction.
Before, it was the main loop only (`result.usage`).
- **`SessionUsage.unattributed`**: what the total includes that no
`byAgent` entry accounts for (claude's subagents and compaction, which
its stream does not attribute per agent). `byAgent` plus `unattributed`
sums to `total`.
- **`SessionUsage.withChildren`**: the total plus the total of every
session derived from this one in `graph()` (codex child threads, grok
child sessions, OpenCode v2 children), each counted once.
- **Open errors keep their native cause** (#284): a failed codex, ACP or
claude open carries `cause: { method, native }` (redacted), so a host
can diagnose a failure even when no Session was returned.

**Fixed**
- **Known session credentials are redacted from every record and error**
(#286), not only from error text: session env and MCP env values chosen
by name, MCP credential headers, password-bearing connection URLs, and
pi's resolved model key. Original runtime input is unchanged. Limit: a
key the model repeats back across several streamed text deltas is not
caught, so SessionView text and coalesced events can still show it.
- **ACP error `data` is redacted** (#284); it used to bypass MCP
credential redaction.
- **Claude resume of a missing session fails at open** (#285, #287) with
claude's own text ("No conversation found with session ID: …") and
`cause: { method: "initialize", native }`, instead of returning a
Session that exits before its first prompt. A normal resume now waits
for claude's `initialize` answer (about 1 s observed).
- **Claude's `initialize` answer is no longer recorded** (#287): it
carries the account's email, organization and subscription. This
affected every open with `serviceTier` since that option shipped.
- **pi provider auth and model catalog use the agent dir sessions use**
(#289, #290): with `OAR_PI_AGENT_DIR` set, `createPiProviderAuth()` and
`createPiModelCatalog()` read and write that dir's `auth.json` and
`models.json` instead of pi's own. An empty `OAR_PI_AGENT_DIR` now
counts as unset everywhere, instead of becoming a relative path.

**Behavior changes**
- Narrow on `failure` before reading `credential` or `resetsAt` (see
above).
- Some claude rate-limit failures are now `quota` (with `resetsAt`)
instead of `rate_limited`; `failureAdvice` says `retry: "later"` for
them.
- Claude totals grow: they now include subagent and compaction tokens. A
resumed claude Session asks `get_usage` once at open for its baseline
(consumed privately, never recorded); if that answer does not come,
`usage().total` stays null for the Session rather than reporting the
lifetime figure.
- After a claude open with `serviceTier`, `serviceTier()` is null until
the first turn reports it; no `service_tier` event is emitted at open.
- Redaction now applies to every record, so a host comparing raw records
with what it sent may see `[redacted]` where a known credential
appeared.

**Known issues**
- `createPiModelCatalog().providers()[].configured` is false for a
stored credential until `refresh()` (#291). Use
`createPiProviderAuth().status(id)`.
- A Windows CI flake in the credential-redaction vendor test (#288);
tests only.

Validation: every PR passed all 17 checks on its final head. #284, #286,
#287, #280 and #290 merged with trees equal to their CI trees. #292 was
checked on its base, so its combination with #290 (disjoint files) was
verified locally (typecheck, lint, full tests: 1446 passed), and the
merged tree equals that verified tree. Lookout verified #286, #287, #290
and #292 against real binaries. After this PR passes CI and merges, tag
its exact squash commit as `v0.50.0` to trigger npm trusted publishing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: exe.dev user <[email protected]>
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.

A provider error that quotes the API key lands verbatim in records

2 participants