fix(server): bound thread shell-summary reads #7486
main fromfix/bound-thread-shell-summary·opened View on GitHubwhat changed#
- normalize user-input request ids and state transitions when projecting activities
- maintain a one-row pending-input summary per thread through indexed old/new request lookups
- read latest user-message timestamps through a partial covering index
- repair old and new thread owners after destructive activity-id and message-id upserts
- reconcile existing shell rows in migration 42 and self-heal a missing lifecycle summary on replay
why#
fixes #5719.
common assistant messages and routine activities previously rebuilt thread shell fields by loading and decoding full message and activity history. the first fix replaced that with a scalar aggregate, but review found the aggregate still scanned and decoded every lifecycle row.
this revision moves normal runtime work to indexed point lookups plus one summary row. migration 42 safely upgrades databases that already recorded migration 41, ignores malformed json and non-string failure details, and repairs stale shell fields. live updates, owner-changing upserts, cursor replay, and revert reconstruction now use the same sqlite ordering and normalized state.
testing#
vp test run apps/server/src/orchestration apps/server/src/persistence(302 passed)vp run --filter t3 typecheckvp check <changed server files>git diff --check
regressions cover 10,000 matching lifecycle rows with large payloads, malformed lifecycle json, non-string failure details, activity-id and message-id replacement within and across threads, missing-summary replay, equal timestamps, stale/unknown response failures, migration 41-to-42 upgrades, shell-row reconciliation, and exact production query plans.
checklist#
- i have performed a self-review of my changes
- i have added tests that prove my fix is effective
- new and existing tests pass locally
Note
Medium Risk Touches projection correctness for thread list badges and pending-input counts across migrations, transactional upserts, and revert rebuild paths; wrong deltas would show stale UI state but is well-covered by tests.
Overview
Thread list shell summary fields (latest_user_message_at, pending_user_input_count, etc.) no longer rebuild by loading full message/activity history on every routine event.
Persistence: Activities now store normalized user_input_request_id / user_input_state and maintain a per-thread projection_thread_user_input_summaries row via transactional upserts (including cross-thread activity-id moves). Messages upsert refreshes latest_user_message_at on affected threads through an indexed “latest user message” query.
Projection pipeline: In-memory derivePendingUserInputCountFromActivities and the old refreshThreadShellSummary full-scan path are removed. Common events update shell fields incrementally; thread.reverted still calls rebuildThreadShellSummary, which uses scalar/count queries instead of hydrating payloads.
Migrations 41–42: Add lifecycle indexing, then upgrade to the summary table + covering indexes and backfill/reconcile existing projection_threads rows (including safe handling of malformed JSON).
Note
Bound thread shell-summary reads using pre-aggregated counts instead of full activity hydration#
- Thread shell summary fields (
pending_user_input_count,latest_user_message_at) are now maintained incrementally inprojection_thread_user_input_summariesand directly onprojection_threads, rather than being recomputed by scanning all activities/messages. - Activity upserts and deletes in
ProjectionThreadActivities.tsmaintain per-thread pending counts via delta updates to the summary table, including correct handling of cross-thread activity moves. - Message upserts and deletes in
ProjectionThreadMessages.tssynchronizelatest_user_message_atonprojection_threads, including correcting the previous thread when a message moves. ProjectionPipeline.tsprojection handlers now call targeted repository aggregates per event type;thread.revertedtriggers a fullrebuildThreadShellSummaryusing persisted aggregates.- Migration 042 backfills
user_input_request_id/user_input_statecolumns on activities, creates the summary table, and reconciles existing thread-level counts and timestamps. - Risk: upserts for activities and messages now run in transactions with additional reads and writes, increasing per-event DB load.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR introduces database schema changes (new columns, tables, indexes) and refactors shell summary tracking from in-memory full-collection scans to transactional incremental updates with delta tracking. The PR's own description labels it 'Medium Risk' affecting projection correctness, warranting human review.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
83d769f· PR result:6dba7cc· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.