Skip to content

refactor(session): simplify archive write locking - #1375

Merged
jeff-r2026 merged 1 commit into
Tencent:mainfrom
XY-code1:fix/session-archive-locks
Oct 25, 2026
Merged

jeff-r2026 merged 1 commit into
Tencent:mainfrom
XY-code1:fix/session-archive-locks

Conversation

@XY-code1

Copy link
Copy Markdown
Collaborator

Summary

  • make archive write methods return one explicit written | busy result and remove every redundant external withSessionIndexLock wrapper
  • remove the AsyncLocalStorage re-entry path that existed only for nested locking
  • reject inherited object keys in sessionPlatformFacts with Object.hasOwn
  • preserve existing busy diagnostics for push, pull, migration, workflow archive, and merge-rebuild paths

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature causing existing behavior to change)
  • Documentation only
  • Refactor / internal cleanup

Test Plan

  • npx tsc --noEmit passes
  • npm run lint passes
  • npx vitest run passes
  • Added/updated tests for the change

Verified with:

  • npm run typecheck
  • npm run lint -- --max-warnings=0
  • npm run build
  • focused unit coverage for platform facts, archive locking/concurrency, busy push/pull/migrate handling, and merge rebuilds
  • built CLI fixture: teamai session push exited 0 and wrote exactly one archived JSONL

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

@XY-code1

Copy link
Copy Markdown
Collaborator Author

@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:

  • archive write methods now return one explicit written | busy result;
  • redundant external withSessionIndexLock wrappers were removed;
  • the AsyncLocalStorage lock re-entry path was removed after auditing the write call graph;
  • sessionPlatformFacts now rejects inherited keys with Object.hasOwn;
  • focused regressions cover inherited keys, concurrent public writes, and busy push/pull/migrate paths.

The five archive writers remain self-locking, readers remain lock-free, and the existing user-facing busy diagnostics are preserved. Thank you!

@github-actions

Copy link
Copy Markdown

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 teamai session push exited 0 and wrote exactly one archived JSONL. The disclosed broader-suite failures do not make that record insufficient.

Review was read-only; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:17 still 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 get busy wrapped in a done result. 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 in withSessionIndexLock, which is not re-entrant."
  • [P3 nit] The sessionPlatformFacts fix is reachable from more than the issue suggests: workflow tool strings from lease files reach platformForTool (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 jeff-r2026 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@jeff-r2026
jeff-r2026 merged commit 99fd56c into Tencent:main Oct 25, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session archive: drop redundant index-lock wrappers and own-key the platform facts lookup

3 participants