Skip to content

fix(server): keep PR reads cached after text-only turns - #44190

Closed
juliusmarminge wants to merge 3 commits into
mainfrom
factory/pr-44184
Closed

juliusmarminge wants to merge 3 commits into
mainfrom
factory/pr-44184

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

Every finished agent turn dropped all cached pull request reads, so even a turn that only answered in text made the next PR read go back to the forge API. Now a turn that completes with only assistant text, reasoning and user messages keeps the PR cache. Turns that ran tools, subagents or background work, resumed attempts, and failed or interrupted turns still refresh it as before.

Fixes #44178

Supersedes #44184. The change is @kurtextrem's; their commits are kept.

Reproduction on main

On macOS desktop, open an open PR's detail panel in a GitHub-backed project and wait for activity to load. Leave it open while an agent completes a fresh prompt asking only for a short text summary without tools. Compare server traces on main and the patch: count turn-end PullRequestService.refreshAfterTurn calls and GraphQL requests under pullRequests.detail, pullRequests.activity, and file metadata during the second after completion; repeat several turns and compare total requests over five minutes. The claimed fixture result is one blanket refresh on main versus zero with the patch; repeat with a shell or dynamic-tool turn to confirm refreshes remain. These steps were inspected, not executed.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/orchestration-v2/RunExecutionService.test.ts: 87 passed
  • Same test with main's RunExecutionService.ts, -t "refreshes PR readers": read-only row fails, shell row passes (proves the fix)
  • vp test run on RunFinalizationQueue, RunFinalizationService, RunExecutionService and runtimeLayer tests: 312 passed
  • vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (2 files) all pass

Not in this change

  • Child and subagent run finalization paths still always refresh after their turns; the PR scoped the guard to root runs and I left it there.
  • The PR watch reactor's reader notification test change was removed as unrelated existing behaviour, not because it was wrong.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

kurtextrem and others added 3 commits November 27, 2026 13:08
A fresh completed turn with no tool or background activity does not need to invalidate shared PR reads. Keep the existing refresh for turns that may have written to the host, including external git and gh commands.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the watch-reactor reader assertion, which covers existing behavior this change does not touch, and fold the tool rows of the post-turn refresh table into one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 0 B (0.0%) 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 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 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 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 7d13649 · PR result: 86bf75a · 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.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Run execution now tracks events that may change pull requests. A completed turn skips the post-turn refresh when no such events were detected. Other terminal outcomes retain the refresh effect. Tests cover completed read-only and shell-command turns.

Changes: Conditional pull-request refresh

Layer / File(s) Summary
Track possible pull-request changes
apps/server/src/orchestration-v2/RunExecutionService.ts
Run initialization and accepted events set mayHaveChangedPullRequests for specified attempt states and event types.
Gate completed-turn refresh and test behavior
apps/server/src/orchestration-v2/RunExecutionService.ts, apps/server/src/orchestration-v2/RunExecutionService.test.ts
Completed turns skip the refresh when the flag remains false. Termination tests check that read-only turns do not refresh and turns with a shell command do.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant ProviderThread
  participant RunExecutionService
  participant PullRequestService
  participant PRReaders
  ProviderThread->>RunExecutionService: Send turn items and background-work updates
  RunExecutionService->>RunExecutionService: Track events that may change pull requests
  ProviderThread->>RunExecutionService: Complete turn
  alt Possible changes or terminal status is not completed
    RunExecutionService->>PullRequestService: Run refreshAfterTurn
    PullRequestService-->>PRReaders: Clear shared reads and signal readers
  else Completed with no possible changes
    RunExecutionService->>RunExecutionService: Pass Effect.void
  end
Loading

Suggested reviewers: greglum, mit-consulting

Merge Risk: Minimal · up to 86bf7

This change skips the post-turn pull-request refresh for completed turns that only contain text. Turns with tools, background work, resumed attempts or failures still refresh. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(server): keep PR reads cached after text-only turns" matches the main change: a completed root turn with only assistant text, reasoning, and user messages now keeps the cached pull requ…
Description check Passed The description follows the template's main sections. Problem, Change, Scope, Verification, and the agent attribution line are all present. The Problem and Change sections explain the stale refresh be…
Linked Issues check Passed [#44178] Requirement: a completed read-only root turn keeps cached open-PR data, and PR-changing turns still refresh. The change in apps/server/src/orchestration-v2/RunExecutionService.ts sets PR-refr…
Out of Scope Changes check Passed The changes are limited to RunExecutionService.ts (finalization refresh eligibility) and its test file. Every change directly implements the refresh-skip guard for read-only root turns described in #4…
Full details: Title check

Explanation

The title "fix(server): keep PR reads cached after text-only turns" matches the main change: a completed root turn with only assistant text, reasoning, and user messages now keeps the cached pull request reads instead of refreshing them. It follows the conventional commit format and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template's main sections. Problem, Change, Scope, Verification, and the agent attribution line are all present. The Problem and Change sections explain the stale refresh behavior and the narrowed refresh guard. Scope links the issue (#44178) and notes the superseded PR. Verification lists focused test runs with results and a reproduction on main. The Evidence section is explicitly marked as not yet captured, and the author states that the reproduction steps were inspected but not executed. This is a remaining gap before merge. The template also says to state anything that could not be checked, and the real-app before/after evidence is still pending, so the description is mostly complete but not fully so.

Resolution

Before merge, upload the real-app before and after evidence the Evidence section says is pending, or remove that placeholder and state that it was not captured. Also consider stating in the Problem section the expected behavior and reproduction environment in one or two sentences, since the template asks for it.

Full details: Linked Issues check

Explanation

[#44178] Requirement: a completed read-only root turn keeps cached open-PR data, and PR-changing turns still refresh. The change in apps/server/src/orchestration-v2/RunExecutionService.ts sets PR-refresh eligibility in startRootRun and during ingestion. Eligibility turns on for tool-like turn items, subagent updates, runtime requests, new child app threads, pending background work, and provider-thread pending work. At finalization, a completed run skips refreshAfterTurn only when no eligibility condition fired. Other terminal outcomes (failed, interrupted, cancelled, resumed attempts) still refresh. The added RunExecutionService.test.ts coverage reports that the read-only row fails on main and passes with the patch, while the shell row passes on both. This matches the expected behavior. Out-of-band freshness (push, comment) relies on the watcher path, which the PR does not modify, so that path is unchanged. Not verified: the real-app before and after evidence is still pending, and the watcher same-head signal described in the issue is not addressed. The issue does not list that signal as an acceptance criterion. Non-coding reproduction steps were not executed.

Full details: Out of Scope Changes check

Explanation

The changes are limited to RunExecutionService.ts (finalization refresh eligibility) and its test file. Every change directly implements the refresh-skip guard for read-only root turns described in #44178. The PR states that child and subagent finalization paths, and the PR watch reactor, are left unchanged. The removal of the reactor test change is described as a reversal of an unrelated edit, not as added scope. Supporting test coverage for the guard is in scope. The file-level diff could not be read in full because of truncation, so the scope judgment relies on the supplied summary and PR description.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7d13649 and 86bf75a.

Files selected for processing: 2

  • apps/server/src/orchestration-v2/RunExecutionService.test.ts
  • apps/server/src/orchestration-v2/RunExecutionService.ts

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

@juliusmarminge

Copy link
Copy Markdown
Member Author

The automated pipeline ran the reported steps in the real app without this change, and the slowness could not be measured: the commit before this change was as fast. So it cannot show that this change fixes anything.

What was run on 7d13649477, the commit before this change:

For each commit, create a GitHub-backed project and text-only replay thread; open PR 44184's detail panel on Timeline and wait for activity to load. Keep it open while submitting seven text-only prompts 40 seconds apart over five minutes. Repeat on fresh state, giving 14 measured turns per commit. Measure CLI action duration, blanket refresh calls, actual GraphQL executions, and PR-reader ancestry during the second beginning at the same final-events boundary on both commits. After the second window, run a replayed shell-tool control. All text turns completed with matching replies; the shell-tool control completed and triggered one blanket refresh on each commit.

How: Real Electron desktop builds on the same leased macOS 26 Apple silicon Mac, with fresh synthetic databases, identical light theme and window bounds. Projects were created through the server API. Prompts were submitted through the real server CLI using Replay's text-only multi-turn model. Captured app-only recordings and sanitized server spans. No tests were used as evidence.

Closing this pull request. #44178 has been asked for the missing steps; once the problem can be shown this can be reopened, or the fix built again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Read-only agent turns refetch open PR details from GitHub

2 participants