[Bug]: t3 repeatedly crashing on long thread, says it is network connectivity, but is actually do to unbounded query caused by Backend OOM crash when loading a thread with large tool-activity history #5351
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/server
Steps to reproduce#
- Accumulate a large amount of tool activity in a single thread, especially large command output, file reads, diffs, or other
tool.completedpayloads. - Quit and reopen T3 Code, or navigate back to the large thread.
- T3 loads the complete thread detail, including every activity payload.
- Backend memory grows to approximately 3.4–3.6 GiB.
- V8 aborts the backend with
JavaScript heap out of memory. - The UI reports a generic connection/setup failure.
In my case, the affected thread was also still marked running, so it continued accumulating activity until T3 Code was fully stopped.
Expected behavior#
Loading a large thread should not materialize its complete activity history in one operation.
The server should:
- Return only the newest bounded activity window, with a
hasMoreActivitiesindicator. - Paginate or lazy-load older activity.
- Avoid selecting/decoding large
payload_jsonvalues until requested. - Preserve unresolved approvals and user-input requests even when truncating history.
- Avoid prewarming complete details for hidden or archived threads.
- Consider externalizing or otherwise bounding unusually large tool results.
Messages and checkpoints can remain complete because they are not the dominant data here.
Actual behavior#
The server trace shows this unbounded query:
SELECT
activity_id AS "activityId",
thread_id AS "threadId",
turn_id AS "turnId",
tone,
kind,
summary,
payload_json AS "payload",
sequence,
created_at AS "createdAt"
FROM projection_thread_activities
WHERE thread_id = ?
ORDER BY
CASE WHEN sequence IS NULL THEN 0 ELSE 1 END ASC,
sequence ASC,
created_at ASC,
activity_id ASC
### Impact
Major degradation or frequent failure
### Version or commit
_No response_
### Environment
_No response_
### Logs or stack traces
```shell
The database is large but valid:
state.sqlite size: 1,747,128,320 bytes
PRAGMA quick_check: ok
orchestration_events: 797.2 MiB
projection_thread_activities: 710.4 MiB
One thread accounts for:
Projected activities: 60,522 rows
Projected payload size: 321.6 MiB
Largest projected payload: 1.2 MiB
thread.activity-appended: 60,568 events
Event payload size: 337.0 MiB
tool.completed activities: 16,581 rows
tool.completed payload size: 310.9 MiB
Projected messages: 2,525
Total message text: 0.84 MiB
This means the actual conversation text is small. Almost all of the size comes from tool-activity payloads stored in both the projection and event log.
`StatementSync.all()` first materializes hundreds of megabytes of strings and row objects. JSON decoding/schema validation and the thread snapshot then multiply the retained heap enough to exceed V8's limit.
### Expected behavior
Loading a large thread should not materialize its complete activity history in one operation.
The server should:
- Return only the newest bounded activity window, with a `hasMoreActivities` indicator.
- Paginate or lazy-load older activity.
- Avoid selecting/decoding large `payload_json` values until requested.
- Preserve unresolved approvals and user-input requests even when truncating history.
- Avoid prewarming complete details for hidden or archived threads.
- Consider externalizing or otherwise bounding unusually large tool results.
Messages and checkpoints can remain complete because they are not the dominant data here.
### Related work
PR #5147 fixed two other OOM paths: stale-cursor global event replay and full-database snapshot hydration:
https://github.com/pingdotgg/t3code/pull/5147
This report is a different remaining path: direct thread-detail hydration through `listThreadActivityRowsByThread` / `getThreadDetailById`.
A previous proposed fix capped initial history at the newest 500 activities, but that PR was closed without merging:
https://github.com/pingdotgg/t3code/pull/4948
I also checked `v0.0.32-nightly.20260804.998`; its per-thread activity query still uses `SqlSchema.findAll` without a `LIMIT`, so updating to that nightly does not resolve this particular crash.
### Workaround
Increasing `--max-old-space-size` may allow the thread to load temporarily, but does not fix the unbounded query.
The reliable local workaround is to:
1. Fully stop T3 Code and its backend/provider children.
2. Make a verified SQLite backup.
3. Remove the affected thread's projected activity rows and corresponding `thread.activity-appended` events.
4. Stop its stale running session.
5. Checkpoint and `VACUUM` the database.
This preserves the thread's messages and filesystem/worktrees but removes its tool-activity timeline.
### Diagnostics available
I can provide:
- The macOS `.ips` crash report.
- A sanitized `server-child.log` excerpt containing the V8 OOM.
- A sanitized trace containing the exact SQL query.
- Aggregate SQLite counts and payload lengths.
I cannot provide the complete SQLite database because its tool payloads may contain private source code, command output, paths, or credentials.
Attach the `.ips` crash report if possible, but inspect and sanitize logs before uploading. Do not attach `state.sqlite`; it contains conversation and tool-output data.
Screenshots, recordings, or supporting files#
No response
Workaround#
No response
ahansen1234(GitHub profile, opens in a new tab) added labelsbug
ahansen1234(GitHub profile, opens in a new tab) added labelsneeds-triage
ahansen1234(GitHub profile, opens in a new tab) changed the title
juliusmarminge closed this
Sign in to join this conversation.