Repository navigation
Prune backups by age, and keep an extension's own field spelling - #2
CaffreySun wants to merge 3 commits into
Conversation
The backup directory is shared by every integration, and a backup's name
starts with the name of the file it came from:
settings.json.1789440066.d62d57de
agentpet.ts.1789446695.aa1d698b
Sorting those names is chronological only while every backup in the
directory comes from the same file. With two integrations writing here —
which is the case on main today — one integration's backups sort ahead of
the other's however new they are, so the backup taken during a call was the
first one that call pruned, and the path the caller had just been handed was
already gone.
Age now comes from the filesystem (.contentModificationDate), with the name
settling ties inside a single clock tick. The new test takes a backup under a
second name and asserts the reported path still exists afterwards; against
the old ordering it fails with that path already removed.
The capture and spool allowlist knew Claude Code's `session_id` and
`tool_name` only. The in-process extensions send the camelCase names their own
API uses — Pi's extension already sends `toolName` beside a snake-case session
id — so those fields were dropped on the way to disk.
Dropping the tool name costs a label. Dropping the session id costs the row:
an event spooled while the app was down replays with no session, falls back to
the shim's parent pid, and draws a second row for a session that is already on
screen under its real one.
Both spellings are kept. The list stays hand-written rather than derived from
the profiles: a profile's `summaryField` is the user's own prompt on
`UserPromptSubmit`, and an allowlist that followed profiles would follow
prompts onto disk.
The test spools a camelCase payload and asserts the session id and the tool
name survive while tool arguments and prompt text do not; without the fix the
record reads {"cwd":…,"_omitted_keys":["args","sessionId","text","toolName"]}.
Its comment credited the loss to "an in-process extension", which is not where the camelCase spelling comes from: Pi's extension sends `session_id` and only its tool name is camelCase, so nothing of ours has ever lost a session this way. What the test covers is a payload that spells the session id only in camelCase; the redaction path does not care which agent sent it, so the envelope's agent is `generic-cli` rather than a named one whose wire someone might go and check. Found while reviewing the rebase of the Oh My Pi branch, which carries the same test and got the same correction. 511 tests.
|
One wording fix on top, from the review of the Oh My Pi branch (which carries the same test):
Nothing else here changed. |
|
Superseded by main: (For the record, the third commit on this branch, |
The capture comment credited the camelCase session id to in-process
extensions, and that is wrong twice over: Grok's captured wire carries
both spellings of every core field, and the extensions we ship report
`session_id` with a camelCase `toolName`. Antigravity's wire is camelCase
throughout, which the old wording ("hooks use session_id") also missed.
The spool test was named after a wire that does not spell it that way;
the redaction path does not care which agent sent the payload, so the
envelope is agent-neutral now.
Wording fix ported from #2 (1a0bad5; author CaffreySun), whose branch
was closed as superseded before this part of it landed.
Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
The capture comment credited the camelCase session id to in-process
extensions, and that is wrong twice over: Grok's captured wire carries
both spellings of every core field, and the extensions we ship report
`session_id` with a camelCase `toolName`. Antigravity's wire is camelCase
throughout, which the old wording ("hooks use session_id") also missed.
The spool test was named after a wire that does not spell it that way;
the redaction path does not care which agent sent the payload, so the
envelope is agent-neutral now.
Wording fix ported from #2 (1a0bad5; author CaffreySun), whose branch
was closed as superseded before this part of it landed.
Co-Authored-By: CaffreySun <sunhongwei0913@163.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
The two fixes from #1 that do not depend on the Oh My Pi feature — split out so they can land on main while the feature PR is rebased, as suggested there.
Both are live on main today, now that several integrations share the runtime's directories.
1. Backups were pruned by file name
ConfigTransaction.pruneBackups()sorted bylastPathComponent, and a backup is named<file>.<timestamp>.<fingerprint>. That is chronological only while every backup in the directory comes from the same file. With two integrations writing there, one integration's backups sort ahead of the other's however new they are — so the backup taken during a call was the first one that call pruned, and the path the caller had just been handed was gone.Age now comes from
.contentModificationDate, with the name breaking ties inside a clock tick. Regression test: take a backup under a second file name, assert the path the call reported still exists. Against the old ordering it fails with exactly that path already removed.2. The capture allowlist knew only one agent's spelling
EventCapture.capturableKeyshadsession_id/tool_name, and nothing else. The in-process extensions send the camelCase names their own API uses — Pi's extension already sendstoolNamebeside a snake-case session id — so those fields were dropped on the way to disk.Dropping the tool name costs a label; dropping the session id costs the row: an event spooled while the app was down replays with no session, falls back to the shim's parent pid, and draws a second row for a session already on screen under its real one. Both spellings are kept now, and the list stays hand-written — deriving it from the profiles would put
UserPromptSubmit's prompt on disk.Regression test: spool a camelCase payload, assert the session id and tool name survive while tool arguments and prompt text do not. Without the fix the record reads:
{"cwd":"/tmp/project","_omitted_keys":["args","sessionId","text","toolName"]}Verification
swift build --build-tests,swift test --parallelon current main → 511 tests, 81 suites, 0 failures.git difftouches four files: two sources, their two test files. No version, workflow or release metadata.