Skip to content

fix: remove tree field from session detail API to prevent stack overflow on long linear sessions - #38

Closed
fallleave001 wants to merge 1 commit into
agegr:mainfrom
fallleave001:fix/session-tree-overflow
Closed

fallleave001 wants to merge 1 commit into
agegr:mainfrom
fallleave001:fix/session-tree-overflow

Conversation

@fallleave001

Copy link
Copy Markdown
Contributor

Summary

Fix HTTP 500 RangeError: Maximum call stack size exceeded when loading a session with 2000+ messages that has never used the /tree branch feature.

Root Cause

GET /api/sessions/[id] includes the tree field from SessionManager.getTree(). For a linear session with no branches, this produces a deeply nested chain where each level contains the next message. With 3523 messages, the tree is 3511 levels deep. NextResponse.json() → JSON.stringify() overflows Node.js's call stack at ~2000 levels.

Fix

Remove tree: m from the response JSON. The tree field is not used by the UI — session list and message content display correctly without it.

Testing

  1. Create a long conversation (2000+ messages) without using /tree branches
  2. Open the session in pi-web — should load normally (was HTTP 500)
  3. Verify all messages are displayed correctly

…low on long linear sessions

sm.getTree() produces a deeply nested chain for long linear sessions
(3000+ messages = 3000-level depth), causing JSON.stringify to overflow
the call stack. The tree field is unused by the UI.
@agegr

agegr commented Jun 4, 2026

Copy link
Copy Markdown
Owner

The stack overflow root cause looks valid, but the fix removes an API field that the UI still consumes for in-session branch navigation. useAgentSession passes data?.tree ?? [] to BranchNavigator, so branched sessions will now appear to have no branches and users lose the ability to switch leaves.

The manual testing only covers long linear sessions. Please also test a session that has used /tree, or replace the recursive tree payload with a non-recursive / lazy branch representation instead of removing the field outright.

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.

3 participants