fix(client): late answers no longer vanish when only part of a thread is loaded #16437
main fromrefs/pull/16437/head·opened View on GitHubProblem#
When a thread's history is only partly loaded, applyOrchestrationV2ProjectionEvent drops any new
turn item whose ordinal is at or below latestLocalTurnOrdinal, treating it as unloaded history.
Every applied turn-item.updated raises that watermark (threads.ts). So if a later item of the
running turn arrives first (for example an approval request at ordinal 13), the answer at ordinal 12
that arrives next is dropped by shouldDropMissingPartialTurnItem and never appears, even though its
run is on screen.
Fix#
In shouldDropMissingPartialTurnItem, keep a missing item when the loaded window already shows an
earlier local item of the same run. It is then inserted by ordinal as usual. Items from runs outside
the loaded window, and items older than the window, are still dropped.
Why this qualifies#
A very small, focused fix for an obvious bug: one guard in one client reducer, plus a test. No contract, server, or UI change.
Verification#
Test: packages/client-runtime/src/state/orchestrationV2Projection.test.ts,
partial timeline: $name that arrives after a later sibling, two cases:
keeps an item from a loaded run: window holds items 11 and 13 of one run, watermark 13; item 12 of that run arrives and must sit between them.drops an item from an unloaded run: the same item 12 from a run that is not in the window is still dropped (reducer returns the same projection).
Before the fix (cd packages/client-runtime && vp test run src/state/orchestrationV2Projection.test.ts):
× partial timeline: keeps an item from a loaded run that arrives after a later sibling
AssertionError: expected [ 'item-first', 'item-later' ] to deeply equal [ 'item-first', 'item-late', …(1) ]
Tests 1 failed | 9 passed (10)
After the fix, the same command passes, along with the neighbouring partial-history suites:
vp test run src/state/orchestrationV2Projection.test.ts src/state/threads-sync.test.ts src/state/threadHistoryMerge.test.ts: all pass.vp run typecheckinpackages/client-runtime: exit 0.vp lint --report-unused-disable-directives packages/client-runtime/src/state: no findings in the touched files.vp fmt --check packages/client-runtime/src/state: clean.
Not checked#
Not reproduced in a running app. The test drives the reducer directly with the event order that triggers the drop; I did not capture a live session where a provider emits a later item before the answer.
Found and fixed in a downstream fork (Scient), then ported to current main. Ported and verified with Claude Opus 5.5 in Claude Code; the original fix was written with Codex (gpt-6.1-sol).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
92f03eeMacroscope's review found this PR approvable — This is a narrowly scoped client-side bug fix that preserves existing behavior outside partial timelines and adds regression coverage for both retained and dropped late items. Its runtime impact is isolated to correctly inserting late items from runs already present in the loaded window.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
6281fee6-1e25-4cd3-8d68-31dcd57ad1c1
📥 Commits
Reviewing files that changed from the base of the PR and between 9bd1d8009a6b7c50f9dd9458e2bf27d481ff3b43 and 92f03ee3e55aa05e205d977b81a64d8aa7491e35.
📒 Files selected for processing (2)
packages/client-runtime/src/state/orchestrationV2Projection.test.tspackages/client-runtime/src/state/orchestrationV2Projection.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 projection now preserves certain late turn items in partial timelines when a visible item belongs to the same run. Tests cover items from loaded and unloaded runs.
Changes#
Partial Timeline Projection
Layer / File(s) Summary Preserve late items from loaded runs
packages/client-runtime/src/state/orchestrationV2Projection.ts,packages/client-runtime/src/state/orchestrationV2Projection.test.tsThe projection preserves a missing item when a visible item from the same run has an ordinal at or before its ordinal. Tests check insertion by ordinal for a loaded run and no change for an unloaded run. Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
92f03No merge-blocking issue is established for partial-timeline late-item handling; the change is mergeable after normal checks.
Architecture Summary#
Architecture risk: 🔵 Low · up to
92f03The change affects 1 system.
Changed systems:
packages/client-runtimeArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
- observed — packages/client-runtime (library) was modified; 2 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in packages/client-runtime/src/state/orchestrationV2Projection.test.ts: Adds parameterized coverage for late items in a partial timeline: an item from the loaded run is expected to appear in ordinal order between existing items, while an item from an unloaded run is expected to leave the projection unchanged. The event is applied with
partialTimelineenabled and the later sibling’s ordinal as the watermark. - observed — Modified behavior in packages/client-runtime/src/state/orchestrationV2Projection.ts:
shouldDropMissingPartialTurnItemnow returnsfalsefor an item with a non-nullrunIdwhen a local visible item from the same run has an ordinal less than or equal to its own, before applying the existing partial-timeline age checks.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title clearly summarizes the main fix: late answers no longer disappear when only part of a thread is loaded. Description check ✅ Passed The description explains the problem and fix, justifies the scope, and reports focused tests and checks with their results. It also states what was not verified. 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. ✨ 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.Note
Grok responding on behalf of Julius.
Thanks for this, @yaacovcorcos. #17764 just merged and covers the same case:
shouldDropMissingPartialTurnItemnow keeps a missing item when the loaded window already shows an earlier item of the same run, with tests for your "late item of a loaded run" and "item of an unloaded run is still dropped" cases. It also keeps items of runs that are still queued. Closing this one as superseded by #17764.juliusmarminge closed this
Sign in to join this conversation.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. To continue using code reviews, add credits to your account and enable them for code reviews in your settings.