Repository navigation
fix(cli): replace the CLI session and generated remote config instead of rewriting them in place - #4797
Conversation
… of rewriting them in place Both writers truncated the destination and wrote into it, so a concurrent reader could see an empty or partial file. They now publish a complete file through the shared temp-and-rename helper. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Size Report
Startup median (7 runs, lower is better):
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Apex Sentinel: 2 new findings on 045ce74. The verdict and the full list are in the summary comment.
… any umask Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The PR is ready at f880ad6, with no blocking problems in the code. CI is still running (Smoke Tests and Coverage), and none of those jobs has failed. Please wait for them to go green before merge. The diff only touches the auth-session and generated remote config writes, which device smoke routes do not run, and Coverage runs the new unit tests. There are no conflicts. Windows has no CI here: libuv opens files with FILE_SHARE_DELETE, so the rename-over-open-file replace should succeed, but it is not exercised. Not blocking: you can take or leave these. (1) The old chmod in auth-session.ts was wrapped in try/catch, and the exactMode chmod in atomic-publish.ts is not, so login and connect now throw on a state directory whose filesystem rejects chmod with EPERM. That is fine if #4783 admission already refuses those roots. If not, please say in the PR body that the best-effort chmod is gone on purpose. (2) The mode assertions in auth-session.test.ts and auth-session-umask.test.ts are not guarded for win32, unlike the sibling tests, so they would fail on Windows. (3) In auth-session-umask.test.ts the writes and the umask change run before the try/finally, so a throw leaks the temporary directory. Opening the try right after mkdtempForTestSync fixes it. On the earlier threads: the exact-mode one is fixed at this head, since exactMode: true now gives 0600 under umask 0700, so it can be resolved: #4797 (comment). The symlink one does not apply, because rename replacing a linked cli-session.json is the intended #4783 rule and root admission refuses planted links, so it can be resolved too: #4797 (comment). |
…temp dir inside its cleanup Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Apex Sentinel · ✅ Approve · review of
|
| Where | Finding |
|---|---|
src/cli/auth-session.ts:299 |
🆕 Non-best-effort chmod now fails login/connect on filesystems without chmod |
Reviewed with this repository's own Sentinel configuration (74771e19193d).
💬 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.
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 92d5720. The verdict and the full list are in the summary comment.
* origin/main: (70 commits) refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (callstack#4774) fix(android): require acknowledgements for test IME typing (callstack#4722) feat(scroll): add scroll refresh for pull-to-refresh (callstack#4770) refactor(host-kit): add request Scope and use it for the wait capture deadline (callstack#4794) fix(android): let permission all change nothing on an app that declares no permissions (callstack#4796) fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (callstack#4797) fix(host-kit): accept a group-writable script directory the user owns (callstack#4799) fix(cli): escape control characters at the CLI's stdout and stderr writes (callstack#4778) fix(audit): do not report rows under a persistent bar that scrolling reveals (callstack#4775) fix(daemon): refuse an unsafe state directory before first use (callstack#4783) refactor: settle remaining single-deadline races through settleWithin (callstack#4788) refactor(host-kit): settle deadline races via settleWithin with R87 race ratchet (callstack#4766) fix(android): authenticate and bound persistent snapshot helper sessions (callstack#4729) fix(daemon): bound upload ingress and finalization (callstack#4721) chore(gates): ratchet wire-published reason literals by value (R89) (callstack#4779) feat(audit): evaluate role-less clickable views on Android (callstack#4780) fix(mutation): keep umask-setting tests out of Stryker's thread pool (callstack#4785) feat(audit): report controls that share one accessible name (callstack#4771) fix(contracts): pair open runtime hints with their apply operation (callstack#4754) refactor(daemon): report startup progress over the launch channel instead of marker files (callstack#4777) ...
* origin/main: feat(gesture): hold before the move with gesture pan --hold-ms (#4767) docs: clarify device verification and security proposals (#4805) fix(daemon-client): say that a hung daemon is stopped before ensureDaemon starts a new one (#4803) test: remove five timing races from CI (#4800) refactor(remote): save a remote script from memory with the local publisher (#4802) refactor(apple-runner): one RUNNER_ERROR_CODES row per runner error code with parity/docs gates (#4774) fix(android): require acknowledgements for test IME typing (#4722) feat(scroll): add scroll refresh for pull-to-refresh (#4770) refactor(host-kit): add request Scope and use it for the wait capture deadline (#4794) fix(android): let permission all change nothing on an app that declares no permissions (#4796) fix(cli): replace the CLI session and generated remote config instead of rewriting them in place (#4797) fix(host-kit): accept a group-writable script directory the user owns (#4799)
Problem
writeCliSessionandwriteGeneratedRemoteConfigtruncated the destination and wrote into it. A reader that opened the file during the write saw an empty or partial file:readCliSessionreturnsnullfor a partial record, so a command that runs whileauth loginwrites reports that no session exists.connectruns with the same profile write the same path, so one can read the profile while the other has it truncated.The window is small. It matters most on a shared host that runs several agents against one state directory.
Change
Both writers publish through
publishFileSyncfrom@agent-device/host-kit/file(temporary sibling, then rename). This is the rule that #4783 set for sensitive files in the state directory. The best-effortchmodafter the write is deleted: the helper sets the temporary file to exactly0600before the rename (exactMode), under any umask, and an older, wider file is replaced. Thatchmodis no longer best-effort, on purpose: #4783 admits the state directory as an owned, private directory before these writes, so a session file that cannot be made private is now an error and not a silently wider file.Evidence
src/cli/__tests__/auth-session.test.ts: "a rewritten CLI session replaces the file, so a reader never sees a partial record". It also asserts that a0644session file ends with no group or other bits.src/cli/connection/generated-config.test.ts: "a rewritten generated remote config replaces the file, so a reader never sees a partial profile".Size
Production: +12 −12, net 0 lines. No new module on an entry closure, so the built CLI startup cost does not change.
Part of #4649 (follow-up to #4783).
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.