Repository navigation
fix: authorize a script destination's final entry in one place - #4677
Conversation
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 1983427. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 6e3377f. The verdict and the full list are in the summary comment.
|
This review covers 6e3377f; ef59074 landed while it ran and gets its own delta review. At 6e3377f the code looks correct, CI is green (18 checks, none failing), and no live device run is needed because this only changes file publication. The Windows branch ( A separate security cross-check found no way for another local user or a hostile daemon to redirect the final write. Because this is a remote-session change, please address two more items before the label:
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 4 new findings on 12bbe35. The verdict and the full list are in the summary comment.
12bbe35 to
5ee544c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 792f3eb. The verdict and the full list are in the summary comment.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I read the code at 4a23dfd and found three problems to fix before merge: one from the review and two from a separate security cross-check. The entry authorization itself is well owned and small. The early repeat path in session-script-destination.ts:421 reads the record without the record lock (:408) and computes its digest outside the lock (:420-423). Commits rename the file and write committedDigest under the lock (:585-594). If client B holds a late version 5, reads the record at revision 6, and client C then commits version 7, B digests d7 against d6 and throws CommittedVersionUnverified('changed'). A commit that stops after its rename but before the record write leaves a publishing {N+1, digest} record. A repeat of N or older takes the early path, never settles publishing, and also reports changed although the entry is the N+1 file. The locked late path (:566-581) handles both cases correctly. The user impact is a false scriptDeliveryFailure (cause script_entry_changed) with the warning "The script saved earlier is no longer at ", while the destination holds a newer version of the same recording. An agent can act on that text, for example by re-recording or reporting data loss. It fails safe, since it never reports a false savedScript, and it needs concurrent deliveries or a crash. On main the early path never reported a false failure. The rule to satisfy: a repeat is judged against the record as settled under the record lock, the same state a commit writes. Please answer the early repeat inside withRecordLock: re-read the record, confirm and judge, run settlePublishing(record, entry), then committedVersionEntry. Then the early and late repeat answers are one locked function. Please add a test that commits a newer version between the early read and the digest, or uses an interrupted-publishing record with an older repeat, and asserts savedScript is still reported. Security cross-check, blocker 2: the digest must belong to the entry that is still there. Security cross-check, blocker 3: UNC named-pipe roots pass as Windows destinations. Related, from the same check: a commit whose staged digest came back empty still proceeds to publish (session-script-destination.ts:579), and a recovery promotion can then keep the previous revision's digest (:607). Please refuse a commit without a staged digest, and clear or set the digest when promoting a pending record. Simplicity question: the repeat-verification half adds a record field, a digest reader, an error class, two causes, three messages, a docs bullet, a ledger rationale and an O_NONBLOCK change to a shared helper. Would one locked repeat answer, used by both the early and late paths, be smaller and also fix the race above? Reporting no savedScript on repeats at all would not be smaller in effect, so the digest looks defensible. Not blocking, take or leave: (1) publishStaged now reports the physical entry path as savedScript and the kept artifact localPath, where main returned the caller's absolute spelling, so through a symlinked cwd a remote open --save-script ./x.ad reports /private/tmp/x.ad while the local route reports the spelled path; a sentence in replay-e2e.md would cover it. (2) The reserved-name regex at atomic-file.ts:338 omits COM0, LPT0, CONIN$ and CONOUT$, which Windows also treats as device names; extend the set or state the subset. (3) The directory and hard-link cases in session-script-writer-entry.test.ts pass without this change, so a header note could label them as behavior pins. (4) The daemon-artifacts-script-entry test mocks confirmScriptDestination with a hand-made entry, so a symlinked-parent fixture would prove the real walk yields the judged entry. (5) The ADR sentence at docs/adr/0016-active-session-script-publication.md:223 names only . and .. as unnamed_entry, so it could list the full refusal set or point to scriptEntryName, and the PR body lacks the touched-file count and linked issue references that docs/agents/pull-requests.md asks for. On the open inline threads: the review threads at #4677 (comment), #4677 (comment), #4677 (comment), #4677 (comment) and #4677 (comment) are fixed at this commit and can be resolved. #4677 (comment) and #4677 (comment) are already marked fixed by the author. #4677 (comment) is fixed except for the early-path race above. CI is pending: 17 checks pass at 4a23dfd, including the host-kit, daemon and remote unit tests; one review check is still running. There are no conflicts. Before merge: the early repeat answered under the record lock, the digest bound to the entry that is still there, and UNC pipe roots refused, each with a test. |
This comment has been minimized.
This comment has been minimized.
|
At e2fd836 the four items from the last review are fixed. Both repeat paths go through one locked function, the digest is bound to the entry's bigint stat before and after the read, A separate security cross-check of this head found three remaining gaps and one contract question, so this is not ready yet.
Not blocking: the new sentence in replay-e2e.md#L84 says symbolic links in a remote saved-script path are resolved. On a Windows client the destination walk does not run, so scope that clause to macOS and Linux. CI was still running when I posted (smoke and coverage), with nothing failed. There are no conflicts. |
|
All four items, plus the non-blocking one, are fixed in 7cfd427 (ledger acknowledgement in d0cecc7):
Non-blocking: the symlink-resolution sentence is scoped to macOS and Linux, and notes that on Windows From a separate delta review, also in 7cfd427:
Each new test fails when its code is broken. |
This comment has been minimized.
This comment has been minimized.
|
At d0cecc7 the four items from the earlier review (#4677 (comment)) are fixed. The code review found one issue, and a separate cross-check of this head found two more, so this is not ready yet.
The earlier inline thread about the early repeat running under Cross-check, item 2: a concurrent delivery can still skip settlement. Client A reads the record at revision 1. Client B then names its pending revision 2, renames it into place, and stops before recording the commit. A skips Cross-check, item 3: a Windows root-relative path reaches the probe before the share check. With a Windows cwd of 17 of 18 checks pass at d0cecc7, and the remaining one is a review check, not a test job. There are no conflicts. |
|
All three are fixed in 2d2f3e9 (ledger acknowledgement in 655206e):
Each new test fails when its code is broken. |
This comment has been minimized.
This comment has been minimized.
|
At 655206e the three items from the d0cecc7 review (#4677 (comment)) are fixed. One helper decides the host path rules, settlement reads the record under the lock before staging, and root-relative Windows paths are qualified before the gate. The code review found no problems. A separate cross-check of this head found four remaining gaps, so this is not ready yet. Windows path spelling. Items 1 and 2 both come from accepting root-relative and extended-length Windows spellings.
The smallest fix for both is to refuse these spellings for a script destination: a root-relative path ( Failed-download recheck. 17 of 18 checks pass; the remaining one is a review check. There are no conflicts. |
|
All four are fixed in f9f52fa (ledger acknowledgement in 3604407). 1 and 2: Windows path spelling. I took the smaller fix. On Windows, a script destination is refused when it is root-relative ( 3: Cleanup and decision. A failed download now releases its staging and decides in one final record-lock acquisition, with the decision after the cleanup. A test commits revision 2 during that cleanup and gets 4: Typed recheck failures. The The concurrency tests moved to their own file ( |
This comment has been minimized.
This comment has been minimized.
|
At 3604407, the old root-relative reproducer is refused and the failed-fetch cleanup now precedes verification, but the earlier review still has findings. Could the existing save-script admission validate the effective caller spelling with the host-kit resolver and the recorder's daemon host context? A local Windows open can launch and publish a session before returning INVALID_ARGS, and an armed ordinary close can tear down the backend before returning the error and leave the session and claim retained. Please cover both routes through the request handler and assert no backend side effects. Admission Could host-kit reject separator-led Windows paths without a drive or complete UNC root before normalization, and enforce that invariant in prepare, judge, and confirm, including retained records? Could every base actually used by resolution be validated, and the expanded home path pass through the same entry rule? With a relative HOME, Could the publication boundary validate the existing volume root and create only components below it? A qualified destination such as Could the concurrency test verify at the real lock boundary that staging removal and digest verification share the same final acquisition? The current mock changes the record during cleanup even if verification takes a separate lock, so the test does not protect that invariant. Please retain the ordering assertion and show the test fails with separate acquisitions. Test A separate cross-check of this head found one more case: after a failed download, staging is cleared before the final record-lock acquisition. If another holder outlasts the acquisition timeout, the callback never runs and Could the shared script-publication fixture own the duplicated record and digest helpers and use its existing record enumeration? The two suites currently repeat the record layout and can diverge. Fixtures Could the replay guide say that an equal or older reply can return the newest committed copy after its digest verifies? A stale revision 1 received after revision 2 can return revision 2, so the current wording can identify the returned recording incorrectly. Guide Could the guide limit the recovery retry to an open recording and state the final-close outcome? A final close retires the record, so a later action cannot recover its file. Guide After fixing admission, please run the public CLI at the fixed head against a Windows daemon with a supported live backend: for fresh open and armed ordinary close, show root-relative and extended forms return INVALID_ARGS / script_ancestor_untrusted / windows_path_form before launch or teardown, with session and foreground state unchanged. Also show a plain valid save and a Windows remote client publishing to a qualified drive-root child or equivalent checked volume, including savedScript and verified file bytes. The supplied evidence has mocked probes but no live run for these routes. Open route Could one host-kit destination parser own path form and entry validation, resolve only used bases, validate the chosen Windows volume once, and use the existing saveScriptFlagOwner admission before dispatch while keeping the failed-fetch lock scope? The replacement still splits policy between two gates; this needs no new flag or wire field. Not blocking: the secondary staging cleanup error could use the existing cleanup diagnostic pattern, and the unrelated empty-directory assertion could be removed or replaced with a check of the configured record directory and dispatch seam; either can be taken or left. All ten listed CI checks are still in progress, with no failure excerpt; the remaining checks were still running when I posted. No conflicts are known. Before merge, please close the Windows admission, base and drive-root gaps, pin the final lock acquisition, correct the replay guide, and provide the exact-head live evidence and completed CI results. |
|
Addressed the findings from the review at
|
…ptVersion The early repeat path now tells the shared judgment that its version was confirmed, so an unconfirmed interrupted save is worded as such. The request, the response fields, the routes and the framing are unchanged for a released daemon and a skewed peer, so the acknowledgement stays additive with no protocol bump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both repeat paths now judge the destination, settle any interrupted version and answer through one function under the record lock, so a repeat is judged against the same state a commit writes. The digest is accepted only while the pathname is still the descriptor's entry with the same device, inode, size and times, so a replacement after the open or a same-length write after the read discloses script_entry_changed. A version whose staged bytes cannot be digested is not committed, and a promoted interrupted version sets or clears the committed digest. Windows names in the UNC pipe namespace, ordinary or extended, are refused before anything else, as are COM0, LPT0, CONIN$ and CONOUT$. The ADR lists the whole refusal set, and the replay guide says a remote savedScript is the physical path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rsion A repeat is answered under the record lock against the settled record, and its digest is bound to the entry still standing. The request, the response fields, the routes and the framing are unchanged for a released daemon and a skewed peer, so the acknowledgement stays additive with no protocol bump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Windows name gate refuses the pipe, IPC$ and mailslot shares in the plain and extended UNC spellings, and the resolved path is judged by the same gate, so a working directory or HOME at an IPC root is refused before any probe, record or dispatch. A version an interrupted commit may already have put in place is settled under the record lock before anything is staged, so a re-offer needs no download. A parent that became a file or vanished during a repeat's digest reads as an absent entry. The replay guide and the ADR say verification covers what size and timestamps can show, scope symlink resolution to macOS and Linux, and the 255-byte limit to POSIX. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sion A version an interrupted commit may already have put in place is settled and answered under the record lock before anything is staged. The request, the response fields, the routes and the framing are unchanged for a released daemon and a skewed peer, so the acknowledgement stays additive with no protocol bump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…paths A delivery now settles from the record read under the lock before it prepares or stages anything, instead of a snapshot read without it, and a download that fails after another delivery could have committed the version is rechecked under the lock before it is reported. A Windows path with one leading separator is qualified against the working directory's root, including an extended UNC or drive root, before it is judged, probed, recorded or published. Path expansion and the name gate read the host path rules from one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ScriptVersion Settlement reads the record under the lock, and a failed download is rechecked under the lock before it is reported. The request, the response fields, the routes and the framing are unchanged for a released daemon and a skewed peer, so the acknowledgement stays additive with no protocol bump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Windows script destination, or the working directory or home it is joined to, is refused when it is relative to the current drive or in extended-length form, with a hint to use a drive-letter or UNC share path; the root qualification added for those forms is gone. A failed download now releases its staging and decides in one final record lock, after the cleanup, so a commit landing in between is reported, and a committed version that fails verification or the ancestry walk reports that refusal instead of the fetch error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ersion A failed download is decided under one final record lock after its staging is released, and typed refusals of the committed version are reported. The request, the response fields, the routes and the framing are unchanged for a released daemon and a skewed peer, so the acknowledgement stays additive with no protocol bump. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 60361b1. The verdict and the full list are in the summary comment.
|
At 60361b1 the earlier code findings are fixed: the vacancy probe treats ENOENT and ENOTDIR as vacant, a dangling final link counts as occupied, and the writer reports the committed entry. A review plus an independent second pass found three remaining items. Each one fails closed, but the second writes to a file the guide says to refuse, so please fix all three before merge.
Not blocking: replay-e2e.md:75 says an ancestry refusal leaves no new directories, but an upper level created before a later refusal remains. ADR 0016 allows that, so the guide could say so. Also, host-kit could own a typed unavailable-entry outcome for destination judgment and verified reads, so On the open threads: #4677 (comment) does not apply, because the client validates the spelling and probes occupancy before dispatch ( |
60361b1 to
32a0053
Compare
|
Pushed
The rebase also regenerates the embedded Swift overlay after #4719 changed its source. The same consistency guard failed on |
Apex Sentinel · ✅ Approve · review of
|
| Command | What it does |
|---|---|
@apex-sentinel-staging note <context> |
Adds context; Sentinel re-checks the cited code |
@apex-sentinel-staging pivot <why> |
Says the finding is wrong; Sentinel re-checks the cited code |
@apex-sentinel-staging like |
Marks the finding as useful |
@apex-sentinel-staging dislike <why> |
Marks it as not useful, so it is not raised again |
On this conversation, comment @apex-sentinel-staging review to run a full review once again.
|
The PR is ready at 32a0053. All three items from the earlier review (#4677 (comment)) are fixed and fail closed. CI is green: 19 checks, none failing, on this head. There are no conflicts, and nothing else needs to happen before merge. Not blocking, and you can take or leave it: on Windows a path like The two code-scanning threads (#4677 (comment) and #4677 (comment)) are fixed at this head: the regex is now a linear loop at The Windows behavior (the bare-home refusal and the UNC reset classification) is checked only under emulated win32 path rules and mocked fs calls, not on a real Windows host or SMB share. An independent second pass over the full change also came back clean. One more optional note: at session-script-destination.ts:650-660, if revision 3 arrives while revision 2 still has an interrupted journal, settlement runs first. An ECONNRESET while removing revision 2's staging then reports |
Summary
Follows #4584. The PR changes 38 files, including the regenerated Swift overlay for #4719.
--save-scriptspelling before dispatch. Refuse ambiguous Windows volumes and unnamed entries, including bare home paths. Create parents below the validated volume and support traverse-only ancestors.ECONNRESET) can reportscript_entry_changed. Other Windows network failures reportscript_download_failed.Validation
a815a42. The embedded Swift guard failed on main. After regeneration, all 72 focused tests passed, including Swift compiler checks.32a0053, all runnable affected checks passed withpnpm check:affected --run --head HEAD(exactCommit: true, three local test workers). GitHub CI is running.32a0053. All 246 focused tests passed. Windows coverage uses filesystem seams.41e14f5, 102 focused tests passed. Four probe regressions failed on93fbd45, including a provider-backed remote open with a regular-file parent.e354988and passed on93fbd45.