Repository navigation
refactor(session): simplify archive write locking - #1375
Conversation
|
@SaulMoro All CI checks have passed. Could you please review this PR when you have a chance? This keeps the change scoped to the remaining items in #1325:
The five archive writers remain self-locking, readers remain lock-free, and the existing user-facing busy diagnostics are preserved. Thank you! |
|
No findings in the specified PR diff. The PR description satisfies the testing requirement: it records a build and a representative real-CLI run where Review was read-only; I did not run, build, or install PR code. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
@XY-code1 Approving at ea4ca4a. Every archive writer now takes the lock once, itself: session push, migrate --push, pull and pull --all, the push/pull merge step and workflow publish --sessions. Nothing calls a writer while holding the lock, and each caller checks for busy before using the result. With the built CLI, on this head and on a build of main (f3cd042), the outputs, exit codes and remote files match after normalizing paths: two concurrent migrate --push writers; migrate --push and pull --all against a held lock (both exit 1 and write nothing); session push with the lock held throughout (exits 1 after about 11 s) and with it released after 3 s (exits 0, "Pushed 2 session(s)", distinct file names for two sessions with the same title and day). tsc, lint and the changed unit files pass, and the new tests fail on main, including rejects inherited object keys. The session-archive-lock, session-publication and workflow-publish-resume e2e files pass.
- [P2 non-blocking]
docs/dev/agent-sessions.md:17still says a command holding the lock can call these writers again without acquiring it. This PR removes that path, so a caller following the doc would wait about 10 s and getbusywrapped in adoneresult. No current code does this. Suggested replacement for those two sentences: "Each takes the lock itself and returns{ status: 'written' | 'busy' }; do not wrap them inwithSessionIndexLock, which is not re-entrant." - [P3 nit] The
sessionPlatformFactsfix is reachable from more than the issue suggests: workflowtoolstrings from lease files reachplatformForTool(handoff.ts:300,local-driver.ts:511,scoring-evidence.ts:132) checked only as non-empty, and that seam has no test. A cast remains there,deleteSession's signature changed with no caller needing it, and the renamed concurrency test passes even with the lock removed (the kept wait test still covers it).
The CI review reports no findings. We agree that nothing blocks, and add the stale doc sentence it did not mention. All CI jobs pass; the GitHub-provider job is skipped by the fork policy.
jeff-r2026
left a comment
There was a problem hiding this comment.
Reviewed and verified on latest main (f3cd042) stacked with the other PRs in this batch: tsc / lint / build pass, related unit and E2E tests pass.
Summary
written | busyresult and remove every redundant externalwithSessionIndexLockwrapperAsyncLocalStoragere-entry path that existed only for nested lockingsessionPlatformFactswithObject.hasOwnType of Change
Test Plan
npx tsc --noEmitpassesnpm run lintpassesnpx vitest runpassesVerified with:
npm run typechecknpm run lint -- --max-warnings=0npm run buildteamai session pushexited 0 and wrote exactly one archived JSONLThe broad Windows test run also exposed pre-existing platform-specific fixture failures (path separator / Git checkout cleanliness), so this PR does not claim the full suite passed locally; hosted CI remains the cross-platform authority.
Related Issues
Closes #1325
Notes for Reviewers
The shared state is the
sessions/archive and its indexes. All five archive writers (saveSession,rebuildIndex,rebuildAllIndexes,commitRebuiltIndexes,deleteSession) still acquire the same lock internally. Readers remain lock-free. Callers now consume the self-locking method result directly, so there is one busy path and no lock re-entry state.