Skip to content

refactor(native-chat): share the catch-up open runner across agents - #31622

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/catchup-shared-runner
Oct 22, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/catchup-shared-runner

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​198 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​198
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​343 $\color{#cf222e}{\Huge{\mathbf{−}}}$​152 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​191

Problem and user-facing change

Codex chats already import turns written outside the chat when the provider resumes. Other agent integrations need the same cancellation, bounded staging and checked journal commit; copying the implementation would let these rules drift. Completing an existing saved item also needs one shared check that its saved identity and revision have not changed before the completion is written.

This extracts the existing handling into one shared runner, preserving Codex’s history selection, order, divider and duplicate prevention. It also closes a deadline gap: if preparation or the final write wait never settles, optional catch-up stops waiting at its deadline or when opening is cancelled. An already admitted write remains owned by the existing journal queue.

Implementation

  • runHistoryCatchUp owns the initial write barrier, cancellation/deadline, current-session checks and one checked commit. Agents supply their saved-history view and history preparation.
  • createHistoryCatchUpBatch keeps the 1,024-operation / 16 MiB budget. It now supports completing a saved item and recording saved items read during planning. The commit checks every expected canonical identity and revision before writing any of the batch. Journal code assigns the written revision; no new saved field or wire format is introduced.
  • Completion commit identities include the full ordered contents and expectations, so different completions of the same item remain distinct. Existing append-only Codex identities remain unchanged. An explicit empty plan can validate its saved reads without writing rows or publishing an update.
  • Codex retains provider-specific discovery and translation. Its saved-history view is captured before provider reads. Finished staging is disposed before commit; the returned mutations remain independent of that staging.
  • Intended difference: preparation and final-write waits honor the deadline/cancellation, and an abandoned invocation cannot later admit a prepared import. Read/staging failures are logged without rejecting provider opening. As before, an actual durable storage failure can fail the current journal and require recovery/reopen.
  • Intended requirement-specific extension to the common pattern: optional incremental continuation of an existing conversation, plus saved-item revision checks for eligible historical completions. Agent adapters retain ownership of eligibility, finality, linkage, source order and divider decisions. No normal send predicate, new UI, setting, minimum server version or persistent coverage marker is added.

The shared extraction is useful alone through the current Codex caller. Other agent integrations land separately; no visible feature in this PR depends on one of them landing first.

Review classification: full path

  • Size: 495 changed production lines across three files, plus one test file.
  • Risk: moves provider-open lifecycle, persisted history, cancellation, write ordering and concurrent commit checks.
  • History: extracts the existing Codex catch-up introduced in A Codex chat shows the turns made outside it #30883; the accepted amendments add bounded waiting and the shared saved-item contract.
  • Effect: host-side provider opening and history writes, beyond one local rendering component.

Validation

  • The two existing Codex suites passed unchanged on the extraction: 27 tests.
  • All 32 tests across the three relevant files passed on the final merged tree at 62efd405b66, including the real-journal saved-item contract flow and stalled preparation/final-write regressions. The normal pre-commit hook passed.
  • Independent round 4 and the narrow final-merge review found no new proven source defect or unlabelled deviation. Full CI passed on 62efd405b66, including static analysis/typecheck, full unit shards, cross-version checks and macOS/Windows packaging.
  • Real Codex QA passed on 62efd405b66: main-created chat state carried through restart/upgrade, real outside same-thread CLI continuation, import once under the existing divider, duplicate-free Session History reopen and two real native replies across app restart. Main/branch screenshots and detailed evidence are attached in the review status comment. QA observed the existing default-tab issue STA-10870 and baseline Setup-output/port-count loss on both builds; those are outside this PR.

Related work

Tracked in the chat/terminal switching lane. Pi #31618, Claude #31615 and OpenCode/Grok #31616 consume the shared runner in their integrations.

The Codex catch-up's agent-neutral parts move to one module: the open-time
envelope (its own deadline and cancellation, never gating the open), the
bounded staged batch, the single settlement commit that re-checks the
journal before writing, and the "Continued outside this chat." divider.
Codex keeps only how it reads its saved turns and what the chat already
holds. No behavior change; the other agents' catch-up builds on this
instead of copying it.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 21, 2026 19:17
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 137c2835-021c-4767-93e6-7796ad0363a4
📥 Commits

Reviewing files that changed from the base of the PR and between f5ef849 and 9f0d55e.

📒 Files selected for processing: 2
  • src/main/native-chat/agent-session-wire/structured-agent-session-history-catch-up.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-history-catch-up.ts

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

📝 Walkthrough

The change adds shared utilities to batch and run history catch-up. The runner handles deadlines, cancellation, journal checks, transition admission, and commit outcomes. Codex history import uses the shared batch builder, and Codex catch-up delegates orchestration to the runner. Tests cover durability stalls, preparation deadlines, cancellation, and failed write barriers.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 9f0d5

No concrete catch-up defect remains identified; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: sharing the native-chat catch-up open runner across agents.
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.
Description check Passed The description is detailed, relevant, and covers the problem, user-facing behavior, implementation, risks, testing, validation, and related work. It does not use the required template headings and do…
Full details: Description check

Explanation

The description is detailed, relevant, and covers the problem, user-facing behavior, implementation, risks, testing, validation, and related work. It does not use the required template headings and does not provide an explicit Linked Issue entry, Visual Proof/N/A statement, or completed checklist items, but the substantive information is mostly complete.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Codex chats need to pick up turns completed outside Orca when they resume. The existing cancellation, bounded staging and checked history commit now live in one shared runner, preserving Codex’s ordering, divider and duplicate prevention. Optional preparation and final-write waits now end at the deadline or cancellation; adapters can also complete an eligible saved item only while its saved identity, revision and read dependencies still match.

The full review completed through round 4, followed by an independent check of the final main merge at 62efd405b66ba8cf1e54246a01497424829fb9e1. No unresolved proven code finding remains. The final merge preserved the four reviewed PR files exactly. The 32 targeted tests and normal commit hook passed; the real-journal contract flow covers matching completion, atomic stale-read refusal and validation without a write.

Full CI passed on this exact head (run 39723995800): static analysis/typecheck, all five full test shards, relay integration, cross-version compatibility and macOS/Windows packaging.

Real Codex 0.162.1 QA passed on macOS using the same thread and cold copy of main-created data: an initial native reply, a real outside CLI resume, one ordered outside pair under one divider, Session History close/reopen without duplicates, then two final-head native sends/replies across a real app restart. Saved options and tab identity/order were retained. The two imported rows and divider remained single after restart. No changed Codex flow was skipped or waived. Owned test processes were stopped and the QA ticket released.

Baseline observations were preserved for separate triage: the configured default shell command was absent on main (existing STA-10870), and old Setup output/port count did not survive the stopped-rig restart on either build. Import-time timestamps and several neighboring UI/status details were the same on main; no new branch-specific chat regression was found. Other platforms, remote transport, folder-workspace UI and large-history performance were not runtime-tested by this macOS run. The deadline failure contracts were covered by targeted tests rather than a simulated app failure.

The deliberate differences from the common pattern are the required incremental continuation of an existing conversation, its saved-item compare-and-commit checks, and the accepted optional-wait deadline. No new saved fields, wire operations, send predicate, settings or user notice were added. The existing journal owns admitted writes. A durable-write failure can still fail the current sink and require reopen; the asynchronous deadline does not preempt synchronous work or all provider I/O. These inherited limits were traced and kept explicit.

For Brennan’s review

Same main-created state and outside input, after the ordinary resumed Send:

Main Final branch
Main catch-up Branch catch-up

History retained after reopening, with a real further reply; branch also went through a full app restart:

Main reopen Final branch restart
Main reopen Branch restart

@brennanb2025
brennanb2025 merged commit 6cd2550 into main Oct 22, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant