Skip to content

fix: authorize a script destination's final entry in one place - #4677

Merged
thymikee merged 35 commits into
mainfrom
fix/script-destination-final-entry
Nov 19, 2026
Merged

thymikee merged 35 commits into
mainfrom
fix/script-destination-final-entry

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Follows #4584. The PR changes 38 files, including the regenerated Swift overlay for #4719.

  • Validate --save-script spelling before dispatch. Refuse ambiguous Windows volumes and unnamed entries, including bare home paths. Create parents below the validated volume and support traverse-only ancestors.
  • Strip trailing separators before probing. A dangling final link counts as occupied. Probe errors defer to delivery, where the exclusive first commit guards against existing entries unless forced.
  • Verify committed bytes under the record lock. Failed-fetch staging cleanup and verification share a lock acquisition. Interrupted-commit recovery keeps staging tracked if removal fails.
  • On repeat delivery, a missing parent, removed drive, or dropped UNC connection (ECONNRESET) can report script_entry_changed. Other Windows network failures report script_download_failed.

Validation

  • Rebased onto a815a42. The embedded Swift guard failed on main. After regeneration, all 72 focused tests passed, including Swift compiler checks.
  • At 32a0053, all runnable affected checks passed with pnpm check:affected --run --head HEAD (exactCommit: true, three local test workers). GitHub CI is running.
  • Five parser, pre-dispatch, and staging-removal regressions fail before the fix and pass at 32a0053. All 246 focused tests passed. Windows coverage uses filesystem seams.
  • On 41e14f5, 102 focused tests passed. Four probe regressions failed on 93fbd45, including a provider-backed remote open with a regular-file parent.
  • Four earlier publication regressions failed on e354988 and passed on 93fbd45.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.40 MB 6.41 MB +6.7 kB
Package (unpacked) 6.40 MB 6.41 MB +6.7 kB
Package (download) 1.94 MB 1.95 MB +2.3 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 21.9 ms 23.8 ms +1.9 ms
CLI --help 45.7 ms 46.2 ms +0.5 ms

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 1983427. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 2 new findings on 6e3377f. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

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 (scriptEntryName UNC rules) has no live run. Not blocking: the current.name !== prepared.name check in confirmScriptDestination cannot fire today, because the only caller prepares and confirms the same record.destination, so you could drop it or let confirm take only prepared; the 'remote commit creates the entry the confirmation authorized' test could use a real link fixture instead of a mock; and scriptEntryName does not check name length, which is fine to leave to the filesystem. The inline thread on the name-mismatch hint (#4677 (comment)) is a minor diagnostic point: a different basename in the same directory is reported as parent_replaced, whose hint does not explain it. The write is still safely refused, and production passes the same destination to both calls. The inline thread on COMMAND_FAILED with typed reasons does not apply, because it matches the other refusals in this family and callers branch on reason (#4677 (comment)). The second thread can be resolved.

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:

  • Overlong names fail late. The spelling check at atomic-file.ts:246-253 does not reject an overlong final name, so private-root/new/<256-byte-name> creates new at 0700 before publication fails with ENAMETOOLONG. A legal 220-byte name also fails, because the temp name appends the PID and a UUID to the full basename (:156-160). This behavior is already on main, but this PR is the one place that owns the final entry. Please reject a final name that cannot fit, temp suffix included, before any directory is created, and keep the temp name bounded.
  • Route coverage. The host-kit tests cover the name rules, but neither route has a test for an overlong name, an existing directory or hard link at the final entry, or each --force mode. Please add one local and one remote case for the refusals this PR moves into the single owner.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 4 new findings on 12bbe35. The verdict and the full list are in the summary comment.

Comment thread packages/remote/src/daemon-artifacts.ts Resolved
@thymikee
thymikee force-pushed the fix/script-destination-final-entry branch from 12bbe35 to 5ee544c Compare November 18, 2026 11:39
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 792f3eb. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

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. contentDigest checks the pathname only when it opens the file, then compares just the descriptor size at the end. If the entry is replaced while it is being read, the old descriptor still hashes to the recorded digest. If the file is updated in place with the same length after its bytes were read, the check also passes. The client then reports the pathname as savedScript even though the current bytes never matched. Locking the early repeat (above) handles the replacement by another client of this record. It does not handle a same-length in-place write. Please carry the descriptor through the digest read, re-stat the pathname after hashing with bigint stats, and accept only if dev, ino, size, mtime and ctime match the descriptor. Otherwise return script_entry_changed. Add tests for a replacement and a same-length change after the open.

Security cross-check, blocker 3: UNC named-pipe roots pass as Windows destinations. windowsEntryName refuses the local device prefix (\\.\pipe\x) but accepts the UNC pipe form, such as \\localhost\pipe\x or \\?\UNC\localhost\pipe\x. That form opens a named pipe, not a file (Microsoft pipe names). Both routes accept it, and a forced remote open creates record state and dispatches before any filesystem error. Please parse ordinary and extended UNC roots in host-kit, refuse a pipe share (case-insensitive) before expansion, record creation or staging, and add these spellings to the shared name table with an early-refusal case on both routes.

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.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

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, \\server\pipe\… roots are refused, and a missing staged digest refuses before publishing. The code review found no new problems. The earlier thread on the early-path race can be resolved: #4677 (comment)

A separate security cross-check of this head found three remaining gaps and one contract question, so this is not ready yet.

  1. Other UNC IPC shares pass the name gate. atomic-file.ts:337 refuses the pipe share but accepts \\server\IPC$\… and \\server\mailslot\…, plus their \\?\UNC\ spellings. Microsoft documents IPC$ as the SMB named-pipe share and mailslot as an IPC endpoint. Please refuse pipe, IPC$ and mailslot (case-insensitive) at the share component for both spellings. Keep accepting the same names as ordinary directories below a normal share. Cover preflight with and without --force.
  2. Expansion can introduce a namespace after the gate. path-resolution.ts:43 checks the raw final segment, then resolveUserPath joins it to the working directory or HOME. If that base is a UNC pipe root, the remote route probes it with existsSync, or with --force it writes the record and sends open, before publication refuses it. Please keep the raw final-segment check and also run the same host-kit gate on the resolved path before returning it.
  3. A repeat of an interrupted revision still needs a fresh download. Suppose revision 2 is renamed into place and the record update then fails, so the record says revision 1 with publishing revision 2. If the daemon re-offers revision 2 after its artifact expired, the early guard at session-script-destination.ts:420 sees only revision 1. It stages, the fetch fails, and the client reports script_download_failed even though the committed bytes are on disk and verifiable. It fails safe, but it is a false failure. Please run the shared locked settlement before staging when the requested revision may already have reached the entry. Return the verified result if settlement turns it into a repeat. Add a test for a post-rename interruption followed by a re-offer of that revision with no artifact.
  4. Contract question: same-tick rewrites on coarse-timestamp volumes. On ext4 with a coarse inode clock, a same-length write in the same jiffy as the read can keep mtime and ctime unchanged, so the old bytes hash correctly and the repeat reports savedScript. That needs a process with write access to the file, so it is not a boundary crossing. The verification contract should still not promise more than it checks. Please qualify the docs and ADR sentence: the entry is verified unchanged as far as size and timestamps can show. Make the positive detection test independent of whether the rewrite lands in a new tick.

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.

@thymikee

Copy link
Copy Markdown
Member Author

All four items, plus the non-blocking one, are fixed in 7cfd427 (ledger acknowledgement in d0cecc7):

  1. IPC shares. The Windows name gate refuses the pipe, IPC$ and mailslot shares, in any case, in both the plain and \\?\UNC\ spellings. The same names below an ordinary share are still accepted. The shared name table covers both cases. Preflight tests cover every spelling with and without --force, and assert that nothing is probed or recorded.
  2. Expansion. resolveScriptDestination keeps the raw final-segment check and runs the same gate on the resolved path before returning it. A working directory or HOME at an IPC root, such as HOME=\\localhost\pipe with --save-script=~/recorder, is now refused before any existsSync probe, record or dispatch. Tests cover a pipe-root working directory and two IPC-root homes, each with and without --force.
  3. Interrupted revision. When an interrupted publishing record covers the requested revision, the locked settlement runs before anything is staged. A version already in place is verified and reported, with no fresh download. A test interrupts after the rename and re-offers that revision with its artifact gone; it reports savedScript. An interrupted version that never reached the entry still downloads, even after its directory was removed.
  4. Contract. The replay guide and the ADR now say that verification covers what size and timestamps can show, and that a same-length rewrite within one tick of a coarse-timestamp filesystem can go unseen. The same-length detection test sets an explicit different mtime, so it no longer depends on clock resolution.

Non-blocking: the symlink-resolution sentence is scoped to macOS and Linux, and notes that on Windows savedScript can keep a junction in its spelling.

From a separate delta review, also in 7cfd427:

  • The replacement test now swaps the parent directory, which leaves the open file's metadata untouched. It fails if the pathname re-stat is removed.
  • A parent that becomes a regular file (ENOTDIR) or disappears during a repeat's digest now reports script_entry_changed.
  • The ADR's 255-byte limit is marked as POSIX; Windows counts UTF-16 code units.

Each new test fails when its code is broken. pnpm check:affected --run --head HEAD passed at d0cecc7.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

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.

hostPath() in path-resolution.ts:13 copies hostPathRules() from atomic-file.ts:262. Both are in the same package, and path-resolution.ts already imports scriptEntryNameOrRefuse from atomic-file.ts. One copy picks the path rules for expanding the destination. The other picks them for the gate that judges the result. The gate only means something if both read the same rules. Nothing is wrong today, because both read process.platform the same way. A later change to one, such as a test seam or an override, would silently split them. The copy is also the only reason resolveUserPath changed for its other callers. Please keep one helper: export hostPathRules from atomic-file.ts, or move it into path-resolution.ts and import it back. Then use it in expandUserHomePath, resolveUserPath and scriptEntryNameOrRefuse, so one function decides the host path rules for both expanding and judging a script destination.

The earlier inline thread about the early repeat running under withRecordLock (#4677 (comment)) no longer applies at this head, so you can resolve it.

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 settledRepeat because of its stale snapshot (session-script-destination.ts:423). Its allocation lock re-reads the record, but allocateStaging only checks that the record exists. If A's artifact has expired, A reports script_download_failed without verifying the file on disk. Please settle from the record read under the lock before preparing or allocating staging. If a download fails after another delivery could have committed the version, recheck under the lock before reporting the failure. Add a regression where the other delivery commits or is interrupted between A's first read and its allocation.

Cross-check, item 3: a Windows root-relative path reaches the probe before the share check. With a Windows cwd of \\server\IPC$, the input \journey.ad passes both checks, because path.win32.isAbsolute treats a single leading separator as absolute. It resolves to \\server\IPC$\journey.ad, but the remote client calls existsSync on the unresolved spelling (without --force) or records that spelling (with --force) (path-resolution.ts:35). An extended-UNC cwd has the same gap from a regular share. Please resolve a single-leading-separator Windows path to a fully qualified destination at the host-kit boundary, run the gate on that value, and use the same value for the probe, the record and the publish. Cover plain and extended UNC bases with both --force settings. This also fits the single hostPathRules change above.

17 of 18 checks pass at d0cecc7, and the remaining one is a review check, not a test job. There are no conflicts.

@thymikee

Copy link
Copy Markdown
Member Author

All three are fixed in 2d2f3e9 (ledger acknowledgement in 655206e):

  1. One helper for host path rules. The copied hostPath() is gone. hostPathRules is exported from atomic-file.ts and used by expandUserHomePath, resolveUserPath and scriptEntryNameOrRefuse, so expanding a destination and judging it read the same rules. Behavior is unchanged, and the Windows-rule tests that depend on choosing the platform at call time still pass.
  2. Concurrent settlement. A delivery now always settles from the record read under the lock before it prepares or allocates staging, never from the earlier snapshot. If a download fails, the version is rechecked under the lock before the failure is reported. If another delivery has committed it, or put it in place before an interruption, with matching content, it reports savedScript. Regressions:
    • another delivery lands between this client's first read and its settlement; the test asserts the artifact is never fetched;
    • another delivery commits between settlement and staging, then the fetch fails;
    • another delivery is interrupted after its rename in that same window, then the fetch fails.
  3. Windows root-relative paths. At the host-kit boundary, a path with one leading separator is qualified against the working directory's root, with that root read directly because Node's win32.resolve drops the server and share of an extended UNC root. That value is gated, probed, recorded and published. Tests cover plain and extended UNC IPC bases, which are refused before any probe or record, and a plain share, an extended share, a drive and an extended drive, which are probed and recorded exactly as qualified. Each case runs with --force on and off.

Each new test fails when its code is broken. pnpm check:affected --run --head HEAD passed at 655206e.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

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.

  1. An extended UNC base can lose its share. With a cwd of \\?\UNC\server\share, the gate's win32.normalize treats \\?\UNC\ as the root. So \..\other\journey.ad is accepted and recorded through share, while host-kit's entry points to \\?\UNC\server\other\journey.ad. The same suffix on a cwd of \\?\UNC\server\IPC$ passes the gate, because normalization erases IPC$ before the share check. A /nested/journey.ad suffix on an extended base also records a different spelling from the one published (path-resolution.ts:60).
  2. A drive-root destination fails at publication. With a cwd of C:\work and --save-script=\journey.ad, preflight returns C:\journey.ad. Both publishers then call mkdirSync on C:\, which Node documents as EPERM for a recursive mkdir of a drive root (atomic-file.ts:227). The force tests stop at preflight, so they don't catch it.

The smallest fix for both is to refuse these spellings for a script destination: a root-relative path (\journey.ad), and any destination or base in extended-length form (\\?\…). Return a typed error that asks for a drive-letter or \\server\share path. That deletes the root computation instead of hardening it, and both cases above become refusals. If you would rather keep support, the requirement is this: identify and validate the full volume before folding any components, bound .. by that root, use that one value for the gate, probe, record and publish, and create only components below an existing drive or share root. Either way, cover nested forward slashes, .. segments and IPC roots, with --force on and off.

Failed-download recheck.
3. A commit can land during cleanup. Delivery A fails to fetch revision 2. Its recheck takes and releases the lock while revision 1 is still current, so A decides on a download failure. Delivery B then commits revision 2 before A takes the lock again to remove its staging, and A still reports script_download_failed (session-script-destination.ts:468). Please do the staging cleanup and the repeat decision in one final lock acquisition, and verify after cleanup.
4. Typed settlement failures are dropped. The recheck wraps settledRepeat in .catch(() => undefined) (session-script-destination.ts:446). If the recheck observes revision 2 but its entry is gone or changed, CommittedVersionUnverified ('changed' or 'unverifiable') or an ancestry refusal is swallowed. A then reports script_download_failed, while the same repeat through the first locked check reports script_entry_changed. Please let typed settlement failures propagate through scriptDeliveryFailure, and keep the download error only when settlement finds no matching revision. Add a failed-fetch test where the recheck finds the committed revision but its entry fails verification.

17 of 18 checks pass; the remaining one is a review check. There are no conflicts.

@thymikee

Copy link
Copy Markdown
Member Author

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 (\journey.ad, /nested/journey.ad) or extended-length (\\?\…). The same applies to the working directory a relative path is joined to, or the HOME a ~/ path is joined to. The refusal is INVALID_ARGS with reason script_ancestor_untrusted and exposure windows_path_form, and its hint asks for a drive-letter or \\server\share path. The root computation from the last round is deleted. Both your cases are now refusals: the share lost under normalization (including IPC$ erased by ..), and the drive-root mkdir. The replay guide and the PR body say these forms are refused on purpose. Tests cover each form as a destination and as a base, including nested forward slashes, .. segments and IPC roots, with --force on and off, all refused before any probe or record. Plain drive and share paths are still probed and recorded as given.

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 savedScript.

4: Typed recheck failures. The .catch(() => undefined) is gone. When the recheck finds the version committed but its entry fails verification, the result is script_entry_changed. When the ancestry walk refuses it, the refusal propagates through scriptDeliveryFailure (script_ancestor_untrusted). The fetch error is reported only when nothing matching is committed. There is one test for each.

The concurrency tests moved to their own file (daemon-artifacts-script-concurrency.test.ts) to keep the entry tests under 1,000 lines. This round leaves atomic-file.ts untouched, for #4670. Each new test fails when its code is broken, and pnpm check:affected --run --head HEAD passed at 3604407.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

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? ///journey.ad passes the current check but normalizes to a root-relative file, allowing a remote caller to probe and register a destination without a validated volume. Path resolution

Could every base actually used by resolution be validated, and the expanded home path pass through the same entry rule? With a relative HOME, ~/journey.ad uses cwd without checking it, so an extended-drive cwd reaches probe and delivery despite the intended refusal. Please add that case to the remote preflight matrix. Path resolution

Could the publication boundary validate the existing volume root and create only components below it? A qualified destination such as C:\journey.ad, or a relative name resolved from a drive root, still calls recursive mkdir on the root, which Node documents as failing on Windows. Please test actual publication to a drive-root child or use a Windows filesystem seam that rejects mkdir on the volume root. Publisher

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 finally skips cleanup, so the staging directory stays until a later sweep. At 655206e finally still attempted cleanup here. Please keep staging registered for finally until the final lock callback starts, then clean up and verify inside that callback, and add a test for a transient acquisition failure after a failed fetch (session-script-destination.ts:446).

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.

@thymikee

Copy link
Copy Markdown
Member Author

Addressed the findings from the review at 3604407 in e5929786ee8533dcf7fa2f5104783946798c8929.

  • Save-script admission calls the host-kit resolver before dispatch. Request-handler tests cover fresh open and armed close for root-relative and extended paths. They assert the typed refusal, unchanged session state, and zero backend binding or inspection calls.
  • Host-kit rejects incomplete Windows volumes before normalization and validates only the bases the path uses. The publication boundaries reject unqualified retained paths. A filesystem seam that fails mkdir on a Windows volume verifies that publication checks the drive root and renames the script into it without trying to create the root.
  • Failed-download staging stays eligible for final cleanup until the final lock callback starts. Cleanup and digest verification run under the same acquisition. Splitting them makes the regression fail on the acquisition identity. Clearing staging before acquisition makes the transient-lock-failure regression leave a staging entry and fail.
  • The replay guide now describes equal or older replies and limits retry recovery to an open recording. The record and digest helpers live in the shared test fixture.

pnpm check:affected --run --head HEAD passed at this exact commit. I had no Windows daemon with a live backend, so the Windows evidence comes from the request-handler and filesystem seams. CI is running on the new head.

thymikee and others added 19 commits November 19, 2026 11:57
…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>
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging 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.

Apex Sentinel: 1 new finding on 60361b1. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

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.

  1. A bare Windows home spelling with a trailing backslash is accepted as a file (atomic-file.ts:411). On Windows, ~\ passes scriptEntryName because the bare-home guard only recognizes a trailing /. The resolver then treats it as a literal file named ~ in the working directory. Please recognize both separators in the bare-home refusal, and cover the parser and the pre-dispatch refusal.

  2. The guide promises a pre-dispatch refusal when occupancy is unknown (replay-e2e.md:88). If the final-entry lstat returns EACCES for an existing file under a directory the caller cannot search, the probe defers to delivery. open then succeeds, and the exclusive commit refuses the occupied target. Please say that open fails when the probe finds an existing entry, and that an unreadable entry, like one that appears later, is caught by the exclusive commit at delivery without overwriting it.

  3. A dropped UNC share during interrupted-commit cleanup reports the generic cause (session-script-destination.ts:662). On a repeat that reaches a pending commit, the root and entry checks pass. Then the share drops with ECONNRESET while the old staging directory is being removed. The settled record is already written, but cleanup throws before digest verification, so the response reports script_download_failed instead of the script_entry_changed the guide promises. Please keep the failed cleanup tracked, and handle the reset under the record lock with the same cause as the other dropped-share checks. Alternatively, narrow the guide's UNC promise to the checks that classify it. Add a test with the reset at staging removal.

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 session-script-destination.ts would not handle Windows share loss at two entry checks.

On the open threads: #4677 (comment) does not apply, because the client validates the spelling and probes occupancy before dispatch (daemon-artifacts.ts:140-145). #4677 (comment) and #4677 (comment) are fixed, because the separator strip is now a linear loop. Please resolve all three. CI is still running on this head, and nothing has failed so far. No conflicts are known.

@thymikee
thymikee force-pushed the fix/script-destination-final-entry branch from 60361b1 to 32a0053 Compare November 19, 2026 11:33
@thymikee

Copy link
Copy Markdown
Member Author

Pushed 32a005325c0a6df1b8a61f3ffc91c43851a7eb0b.

  • Windows refuses a bare home path with either separator, including mixed trailing separators. Parser and remote-open admission tests cover the refusal.
  • The replay guide explains when the occupancy probe fails open and how exclusive delivery protects unreadable and later-arriving entries.
  • A UNC reset during interrupted-commit staging removal reports script_entry_changed. The record lock covers settlement and removal, and the record retains the staging listing if removal fails. The classifier uses Node's filesystem error code from the removal call.

The rebase also regenerates the embedded Swift overlay after #4719 changed its source. The same consistency guard failed on main and on the prior CI merge checkout. The focused Swift run passed 72 tests, and the parser and remote-delivery run passed 246. All runnable affected checks passed on this commit. The three requested review threads are resolved and GitHub CI is running.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 32a0053

Since the review of 60361b1: 0 new · 0 still open · 1 no longer raised

No open findings.

Not in the reviewers' prompt (1 file)
  • packages/capture-kit/src/recording/recording-swift-sources.ts: its very long or mostly numeric lines were cut; reviewers could still search them

Reviewed with this repository's own Sentinel configuration (8804ce24cc1d).

💬 Talking to Sentinel

In a finding's thread, reply with:

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.

@thymikee

Copy link
Copy Markdown
Member Author

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 ~\journey.ad is still not home-expanded, because only ~/ is (https://github.com/callstack/agent-device/blob/32a0053/packages/host-kit/src/internal/path-resolution.ts#L56). It resolves to <cwd>\~\journey.ad and creates a directory named ~. This is unchanged from main, and the write still fails closed. Either expand ~\ like ~/ under win32 in resolveScriptDestination, or state in replay-e2e.md that only ~/ means home on Windows.

The two code-scanning threads (#4677 (comment) and #4677 (comment)) are fixed at this head: the regex is now a linear loop at path-resolution.ts lines 68-72. The two other threads do not apply, so please resolve them. #4677 (comment) does not hold, because the client validates the spelling and checks occupancy before dispatch (daemon-artifacts.ts lines 140-145). #4677 (comment) does not hold either, because the function keys on Node's typed errno code, the platform and the UNC path shape, not on message text (atomic-file.ts lines 307-313).

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 script_entry_changed for a delivery that wasn't a repeat. Choosing the cause from the repeat decision would fix it. The response already fails closed and keeps the staging record.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee
thymikee merged commit 6f75df2 into main Nov 19, 2026
19 checks passed
@thymikee
thymikee deleted the fix/script-destination-final-entry branch November 19, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants