Skip to content

Fix lost session-tab changes during initial census - #17064

Merged
Jinwoo-H merged 1 commit into
mainfrom
sta-5733-session-inventory-census-race
Aug 28, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
sta-5733-session-inventory-census-race

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​994 $\color{#cf222e}{\Huge{\mathbf{−}}}$​64 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​930
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​293 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​245

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

  • Assign a host-local monotonic sequence to logical session-tab notifications.
  • Capture the sequence watermark with the initial census.
  • Buffer and reconcile changes received while the census is in progress.
  • Preserve ordered create/remove/recreate membership transitions.
  • Coalesce ordinary same-membership churn and repeated caller-only follow requests.
  • Suppress projected payloads already represented by the census while delivering later PTY projection changes.
  • Bound initialization buffering to 256 records and census collection to three attempts; fail before publishing partial state if sustained structural churn prevents a stable boundary.
  • Add a deterministic controlled-promise regression suite and register the invariant in the reliability gate.

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 initialized is false. Latest main deterministically 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

  • Actual latest-main source, controlled boundary oracle: 2 expected failures (post-boundary create/remove lost), 3 controls passed.
  • Candidate deterministic race suite: 29/29 passed.
  • Focused inventory/RPC suites: 66/66 passed.
  • Reliability slice: 98/98 passed.
  • Fresh independent review adjacent runtime/fanout/PTY suites: 78/78 passed.
  • pnpm tc and pnpm tc:node passed.
  • Changed-code quality, max-lines ratchet, reliability manifest, and git diff --check passed.
  • Rebuilt headless orca serve focused terminal-create E2E: 1/1 passed on macOS.

Known validation gap: the headed paired host-relaunch journey stalled in transport recovery (connecting, then cleanup tab_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.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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_unstable rather than publishing an inventory known to be incomplete.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

The PR makes initial session-tab inventory collection and concurrent tab notifications an ordered handoff using host-local sequence watermarks.

  • Buffers and reconciles changes that arrive during census collection.
  • Preserves structural create, remove, and recreate transitions while coalescing redundant same-membership churn.
  • Bounds initialization buffering and retries, rejecting unstable censuses rather than publishing partial state.
  • Adds deterministic race coverage and registers the invariant in the reliability gate.

Confidence Score: 5/5

The 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.

Important Files Changed

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
Loading

Reviews (1): Last reviewed commit: "fix(runtime): reconcile session tab cens..." | Re-trigger Greptile

@Jinwoo-H
Jinwoo-H merged commit 6256f3d into main Aug 28, 2026
30 checks passed
@Jinwoo-H
Jinwoo-H deleted the sta-5733-session-inventory-census-race branch August 28, 2026 21:57
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 452e1

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: preventing session-tab changes from being lost during the initial census.
Description check ✅ Passed 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 a…
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.
Full details: Description check

Explanation

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 Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Cancel pending coalesced notifications in the unscoped branch.

When a worktree has pending sequence S1, notifyMobileSessionTabsChanged() can emit newer sequence S2 through notifyMobileSessionTabSnapshots(). The coalescer can then emit S1 after S2, 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 win

Compare client-visible content without version metadata

The title/status path increments snapshotVersion before each scheduled notification. The listener therefore receives a different snapshotVersion for each notification, so isDeepStrictEqual(published, state) returns false and cannot coalesce this churn. Exclude snapshotVersion and publicationEpoch from the comparison.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98619516-3dee-46ff-a33c-2f5920fdf097

📥 Commits

Reviewing files that changed from the base of the PR and between 4fa3022 and 452e14c.

📒 Files selected for processing (6)
  • config/reliability-gates.jsonc
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/session-tabs-inventory-census-race.test.ts
  • src/main/runtime/rpc/methods/session-tabs-inventory-rpc.test.ts
  • src/main/runtime/rpc/methods/session-tabs-inventory.ts
  • src/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.

Comment on lines +536 to +539

await expect(pending).rejects.toThrow('client_disconnected')
expect(internals.mobileSessionTabListeners).toHaveLength(0)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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"; }
done

Repository: 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.ts

Repository: 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:


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.

Comment on lines +261 to +269
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)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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' -print

Repository: 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.ts

Repository: 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.

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