Skip to content

fix: session detail 404 — use resolveSessionFilePath + parseSessionInfoFromLite - #20

Merged
dahai80 merged 1 commit into
mainfrom
fix/session-detail-404
Jul 30, 2026
Merged

dahai80 merged 1 commit into
mainfrom
fix/session-detail-404

Conversation

@dahai80

@dahai80 dahai80 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Problem

GET /api/sessions/:id always returns 404 even with valid sessionId (see #18).

Root Cause

Two bugs in the handler:

  1. Wrong function signature: readSessionLite(projectDir, sessionId) passes 2 args, but readSessionLite only accepts filePath — the sessionId arg is silently ignored. It tries to read a directory as a file → always null → 404.

  2. Path resolution mismatch: The handler builds the project dir manually (getProjectsDir() + sanitizePath(cwd)), skipping canonicalizePath, findProjectDir, and worktree fallback that listSessionsImpl uses. This causes path mismatches between list and detail endpoints.

Fix

  • Use resolveSessionFilePath(sessionId, cwd) — handles symlink resolution, hash mismatches, and worktree fallback (same logic as listSessionsImpl)
  • Call readSessionLite(filePath) with correct single-arg signature
  • Use parseSessionInfoFromLite() to return the same SessionInfo format as the list endpoint (sessionId, summary, firstPrompt, lastModified, createdAt, gitBranch, cwd, fileSize, customTitle, tag)

Closes #18

🤖 Generated with Claude Code

…foFromLite

The GET /api/sessions/:id handler had two bugs:
1. readSessionLite(projectDir, sessionId) passes 2 args but it only
   accepts filePath — sessionId was silently ignored, so it tried to
   read a directory as a file, always returning null → 404
2. Manual path construction (getProjectsDir + sanitizePath) skips
   canonicalizePath, findProjectDir, and worktree fallback that
   listSessionsImpl uses — path mismatches cause 404 even if the
   file read worked

Fix: use resolveSessionFilePath() for proper path resolution (handles
symlinks, hash mismatches, worktrees), then readSessionLite(filePath)
with the correct single-arg call, then parseSessionInfoFromLite() to
return the same SessionInfo format as the list endpoint.

Closes #18

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@dahai80
dahai80 merged commit 292c8d7 into main Jul 30, 2026
1 check passed
dahai80 added a commit that referenced this pull request Jul 31, 2026
- feat: session-project association — projectId field + project API + knowledge injection (#21)
- feat: code generation API — POST /api/code/generate (#22)
- feat: LSP operation API — POST /api/lsp/operation (#23)
- fix: session detail 404 — use resolveSessionFilePath + parseSessionInfoFromLite (#20)
- fix: WS chat binary resolution + Buffer handling + error detail
- fix: ServerWebSocket type for Bun.serve WebSocket handlers
- style: normalize formatting in projectApiServer and listSessionsImpl

Co-Authored-By: Claude <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
…ontext (audit §1.1.1 slice #20) (#190)

updateFileHistoryState + updateAttributionState were two 14-LOC methods
inside getToolUseContext with identical structure: same-ref-skip
setAppState wrappers over a top-level slice. Both perf-critical (the
skip avoids notifying all store listeners on every fileHistory no-op).

Extract to a single generic helper applyNestedStateUpdater<K extends
'fileHistory'|'attribution'>(setAppState, key, updater) in
src/utils/nestedStateUpdater.ts. TS infers the slice type from the
literal key, so the REPL thin wrappers carry no inline type literal and
match the ToolUseContext signatures via inference. Same-ref skip
preserved verbatim.

REPL 6386 -> 6361 (-25 net: -27 body +2 wrapper). 19 -> 20 slices,
cumulative -710 -> -735. Byte-identical: downstream reads the same
updateFileHistoryState / updateAttributionState fields on the context.

4 gates: typecheck 0 / bun test src/__tests__/ 902 pass / biome new
files clean (REPL untouched, no autofix churn) / build:dev pass.

Co-authored-by: Claude Fable 5 <[email protected]>
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.

Bug: GET /api/sessions/:id returns 404 Session not found even with valid sessionId and cwd

1 participant