Skip to content

refactor(server): share scheduling for tasks and limit recovery - #12795

Merged
juliusmarminge merged 6 commits into
provider-limits/failed-turn-transcriptfrom
provider-limits/shared-scheduler
Sep 21, 2026
Merged

juliusmarminge merged 6 commits into
provider-limits/failed-turn-transcriptfrom
provider-limits/shared-scheduler

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Limit retries added a separate 30-second polling loop alongside Scheduled Tasks. Extract the existing five-second task scheduler into one shared server primitive and register both features with it.

The scheduler checks due work on registration, then every five seconds. It owns source lifetimes, error isolation, and preventing overlapping sweeps. Slow task work does not delay limit recovery. Each feature keeps its existing persisted state and dispatch guards, so retries survive restarts without becoming user-visible Scheduled Tasks. Limit recovery uses one focused SQLite query for unarmed failures affected by preferences and due enabled retries. Future, cancelled, archived, settled, and pending-request threads are excluded before decoding. Scheduler ticks no longer rebuild shell snapshots, count transcript history, or traverse fork ancestors.

Stacked on #12783.

Verification: 81 focused tests pass, covering the shared scheduler, overdue work after restart, SQL recovery filtering, cancellation, snooze deadlines, provider-session errors, latest root failures, and 15 dispatch guards. Scoped server typecheck and targeted lint pass. SQLite query-plan inspection confirms indexed latest-run/root-error lookups. The query still checks thread metadata every five seconds; CPU usage on large databases has not been benchmarked. No client presentation changes; automated behavior tests provide the evidence.

Model: GPT-6. Harness: Codex.

Summary by CodeRabbit

  • New Features

    • Added centralized scheduling for recurring background work, including scheduled tasks and usage-limit recovery.
    • Coordinated due work across restarts while preventing overlapping executions.
    • Usage-limit recovery now identifies eligible failed threads and respects recovery timing, auto-resume, and snooze settings.
  • Bug Fixes

    • Improved resilience so failures in one scheduled process do not stop other scheduled work.
    • Prevented overlapping background executions during slow processing.
  • Tests

    • Added coverage for scheduling reliability, restart recovery, timing, cleanup, and recovery eligibility.

Integration verification: the shared scheduler constructor is private, fixing the unused export reported by CI. All five scheduler lifecycle and integration tests pass, including immediate overdue recovery, source isolation, interruption, and no overlapping work. Scoped server typecheck passes.

Built with GPT-6 in Codex.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 20, 2026
Comment thread apps/server/src/scheduling/Scheduler.ts Outdated
Comment thread apps/server/src/scheduledTasks/ScheduledTaskService.ts Outdated
Comment thread apps/server/src/scheduling/Scheduler.ts Outdated
Comment thread apps/server/src/orchestration-v2/runtimeLayer.ts Outdated
Comment thread apps/server/src/orchestration-v2/UsageLimitRecoveryService.ts Outdated
@macroscopeapp

This comment has been minimized.

@macroscopeapp

This comment has been minimized.

@juliusmarminge
juliusmarminge added this pull request to stack #12678 September 20, 2026 21:04
@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 4.9 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 20.4 KiB — 29.3 KiB ✅
Codex Live turn messages — 2 — 8 ✅
Claude Total thread wire — 4.9 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 20.8 KiB — 29.3 KiB ✅
Claude Live turn messages — 2 — 8 ✅

Baseline: unavailable · PR result: 4dc66ff · Source CI: success

Scenario 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.

  • Codex decoded thread snapshot: 106.1 KiB
  • Claude decoded thread snapshot: 106.4 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 304e4e8c-28b1-48d2-9335-1aeabaccb419

📥 Commits

Reviewing files that changed from the base of the PR and between f5cc6ed and f34dc5e3d9b85e2c21355441a1132ceb450dcd30.

📒 Files selected for processing (2)
  • apps/server/src/orchestration-v2/ProjectionStore.test.ts
  • apps/server/src/orchestration-v2/ProjectionStore.ts

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


📝 Walkthrough

Walkthrough

