Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): give completed turns a full session idle window #10689

MergedStiensWout(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/10689/headmerged by juliusmarminge View on GitHub

A provider turn lasting over 30 minutes could be reaped immediately after finishing because the idle clock still pointed to when the turn was sent.

Measure inactivity from the newer of the binding timestamp and the projected session timestamp. Ingestion already updates the latter alongside clearing the active turn, so completed, interrupted, and failed turns get a full idle window without extra event writes or throttling. Active foreground and background work remain protected. Claude cache invalidation after a genuine restart is unchanged.

Fixes #10600.

Validation: 11 reaper tests and 65 ingestion tests pass, plus server typecheck and targeted lint/format checks. The three long-turn cases fail on the original implementation. Tests cover expiry at the threshold and older or missing session metadata.

Authored by GPT-6 via Codex in T3 Code.

Note

Fix makeProviderSessionReaper.sweep to give completed turns a full idle window

  • The reaper now derives a last-activity timestamp as the later of the binding's last-seen time and the projected session's updatedAt, falling back to the binding timestamp when no session timestamp exists. A second inactivity check uses this derived timestamp before checking activeTurnId.
  • Sessions that settle after a long-running turn are no longer reaped immediately; reaping waits until the configured inactivity threshold elapses from the later timestamp.
  • Tests in ProviderSessionReaper.test.ts add a deterministic sweepAt helper using a test Clock, and parameterized coverage for terminal statuses (ready, interrupted, error) and binding idle-window cases.
  • Risk: Sessions without a projected session timestamp still use the binding timestamp; verify that updatedAt is reliably populated in the projection for sessions that go through long turns.
Macroscope summarized 1cee120.

Summary by CodeRabbit

  • Bug Fixes
    • Session cleanup now accounts for the latest session activity when determining inactivity.
    • Long-running sessions receive a full idle period after reaching a completed, interrupted, or errored state.
    • Sessions are less likely to be removed prematurely while recent updates are still being processed.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at 1cee120

      Macroscope's review found this PR approvable — This is a focused server bug fix that preserves the existing idle threshold while ensuring completed long-running turns receive a full idle window before session cleanup. The production change is isolated to the reaper’s timestamp calculation and is covered by deterministic tests for the relevant session states.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. juliusmarminge merged this430fbd1

    4. juliusmarminge closed this

    5. 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: d65fa5ac-d516-492c-84fc-2aa0f00b1750

      📥 Commits

      Reviewing files that changed from the base of the PR and between 991526383f95eefdd66ffd2853136c6dd34ae008 and 1cee120cb18fc19feed90a7b24e9e190c394ce5f.

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

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


      📝 Walkthrough

      Walkthrough

      The idle-session reaper now considers session projection updates when calculating inactivity. Tests use deterministic clock control to verify the full idle window after long-running turns and for sessions with or without session rows.

      Changes

      Session reaper activity tracking

      Layer / File(s)Summary
      Activity timestamp eligibility
      apps/server/src/provider/Layers/ProviderSessionReaper.ts
      The reaper loads the thread snapshot and uses the later of lastSeenAt and session.updatedAt to determine inactivity.
      Deterministic reaper execution
      apps/server/src/provider/Layers/ProviderSessionReaper.test.ts
      Test helpers run the reaper in one scope and use a deferred clock signal to detect completed sweeps.
      Idle-window regression coverage
      apps/server/src/provider/Layers/ProviderSessionReaper.test.ts
      Parameterized tests verify that long-running turns and fresh sessions are stopped only after the configured 1000 ms idle window.

      Priority: ⬆️ High — Impact reflects high issue severity.

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

      Severity of issue fixed: High

      Merge Risk: ⚪ Minimal · up to 1cee1

      Completed turns now receive the configured full idle window before session teardown, reducing unnecessary stop/resume cycles while preserving normal idle expiration behavior. No concrete current-head merge risk remains.

      Suggested reviewers: t3dotgg, juliusmarminge, maria-rcks

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the primary change: completed turns receive a full session idle window.
      Description check✅ PassedThe description explains what changed, why it changed, validation performed, and the related issue. It omits the template's explicit section headings and checklist, but the required information is mos…
      Linked Issues check✅ PassedThe implementation addresses issue #10600 by measuring inactivity from the later of the binding timestamp and projected session timestamp. Tests cover completed, interrupted, and failed turns, while p…
      Out of Scope Changes check✅ PassedThe changes remain focused on idle-session reaping and its tests. No unrelated code or feature changes are identified.
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

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

Sign in to join this conversation.