Skip to content

fix(remote): answer a repeated script delivery from the publication record - #4744

Merged
thymikee merged 17 commits into
mainfrom
fix/script-repeat-from-record
Nov 19, 2026
Merged

thymikee merged 17 commits into
mainfrom
fix/script-repeat-from-record

Conversation

@thymikee

@thymikee thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Summary

A repeated or late-duplicate script delivery (revision ≤ the committed revision) is answered from the client's publication record. It reports the stored absolute destination as savedScript, and adds a warning to the existing warnings array. The warning says the version was already saved, or that it is superseded and names the revision the record last confirmed. It also discloses an interrupted newer save, says the file is not checked again, and gives the recovery: the next recorded action, or after close reusing the original open command with --save-script=<path> --force. The repeat path never downloads, reads, hashes, or re-walks the destination.

Removed: the per-version digest, the bounded verified read, CommittedVersionUnverified, the script_entry_changed and script_entry_unverified causes, the repeat judgement, and host-kit's judgeScriptDestination (isWindowsShareUnavailable is now module-private). Old records that carry a digest or an entry still parse, and those fields are dropped.

Kept: first commits and interrupted-commit settlement, under one locked operation that reads the record, decides repeat or stage, prepares the destination, and allocates staging. A failed fetch or a re-offer of an interrupted version settles under the lock first. A failed fetch stays script_download_failed unless that settlement answers with a published path. A new commit still requires a verified staged file: regular, ≤ 8 MiB, and unchanged through one verified read. Nothing is stored. A failing cleanup after a failed artifact download is reported as a warning instead of an unhandled rejection. The close recovery hint names the file: reuse the original open command with --save-script=<path> --force.

16 files, +695/−1031. Docs: replay-e2e.md and ADR 0016. The wire-compat ledger acknowledges publishScriptVersion and PublishOutcome (local shape only). There are no wire changes and no protocol bump.

Security: the daemon and other local users are untrusted. The change writes nowhere new, and no path comes from the daemon. A committed repeat does no filesystem work. Settling an interrupted version does one confirmation walk and one lstat, the same steps a first commit takes.

Terminal-safe CLI output for every command, including the paths this change reports, is handled separately in #4778.

Validation

At 81fbe880c4 (on main after #4745 and #4747): the remote, host-kit, command-output, wire-compat and eager-closure suites passed. Typecheck, lint, fallow audit --base origin/main, and check:production-exports are clean. Each new test fails under a targeted mutation. CI validates the head.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.41 MB 6.41 MB +51 B
Package (unpacked) 6.41 MB 6.41 MB +51 B
Package (download) 1.95 MB 1.95 MB +139 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 22.4 ms 24.5 ms +2.1 ms
CLI --help 49.2 ms 47.8 ms -1.3 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 456a81e. 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 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: 3 new findings on 3bf4a96. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

The repeat-from-record design is the right shape, and the review of 3bf4a96 found nothing blocking. An independent second pass over 60812c9 found four gaps. Each one keeps writes inside the authorized destination, but they report a wrong path or skip a check, so please fix them before merge.

  1. An edited record can report an unrelated file as savedScript (session-script-destination.ts:653). The parser accepts any string as entry.path, and when its revision matches, a duplicate returns that string as savedScript and can attach it as the artifact's localPath. The test at daemon-artifacts-script-entry.test.ts:498 expects an unrelated file to be reported this way. Please return the stored entry only when trusted state proves it belongs to this publication, and fall back to the authorized destination otherwise. Cover an edited record and a legitimate resolved parent alias.
  2. The pre-download decision uses an unlocked snapshot (session-script-destination.ts:453). A committed repeat or superseded revision returns from a record read outside the lock, even while a publisher holds the lock and is updating the revision. If another publisher commits or records an interrupted publication before staging is allocated, allocateStaging only checks that the record exists, so the request still downloads. The test at daemon-artifacts-script-concurrency.test.ts:51 accepts that extra fetch. Please make the repeat, interrupted-settlement and stage-or-return decision from a fresh read under the record lock, and recheck at allocation.
  3. A failed fetch can miss an installed interrupted commit (session-script-destination.ts:481). If another client installs revision 2 but fails to record it, and this client's fetch then fails, the locked recovery checks only the committed revision and reports script_download_failed, although interrupted settlement could confirm the installed file. The success and re-offer paths both settle first. Please run the same locked settlement after staging cleanup, before reporting the fetch error, and test a failed fetch alongside a commit interrupted after the rename.
  4. New commits skip staged-file validation (session-script-destination.ts:625). The old digest pass required a readable regular file within the byte limit that stayed unchanged through the read. The replacement records only dev and ino, so a staged file that becomes unreadable after the stream succeeds can be installed and recorded. Please keep staged-file validation for first and newer commits in the staging owner, without storing a digest or reading the destination on repeats. If a check is removed on purpose, say so in the ledger rationale.

Not blocking:

  • The recovery hint at :311 promises that the next recorded action writes the reported file again, which is not true through a linked parent.
  • Edited staging and publishing.staging paths still drive recursive cleanup at :563 and :699, as before this PR.
  • From the review of 3bf4a96:
    • writeRecord keeps a legacy committedDigest that parseRecord ignores.
    • ADR 0016 should say an interrupted re-offer is settled before it is answered.

Both ledger digests and acknowledgements match 60812c9, and RPC protocol 3 is unchanged. No conflicts are known.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

Thanks. All four gaps are fixed in 333c999, each with a test that fails when the fix is reverted.

  1. Edited entry: a repeat now reports entry.path only when the record ties it to this publication. The entry revision must equal the committed revision, the path must be absolute and normalized, and its final name must match the destination's entry name. Otherwise the client reports the destination. The old decoy test now covers three edited entries (another file, a relative path, an unnormalized path), and each falls back to the destination while the write still goes to the authorized destination. The existing retargeted-link test covers a legitimate resolved parent alias.
  2. Unlocked decision: the repeat decision now reads the record fresh under the record lock. Staging allocation rechecks under the lock: committed repeat, then settlement of an interrupted commit that names the version, then stage. The concurrency test now lands a commit between the first read and allocation and expects the version to be answered with zero fetches.
  3. Failed fetch: after staging cleanup, in the same lock, the client runs the same settlement before reporting script_download_failed. A new test installs revision 2 without recording it while the fetch fails, and expects savedScript with the revision promoted.
  4. Staged-file validation: before a new version is committed, the staged file must open through openVerifiedFileForRead as a regular file within 8 MiB, and stay unchanged through the read (fstat before and after, plus an lstat of the path). Nothing is stored, and repeats read nothing. New tests cover a staged file that grows past the cap and one swapped for a symbolic link.

Non-blocking items:

  • Recovery hint: it now says the next recorded action writes the recording to the destination. The replay guide says the same.
  • Legacy committedDigest: it is dropped when a record is parsed, so later writes no longer carry it.
  • ADR 0016: it now says that an interrupted re-offer, or a failed fetch, is settled before it is answered. It also describes the staged-file check.
  • Ledger: the rationale states the new settlement timing and that the digest is no longer computed or stored.
  • Edited staging paths: these still drive cleanup as before this PR. I left them unchanged.

#4746 is rebased onto this head and stays move-only.

@thymikee
thymikee added this pull request to stack #4750 November 19, 2026 13:55
thymikee and others added 5 commits November 19, 2026 14:57
…ecord

A version no newer than the committed revision is now answered from the
client's own record: it reports the entry the commit created and adds a
warning that the file is not checked again, with the recovery to use if
it is missing. The repeat path no longer downloads, reads, hashes or
re-walks the destination.

This removes the per-version content digest, the bounded verified read,
the script_entry_changed and script_entry_unverified causes, and
host-kit's judgeScriptDestination. First commits, interrupted-commit
settlement and the record lock are kept. A record that still carries a
digest parses, and the field is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ersion

When a re-offered revision is the one an interrupted commit names, the
client settles that commit under the record lock before it stages or
downloads. A version the commit already renamed into place is answered
from the record, so an expired artifact no longer turns it into a
delivery failure. A version that never reached the entry downloads as
before. No digest and no file read: one confirmation walk and one lstat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eded version

The record keeps the committed entry together with the revision that
created it, and a repeat uses it only while that revision is still the
committed one; otherwise it answers the destination, like a record
without an entry. A released client that advances the revision can no
longer make the client report an older path for a newer version.

A version older than the committed one is now reported as superseded,
naming the revision the file holds. The replay guide, ADR 0016 and the
ledger acknowledgements describe this and when interrupted-commit
settlement runs.

Tests cover the legacy and stale-entry fallbacks, a held download that
loses to a newer commit, an entry that is only reported, the cleanup and
reread sharing one lock, and fs.promises in the no-filesystem spy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Interrupted-commit settlement records the promoted revision before it
removes the interrupted version's staging. That removal is now best
effort, through the existing quiet release, so a failure such as a
dropped Windows share no longer turns a recorded commit into a download
failure. The directory stays listed for retirement or the sweep.

A comment and the replay guide also say that a repeat answered from a
record without an entry for the committed revision names the destination
as the caller spelled it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…staged-file checks

- A repeat is decided from a fresh read under the record lock, and the
  decision is rechecked at staging allocation, so a commit that lands in
  between is answered instead of staged and fetched again.
- A failed fetch settles an interrupted commit that names the version
  before it reports the fetch error.
- A recorded entry is reported only when the record ties it to this
  publication: the committed revision, an absolute normalized path, and
  the destination's own entry name. Otherwise the destination is reported.
- Before a new version is committed, its staged file must be a regular
  file within the 8 MiB cap that stays unchanged while it is read
  through one verified descriptor. Nothing is stored and repeats read
  nothing.
- A legacy committedDigest is dropped when a record is parsed, and the
  recovery hint names the destination.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/script-repeat-from-record branch from 333c999 to abfa16f Compare November 19, 2026 14:03
@thymikee

Copy link
Copy Markdown
Member Author

I rebased this onto main (#4745 and #4747 merged) and force-pushed. The head is now abfa16f.

  • Conflicts: packages/host-kit/src/file.ts and packages/host-kit/src/internal/script-destination-entry.test.ts, the file that replaced atomic-file-entry.test.ts. I kept main's split layout and the Windows allow-list cases. On top of them I re-applied the two deletions: the judgeScriptDestination export and its one test call, and the isWindowsShareUnavailable re-export. In internal/script-destination.ts, the judgeScriptDestination deletion and the now-private isWindowsShareUnavailable applied cleanly.
  • ADR 0016: no conflict. The repeat sentence sits next to main's changes, and both are kept.
  • Name check: it still uses path.basename(record.destination). Host-kit's name rule lives in internal/entry-name.ts, and the only export ./file gives from that file is resolveScriptDestination. Using the rule would mean a new public host-kit export, not a one-line swap.
  • Validation at the new head: the remote, host-kit, wire-compat and eager-closure suites passed (1949 tests). Typecheck, lint, fallow audit --base origin/main and check:production-exports are clean. One host-kit timing test, exec-boundary-faults, failed once in the combined run and passed twice on its own. My host-kit diff does not touch it.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Nov 19, 2026 •

Copy link
Copy Markdown
Member Author

The four gaps from the earlier review (#4744 (comment)) are fixed at abfa16f, each with a regression test, and all 19 checks pass. One defect remains, and there are no conflicts.

When a click fetches revision 2 after revision 1 is saved, a concurrent close can fail to download revision 3 and still retire the same publication (session-script-destination.ts:486, retire at lines 260-264 and 561-575). If the click fetch then fails, readRecord returns undefined, and settledRepeat turns that into the truthy { published: undefined } outcome (lines 698-699). The fetch catch returns it as if settlement had answered the call. The click then succeeds with no savedScript and no scriptDeliveryFailure or warning, while the recording on disk is still revision 1. ADR 0016 requires that disclosure, and both 7b6500c and 60812c9 propagated the fetch error here. Please make the failed-fetch catch return the locked result only when it has a defined published path, and rethrow the original fetch error when the record vanished. The absent-record outcome before staging should stay as it is. A test that fails revision 2 after a concurrent close retires the record would prove it.

The earlier inline threads on re-offering an installed version, the stale-entry fallback, the replay-e2e.md wording and the committed answer after ECONNRESET are fixed at this head, so the author can resolve them: #4744 (comment), #4744 (comment), #4744 (comment), #4744 (comment).

CI is green. Windows behavior of the basename tie check is not exercised. Before merge, the fetch error and the three items below need fixes.

An independent second pass over abfa16f confirms that defect, and finds three more. All of them affect what the response reports. None writes outside the destination.

  1. An edited entry with the same filename can report a file in another directory (session-script-destination.ts:665). A record for /caller/journey.ad passes the check with entry.path set to /unrelated/journey.ad at the committed revision. An equal or older offer then reports the unrelated path in savedScript, localPath and the warning. The edited-entry table at daemon-artifacts-script-entry.test.ts:499 covers a different basename, a relative path and an unnormalized path, but not the same basename. Please use the recorded path only when trusted state establishes the full path for this destination and revision, and report the caller's destination otherwise. Cover an edited same-basename path and a legitimate resolved parent alias, with no repeat-time filesystem walk.
  2. A late commit can be reported as a failure before the allocation recheck (session-script-destination.ts:461). If another delivery commits the revision between the first lock and destination preparation, and the parent then becomes unusable, preparation throws before stageOrAnswer rereads the record. The call returns scriptDeliveryFailure although the record could answer the repeat, and a removed parent may be recreated. Please keep the record read, repeat decision, destination preparation and staging allocation in one locked operation, and prepare only when the locked record still needs work. Test a late commit with a destination that would refuse preparation.
  3. The superseded warning can name the wrong on-disk revision (session-script-destination.ts:327). Suppose revision 2 is committed, and a revision 3 delivery replaces the file but stops before recording its commit. A late offer of revision 1 then says the file holds revision 2, although revision 3 is installed. Please keep superseded replies record-only, but word them as the revision the record last confirmed, and disclose the pending revision when it may already have replaced the file. Align replay-e2e.md with that wording.

Not blocking: edited staging and publishing.staging paths still drive recursive cleanup, as before this PR.

The wire-ledger digests match this head.

…s disclosed

- A failed fetch is reported as script_download_failed unless locked
  settlement answers it with a published path; a record a concurrent
  close retired no longer turns it into a silent success.
- The record no longer keeps the committed entry. A repeat reports the
  destination as the caller spelled it; a record that still carries an
  entry parses and the field is dropped.
- The record read, the repeat decision, destination preparation and
  staging allocation are one locked operation, so a version committed
  meanwhile is answered before the destination is judged.
- The superseded warning names the revision the record last confirmed,
  and discloses an interrupted newer save that may have replaced the
  file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. All four are fixed in 13e45cb, each with a test that fails when its fix is reverted.

  1. Failed fetch after a concurrent close: the fetch error is now rethrown and reported as script_download_failed unless locked settlement answers with a published path. The absent-record outcome before staging is unchanged. New test: the record is removed while revision 2 is fetched and the fetch then fails. The response carries scriptDeliveryFailure with that cause and no savedScript, and the file keeps revision 1.
  2. Same-name edited entry: following the "don't overengineer" direction, the record no longer keeps the entry. A repeat always reports record.destination as the caller spelled it, and the replay guide states this as the rule. That removed the entry field, its tie checks and their tests, and adds no repeat-time walk. Old records that carry entry still parse, and the field is dropped. The one remaining test edits the entry to a same-name file in another directory. It expects the repeat to report the destination, and the next version to be written to the destination host-kit authorizes, with the unrelated file untouched.
  3. Late commit and an unusable parent: the record read, the repeat-or-stage decision, prepareScriptDestination and staging allocation now run as one operation under the record lock. Preparation runs only when the locked record still needs work. New test: a commit lands right after the client's first look at the record, and the parent is then made group/world-writable. The client answers the repeat with zero fetches and without calling prepareScriptDestination.
  4. Superseded wording: a superseded version now reads "Revision N of the recording is superseded: the record last confirmed revision M at ." When the record names an interrupted save, the warning adds "Revision P may already have replaced that file; its save was interrupted." This stays record-only. replay-e2e.md and ADR 0016 match, and the test covers revision 2 confirmed, revision 3 interrupted, and revision 1 offered.

Ledger: both acknowledgements are updated for the moved digests.

Earlier threads: the four inline threads you listed were already resolved after their fixes.

Not changed: edited staging and publishing.staging paths still drive cleanup, as before this PR.

#4746 is rebased onto this head and stays move-only.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The production fixes at 13e45cb look correct and fix the problems from the earlier review (#4744 (comment)). One regression test still does not cover the bug it was written for. All 18 checks pass, and there are no conflicts.

The fix 3 test in daemon-artifacts-script-concurrency.test.ts:266 commits revision 2 and makes the parent 0777 on the first read of the record file. For a click, that first read is the unlocked snapshot readRecord at session-script-destination.ts:444, which runs before any record lock. At abfa16f, the first locked repeat check then already sees revision 2 and returns the repeat before the unlocked preparation runs. So I expect the test to pass on the code the earlier review flagged. It covers the window between snapshot and lock, not the window between lock and preparation, where a late commit made preparation refuse an unusable parent. If the two-lock shape came back, this test would stay green. To fix it, land the commit and the chmod after the first record lock is released. The file already mocks withProcessLock, so a mockImplementationOnce can run the real lock and then call otherDeliveryCommits and chmod 0777 after its task returns. Then assert savedScript === destination and no scriptDeliveryFailure. On abfa16f, preparation refuses the shared parent and the call reports a failure. At head, the single lock has already prepared and allocated staging, so publishStaged answers the repeat from the record. Drop the prepare-not-called and zero-fetch assertions, because one fetch is expected at head in that ordering. The rule to cover: no record state that a lock holder can observe between the repeat decision and staging allocation lets preparation run against a revision the record already committed.

Not blocking, and you can take or leave it: stageOrAnswer (session-script-destination.ts:520) parses the record file four times inside one lock, and nothing else can write the record between the first two reads. Reading it once at the top and answering committedRepeat(record, revision) from that read would be simpler.

Of the four earlier inline threads, all four are fixed at this head, so you can resolve them: the re-offer of an installed version is now settled under the lock (#4744 (comment)); the stale-entry fallback is gone because the entry field and recordedEntry were removed (#4744 (comment)); the replay-e2e.md wording now matches committedRepeat (#4744 (comment)); and the committed answer after ECONNRESET is kept by settleInterrupted (#4744 (comment)).

Windows behavior is not exercised, because the fix 3 test skips on win32 and when running as root. Before merge, the fix 3 test needs to land its commit after the first record lock releases, so it fails when the fix is reverted.

The regression test for the single locked stage-or-answer operation now
commits revision 2 and shares the parent after the first record lock
releases, the window where two locks would let preparation refuse a
version the record already committed. It fails on the two-lock shape
and passes with one lock. The snapshot-window test lands its commit on
the unlocked first read instead of inside the lock.

stageOrAnswer reads the record once and answers from that read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. The fix-3 test is reworked in 64fb12a.

  • Fix-3 test: withProcessLock now has a mockImplementationOnce that runs the real lock and, after its task returns, calls otherDeliveryCommits and chmods the parent to 0777. The test asserts savedScript === destination and no scriptDeliveryFailure. The prepare-not-called and zero-fetch assertions are dropped.
    • On abfa16f689 source (that version of session-script-destination.ts against this test file), the test fails: no savedScript, because preparation refuses the shared parent and the call reports a delivery failure.
    • At 64fb12adb3 it passes.
  • Snapshot-window test: the old fix-2 test committed during prepareScriptDestination, which now runs inside the lock where no other publisher can write. It now commits on the unlocked first record read, and still expects zero fetches. It fails when the repeat answers under the lock are removed.
  • Optional cleanup: stageOrAnswer now reads the record once, answers committedRepeat(record, revision) from that read, and settles an interrupted commit that names the version from the same read. lockedRepeat is deleted. No ledger digest moved.
  • Earlier threads: each of the four has a one-line reply, and all were already resolved.

Validation: the remote, host-kit, wire-compat and eager-closure suites passed (1947 tests). Typecheck, lint, fallow audit --base origin/main and check:production-exports are clean.

#4746 is rebased onto this head and stays move-only, with the ADR line commit on top.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 64fb12a the fix 3 test blocker from the previous review is resolved: the commit and the parent permission change now land after the first record lock releases, and the test fails against the abfa16f source. The single record read in stageOrAnswer is in, and the four earlier threads are resolved. A second, independent correctness pass confirmed that all four problems from the abfa16f pass are fixed (each check passes at head and fails at abfa16f), and that the repeat decision, preparation and staging allocation all come from one locked read. There are no conflicts.

One user-facing problem remains, so no label yet:

The close recovery hint selects a different destination. When a duplicate close or a closing batch reports a caller-chosen journey.ad from the record after the file was removed, the warning at session-script-destination.ts:308 tells the caller to recover with open --save-script --force. A bare remote --save-script allocates recording-<timestamp>.ad in the current directory, as replay-e2e.md:89 documents, so following the hint leaves journey.ad missing. The new guidance at replay-e2e.md:88 repeats the same command. Please make the hint say open --save-script=<path> --force with the path named in the warning, align the website and remote recording help with it, and assert the destination argument in the closing repeat warning test.

Not blocking:

  • artifact-download.ts:125 can raise an unhandled rejection when cleanup rm fails after a failed fetch, for example when the staging share disconnects. This exists on main too; a rejection handler that keeps the original error and reports cleanup separately would close it, here or in a follow-up.
  • Settlement, retirement and sweep pass the recorded staging and publishing.staging strings to recursive removal, trusting private client state. That is unchanged from main, but if the record is meant to tolerate on-disk edits, those paths need the same validation the destination gets.
  • savedScript exposure differs by surface: raw single-command results and SDK close expose it, a successful batch only with the matching artifact, and receipt-only or failed batches only in the warning (error.details.warnings for failures). The docs could name those surfaces, and scope the symlink-resolution claim to fresh commits.
  • The ledger rationale could say that an unconfirmed offer below the pending revision can also settle it, and that a legacy nested publishing.digest is ignored until its pending record settles.

CI is still finishing at this head.

Move the sentence that the publication record is owner-private client
state, and that cleanup trusts its staging list, from
docs/agents/security.md into ADR 0016's staging paragraph, so the agent
guidance stays within its size budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

At ae1127a both items from the previous review are in: cleanup is main's trusted-record behavior again, ADR 0016 says the record is owner-private client state, and the savedScript surfaces are named. A second, independent correctness pass confirmed the cleanup matches main's staging-list ownership and that the earlier fixes are intact. All required checks pass.

It also found four places where the docs or a rendered hint still say something the code does not do. They are small, but each can mislead a caller recovering a recording, so no label yet:

  1. The repeat path is not the spelling the caller typed. replay-e2e.md:87 says a repeat reports the destination as spelled. Remote open resolves relative and ~ paths and strips trailing separators before it writes the record, so ./workflow.ad comes back absolute. The path and the repeat warning are added by client-side artifact materialization, not by the raw HTTP RPC response. Please describe it as the stored absolute destination (before parent links are resolved), and name the client-materialized response as the surface that carries it. Line 88 needs the same wording.
  2. The repeat guarantee outlives its record. If a concurrent close retires the publication record before an action's response arrives, publishScriptVersion finds no active record and returns no destination or warning. The scripting help (cli-help.ts:156) and the guide's equal-or-older rule promise the warning unconditionally. Please scope both to versions the client can answer from a matching active record, and qualify the next-action recovery on the session still recording.
  3. A daemon-side close failure does not name a path. When the daemon cannot write the final version, remoteCloseScript and withRemoteScriptVersion return a typed failure and warning with no caller path, but the recovery paragraph at replay-e2e.md:88 tells the caller to use the path named in the warning. Please give the original open destination as the general close-failure recovery, and describe the quoted command only as part of a closing repeat warning, which does carry the path.
  4. The CLI close text can change the quoted destination. For a destination containing a newline, the response carries a correctly quoted argument, but the close text renderer (output-common.ts:136) collapses the newline to a space inside the quoted argument, so copying the rendered command with --force targets a different file. Please preserve the quoted argument in the text warning, or drop the path from the text form when it cannot round-trip, and cover the close text surface with a newline in the destination.

Not blocking, and already true on main: fresh POSIX publication directories and files are created 0700 and 0600, but the recursive mkdir leaves existing components alone. remote-connection-state.ts:259 creates the state directory with the umask default, and an existing session-scripts directory is not tightened, so under a group-writable umask another group member could plant a retired record that the next open sweeps. Either a follow-up from the state-directory owner that makes every level owner-only (and checks the owner of an existing session-scripts), or an ADR sentence that the record is owner-private when the state directory is owner-only, would close it.

The thread about a non-own staging path being re-swept forever no longer applies and can be resolved: #4744 (comment).

@apex-sentinel-staging

This comment has been minimized.

… docs

- A record-again hint for a path with a newline or another control
  character names <path> instead of the path, so a rendered text line
  cannot turn it into a command for a different file.
- The next-action recovery applies while the session is still
  recording.
- The replay guide and scripting help scope the repeat warning to an
  active record, describe the reported path as the stored absolute
  destination added by client-side materialization, and give the
  original open destination as the general close recovery.
- ADR 0016 scopes the trusted-record sentence to an owner-only state
  directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. All four gaps are fixed in 79a97c8. I also took the simple option for the state directory.

  1. Repeat path and surface (replay-e2e.md 87–88): a repeat now reports the stored absolute destination. Relative and ~ paths are resolved and trailing separators removed, with parent links not resolved. The guide now says the client adds savedScript and the warnings when it materializes a remote response, and that the raw HTTP RPC response does not carry them.
  2. Active-record scope: the guide and the scripting help (cli-help.ts) scope the repeat warning to versions the client answers while it still holds the recording's active record. The guide also says that a close which retired the record first leaves no warning. The next-action recovery is qualified as applying while the session is still recording, in the docs and in the warning text itself.
  3. Close-failure recovery: the general recovery is now "record again to the original open destination with open --save-script=<path> --force". The quoted command is described only as part of a closing repeat warning, which carries the path.
  4. CLI close text: for a path with a newline or another control character, the record-again hint now names <path> instead of the path, so a collapsed text line can't produce a command for a different file. The full path stays in the warning's "saved to" text and in the JSON.
    • Remote test: a closing repeat with line\nbreak.ad in the path expects the placeholder hint. It fails when the path is always quoted.
    • Close text test: a command-output test renders that warning through the CLI close text formatter, and asserts the placeholder survives with no quoted --save-script=' command. The two packages don't depend on each other, so this test pins the rendering rather than detecting a source regression. The remote test is the one that does.

State directory (optional): ADR 0016 now reads "When the state directory is owner-only, the record is owner-private client state, so cleanup trusts its staging list." The creation code is unchanged.

Review-bot thread (discussion_r4631120964): already resolved, with a reply saying the check was reverted per the maintainer review.

Ledger: no digest moved.

Validation: the remote, host-kit, command-output, wire-compat and eager-closure suites passed (2225 tests), plus the CLI entry and router tests. Typecheck, lint, fallow audit --base origin/main, check:production-exports and check:agent-guidance are clean.

#4746 is rebased onto this head and stays move-only, with the ADR line commit on top.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 79a97c8 the four items from the previous review are in. The guide describes the stored absolute destination, the repeat warning is scoped to an active record, close-failure recovery points at the original open destination, and a newline path shows <path>. All 217 wire declaration digests match the ledger, and CI passes. Two small accuracy gaps remain, so no label yet:

  1. The placeholder misses C1 control characters. recordAgainCommand replaces only C0 and DEL. A POSIX destination containing U+0085 (NEXT LINE) or U+009B is accepted, emitted literally in the quoted --save-script value, and kept by collapseWarningText. The guide promises <path> for any control character. Please test /[\u0000-\u001f\u007f-\u009f]/ (or a Unicode control-character class) in recordAgainCommand, and add a C1 case next to the newline test.
  2. An in-flight delivery can still warn after retirement. replay-e2e.md:88 says a close that retired the record first leaves an older version with no warning. But if a revision 2 download is already running when a close commits revision 3 and retires the record, and the revision 2 fetch then fails, publishScriptVersion keeps the fetch failure and reports scriptDeliveryFailure plus a warning (pinned by the concurrency test at line 254). Please scope the silent case to offers whose record is already retired when the client decides whether to stage them, and say that a failed in-flight download still reports its delivery failure.

Not blocking:

  • The newline destination test at daemon-artifacts-script-entry.test.ts:564 also runs on Windows, where entry-name.ts:124 refuses control characters in the final name, so revision 1 never commits there. Please skip it off POSIX.
  • The recovery example names only --save-script and --force. A recording opened with an app, a URL or an explicit device needs those arguments again, so "reuse your original open command with --save-script=<path> --force" would be clearer.
  • ADR 0016 line 229 and the ledger rationale still say a repeat reports the destination "as the caller spelled it". Use the stored-absolute wording the guide now has.
  • The CLI close text test at cli-output.test.ts:290 renders the already-fixed warning, so it passes on the old code too. Feed it the old quoted-newline warning, or drop it.

…he repeat docs

- The record-again hint names <path> for a C1 control character too,
  and says to reuse the original open command, since its app, URL and
  device arguments are needed again.
- The replay guide limits the silent case to offers whose record is
  already retired at the staging decision; a failed in-flight download
  still reports its delivery failure.
- ADR 0016, the ledger rationale and a doc comment describe repeats as
  reporting the stored absolute destination.
- The control-character destination tests skip off POSIX, and the CLI
  close text test that passed on the old rendering is dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. Both gaps and all four recommended items are in 1925845.

  1. C1 controls: the record-again hint now names <path> for C0, DEL and C1 (U+0080–U+009F). oxlint's no-control-regex refuses a literal control-character class, so the check is the equivalent character-range test instead of a regex. The newline test is now a table with U+0085 and U+009B cases next to the newline case. With the check limited to C0 and DEL, both C1 cases fail.
  2. Silent case: replay-e2e.md now says an offer whose record a close has already retired, when the client decides whether to stage it, gets no warning. It also says a download already running that then fails still reports its scriptDeliveryFailure and warning, as the concurrency test pins.

Recommended:

  • Windows: the control-character destination tests skip on Windows, where the name rule refuses control characters.
  • Recovery wording: the closing hint now says "reuse your original open command with --save-script=<path> --force". The script_target_exists hint says the same, and the guide adds that the app, URL and device arguments are needed again. The scripting help is aligned.
  • Stored-absolute wording: ADR 0016 and the publishScriptVersion ledger rationale now say a repeat reports the stored absolute destination, and so does the committedRepeat doc comment. No digest moved.
  • cli-output.test.ts: dropped. Feeding it the old quoted-newline warning would fail on the current code too, because the renderer does not unquote, so it could not tell the two versions apart. The remote table is the regression test.

Validation: the remote, host-kit, command-output, wire-compat and eager-closure suites passed (2226 tests), plus the CLI entry and router tests. Typecheck, lint, fallow audit --base origin/main, check:production-exports and check:agent-guidance are clean.

#4746 is rebased onto this head and stays move-only, with the ADR line commit on top.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At 1925845 both items from the previous review are in: the record-again hint uses <path> for C0, DEL and C1, with U+0085 and U+009B cases, and the guide limits the silent case to an already-retired record while a failed in-flight download still reports. The recommended items are in too. All 217 ledger digests and 73 acknowledgements match, and CI passes. One small gap remains, so no label yet:

The first sentence of the repeat warning prints the raw destination. At session-script-destination.ts:335, repeatedVersionText puts the literal destination before the recovery arguments. A valid POSIX name containing ESC[8m saves normally, and the CLI warning renderer (output-common.ts:136) keeps the escape sequence, so a terminal that honors SGR conceal hides the rest of the warning, including the <path> recovery hint. The new control-character tests currently require the raw character in that sentence. Please escape C0, DEL and C1 characters in the displayed destination (for example as \x1b), keep savedScript exact and the <path> placeholder, and assert that the rendered closing warning shows the recovery text with no literal control characters.

Not blocking:

  • ADR 0016 line 229 and the comment at line 719 say nothing about the staged file is stored, but publishStaged writes its device and inode into publishing.file before the link or rename (lines 651–654) so an interrupted process can recover. Say the content digest was removed and the pending file identity is still recorded.
  • At line 725, a staged file that grows past the cap before the verified open is read for up to 8 MiB plus one chunk before it is refused. The removed digest path refused it from the first fstat. Keeping a pre-read size check next to the streamed size and identity checks would restore that.

- The repeat warning shows C0, DEL and C1 characters in the destination
  escaped (for example \x1b), so a name with an escape sequence cannot
  hide the recovery hint; savedScript keeps the exact path.
- The staged-file check refuses a file already over the cap from its
  size, before reading it.
- ADR 0016 and the check's comment say no content digest is kept and
  the pending file identity is recorded until the commit settles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. The gap and both recommendations are in da315b7.

  1. Escaped destination in the warning: repeatedVersionText now shows the destination with C0, DEL and C1 characters escaped as \xNN, so ESC[8m reads \x1b[8m and can't conceal the recovery text. savedScript stays exact, and the hint keeps the <path> placeholder. The control-character table now includes an SGR conceal case next to newline, U+0085 and U+009B. Each case expects the escaped path in the warning, the hint text, the exact savedScript, and no literal C0, DEL or C1 character anywhere in the warning. Printing the raw destination fails all four cases. The replay guide mentions the escaping.
  2. Stored-identity wording: ADR 0016 and the staged-check comment now say no content digest is kept, and that the record names the staged file's device and inode only while its commit is pending, so an interrupted process can settle it.
  3. Pre-read size check: the staged-file check refuses a file whose opened size is already over the cap, before reading it. The over-cap staged test now asserts zero readSync calls, and removing the check fails it.

Ledger: no digest moved.

Validation: the remote, host-kit, command-output, wire-compat and eager-closure suites passed (2235 tests), plus the CLI help test. Typecheck, lint, fallow audit --base origin/main, check:production-exports and check:agent-guidance are clean.

#4746 is rebased onto this head and stays move-only, with the ADR line commit on top.

@thymikee

Copy link
Copy Markdown
Member Author

At da315b7 the repeat warning escapes control characters in the destination, savedScript stays exact, an over-cap staged file is refused before any read, and the ADR wording is fixed. The locked repeat and interruption decisions and all 217 ledger digests check out.

The same raw-path problem still shows up on other text surfaces, so no label yet:

  • Delivery failures. scriptDeliveryFailure builds its text from the raw destination at line 822, line 834 (script_target_exists) and line 841 (script_download_failed). With a name containing ESC[8m, a collision after the vacancy probe, or a failed final save, hides the rest of the line, including the --save-script=<path> --force hint.
  • Preflight refusals. The remote open vacancy error (verified-file.ts:156) and the ancestry refusal text (script-destination-refusal.ts:71 and :92) print raw paths too.
  • close --level full. That path skips serializeCloseResult (generic.ts:51) and JSON.stringifys savedScript. JSON.stringify escapes C0 but emits C1 literally, so both the text and --json output carry a raw U+009B. The guide (replay-e2e.md:87) also says CLI close JSON omits savedScript, which is not true at this level.

Escaping each message as it is found keeps missing sites. Please do it once at the CLI output boundary instead. Have the warning and error text renderer (collapseWarningText and the error printer in output-common.ts) show C0, DEL and C1 as \xNN for every message, and have the CLI JSON writer escape DEL and C1 (\u009b). That covers every current and future message that names a path, including the host-kit refusals. It also lets displayedPath go, because the boundary does that job. Structured fields keep the exact value, since escaped JSON round-trips. Then either document what close --level full returns or apply the documented close projection there. Add one rendered-output test each for a delivery-failure warning, a preflight refusal, and close --level full in text and --json.

Not blocking: the control-character table skips every row on Windows, but entry-name.ts:80-83 only rejects characters below U+0020 there, so the U+0085 and U+009B rows could still run on Windows.

@apex-sentinel-staging

This comment has been minimized.

- The CLI warning and error renderer shows C0 (except newline and tab),
  DEL and C1 characters as \xNN, so any message that names a path,
  including delivery failures and host-kit preflight refusals, cannot
  drive the terminal.
- The CLI JSON writer escapes DEL and C1 as \uNNNN, which
  JSON.stringify leaves raw; output stays valid JSON and parses to the
  exact values. close --level full uses the same writer for its text.
- The remote repeat warning no longer escapes its own path: structured
  fields keep the exact value and the boundary does the escaping.
- The replay guide says close --level full prints savedScript, and
  describes the boundary escaping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. Escaping now happens once at the CLI output boundary, in 52bde73.

  • Text: escapeControlCharacters in output-common.ts shows C0 (except newline and tab, which are layout), DEL and C1 as \xNN. collapseWarningText applies it to every response warning. formatHumanError applies it to the summary and each body line, so it covers the error message, hint, cause and run warnings. That includes host-kit refusals such as the vacancy error and the ancestry refusals.
  • JSON: stringifyJson in src/commands/output/json.ts escapes DEL and C1 as \uNNNN, which JSON.stringify leaves raw. printJson uses it. These characters can only appear inside strings, so the output stays valid JSON and parses to the exact values.
  • Per-site escaping removed: displayedPath is gone. The remote response keeps the exact path in savedScript and in the warning text, and only the boundary escapes.
  • close --level full: I picked the docs change. The leveled path now prints through the same stringifyJson for both text and --json. replay-e2e.md says that at the default level the CLI open/close JSON omits savedScript, while close --level full prints the full close result with savedScript. That keeps --level full consistent with every other command's leveled output, instead of adding a close-only projection.
  • Rendered-output tests: each fails when its boundary escape is removed.
    • A delivery-failure warning (ESC[8m and U+0085 in the path) is rendered through the CLI close formatter.
    • A preflight-style refusal (ESC[8m and U+009B in the message and hint) goes through formatHumanError.
    • close --level full with U+009B and DEL in savedScript runs through the generic CLI path, in text and --json. The test asserts escaped output, no raw C1 or DEL, and an exact parsed savedScript.
  • Optional, done: the U+0085 and U+009B rows of the remote table run on Windows too. Only the rows below U+0020 (newline, ESC) skip there.

Ledger: no digest moved, and the eager-closure check stays green.

Validation: the src, command-output, remote, host-kit, client, wire-compat and eager-closure suites passed (19,108 tests). Typecheck, lint, fallow audit --base origin/main, check:production-exports and check:agent-guidance are clean.

#4746 is rebased onto this head and stays move-only, with the ADR line commit on top.

@thymikee

Copy link
Copy Markdown
Member Author

At 52bde73 escaping lives in one shared renderer: collapseWarningText and formatHumanError show C0, DEL and C1 as \xNN, the CLI JSON writer escapes DEL and C1, and response fields stay exact. That is the right design, and the paths it covers (response warnings, error summaries and body lines, host-kit refusals, close --level full) are correct. All 217 ledger digests match.

Some CLI formatters still write warning text without going through it, so no label yet:

  • Default open. management/output.ts:102 pushes Warning: ${warning} raw. The dispatcher then compares its escaped copy with that raw line, finds no match, and appends a second, escaped copy, so the raw line still reaches stdout.
  • snapshot and snapshot diff. snapshot.ts:323 inserts raw warnings into the notices, and diff.ts:23 writes those notices through its own handler.
  • screenshot. screenshot.ts:33 joins result.warnings raw at the default level (lines 48-49). At --level full without --json it uses native JSON.stringify, which leaves DEL and C1 raw in warnings, savedScript and artifact paths.

Each round has found another formatter that skips the renderer, so please close this at the one point every formatter shares: the CLI's stdout and stderr write. Escape C0 (except newline and tab), DEL and C1 there, and every formatter, current and future, is covered. Keep the renderer only for the warning folding and layout it already does. If text output must keep some control characters on purpose, add a narrow raw-write escape hatch for that call. Add one end-to-end test per surface above (default open with a failed delivery, snapshot with a delivery warning, screenshot at default and --level full) asserting that a single escaped warning reaches stdout.

Not blocking:

  • error.ts:163 builds a JSON details dump, and line 70 then escapes it as text, so a failed batch with U+009B in error.details.warnings prints \x9b inside a JSON block, which no longer parses. Serialize that block with the CLI JSON writer (\u009b) instead.
  • replay-e2e.md:88 says every C0 character is escaped, but tabs and error-body newlines are kept and warning lines fold newlines to spaces. Document those layout rules next to the exact-JSON note.

…ion change

Terminal-safe CLI output is an independent invariant for every command,
so it moves to its own change. This restores the CLI warning and error
renderer, the CLI JSON writer and their tests, and drops the replay
guide sentences about CLI-wide escaping and close --level full. The
remote warning keeps the exact path, and the record-again hint keeps
its <path> placeholder for control characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

At b673232 the CLI output-layer escaping is gone, and the remote, host-kit and docs scope matches what was reviewed before: exact savedScript and warning text, the <path> placeholder for C0, DEL and C1, the locked repeat and interruption decisions, the pre-read size check, and the dev/ino wording. A second, independent correctness pass agrees, and CI is green.

One docs line needs to go back to its earlier scope before the label:

  • close --level full does carry savedScript. replay-e2e.md:87 now says the CLI close JSON output does not carry savedScript. But generic.ts:46-51 prints the leveled close result verbatim, and the remote client adds savedScript to it (session-script-destination.ts:233), so close --level full prints it in text and with --json. Please restore the 52bde73 scoping without the escaping clause: at the default level the CLI open and close JSON output and the Node SDK open result do not carry savedScript, while close --level full prints the full close result, savedScript included.

Not blocking: the comment at daemon-artifacts-script-entry.test.ts:590 still says the CLI output boundary escapes control characters, and the PR body still has the CLI output boundary paragraph, the old file count and validation at 52bde73. Updating both, and linking the terminal-safe-output PR once it is open, would keep the record straight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 81fbe88

Since the review of b673232: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (0ba31d87a14d).

💬 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

This PR is ready at 81fbe88. The delta from b673232 is the two lines asked for: replay-e2e.md scopes savedScript again (absent from the CLI open and close JSON at the default level, printed by close --level full), and the stale test comment now describes the exact response path. The remote and host-kit code is unchanged from b673232, which the line-by-line review and the second, independent correctness pass both cleared apart from this docs line. All checks are green, and there are no conflicts.

Terminal-safe CLI output (escaping control characters in what the CLI prints) is tracked in a separate PR, so this one keeps savedScript and the warning text exact.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. Per our review scope rule, terminal-safe output for every CLI command is an independent invariant that predates this PR, so I've split it out:

  • This PR is back to the remote-only simplification. b673232 took out the CLI renderer and JSON writer escaping and their tests. 81fbe88 restores the close --level full note in replay-e2e.md without the escaping clause. Line 87 now says the default-level CLI open/close JSON omits savedScript, while close --level full prints the full close result, savedScript included. I also fixed the stale test comment. savedScript and the warning keep the exact path, and the record-again hint keeps its <path> placeholder. 16 files.

  • fix(cli): escape control characters at the CLI's stdout and stderr writes #4778 (fix/cli-terminal-safe-output, from main) escapes at the CLI's stdout/stderr writes, as you proposed:

    • text shows C0 (except newline and tab), DEL and C1 as \xNN;
    • JSON escapes DEL and C1 as \uNNNN and parses back exact;
    • colored diff and proxy output escapes its own values and uses a narrow raw path, as does the CDP passthrough;
    • default open no longer duplicates a multi-line warning, and the error details block uses the JSON serializer.

    It adds one end-to-end test per surface: open, snapshot, snapshot diff with color off and on, screenshot at default and --level full, close, an error, and --json.

#4746 is rebased onto 81fbe88 and stays move-only, with the ADR line commit on top.

@thymikee
thymikee merged commit 84dbfe3 into main Nov 19, 2026
21 of 23 checks passed
@thymikee
thymikee deleted the fix/script-repeat-from-record branch November 19, 2026 18:25
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.

1 participant