Repository navigation
Fix lost session-tab changes during initial census - #17064
Conversation
Greptile SummaryThe PR makes initial session-tab inventory collection and concurrent tab notifications an ordered handoff using host-local sequence watermarks.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness, security, or quality issues identified. Session-tab mutations are applied before their sequence increments, the census reads snapshots and its watermark synchronously, and buffered post-boundary changes are replayed in order with bounded failure under sustained structural churn.
|
| Filename | Overview |
|---|---|
| src/main/runtime/orca-runtime.ts | Adds monotonic sequencing to logical session-tab notifications and preserves scheduling watermarks across coalesced delivery. |
| src/main/runtime/rpc/methods/session-tabs-inventory.ts | Implements bounded census buffering, watermark reconciliation, projection-aware deduplication, and ordered transition replay without an identified correctness defect. |
| src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts | Adds deterministic coverage for census boundaries, structural transitions, projection changes, caller-only follow intent, overflow retries, and cancellation cleanup. |
| src/main/runtime/rpc/methods/session-tabs-inventory-rpc.test.ts | Updates RPC inventory tests for the sequenced listener and census collection contract. |
| config/reliability-gates.jsonc | Registers session-tab subscription linearizability and its deterministic regression suite in the paired-terminal reliability gate. |
Sequence Diagram
sequenceDiagram
participant C as Client
participant S as Subscription
participant R as Runtime
C->>S: Subscribe to session tabs
S->>R: Register change listener
S->>R: Collect census with sequence watermark
par Census collection
R-->>S: Buffer concurrent sequenced changes
end
R-->>S: Initial snapshots + watermark
S-->>C: Publish initial snapshots
S->>S: Sort and reconcile changes newer than watermark
S-->>C: Publish required updates in sequence order
alt Sustained structural churn
S->>R: Retry census (maximum three attempts)
S-->>C: Reject as inventory unstable if retries exhaust
end
Reviews (1): Last reviewed commit: "fix(runtime): reconcile session tab cens..." | Re-trigger Greptile
📝 WalkthroughWalkthroughThe runtime now assigns monotonic change sequences to mobile-session-tabs notifications and exposes sequence-aware inventory methods. The inventory subscription buffers, coalesces, orders, deduplicates, and replays changes around authoritative censuses. It retries unstable censuses and bounds initialization state. New tests cover real and mock runtimes, cleanup, overflow, ordering, and subscriber behavior. Reliability-gate configuration registers the new census-race test and its assertions. Merge Risk: 🟡 Moderate · up to The PR fixes initial session-tab census races, but the current implementation can still deliver a stale tab update after a newer one, lose a pre-census follow request, and continue fallback census work after disconnect; an added regression test also contains an assertion that cannot validate listener cleanup. These bounded issues should be corrected or explicitly accepted before merging. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description is complete and follows the required template. It explains the problem, changes, rationale, linked issue, visual proof, testing, review, scope, and checklist. The blank AI Disclosure and unchecked manual-testing item are minor gaps because automated validation and manual E2E results are documented. Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 4 files. (2 skipped: 1 unsupported, 1 too large.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/runtime/orca-runtime.ts (1)
34659-34673: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winCancel pending coalesced notifications in the unscoped branch.
When a worktree has pending sequence
S1,notifyMobileSessionTabsChanged()can emit newer sequenceS2throughnotifyMobileSessionTabSnapshots(). The coalescer can then emitS1afterS2, regressing listener ordering. Cancel each pending worktree notification before bulk delivery, as the scoped branch does.
🧹 Nitpick comments (1)
src/main/runtime/rpc/methods/session-tabs-inventory.ts (1)
173-180: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winCompare client-visible content without version metadata
The title/status path increments
snapshotVersionbefore each scheduled notification. The listener therefore receives a differentsnapshotVersionfor each notification, soisDeepStrictEqual(published, state)returnsfalseand cannot coalesce this churn. ExcludesnapshotVersionandpublicationEpochfrom the comparison.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 98619516-3dee-46ff-a33c-2f5920fdf097
📒 Files selected for processing (6)
config/reliability-gates.jsoncsrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.tssrc/main/runtime/rpc/methods/session-tabs-inventory-rpc.test.tssrc/main/runtime/rpc/methods/session-tabs-inventory.tssrc/main/runtime/rpc/methods/session-tabs.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.
|
|
||
| await expect(pending).rejects.toThrow('client_disconnected') | ||
| expect(internals.mobileSessionTabListeners).toHaveLength(0) | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Description: Resolve the declared container type of mobileSessionTabListeners in the runtime.
fd -t f 'orca-runtime.ts' | xargs rg -n -C3 'mobileSessionTabListeners'Repository: stablyai/orca
Length of output: 5334
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- scoped repository guidance ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- test declarations and assertion imports ---'
sed -n '1,90p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
sed -n '510,545p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
printf '%s\n' '--- applicable guidance headers/content ---'
for f in /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/*.md /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/*.md /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/architecture/*.md; do
[ -f "$f" ] && { echo "### $f"; head -80 "$f"; }
doneRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- Vitest version and local matcher references ---'
rg -n -m 20 '"vitest"|toHaveLength' package.json pnpm-lock.yaml src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
printf '%s\n' '--- runtime listener contract ---'
sed -n '3238,3262p' src/main/orca-runtime.ts
sed -n '11280,11302p' src/main/orca-runtime.tsRepository: stablyai/orca
Length of output: 486
🌐 Web query:
Vitest 4.1.5 toHaveLength matcher Set length property official documentation
💡 Result:
The toHaveLength matcher in Vitest asserts that an object has a.length property and that this property is equal to the expected numeric value [1][2]. Because the matcher specifically checks for the existence of a.length property, it does not natively support JavaScript Set objects, which use the.size property instead of.length [1][3]. If you attempt to use toHaveLength on a Set, the assertion will fail because the Set does not have a.length property [1][3]. To assert the number of elements in a Set, you should instead compare the size property, for example: expect(mySet.size).toBe(expectedValue); Or, if you prefer to maintain an expect-style chain for iterables, you can access the size property directly in the expectation: expect(new Set([1][2][4]).size).toBe(3);
Citations:
- 1: https://vitest.dev/api/expect.html
- 2: https://github.com/vitest-dev/vitest/blob/206e8cff/docs/api/expect.md
- 3: https://github.com/vitest-dev/vitest/blob/206e8cff/packages/expect/src/jest-expect.ts
- 4: https://github.com/vitest-dev/vitest/blob/v4.1.10/docs/api/expect.md
Use size for the Set-backed listener collection. Vitest’s toHaveLength checks length, but mobileSessionTabListeners is a Set and exposes size. This assertion fails even when the set is empty and does not verify listener removal.
| bufferedChanges.sort((left, right) => left.changeSequence - right.changeSequence) | ||
| for (const buffered of bufferedChanges) { | ||
| if (closed) { | ||
| break | ||
| } | ||
| if (buffered.changeSequence > changeSequence) { | ||
| publishChange(buffered.snapshot, buffered.changeSequence) | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Description: Determine whether inventory census reads can carry navigationIntent.
set -euo pipefail
fd -t f 'orca-runtime.ts' src/main/runtime --exec rg -n -C 6 \
'navigationIntent|listAllMobileSessionTabsInventoryWithChangeSequence|listAllMobileSessionTabsWithChangeSequence|listAllMobileSessionTabsInventory\b'
# Test: confirm whether any census-race test asserts a follow intent buffered before the census.
fd -t f 'session-tabs-inventory-census-race.test.ts' src --exec rg -n -C 6 'navigationIntent|follow'Repository: stablyai/orca
Length of output: 9011
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- repository conventions and learnings ---'
find /tmp/coderabbit-repo-knowledge/stablyai/orca-89dc44e4 -mindepth 2 -maxdepth 2 -type f -name '*.md' -print \
-exec sh -c 'printf "\n--- %s ---\n" "$1"; head -120 "$1"' _ {} \;
printf '%s\n' '--- session-tabs-inventory.ts ---'
sed -n '1,290p' src/main/runtime/rpc/methods/session-tabs-inventory.ts
printf '%s\n' '--- runtime census and emission paths ---'
fd -t f 'orca-runtime.ts' src/main/runtime --exec sed -n '7480,7585p;34680,34720p' {}
printf '%s\n' '--- snapshotVersion and publicationEpoch definitions/usages ---'
rg -n -C 8 'snapshotVersion|publicationEpoch' src/main/runtime src/shared --glob '*.ts'Repository: stablyai/orca
Length of output: 285
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- session-tabs-inventory.ts ---'
sed -n '1,290p' src/main/runtime/rpc/methods/session-tabs-inventory.ts
printf '%s\n' '--- runtime census and emission paths ---'
fd -t f 'orca-runtime.ts' src/main/runtime --exec sed -n '7480,7585p;34680,34720p' {}
printf '%s\n' '--- snapshotVersion and publicationEpoch definitions/usages ---'
rg -n -C 8 'snapshotVersion|publicationEpoch' src/main/runtime src/shared --glob '*.ts'
printf '%s\n' '--- repository conventions and learnings ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -mindepth 2 -maxdepth 2 -type f -name '*.md' -print \
-exec sh -c 'printf "\n--- %s ---\n" "$1"; head -120 "$1"' _ {} \;Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
set -euo pipefail
runtime_file="$(fd -t f 'orca-runtime.ts' src/main/runtime | head -1)"
printf '%s\n' '--- collector and replay implementation ---'
sed -n '1,285p' src/main/runtime/rpc/methods/session-tabs-inventory.ts
printf '%s\n' '--- runtime method locations ---'
rg -n 'collectAllMobileSessionTabs|listAllMobileSessionTabsInventoryWithChangeSequence|emitMobileSessionTabsSnapshotToClient|mobileSessionTabsChangeSequence|snapshotVersion' "$runtime_file"
printf '%s\n' '--- runtime census implementation ---'
sed -n '7528,7585p' "$runtime_file"
printf '%s\n' '--- runtime client emission implementation ---'
sed -n '34685,34718p' "$runtime_file"
printf '%s\n' '--- relevant census-race tests ---'
sed -n '390,505p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
sed -n '665,700p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
printf '%s\n' '--- repository convention files ---'
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -mindepth 2 -maxdepth 2 -type f -name '*.md' -printRepository: stablyai/orca
Length of output: 26079
🏁 Script executed:
#!/bin/bash
set -euo pipefail
runtime_file="$(fd -t f 'orca-runtime.ts' src/main/runtime | head -1)"
printf '%s\n' '--- snapshot mutation and notification paths ---'
sed -n '6725,6785p;6938,6970p;7335,7370p' "$runtime_file"
sed -n '7825,7990p' "$runtime_file"
sed -n '8535,8635p' "$runtime_file"
sed -n '9340,9380p;9688,9720p' "$runtime_file"
printf '%s\n' '--- exact dedupe-related tests ---'
rg -n -C 12 'dedup|unchanged|same.*snapshot|same.*version|repeated.*sync|title-flip|coalesc' \
src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts \
src/main/runtime/graph-sync-mobile-snapshot-gating.test.ts \
src/main/runtime/mobile-session-tabs-churn-coalescing.test.tsRepository: stablyai/orca
Length of output: 50369
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- navigationIntent consumers and producer contract ---'
rg -n -C 10 'navigationIntent|emitMobileSessionTabsSnapshotToClient\(' \
src/main src/renderer src/shared --glob '*.ts' --glob '*.tsx'
printf '%s\n' '--- census-boundary test context ---'
sed -n '450,500p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
sed -n '675,700p' src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
printf '%s\n' '--- runtime notification paths without snapshot rebuilding ---'
runtime_file="$(fd -t f 'orca-runtime.ts' src/main/runtime | head -1)"
sed -n '6950,6965p;34650,34675p;34695,34712p' "$runtime_file"Repository: stablyai/orca
Length of output: 50369
Preserve pre-census navigationIntent against the census state. When a follow event is buffered before census completion, the changeSequence filter drops it. The census snapshot has no navigationIntent, and the renderer only follows activeTabId when navigationIntent === 'follow'. Re-emit the intent against the census snapshot for that worktree.
(cherry picked from commit 6256f3d)
ELI5
When a client first connects to an Orca host, the host sends an initial list of session tabs. A tab created or removed while that list was being prepared could fall into a gap: it was absent from the list, and its change notification was discarded. This PR makes the initial list and concurrent tab changes one ordered handoff, so the client converges to the host's actual tabs.
What Changed
No wire field/opcode or renderer retry/polling behavior is added.
Why
The existing listener is installed before the asynchronous census resolves, but callbacks are discarded while
initializedis false. Latestmaindeterministically loses a post-boundary creation and removal. Fixing the subscription/runtime authority keeps the snapshot and concurrent changes linearizable without spreading recovery logic into consumers.Linked Issue
Visual Proof
N/A — this is a main-runtime ordering fix with no visual design change.
Testing
mainsource, controlled boundary oracle: 2 expected failures (post-boundary create/remove lost), 3 controls passed.pnpm tcandpnpm tc:nodepassed.git diff --checkpassed.orca servefocused terminal-create E2E: 1/1 passed on macOS.Known validation gap: the headed paired host-relaunch journey stalled in transport recovery (
connecting, then cleanuptab_not_found) before reaching a census assertion. A supplemental paired Cmd-J journey mirrored the host inventory but later failed active-tab visibility. No live Windows, Linux, or SSH E2E was run; the change is host-local, adds no platform-specific behavior, and does not alter wire bytes.AI Disclosure
Review
A fresh independent subagent reviewed the exact rebased diff and reported CLEAN: no validated correctness, design, performance, cleanup, fanout, mixed-version, SSH/folder-workspace, or cross-platform regression. Earlier delegated design, adversarial, and performance review rounds also reached a clean final round.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
The bounded failure policy is deliberate: after 256 buffered structural transitions repeatedly invalidate three census attempts, the subscription rejects with
session_tabs_inventory_unstablerather than publishing an inventory known to be incomplete.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)