Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): let agents watch reopened pull requests #15741

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

After a linked PR was reopened on GitHub, asking an agent to monitor it could still fail with "The pull request is closed, so there is nothing to watch." The tool trusted T3's saved closed state until its slower background refresh ran.

Fixes #15744.

Starting a watch now refreshes a cached closed PR from its host, saves the current state, and starts monitoring if it is open. PRs that remain closed or merged are refused, and a failed host read is reported without starting a watch. The transition lives in the existing watch service and uses the existing snapshot mapping and provider abstraction.

This is a focused fix for an obvious stale-state bug in the existing MCP watch capability. It adds a host refresh only when a watch request encounters a cached closed state. Periodic polling and client contracts are unchanged.

Verification

  • Reproduced live: GitHub reported a reopened PR as open while list_thread_pull_requests still reported closed and watch_pull_request refused it.
  • The reopened-PR regression failed with that same error before the fix, then passed after it.
  • Five focused suites pass, 65 tests: pull request MCP handlers, MCP HTTP registration, worktree MCP registration, watch evaluation, and PR synchronization. These cover reopened, still closed, merged, unwatch, and failed-refresh paths.
  • Targeted lint and formatting pass for all changed files; the server package typecheck passes.
  • Codex GPT-6-Astra reviewed correctness, authorization, concurrency, caching, tests, and final runtime wiring with no actionable findings.

Model: GPT-6.1-Sol, reviewed by GPT-6-Astra. Harness: Codex through T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at b912e41

      Macroscope's review found this PR approvable — This is a contained fix for stale pull-request state: an explicit watch request now performs a fresh host read for cached closed PRs before enabling the existing watcher. Existing merged, still-closed, unwatch, and failure paths are covered without changing product defaults or deployment behavior.

      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 in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      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: Advanced
      • Run ID: 72d6e43d-71a4-45c4-8834-eeeca7842085
      📥 Commits

      Reviewing files that changed from the base of the PR and between 4ee6bfd50ef4a089440d5c3662db2298da9cc50e and 3356d07eb4975d045ea2ae0f9b55204aa5e1c61d.

      📒 Files selected for processing (8)
      • apps/server/src/mcp/McpHttpServer.test.ts
      • apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts
      • apps/server/src/mcp/toolkits/pullRequests/handlers.ts
      • apps/server/src/mcp/toolkits/pullRequests/tools.ts
      • apps/server/src/mcp/toolkits/worktree/registration.test.ts
      • apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
      • apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
      • apps/server/src/server.ts

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


      📝 Walkthrough

      Walkthrough

      The pull-request watch flow now runs through PullRequestWatchReactor. When a saved pull-request snapshot is closed, the reactor refreshes it before starting a watch. The MCP handler delegates watch changes to the reactor and returns its watch status.

      Changes

      Pull-request watch flow

      Layer / File(s)Summary
      Watch reactor state and refresh
      apps/server/src/orchestration-v2/PullRequestWatchReactor.ts, apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
      The reactor adds setWatching, which checks the thread’s pull-request link. For a closed link, it invalidates and refreshes the summary, syncs the snapshot, and rejects the request if the refreshed state is not open. It returns the watch status before and after dispatch.
      MCP handler delegation
      apps/server/src/mcp/toolkits/pullRequests/handlers.ts, apps/server/src/mcp/toolkits/pullRequests/tools.ts, apps/server/src/server.ts
      The handler delegates watch changes to the reactor and maps errors. The tool error type uses the reactor’s PullRequestNotOpenError. Runtime composition retains the reactor services.
      Watch refresh test coverage
      apps/server/src/mcp/McpHttpServer.test.ts, apps/server/src/mcp/toolkits/pullRequests/handlers.test.ts, apps/server/src/mcp/toolkits/worktree/registration.test.ts
      Tests provide reactor and pull-request service mocks. Handler tests cover successful refresh to open, a refreshed closed state, refresh failure, and no service reads for a merged pull request.

      Priority: ⬇️ Low

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

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant MCPHandler as PullRequestsToolkitHandlers
        participant WatchReactor as PullRequestWatchReactor
        participant PullRequestService
        participant Orchestrator
        MCPHandler->>WatchReactor: setWatching(watch command)
        WatchReactor->>Orchestrator: Load thread shell
        WatchReactor->>PullRequestService: Invalidate closed pull-request cache
        WatchReactor->>PullRequestService: Read fresh summary
        WatchReactor->>Orchestrator: Sync refreshed snapshot
        WatchReactor->>Orchestrator: Dispatch watch command
        WatchReactor-->>MCPHandler: Return watch status

      Suggested reviewers: t3dotgg, juliusmarminge

      Merge Risk: ⚪ Minimal · up to 3356d

      The reopened-pull-request watch flow is ready to merge after normal checks. The examined periodic-sync interleaving does not establish a failure to start or maintain the watch.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to 3356d

      The change preserves existing access checks and monitoring scope, and a failed refresh does not start monitoring. The main uncertainty is how an activation still awaiting refresh should interact with a concurrent stop or unlink. Existing safeguards prevent automatic wake-ups on settled threads.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The added activation work concerns the matching PR in the authorized invocation thread: a provider-summary read and snapshot update precede the existing monitoring command. Subsequent monitoring can deliver agent wake messages, but the inspected change adds no provider-side mutation or new credential privilege.

      Trust Boundaries and Controls

      • observed — Persistence rejects deleted threads and watch activation on provider-native subagent threads. Background progress and wake delivery require the current watch generation; wake delivery also rejects archived, settled and provider-native subagent threads. These existing controls limit the effect of stale background reads and concurrent settlement.

      Resilience and Maintainability Implications

      • observed — The failed-refresh regression asserts that no state command is dispatched. Existing monitoring ends on non-open host detail or repeated read failures, and cleanup carries the watch generation so an old sweep cannot remove a replacement watch. Read-failure counters remain in memory, so restart can delay failure-based cleanup.

      Hardening Proposals

      • proposed — Define the ordering contract for activation racing with stop or unlink. If cancellation must supersede an activation already awaiting refresh, use an expected lifecycle generation checked at commit time. This is conditional hardening, not a verified security finding.
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 8 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly summarizes the main change: agents can watch pull requests that were reopened.
      Description check✅ PassedThe description explains the stale-state problem, the change, and why this focused fix needs no prior approval. It also reports specific verification results and identifies the model and harness.
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    4. Reviewed the remaining docstring-coverage warning. This PR only exports the existing snapshotFieldsOf mapper; its behavior is unchanged and the field mapping is explicit. The repository asks comments to explain non-obvious constraints rather than repeat readable code, so the generic 80% threshold does not identify a documentation gap here.

      The conditional concurrency-hardening suggestion does not identify a reproduced failure and was not retained as an actionable finding. CodeRabbit completed its review through 3356d07 with no actionable comments, and the latest CI checks pass.

    5. Note

      Grok responding on behalf of Julius.

      Thanks for this one. #16208 just merged and folds in a smaller version of this fix: a PR saved as closed can be watched, and the first host read ends the watch if it is still closed. That covers #15744, so I am closing this as superseded.

    6. juliusmarminge closed this

Sign in to join this conversation.