Skip to content

fix(server): stop large thread history from exhausting memory - #4948

Closed
t3dotgg wants to merge 1 commit into
mainfrom
t3code/review-fix-plan
Closed

fix(server): stop large thread history from exhausting memory#4948
t3dotgg wants to merge 1 commit into
mainfrom
t3code/review-fix-plan

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Jul 30, 2026

Copy link
Copy Markdown
Member

Large retained threads can exhaust the server heap when their activity history is hydrated, when the compatibility snapshot endpoint reads every thread body, or when a stale client cursor replays the global event log without a bound.

This keeps initial thread detail to the newest 500 work activities while preserving unresolved approval and user-input requests. It switches project resolution to the lightweight command read model, caps reconnect replay at 1,000 events with a projected snapshot fallback, and stops prewarming hidden sidebar thread details. Web and mobile show a small notice when older work activity is omitted. Messages and checkpoints remain complete.

This intentionally defers older-activity pagination. Based on the server work and investigation in #3510 by @olafura.

Fixes #2761. Addresses #996.

Verification:

  • 278 focused tests across server, CLI, contracts, web timeline, and sidebar logic
  • targeted typechecks for contracts, server, web, and mobile
  • targeted lint, formatting, and mobile static checks

Built by gpt-5.6-sol in the Codex harness through T3 Code.


Note

High Risk
Changes core projection hydration, snapshot HTTP behavior, and thread WebSocket catch-up—areas that affect memory, reconnect correctness, and whether actionable approvals/user-inputs appear outside the activity window.

Overview
This PR caps memory and reconnect cost for threads with very large activity histories.

Server read model: getThreadDetailById now returns only the latest 500 work activities (plus pinned unresolved approval/user-input rows outside that window) and sets optional hasMoreActivities when older items exist. Messages and checkpoints stay fully loaded.

Compatibility snapshot: The orchestration /snapshot HTTP endpoint and project CLI offline path now use getCommandReadModel() instead of hydrating every thread body.

WebSocket reconnect: subscribeThread bounds event replay to the projection head (max 1,000 events); stale cursors get a fresh thread detail snapshot instead of unbounded readEvents replay.

Clients: Web and mobile show “Earlier work activity not shown” when bounded; the web sidebar stops prewarming hidden thread-detail subscriptions. Contracts add optional hasMoreActivities on thread payloads.

Reviewed by Cursor Bugbot for commit 1c3bf90. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Limit thread history to 500 activities to prevent memory exhaustion on large threads

  • Thread detail queries in ProjectionSnapshotQuery.ts now window activity to the 500 most recent items, with a hasMoreActivities flag set when older items exist.
  • Unresolved pending approvals and user-input requests outside the window are pinned via a separate SQL query so actionable items remain visible.
  • WebSocket thread subscriptions in ws.ts now bound catch-up replay to the captured projection head; stale cursors trigger a full snapshot replacement instead of unbounded replay.
  • The sidebar no longer prewarms thread detail subscriptions for visible threads — subscriptions are created only on navigation.
  • Web and mobile UIs show an 'Earlier work activity not shown' header and suppress the empty-state placeholder when hasMoreActivities is true.
  • Behavioral Change: clients on pre-windowing servers will not receive hasMoreActivities and will continue to see full history; the field is optional in the contract for compatibility.

Macroscope summarized 1c3bf90.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 89143f16-ec72-4b85-88a8-7499acda4b8b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Jul 30, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a significant runtime behavior change that limits thread activity history to 500 items to prevent memory exhaustion. Users with large threads will see truncated history with an indicator. The change also removes sidebar thread prewarming and adds complex pinned-activity logic to preserve actionable items. Human review recommended due to the user-visible impact.

You can customize Macroscope's approvability policy. Learn more.

@t3dotgg
t3dotgg force-pushed the t3code/review-fix-plan branch from c8e508e to 122963a Compare July 30, 2026 09:22
Comment thread apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
@t3dotgg
t3dotgg force-pushed the t3code/review-fix-plan branch from 122963a to 450b199 Compare July 30, 2026 09:33

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 450b199. Configure here.

Comment thread apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts Outdated
@t3dotgg
t3dotgg force-pushed the t3code/review-fix-plan branch from 450b199 to 1c3bf90 Compare July 30, 2026 09:42
@t3dotgg

t3dotgg commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

This is slop

@t3dotgg t3dotgg closed this Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Degraded performance of the remote webapp on large threads.

1 participant