fix(server): give completed turns a full session idle window #10689
main fromrefs/pull/10689/head·merged by juliusmarminge View on GitHubA 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 checkingactiveTurnId. - 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
sweepAthelper using a testClock, 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
updatedAtis reliably populated in the projection for sessions that go through long turns.
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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
1cee120Macroscope'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).juliusmarminge merged this430fbd1
juliusmarminge closed this
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.tsapps/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.tsThe reaper loads the thread snapshot and uses the later of lastSeenAtandsession.updatedAtto determine inactivity.Deterministic reaper execution
apps/server/src/provider/Layers/ProviderSessionReaper.test.tsTest 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.tsParameterized 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
1cee1Completed 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 name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring 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 name Status Explanation Title check ✅ Passed The title clearly and concisely describes the primary change: completed turns receive a full session idle window. Description check ✅ Passed The 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 ✅ Passed The implementation addresses issue #10600by 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 ✅ Passed The 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.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes