Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): preserve agent roster across chat pagination #12135

ClosedGigioxx(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/12135/headopened View on GitHub

Fresh clients can show fewer agents and lower token totals than clients that loaded the same thread earlier. The Agents panel folds chat activities, but a fresh snapshot only includes the recent turn window and up to 500 activities.

Preserve lifecycle rows for known agents through the existing pinned-activity query, including status rows without an agent marker and agent tool heartbeats. Ignore malformed historical payloads in this scan. Ordinary chat history stays paginated. This uses the shared HTTP/WebSocket snapshot path without changing client code or contracts.

Fixes #12131.

Verified with a regression that fails before the fix, 80 focused snapshot/subagent tests, server typecheck, and scoped lint/format. Two isolated Chromium sessions reproduce 9 idle / 9.0M tokens before and 17 idle / 17.0M on a fresh client after. Loading earlier turns and reloading preserve the totals. Synthetic fixture on Linux; native macOS and an actual relay connection were not tested.

Before: fresh clientAfter: fresh client
Before: nine idle agentsAfter: seventeen idle agents

Reproduction details and loaded-history comparison.

Implemented with GPT-6 Astra in Codex. Reviewed with Claude Sonnet 5 in Claude Code (approved, no blockers).

Summary by CodeRabbit

  • Bug Fixes

    • Preserved agent task lifecycle activity across paginated snapshots and activity limits.
    • Kept related task and tool progress events available together, even when many other activities are present.
    • Improved snapshot consistency when large volumes of unrelated activity are added.
    • Safely handled activities with malformed payload data during snapshot retrieval.
  • Tests

    • Added coverage for lifecycle events spanning multiple turns, page boundaries, activity caps, and malformed payloads.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Would Approve

      Macroscope's review found this PR approvable — This is a focused server-side pagination bug fix with targeted tests, preserving agent lifecycle rows without changing schemas, APIs, or deployment behavior. An automated High-severity finding notes that malformed legacy JSON may still fail the new historical scan, which should be handled by the correctness workflow.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 613febaa-3ece-4bfe-9339-a794de3f10c1

      📥 Commits

      Reviewing files that changed from the base of the PR and between 642952ea562e71adba148d37615eebdf0facbeab and 9aaed7b7864a6b6319b6e4c3e6a0c59933ea852c.

      📒 Files selected for processing (2)
      • apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts
      • apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts

      Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


      📝 Walkthrough

      Walkthrough

      The projection query now pins agent task and tool lifecycle activities by task ID. A new test verifies retention across turn pagination and a 500-row activity cap while excluding unrelated background activity.

      Changes

      Agent lifecycle activity retention

      Layer / File(s)Summary
      Lifecycle activity pinning
      apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
      The pinned_activity_ids CTE retains task and tool lifecycle rows linked to agent lifecycle activities. The query validates JSON before extracting payload fields.
      Lifecycle retention validation
      apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts
      The test adds synchronous payload encoding, seeds agent activity batches, and checks retention across turn windows, older cursors, and 501 noise rows. It also verifies that old-background is excluded.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 9aaed

      The change preserves the required agent lifecycle activities across pagination and caps, with regression coverage and no evidenced merge-blocking risk.

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedThe changes satisfy the coding requirements in #12131. pinnedThreadActivityIdsCte preserves agent lifecycle rows and related tool heartbeat rows across paginated and fresh snapshot queries. Valid JS…
      Out of Scope Changes check✅ PassedThe production change updates the existing pinned-activity query that supplies thread snapshots. The test change validates lifecycle retention, pagination, activity caps, and malformed payload handlin…
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      Title check✅ PassedThe title clearly describes the main change: preserving the agent roster during chat pagination. It is concise and specific.
      Description check✅ PassedThe description clearly explains the problem, implementation, scope, validation, and UI impact. It includes before-and-after screenshots and reproduction details. It does not use the template headings…
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Comment `@coderabbitai help` to get the list of available commands.
    4. Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work.

      Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look.

    5. juliusmarminge closed this

Sign in to join this conversation.