fix(remote): end a closed script record even when its staging cannot be removed
Merged
TH
14h ago+196+196+012345678901234567890123456789-17-17-01234567890123456789
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
retiredbefore 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
finallyblock, 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](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.