Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop routine events from rescanning thread history #7356

Closeddain(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/7356/headopened View on GitHub

Fixes #5719.

What Changed

The threads projector no longer calls refreshThreadShellSummary for assistant messages or routine activities. Those events still update their normal projections and advance the thread's updatedAt, but they skip the second operation that reloads the thread's complete message, proposed-plan, activity, and approval histories.

The existing full refresh remains in place for events that can change the current shell summary:

  • user messages
  • approval and user-input lifecycle activities
  • proposed plans and explicit approval/user-input responses
  • session and latest-turn changes
  • thread reverts

A focused projection-pipeline regression test verifies that an assistant message and a routine tool.updated activity each produce only the expected thread timestamp update, rather than that update followed by a summary rewrite.

Why

refreshThreadShellSummary derives four fields: the latest user-message time, pending approval count, pending user-input count, and actionable-plan state. Assistant messages and ordinary tool/context activities cannot change any of them, but every such event currently reloads all four backing collections.

On a high-activity thread with 27,303 activities and 23,778 messages, activity projection averaged 734 ms per event. A burst of 526 routine activity and assistant-message events therefore accounted for approximately 386 seconds of serialized projection work, delaying unrelated threads behind the same global ingestion worker.

This change removes that measured hot path without changing summary derivation or introducing incremental counters.

Related: #5855 and #6608 address the same projection cost with broader changes. This PR intentionally keeps the existing summary implementation and only avoids invoking it for events that cannot affect its result.

Verification

  • vp test run apps/server/src/orchestration/Layers/ProjectionPipeline.test.ts — 22 passed
  • server typecheck passed
  • targeted lint and formatting passed
  • server bundle build passed
  • git diff --check passed

No schema, projector cursor, transaction, replay, queue, client, or UI changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • No UI changes; screenshots are not applicable
  • No animation or interaction changes; video is not applicable

Model and harness: GPT-5.6 Sol using the Codex harness in T3 Code.

Note

Stop assistant messages and routine activities from rescanning thread history

  • Adds eventCanChangeThreadShellSummary in ProjectionPipeline.ts to gate calls to refreshThreadShellSummary. Only user messages and specific activity kinds (approval.requested, approval.resolved, user-input.requested, etc.) qualify.
  • Assistant messages and routine activities (e.g. tool.updated) now only update the thread shell updatedAt timestamp instead of triggering a full summary refresh.
  • Behavioral Change: previously every thread.message-sent and thread.activity-appended event caused a summary rescan; now only a subset does.
Macroscope summarized 77b586e.

Note

Medium Risk Changes which events recompute thread list/shell summary fields; incorrect gating could leave stale pending counts or user-message timestamps, though existing tests cover approval/user-input paths and the new assistant/tool cases.

Overview Skips expensive thread shell summary rescans for assistant messages and routine activities (e.g. tool.updated) during orchestration projection, while still bumping the thread shell updatedAt.

Adds eventCanChangeThreadShellSummary in ProjectionPipeline.ts so refreshThreadShellSummary runs only when an event can change derived fields (latest user message time, pending approvals/user input, actionable plans). User messages and approval/user-input lifecycle activities still trigger a full refresh; proposed plans and explicit response events behave as before.

A regression test uses a SQLite trigger on projection_threads to assert assistant messages and routine activities cause a single row update (timestamp only), not a second update from summary refresh.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 77b586e3eaa35db26fccbe68a60e4a936a964e77. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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: aa0c1725-906e-4497-beb0-7514139b989d

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Needs human review

      This PR changes when the thread shell summary refresh occurs, gating a database read/write operation based on event type. While the optimization logic appears correct, changes that determine whether significant processing work happens warrant human review to verify the gating conditions are complete.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Closing in favor of merged #8150, which skips full thread-history scans for assistant messages and routine activity. Your work is credited in #8150.

Sign in to join this conversation.