The PR adds a shared Effect scheduler with scoped registrations, serialized execution, failure handling, and five-second polling. Scheduled-task and usage-limit recovery services use it. The projection store supplies filtered recovery candidates. Tests cover concurrency, cleanup, restart, and recovery behavior.

Changes

Shared scheduler adoption

Layer / File(s) Summary
Scheduler implementation and behavior
apps/server/src/scheduling/Scheduler.ts, apps/server/src/scheduling/Scheduler.test.ts
Adds scoped registration, five-second polling, per-source serialization, failure handling, scope cleanup, and scheduler behavior tests.
Limit-recovery candidate projection
apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ProjectionStore.test.ts, apps/server/src/orchestration-v2/ProviderTurnControlService.test.ts
Adds the candidate type and store method. SQL and in-memory implementations filter candidates by thread state, reset timing, recovery state, and configuration.
Service registration and production wiring
apps/server/src/scheduledTasks/*, apps/server/src/orchestration-v2/UsageLimitRecoveryService.ts, apps/server/src/orchestration-v2/runtimeLayer.ts, apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
Moves scheduled-task and usage-limit recovery polling to the shared scheduler. Production and test layers provide Scheduler.layer.
Cross-service integration validation
apps/server/src/scheduling/Scheduler.integration.test.ts
Tests scheduled-task execution and persisted usage-limit recovery at reset time and after restart.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Suggested reviewers: saphid

Sequence Diagram(s)

sequenceDiagram
  participant Scheduler
  participant ScheduledTaskService
  participant UsageLimitRecoveryService
  participant ProjectionStore
  participant OrchestrationService
  Scheduler->>ScheduledTaskService: Run registered due-task work
  ScheduledTaskService->>OrchestrationService: Dispatch due task
  Scheduler->>UsageLimitRecoveryService: Run registered recovery work
  UsageLimitRecoveryService->>ProjectionStore: Get limit-recovery candidates
  UsageLimitRecoveryService->>OrchestrationService: Dispatch recovery retry
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 12 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary change: sharing one server scheduler between scheduled tasks and limit recovery.
Description check ✅ Passed The description explains what changed, why the shared scheduler is needed, implementation details, verification results, and UI impact. The checklist section from the template is not included, but the…
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

@macroscopeapp

macroscopeapp Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a new production scheduler and changes the timing, lifecycle, concurrency, and persistence-query behavior of both scheduled tasks and usage-limit recovery. Because it restructures shared background infrastructure and alters existing runtime workflows, human review is warranted.

No code changes detected at 4dc66ff. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Sep 20, 2026
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from f5cc6ed to bbf610b Compare September 21, 2026 00:56
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from bbf610b to f624664 Compare September 21, 2026 00:59
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from f624664 to f34dc5e Compare September 21, 2026 01:02
@juliusmarminge
juliusmarminge removed this pull request from stack #12678 September 21, 2026 01:09
@juliusmarminge
juliusmarminge added this pull request to stack #12821 September 21, 2026 01:09
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from f34dc5e to 47a7d48 Compare September 21, 2026 01:11
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from 57dc0ac to 62c0cf7 Compare September 21, 2026 01:16
Comment thread apps/server/src/orchestration-v2/runtimeLayer.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Effect Service Conventions found one blocking issue; see the inline review comment for the required namespace-import fix.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/scheduling/Scheduler.ts
@macroscopeapp

macroscopeapp Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Effect Service Conventions found one blocking issue; see the inline review comment for the required exported service constructor fix.

Posted via Macroscope — Effect Service Conventions

@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from 62c0cf7 to 3b70bfc Compare September 21, 2026 01:23
@juliusmarminge
juliusmarminge force-pushed the provider-limits/shared-scheduler branch from 3b70bfc to 4dc66ff Compare September 21, 2026 01:34
@juliusmarminge
juliusmarminge merged commit 61a3501 into t3code/codex-turn-mapping Sep 21, 2026
34 of 42 checks passed
@juliusmarminge
juliusmarminge deleted the provider-limits/shared-scheduler branch September 21, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant