fix(server): pause periodic PR discovery without foreground clients#23852
Problem
A headless Linux server kept discovering branch pull requests every minute after its client disconnected, spending GitHub quota without anyone using the client. Reproduced on current main with an active branch thread: listPullRequestsByHead continued after the browser left and no server sockets remained.
Change
Check the existing background activity policy before each periodic branch-discovery sweep. Discovery resumes on the next minute tick when foreground activity permits opportunistic work. Startup backfill and thread-event refreshes remain available to headless agents and scheduled tasks. The existing foreground and host/client power constraints apply; no new settings or persisted state are added.
Scope and approval
Fixes #23702
Triaged bug via the automated issue flow: #23702. This change only bounds recurring branch discovery. Existing PR-summary polling is unchanged.
Verification
- Regression test against the baseline service: fails with 10 unwanted lookups in 10 simulated idle minutes. Patched service: 6/6 tests pass in
ThreadPullRequestService.test.ts. The test also proves checkpoint-triggered discovery still runs without foreground demand. - Focused server typecheck passes. Targeted lint has only the existing unused
layerwarning; diff check passes. - Two independent diff reviews (Codex and Claude): MERGE. Proof audit: SUFFICIENT.
- Real Linux dev server, isolated copied state and a local git fixture with a GitHub remote. Browser paired, then disconnected. The patched server remained alive and produced zero branch-discovery spans during 21:10:11ā21:14:42 UTC, covering multiple minute ticks. A foreground activity RPC then resumed synchronization on the next tick, with a successful GitHub branch lookup.
| Proof | Before | After |
|---|---|---|
| Deterministic service test | 10 extra lookups; exit 1 | 6 tests pass; exit 0 |
| Real server | Recurring idle branch requests | No recurring branch discovery |
Foreground positive control Ā· Proof matrix
Server-only change: visual matrix empty, screenshots and pixel diffs not applicable. Dev-watcher restarts are disclosed and excluded from the 271-second stable observation. Existing PR-summary requests continued during that interval; this evidence does not claim all idle GitHub traffic stops or attribute shared-account quota changes to this server. The original 450-thread/90-clone scale and quota-exhaustion state were not recreated. No platform-specific code changed; desktop/mobile shells and remote transports were not separately exercised.
Evidence captured at implementation head 29ce300674; the final merge from main changes only unrelated mobile dependencies. The audited server files are identical.
Models and harness: Codex gpt-6.1-sol and Claude claude-opus-5-5 through T3 Code.
Checks
- SuccessfulCodeRabbitGitHub
Review completed
- SkippedDeploy web previewGitHub
- SkippedBuild preview JS bundleGitHub
- SkippedEAS PreviewGitHub
- SkippedEAS PreviewGitHub
- SkippedBuild preview JS bundleGitHub
- SkippedDeploy web previewGitHub
- SuccessfulCheckGitHub
- Skipped
- SkippedRustGitHub
- SkippedTest WebGitHub
- SkippedRelease SmokeGitHub
- SuccessfulTestGitHub
- SuccessfulBuild and TypecheckGitHub
- SuccessfulLabel PR 23852GitHub
- Skipped
- SuccessfulLabel PR sizeGitHub
- Skipped
- Successful
- Successful
- SkippedEAS PreviewGitHub
- SuccessfulPrepare PR size configGitHub
- SuccessfulNative fingerprint diffGitHub
- SuccessfulTest Server 6GitHub
- SuccessfulTest Server 8GitHub
- SuccessfulTest Server 4GitHub
- SuccessfulCollect PR targetsGitHub
- SuccessfulTest Server 3GitHub
- SuccessfulTest Server 7GitHub
- SuccessfulTest Server 5GitHub
- SuccessfulTest Server 2GitHub
- SuccessfulTest Server 1GitHub
- SuccessfulLintGitHub
- SuccessfulChangesGitHub
Added 3 commits
Approvability
Verdict: Approved at ab14184
Macroscope's review found this PR approvable ā This focused bug fix pauses only the periodic pull-request discovery sweep when no foreground client or permitted background demand exists, while preserving initial backfill and event-driven refreshes. It adds targeted regression coverage and does not alter schemas, defaults, deployments, or security-sensitive code.
You can add or adjust custom eligibility rules. Learn more.
No actionable comments were generated in the recent review. š
ā¹ļø Recent review info
āļø Run configuration
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: fix/issue-23702
- File: .coderabbit.config.ts
- Commit: ab14184
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
9040e83e-fe1c-40f6-90ce-b76336d510aa
š„ Commits
Reviewing files that changed from the base of the PR and between 2c8bdf6177159d8fcd12a897d7c9311f6eb93237 and ab1418478c65754a3637796ff61657c26aae2e56.
š Files selected for processing: 2
apps/server/src/orchestration-v2/ThreadPullRequestService.test.tsapps/server/src/orchestration-v2/ThreadPullRequestService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
š Walkthrough
The periodic pull-request sweep now checks
BackgroundPolicy.shouldRunOpportunisticWorkbefore proceeding. A regression test verifies that an idle interval does not trigger additional lookups, while a checkpoint event still triggers a lookup.Changes: Pull-request discovery
Layer / File(s) Summary Policy-gated periodic sweep
apps/server/src/orchestration-v2/ThreadPullRequestService.ts,apps/server/src/orchestration-v2/ThreadPullRequestService.test.tsThe service skips the periodic sweep when shouldRunOpportunisticWorkis false. The test verifies that checkpoint events still trigger lookups and that no additional lookups occur during a ten-minute idle interval.Priority: ā Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix Ā· Severity of issue fixed: Medium
Suggested reviewers:
t3dotgg,brechard
Merge Risk: āŖ Minimal Ā· up to ab141
The change appears ready to merge after normal checks: idle periodic discovery is paused, while checkpoint-triggered discovery remains available.
Pre-merge checks: Passed 3 Ā· Failed 1
Failed Failed checks: 1 warning
Check name Status Explanation Resolution Linked Issues check Warning The change addresses #23702's recurring idle discovery requirement.ThreadPullRequestServiceV2gates periodic sweeps onshouldRunOpportunisticWork, and the regression test covers idle minutes and ā¦Honor a known source-control quota pause until its reset before retrying periodic discovery, and add a regression test that verifies no retry occurs during the pause. Passed Passed checks: 3 passed
Check name Status Explanation Title check Passed The title clearly summarizes the main change: periodic PR discovery pauses when no foreground clients are active. Description check Passed The description covers the problem, change, scope and approval, and verification. It also states limitations and distinguishes recurring branch discovery from startup backfill, thread-event refreshes,⦠Out of Scope Changes check Passed The service change and regression test relate directly to #23702's idle branch-discovery behavior. The supplied change summary shows no unrelated changes.Full details: Description check
Explanation
The description covers the problem, change, scope and approval, and verification. It also states limitations and distinguishes recurring branch discovery from startup backfill, thread-event refreshes, and PR-summary polling.
Full details: Linked Issues check
Explanation
The change addresses
#23702's recurring idle discovery requirement.ThreadPullRequestServiceV2gates periodic sweeps onshouldRunOpportunisticWork, and the regression test covers idle minutes and checkpoint-triggered discovery. However,#23702also requires a known quota pause to be honored until reset. The reviewed change does not add that behavior;BackgroundPolicy.shouldRunOpportunisticWorkchecks foreground activity and power constraints, not quota state. A paused provider can still be retried on a later sweep when opportunistic work is allowed.Resolution
Honor a known source-control quota pause until its reset before retrying periodic discovery, and add a regression test that verifies no retry occurs during the pause.
⨠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.
Thread transfer impact
ā Thread transfer remains within every enforced ceiling.
| Provider | Metric | Main baseline | This PR | Impact | PR ceiling | |
|---|---|---|---|---|---|---|
| Codex | Total thread wire | 5.0 KiB | 5.0 KiB | ā7 B (ā0.1%) | 6.8 KiB | ā |
| Codex | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | ā |
| Codex | Live turn WebSocket wire | 1.2 KiB | 1.2 KiB | ā7 B (ā0.6%) | 2.0 KiB | ā |
| Codex | Live turn WebSocket decoded | 20.9 KiB | 20.9 KiB | 0 B (0.0%) | 29.3 KiB | ā |
| Codex | Live turn messages | 2 | 2 | 0 (0.0%) | 8 | ā |
| Claude | Total thread wire | 5.0 KiB | 5.0 KiB | +31 B (+0.6%) | 6.8 KiB | ā |
| Claude | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | ā |
| Claude | Live turn WebSocket wire | 1.2 KiB | 1.2 KiB | +31 B (+2.6%) | 2.0 KiB | ā |
| Claude | Live turn WebSocket decoded | 21.2 KiB | 21.2 KiB | +41 B (+0.2%) | 29.3 KiB | ā |
| Claude | Live turn messages | 1 | 2 | +1 (+100.0%) | 8 | ā |
Baseline: 2c8bdf6 Ā· PR result: ab14184 Ā· 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: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
The known quota pause already blocks requests locally before network I/O in GitHubRequestPolicy.ts and SourceControlRateLimit.ts. This PR stops the recurring idle sweep entirely, including re-entry during a known pause. Foreground local retries and warning stacks remain tracked in #19781, which the report explicitly separates. The linked-issue warning needs no additional change in this PR. All 28 current-head checks pass; CodeRabbit reports no actionable code comments, and Macroscope approved.