Repository navigation
fix(remote): end a closed script record even when its staging cannot be removed - #4586
Conversation
…be removed A close removed the staging directories its record listed before removing the record. When a staging directory could not be removed, the record stayed and still authorized later versions, so a delayed or forged response naming the publication could overwrite the caller's file. The record is now written retired before any cleanup, and a retired record authorizes nothing; the sweep finishes its cleanup later. A record that cannot be written retired is removed at once. Retirement runs in a finally block, so the close keeps its first error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Size Report
Startup median (7 runs, lower is better):
|
… active Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
All reported issues were addressed
You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
…f retired Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apex Sentinel · ✅ ApproveSince the last review: 0 new · 0 still open · 2 no longer raised (2 marked fixed) No open findings. 1 finding below 💬 Talking to SentinelIn a finding's thread, reply with:
On this conversation, comment Earlier reviewsReview of
|
| Where | Finding |
|---|---|
packages/remote/src/session-script-destination.ts:260 |
Retiring a stale record refreshes its mtime, so its staging retry waits 7 days |
packages/remote/src/session-script-destination.ts:260 |
removeRecord's rm fallback can throw, masking the write error and skipping staging cleanup |
Reviewed with this repository's own Sentinel configuration (669fa754824f).
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 9f5fba3. The verdict and the full list are in the summary comment.
…te error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not be removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR is ready at 760054c. The code looks right: a closed script record now ends even when its staging cannot be removed, and the new tests cover that path. All 21 checks pass at this head, and there are no conflicts. Nothing else needs to happen before merge. Not blocking, and you can take or leave these: the settleAfter comment at https://github.com/callstack/agent-device/blob/760054c/packages/remote/src/session-script-destination.ts#L133 still says a record that cannot be retired "stays inert", but the ADR says it can stay active, so the comment could say that a retirement failure is logged and never changes the close outcome; the ADR residual at https://github.com/callstack/agent-device/blob/760054c/docs/adr/0016-active-session-script-publication.md#L200 could also name a close that cannot take the record lock, not only a state directory that allows no write; and the double-failure fallback at https://github.com/callstack/agent-device/blob/760054c/packages/remote/src/session-script-destination.ts#L280 could shrink to removing staging only once the record file is gone, leaving the record and its list untouched otherwise. The tests inject the filesystem failures (EACCES, ENOSPC) rather than reproducing them. The earlier review threads no longer need action. The first thread (#4586 (comment)) is now the documented ADR residual, so please resolve it. The other two threads (#4586 (comment) and #4586 (comment)) are fixed at this head, because the tests now assert the retired record and the ok close result. Both remaining threads (#4586 (comment) and #4586 (comment)) were fixed in fbfd5c6, since removeRecord rethrows the original error and the fallback tries each staging directory once. |
Problem
A remote
closeretires the client record for itsopen --save-scriptpublication. Retirement removed the staging directories the record listed, then removed the record. If a staging directory could not be removed, the error stopped retirement and was logged, and the record stayed active. A delayed response, or a daemon that knows the publication ID, could then deliver another version and overwrite the caller's file after the session had closed.Change
retiredbefore any cleanup. A retired record authorizes no version: publishing, staging allocation and the final rename all read it as absent.finallyblock, so the close keeps its first error.Tests
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.