Make session operations independent of transcript history - #76
Conversation
There was a problem hiding this comment.
💡 Codex Review
pi-web/server/session/service.ts
Line 853 in 3c26547
After a server restart, a URL containing the ID of a session created in a non-global working directory returns 404 because knownCwds() initially contains only the global cwd and the URL carries no cwd. The removed SessionManager.listAll() fallback previously supported this documented bookmark/copied-link flow; the filename scan therefore also needs a bounded fallback across all workspace session directories rather than stopping after the process-local known set.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let sessionName: string | undefined; | ||
| let firstMessage: string | undefined; | ||
| for (const entry of entries) { | ||
| if (entry?.type === "session_info") sessionName = typeof entry.name === "string" && entry.name ? entry.name : undefined; |
There was a problem hiding this comment.
Preserve renames that fall outside the bounded windows
For a cold session renamed after its first 32 KiB and followed by more than 8 KiB of transcript, the authoritative session_info entry is in the unread middle of the file. This loop consequently reports an older head-window name or no name at all, so a renamed session reverts in the drawer after restart; the latest name needs storage or indexing that remains accessible without parsing the transcript body.
Useful? React with 👍 / 👎.
|
Reviewed against the #74 contract — this is the right shape: Phases 1–2 with no worker and no cache, a net-simpler hot path, and CI is green. Requesting the following before merge; all four are small. 1. Narrow the The filename-suffix path returns 2. Record the accepted semantic deltas in the PR description These match the #74 contract but should be documented as deliberate:
3. Comment the head/tail boundary loss ( An entry straddling the 32 KiB head cut is silently dropped — including the contiguous 32–40 KiB case, where the tail's "discard first partial line" throws away the continuation of the head's last line. 4. Don't let The acceptance list in #74 includes tests this PR doesn't add:
Either add them here or split them into a follow-up issue and reference it from #74 before this auto-closes — otherwise the budgets exist only in prose. Also worth a deploy note: after merge, restart the supervised child on the long-running instance and re-measure |
|
Addressed in
Also addressed the Codex review: unknown bookmarked session IDs now fall back to scanning workspace directory names and filename suffixes, then perform one bounded read of the matching header to recover/validate cwd. This restores post-restart copied-link discovery without parsing transcript bodies. Validation after the changes: typecheck passed; 65 focused tests passed. |
|
Correction to my previous response: the requested regression coverage is now included in this PR at |
|
Re-reviewed at
Also good catch on the regression my first pass missed: dropping One optional nit, non-blocking: the source-text assertions in Merge-ready from my side. Post-merge on the long-running instance: |
Summary
SessionManager.list()in the interactive list path with bounded shallow JSONL projectionsThe shallow lister reads at most a 32 KiB head and 8 KiB tail from each session, so list cost depends on directory entry count rather than accumulated transcript bytes.
Deliberate semantic deltas
modifiedis file mtime, so metadata writes such as rename/model changes can slightly affect ordering.firstMessagehas whitespace collapsed rather than preserving upstream raw whitespace.messageCountis omitted for cold sessions because calculating it requires parsing the transcript body; live sessions retain an exact count.Closes #74
Validation
npm run typechecknpm run buildnpx vitest run tests/shallow-session-list.test.ts tests/session-list-lifecycle.test.ts tests/session-refresh-contract.test.ts tests/session-service.test.ts tests/api.test.ts(69 passed)npm testwas run until the 300-second harness timeout; completed suites passed, with unrelated retried/flaky artifact-preview and Git E2E cases and no session-related failuresDeploy follow-up
After merge, restart the supervised child on the long-running instance and re-measure
/api/sessionsTTFB and pinned-tab switching against #74 (warm list p95 <100 ms; trivial endpoints p95 <50 ms during refresh).