fix(session): rebuild index on boot to find missing sessions - #1390
Conversation
- persist workDir into state.json so session dirs are self-describing and summaries do not depend on the index's one-way-hashed workDir - relax readSessionIndex so a stale or non-absolute index workDir no longer drops an otherwise valid entry - serialize in-process index appends to avoid torn jsonl lines - add SessionStore.reindex() and run it once at server boot so the scan-free request path can find sessions whose index line is missing or stale
🦋 Changeset detectedLatest commit: f6f9d3f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bb3712a2f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (resolve(sessionDir) !== resolve(expectedDir)) continue; | ||
|
|
||
| const existing = index.get(id); | ||
| if (existing !== undefined && resolve(existing.sessionDir) === resolve(sessionDir)) continue; |
There was a problem hiding this comment.
Repair entries even when only workDir is stale
When an existing index line already points at the correct sessionDir but has a stale or bogus workDir (the kind of entry readSessionIndex now intentionally keeps), this early continue prevents boot reindex from appending the recovered workDir. That leaves legacy sessions whose state only has custom.cwd without a top-level workDir still using entry.workDir in summaryFromDir, so list/resume/fork can continue to use the wrong cwd even after the rebuild; the skip should also compare the recovered workDir before treating the entry as healthy.
Useful? React with 👍 / 👎.
Related Issue
No linked issue; the problem is described below.
Problem
Some sessions that still exist on disk (and that the TUI can see and resume) are missing from the web session list, and opening them directly by session id returns 404. Forking such a session in the TUI makes the new id accessible again.
Root cause: the server's session list/detail path reads only the global session index and does not fall back to scanning directories. If a session's index line is missing or invalid (e.g. never written, home-dir relocation, or a torn line from concurrent appends), the server cannot find it — while the TUI, which scans the per-workdir directory directly, still can. Forking rewrites a fresh, valid index line, which is why it masks the bug.
What changed
workDirintostate.json, and read summaries from there. This is required because the bucket directory name is a one-way hash of the workDir, so a disk-only rebuild cannot recover it otherwise; it also removes a class of index invalidation caused by home-dir relocation.workDir, and serialize in-process index appends to avoid torn lines.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.