Skip to content

fix(remote): end a closed script record even when its staging cannot be removed - #4586

Merged
thymikee merged 5 commits into
mainfrom
fix/remote-script-retire-inert
Nov 16, 2026
Merged

thymikee merged 5 commits into
mainfrom
fix/remote-script-retire-inert

Conversation

@thymikee

@thymikee thymikee commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Problem

A remote close retires the client record for its open --save-script publication. 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

  • The record is written retired before any cleanup. A retired record authorizes no version: publishing, staging allocation and the final rename all read it as absent.
  • Staging cleanup and record removal follow. If they fail, the retired record stays until the stale sweep finishes the cleanup.
  • If the record cannot be written retired, it is removed at once, so a failed write never leaves it authorizing a version.
  • Retirement runs in a finally block, so the close keeps its first error.
  • ADR 0016 states the rule.

Tests

  • A close whose staging directory cannot be removed: a later version for the same publication is dropped and the file keeps its content. This fails on main.
  • A close that cannot write the retired record: the record is removed and a later version is dropped. This fails without the fallback.

🤖 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

…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>
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.32 MB 6.32 MB +416 B
Package (unpacked) 6.32 MB 6.32 MB +416 B
Package (download) 1.92 MB 1.92 MB +96 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 32.2 ms 33.8 ms +1.6 ms
CLI --help 61.8 ms 67.3 ms +5.5 ms

… active

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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-staging

apex-sentinel-staging Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 2 no longer raised (2 marked fixed)

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (36dbd2616fc6).

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

Earlier reviews

Review of 9f5fba3d · 16.11.2026 12:57 UTC

Apex Sentinel · ✅ Approve

2 finding(s): 2 minor.

🟡 Minor (2)

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

@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 9f5fba3. The verdict and the full list are in the summary comment.

thymikee and others added 2 commits November 16, 2026 14:00
…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>
@thymikee

Copy link
Copy Markdown
Member Author

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.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 16, 2026
@thymikee
thymikee merged commit 1b3ea98 into main Nov 16, 2026
21 checks passed
@thymikee
thymikee deleted the fix/remote-script-retire-inert branch November 16, 2026 14:22
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