Skip to content

fix(ai-vault): support session scanning in SSH worktrees - #11004

Merged
AmethystLiang merged 10 commits into
mainfrom
scanning-sessions-in-ssh-worktree-does-not-work
Aug 3, 2026
Merged

AmethystLiang merged 10 commits into
mainfrom
scanning-sessions-in-ssh-worktree-does-not-work

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds relay-side Agent Session History scanning for SSH worktrees. Previously session listing relied entirely on desktop-side filesystem crawling. This change enables scanning directly on the SSH host when the relay supports it, with automatic fallback to desktop crawling for older relays.

Key improvements:

  • Relay-side scanning eliminates per-file network roundtrips
  • Cancellation support via AbortSignal throughout the scan pipeline
  • Graceful handling of result validation with per-entry error collection
  • Scope path truncation (64 item limit) with user-facing warnings
  • Coalesced in-flight scans with independent caller cancellation, force preemption of a hung scan, and cache fencing so an aborted scan never poisons the cache
  • Bounded all-host SSH legs: the legacy desktop crawl now runs inside the same timeoutMs budget as the relay round trip, and a host that throws or times out degrades to one issue row instead of discarding local/runtime results

Screenshots

No visual change.

Testing

  • pnpm run typecheck:node, pnpm run typecheck:web
  • pnpm run check:code-quality:changed (0 new findings / 47 changed files), pnpm run check:max-lines-ratchet, git diff --check, oxfmt --check
  • Focused vitest over all changed AI Vault / relay / renderer files — 215 files, 1756 tests passing
  • New/extended unit tests:
    • ai-vault-scan-coordinator.test.ts — waiter lifecycle, forced preemption, abort fencing
    • ssh-session-list.test.ts (new) — bounded legacy crawl, unbounded when no budget, crawl throw degrades to a host issue, caller cancellation still propagates
    • session-list-results.test.ts (new) — scope-truncation notice survives mergeAiVaultListResults, one notice per host, never counted as a skipped transcript
    • ai-vault-scan-coalescing.test.ts (new) — coalescing across independent caller signals
    • ai-vault.test.ts — all-scope host-discovery failures and a throwing local leg both degrade to issue rows without dropping other hosts
    • session-list-result-validation.test.ts — all-invalid relay payload rejects so the leg falls back
    • ai-vault-scan-issue-state.test.ts / ai-vault-session-refresh.test.ts — issue classification, skipped-transcript reasons, cancellation recognition
  • E2E driver updated (ssh-codex-reconnect-replay-driver.ts) to poll for remote worktrees instead of assuming instant availability

Review Answers

Does the relay path avoid the SSH filesystem stream/mux limits (#11396, #11364)?

Partly — and the distinction matters:

  • Transport: yes. AiVaultHandler (src/relay/ai-vault-handler.ts) runs scanRemoteAiVaultSessions (src/main/ai-vault/remote-session-scanner.ts) inside the remote relay process, against a host-local provider built by createRelayAiVaultFilesystemProvider() — readdir/lstat from node:fs/promises plus readRelayFileContent. No transcript bytes cross the desktop SSH filesystem stream/mux, so the chunked-stream pump and its unacked-chunk backpressure are out of the picture entirely. This does not reduce [Bug]: SSH AI Vault skips session transcripts larger than 10 MB #11396's urgency: that issue tracks the 10 MiB cap, which remains on both paths.
  • 10 MiB cap: no, it still applies. readRelayFileContent enforces MAX_TEXT_FILE_SIZE = 10 * 1024 * 1024 (src/relay/fs-handler-utils.ts:25) before returning content, exactly mirroring the desktop reader's own 10 * 1024 * 1024 (src/main/ssh/ssh-filesystem-stream-reader.ts:9). A >10 MiB transcript is skipped on both paths; it is just skipped host-locally now instead of after a stream setup. Raising that cap for transcripts is out of scope here.

Does the older-relay fallback still carry the original risks?

Yes. When the relay has no aiVault.listSessions method the leg falls through to the desktop crawl over ssh-filesystem-stream-reader.ts, so both the missing per-read inactivity timeout and the 10 MiB cap still apply. This PR bounds that crawl with an overall wall-clock budget in all-host scope (scanRemoteSessionsWithinBudget in ssh-session-list.ts), which stops one stalled host from holding every other host's results hostage — but it does not add the per-read inactivity timeout. #11364 remains a required companion, not something this PR closes.

How does the 64-path scope warning behave end to end?

It is an AiVaultScanIssue with kind: 'scope', emitted identically by both legs (relay leg in ai-vault-handler.ts, fallback leg via scopeTruncationIssue in ssh-session-list.ts) so neither can silently scan more paths than the other. It survives mergeAiVaultListResults, which concatenates every result's issues without dedup — covered by session-list-results.test.ts, including one notice per host and a scope notice surviving alongside a failing host. It renders through AiVaultScanIssueBanners (mounted in AiVaultPanel.tsx:338) using the scanner-authored issue.message. Because skippedAiVaultTranscriptCount counts only issues with no kind, it is excluded from the skipped-transcript footer.

First user prompt, relative to #12006 on main

Keeping remote prompts null — no change needed here. Two independent reasons:

  1. This branch predates Add first user prompt to AI Vault session history row #12006: firstUserPrompt does not exist anywhere in the branch's source (src/main/ai-vault/session-first-user-prompt-read.ts and friends are origin/main-only). There is nothing in this diff that can regress or implement it.
  2. Main's own reader already takes this posture deliberately. readAiVaultFirstUserPrompt returns { prompt: null } for any executionHostId !== LOCAL_EXECUTION_HOST_ID, with the comment "transcript bodies live on the session host. Remote rows are skipped (same posture as listSubagentSessions); UI falls back to preview text." So after this branch merges main, SSH rows will resolve to null and fall back to preview text, which is the intended behavior — not a regression introduced here.

Serving full first prompts for remote hosts would need a new relay method to read the transcript body host-side. That is a separate change and is not attempted in this PR.

CI Housekeeping

Run 30385188010 is stale — it predates the fixes in the current working tree.

  • static analysis — real, work-caused, now fixed. It failed on a single --deny-warnings warning, "Modules should not be imported multiple times in the same file": remote-session-scanner.ts imported from ./remote-session-scanner-types twice (lines 17 and 24 at that commit). The current tree merges them into one import type, and check:code-quality:changed now reports 0 new findings.
  • e2e 9-of-10 — cancelled, not a failure. The GitHub API job conclusion is literally cancelled; it is not independent evidence of a broken test and should not be counted as one.
  • e2e 1/3/7-of-10 — unrelated red. Failures are agent-session force-exit/quit resume, new-workspace Jira/GitHub linked-item project switching, and OpenCode alt-screen reveal artifacts (STA-2694). None touch AI Vault.
  • tests 7/16 — unrelated infrastructure error. All 2175 tests passed; the job failed on an unhandled EPIPE thrown from wsl-hook-relay-sentinel.ts during wsl-hook-relay-live.integration.test.ts teardown.

No live reproduction of the e2e shards was attempted locally; the above is read off the run's logs and job conclusions.

Notes

  • Relay method aiVault.listSessions timeout: 130s; timeouts do not trigger fallback crawl
  • force propagates desktop → relay (SshAiVaultRelayListParams.force) but is deliberately excluded from the relay coordinator's coalescing key, so a forced refresh preempts a stale scan instead of fragmenting the cache
  • A forced scan preempts an in-flight one immediately if that scan was unforced, or after 5s if it was forced (FORCED_SCAN_PREEMPT_AFTER_MS), so a hung scan can't strand every later Refresh
  • Cancellation is recognized in the renderer by shared message constant (AI_VAULT_SCAN_CANCELLED_MESSAGE) because IPC drops Error.name; a cancelled scan leaves the existing list in place rather than painting an abort error over good state
  • A relay payload whose sessions are all invalid now throws in parseAiVaultListResult so the leg falls back to the desktop crawl, instead of silently reporting an empty host
  • Host-level issues (connection failures) block results; file-level issues are counted in skipped transcript footer, and their distinct reasons (capped at 3) are now shown instead of a bare count
  • Platform-aware: relay automatically detects current platform and uses correct remote path separators

Known out-of-scope risks: #11364 (missing per-read inactivity timeout on the legacy SSH stream reader) is still required as a companion; #11395 remains open for the legacy fallback path, and #11396 remains open for both relay and legacy paths because both enforce the 10 MiB cap.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b0d1a5d-89bc-470f-a460-2ec7b376e50b

📥 Commits

Reviewing files that changed from the base of the PR and between 8e7355173b8cc3ec601d67e9c52d5b26a4197f87 and a286c70.

📒 Files selected for processing (86)
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/ai-vault/ai-vault-scan-cancellation.test.ts
  • src/main/ai-vault/ai-vault-scan-cancellation.ts
  • src/main/ai-vault/ai-vault-scan-coordinator.test.ts
  • src/main/ai-vault/ai-vault-scan-coordinator.ts
  • src/main/ai-vault/cached-session-list.ts
  • src/main/ai-vault/remote-session-content-lines.ts
  • src/main/ai-vault/remote-session-file-stat.ts
  • src/main/ai-vault/remote-session-scan-batching.test.ts
  • src/main/ai-vault/remote-session-scan-batching.ts
  • src/main/ai-vault/remote-session-scan-concurrency.ts
  • src/main/ai-vault/remote-session-scan-issues.ts
  • src/main/ai-vault/remote-session-scanner-codex-index.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/remote-session-scanner-sources.ts
  • src/main/ai-vault/remote-session-scanner-types.ts
  • src/main/ai-vault/remote-session-scanner.test.ts
  • src/main/ai-vault/remote-session-scanner.ts
  • src/main/ai-vault/runtime-session-scanner.test.ts
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ai-vault/session-list-result-validation.test.ts
  • src/main/ai-vault/session-list-result-validation.ts
  • src/main/ai-vault/session-list-results.test.ts
  • src/main/ai-vault/session-list-results.ts
  • src/main/ai-vault/session-scanner-antigravity-parser.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/session-scanner-copilot-parser.ts
  • src/main/ai-vault/session-scanner-cursor-parser.ts
  • src/main/ai-vault/session-scanner-droid-parser.ts
  • src/main/ai-vault/session-scanner-gemini-parsers.ts
  • src/main/ai-vault/session-scanner-graph-parsers.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-bounds.test.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-list.ts
  • src/main/ai-vault/session-scanner-primary-parsers.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/ai-vault/session-scanner.test.ts
  • src/main/ai-vault/session-scanner.ts
  • src/main/ai-vault/ssh-session-list.test.ts
  • src/main/ai-vault/ssh-session-list.ts
  • src/main/ipc/ai-vault-host-discovery.ts
  • src/main/ipc/ai-vault-host-leg-cache.ts
  • src/main/ipc/ai-vault-runtime-scan.ts
  • src/main/ipc/ai-vault-scan-coalescing.test.ts
  • src/main/ipc/ai-vault.test.ts
  • src/main/ipc/ai-vault.ts
  • src/main/ipc/ssh.ts
  • src/main/runtime/rpc/methods/ai-vault.test.ts
  • src/main/runtime/rpc/methods/ai-vault.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/relay/ai-vault-handler.test.ts
  • src/relay/ai-vault-handler.ts
  • src/relay/relay.ts
  • src/renderer/src/components/right-sidebar/AiVaultPanel.tsx
  • src/renderer/src/components/right-sidebar/AiVaultPanelControls.tsx
  • src/renderer/src/components/right-sidebar/AiVaultPanelHeader.tsx
  • src/renderer/src/components/right-sidebar/AiVaultScanIssueBanners.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionLimitMenu.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionListStates.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionVirtualList.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-limit.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-result-cache.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-options-persistence.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-options-persistence.ts
  • src/renderer/src/components/right-sidebar/use-persisted-ai-vault-view-options.test.tsx
  • src/renderer/src/components/right-sidebar/use-persisted-ai-vault-view-options.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/ai-vault-session-depth.test.ts
  • src/shared/ai-vault-session-depth.ts
  • src/shared/ai-vault-types.ts
  • src/shared/ssh-ai-vault-relay.ts
  • tests/e2e/ssh-codex-reconnect-replay-driver.ts

📝 Walkthrough

Walkthrough

This change adds cancellation-aware AI Vault scanning across local, runtime, remote, and SSH paths. It adds bounded and unlimited session-history limits, depth-aware caches, scan coordination, result validation, issue aggregation, SSH relay requests, IPC cancellation, and renderer controls. Remote parsing now streams lines with cancellation checks. Relay and fallback scans use separate time budgets. WSL stdin EPIPE handling and SSH reconnect worktree setup are also updated.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.75% which is insufficient. The required threshold is 80.00%. 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 identifies the main change: AI Vault session scanning for SSH worktrees.
Description check ✅ Passed The description clearly covers the change, testing, review findings, platform behavior, risks, follow-up work, and no visual change.
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 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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/renderer/src/components/right-sidebar/AiVaultPanel.tsx (1)

337-349: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Host-level issues get folded into the generic "transcript skipped" count when sessions are also present.

blockingAiVaultScanIssue only surfaces a kind: 'host' issue when sessions.length === 0; if a scan returns some sessions plus a host-level failure (e.g. 'all' scope: local succeeds, one SSH host is unreachable), the fallback branch renders scanResult.issues.length transcripts skipped — mislabeling a host connectivity failure as a skipped transcript file. Consider filtering kind === 'host' issues out of this count (or surfacing them with their own copy) so the message stays accurate in the partial-success case.

src/main/ipc/ai-vault.ts (1)

121-161: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Forward cancellation options to local and runtime scans.

scanAiVaultSessionsByHostScope only passes signal into the SSH scan path. With cancellation enabled, local-filesystem scans and runtime RPC aiVault.listSessions calls can continue to completion even after the caller cancels an 'all' or runtime-scope request; pass the abort signal through both scan paths.

🧹 Nitpick comments (1)
src/main/ai-vault/remote-session-scanner.ts (1)

251-264: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Three near-identical batch/cancel/yield loops could be a single shared helper.

mapRemoteScanConcurrently, mapDiscoveryConcurrently, and the inline loop in scanRemoteInScopeSessions all implement the same "slice into batches of N, check cancellation, Promise.all the batch, yield to the event loop" pattern with only the concurrency constant differing.

  • src/main/ai-vault/remote-session-scanner.ts#L251-L264: mapRemoteScanConcurrently — candidate location for a shared generic helper (e.g. in the scanning-contracts layer alongside throwIfRemoteSessionScanCancelled).
  • src/main/ai-vault/remote-session-scanner-discovery.ts#L138-L151: mapDiscoveryConcurrently duplicates the same logic with REMOTE_DISCOVERY_CONCURRENCY.
  • src/main/ai-vault/remote-session-scanner.ts#L135-L167: the inline batching loop in scanRemoteInScopeSessions duplicates the same logic again instead of calling a shared helper.
♻️ Suggested shared helper shape
export async function mapConcurrentlyWithCancellation<T, U>(
  items: readonly T[],
  concurrency: number,
  mapper: (item: T) => Promise<U>,
  signal?: AbortSignal
): Promise<U[]> {
  const results: U[] = []
  for (let index = 0; index < items.length; index += concurrency) {
    throwIfRemoteSessionScanCancelled(signal)
    const batch = items.slice(index, index + concurrency)
    results.push(...(await Promise.all(batch.map(mapper))))
    await yieldToEventLoop()
  }
  return results
}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6963214b-dad0-4f66-a5c3-f9c2b36c43f2

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb3276 and cffffc4.

📒 Files selected for processing (36)
  • src/main/ai-vault/remote-session-content-lines.ts
  • src/main/ai-vault/remote-session-file-stat.ts
  • src/main/ai-vault/remote-session-scan-cancellation.ts
  • src/main/ai-vault/remote-session-scan-issues.ts
  • src/main/ai-vault/remote-session-scanner-codex-index.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/remote-session-scanner-sources.ts
  • src/main/ai-vault/remote-session-scanner-types.ts
  • src/main/ai-vault/remote-session-scanner.ts
  • src/main/ai-vault/runtime-session-scanner.test.ts
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ai-vault/session-list-result-validation.test.ts
  • src/main/ai-vault/session-list-result-validation.ts
  • src/main/ai-vault/session-list-results.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/ssh-session-list.ts
  • src/main/ipc/ai-vault.test.ts
  • src/main/ipc/ai-vault.ts
  • src/main/ipc/ssh.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/relay/ai-vault-handler.test.ts
  • src/relay/ai-vault-handler.ts
  • src/relay/ai-vault-scan-coordinator.test.ts
  • src/relay/ai-vault-scan-coordinator.ts
  • src/relay/relay.ts
  • src/renderer/src/components/right-sidebar/AiVaultPanel.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/ai-vault-types.ts
  • src/shared/ssh-ai-vault-relay.ts
  • tests/e2e/ssh-codex-reconnect-replay-driver.ts

Comment thread src/main/ai-vault/ssh-session-list.ts Resolved
Comment thread src/main/ipc/ai-vault.ts Resolved
Comment thread src/relay/ai-vault-handler.ts Resolved

@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: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 763aea50-56e5-4baf-9e07-80309a317faf

📥 Commits

Reviewing files that changed from the base of the PR and between cffffc4 and 22b6da3.

📒 Files selected for processing (8)
  • src/main/ai-vault/ai-vault-scan-coordinator.test.ts
  • src/main/ai-vault/ai-vault-scan-coordinator.ts
  • src/main/ai-vault/remote-session-content-lines.ts
  • src/main/ai-vault/remote-session-scan-batching.ts
  • src/main/ai-vault/remote-session-scanner-codex-index.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/remote-session-scanner.ts
  • src/main/ai-vault/ssh-session-list.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/ai-vault/remote-session-content-lines.ts
  • src/main/ai-vault/remote-session-scanner-codex-index.ts
  • src/main/ai-vault/ssh-session-list.ts

@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai[bot] resvoled

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Confirmed. Thank you for resolving the issue.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

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

🧹 Nitpick comments (1)
.github/workflows/adhoc-mac-build.yml (1)

165-178: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Two copies of the origin/main version lookup exist. The workflow reads origin/main:package.json in shell, and the script reads it again in readMainPackageJsonVersion. Only one copy runs in CI, because the workflow always sets ORCA_ADHOC_BASE_VERSION, so the script path stays untested in CI and can drift.

  • .github/workflows/adhoc-mac-build.yml#L165-L178: delete the inline node -e reader and the base_version export. Let config/scripts/adhoc-build-version.mjs resolve the base version through resolveAdhocBaseVersion. Keep the git fetch only if the script must not fetch.
  • config/scripts/adhoc-build-version.mjs#L113-L129: keep this as the single owner of the lookup, and log the failure reason on stderr before returning undefined so a fallback to the branch version is visible in the workflow log.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 621426c7-5d69-40b1-8069-8bb2e018cbd3

📥 Commits

Reviewing files that changed from the base of the PR and between 22b6da3 and a26a18eb3fd83f7e7d2db9a6a7c3e02e0f79089a.

📒 Files selected for processing (3)
  • .github/workflows/adhoc-mac-build.yml
  • config/scripts/adhoc-build-version.mjs
  • config/scripts/adhoc-build-version.test.mjs

@AmethystLiang
AmethystLiang force-pushed the scanning-sessions-in-ssh-worktree-does-not-work branch from fd18e4f to 8e73551 Compare August 3, 2026 22:44

@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: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/ai-vault/session-scanner.ts (1)

127-152: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check cancellation before scheduling the cache write and returning.

If cancellation occurs after scanInScopeSessions settles, this function can return a completed result for a cancelled request. It can also persist that result before the caller observes cancellation.

Proposed fix
     const scopeSessions = await scanInScopeSessions({
       discoveries,
       scopePaths: options.scopePaths ?? [],
       limit,
       alreadyParsedFilePaths: new Set(cappedSessions.map((session) => session.filePath)),
       platform,
       executionHostId,
       issues,
       parseStats,
       signal: options.signal
     })
+    throwIfAiVaultScanCancelled(options.signal)
 
     span.setAttribute('candidates', candidates.length)
🧹 Nitpick comments (5)
src/main/ai-vault/session-list-results.ts (1)

61-68: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Reuse the shared depth normalization.

This limit normalization now duplicates requestedAiVaultSessionDepth in src/shared/ai-vault-session-depth.ts and the same expression in scanRemoteAiVaultSessions. The local copy also omits the Number.isFinite guard, so a non-finite limit reaches slice instead of falling back to DEFAULT_AI_VAULT_SCAN_LIMIT. Deriving the depth once keeps the three sites in agreement.

♻️ Proposed refactor
-  const limit = unlimited
-    ? Number.POSITIVE_INFINITY
-    : rawLimit && rawLimit > 0
-      ? Math.floor(rawLimit)
-      : DEFAULT_AI_VAULT_SCAN_LIMIT
+  const depth = requestedAiVaultSessionDepth({ limit: rawLimit, unlimited })
+  const limit = depth === 'unlimited' ? Number.POSITIVE_INFINITY : depth

Update the import accordingly:

-import { DEFAULT_AI_VAULT_SCAN_LIMIT } from '../../shared/ai-vault-session-depth'
+import { requestedAiVaultSessionDepth } from '../../shared/ai-vault-session-depth'
src/main/ai-vault/ai-vault-scan-coordinator.ts (1)

78-131: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid aborting an entry after it resolved successfully.

detach runs before resolve in the success path. When the last waiter leaves, entry.waiterCount reaches 0 and entry.controller.signal.aborted is still false, so entry.controller.abort() fires on an already-settled scan. Any consumer that keys cleanup or logging off that signal sees a spurious cancellation. Skip the abort when the entry promise already settled.

♻️ Suggested guard
 type ScanEntry = {
   controller: AbortController
   force: boolean
   startedAt: number
   promise: Promise<AiVaultListResult>
   waiterCount: number
+  settled: boolean
   preemptedBy: ScanEntry | null
 }
-        if (entry.waiterCount === 0 && !entry.controller.signal.aborted) {
+        if (entry.waiterCount === 0 && !entry.settled && !entry.controller.signal.aborted) {
src/relay/ai-vault-handler.test.ts (1)

148-151: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wait for the scan call instead of one microtask tick.

The coordinator starts scanRemoteSessions inside a Promise.resolve().then(...) continuation. A single await Promise.resolve() depends on the exact microtask count between dispatcher.call and that continuation, so this assertion can flake if the call chain gains one more await. The other tests in this file already use vi.waitFor.

💚 Suggested change
     const second = dispatcher.call(SSH_AI_VAULT_LIST_SESSIONS_METHOD, { limit: 20 })
-    await Promise.resolve()
-
-    expect(scanRemoteSessions).toHaveBeenCalledTimes(1)
+    await vi.waitFor(() => expect(scanRemoteSessions).toHaveBeenCalledTimes(1))
src/renderer/src/components/right-sidebar/AiVaultSessionLimitMenu.tsx (1)

63-77: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive the performance label from the limits list instead of a hardcoded value.

Line 69 compares limit === 500 to pick between "May be slower" and "Slowest". This ties the label logic to one specific value in AI_VAULT_SESSION_LIMITS. If a maintainer adds, removes, or reorders a tier in that array later, this comparison silently misclassifies the new tier, and no compiler error signals the mismatch.

Derive the tier label from the array position instead of a literal value, for example by treating the last non-unlimited entry as "Slowest" and all other non-default numeric entries as "May be slower".

♻️ Proposed refactor to derive labels from the limits list
+const numericLimits = AI_VAULT_SESSION_LIMITS.filter(
+  (limit): limit is Exclude<AiVaultSessionLimit, 'unlimited'> => limit !== 'unlimited'
+)
+const slowestNumericLimit = numericLimits[numericLimits.length - 1]
+
 export function AiVaultSessionLimitMenu({
   sessionLimit,
   onSessionLimitChange
 }: {
   sessionLimit: AiVaultSessionLimit
   onSessionLimitChange: (limit: AiVaultSessionLimit) => void
 }): React.JSX.Element {
   ...
               <span className="ml-auto text-[11px] font-normal text-muted-foreground">
                 {limit === DEFAULT_AI_VAULT_SESSION_LIMIT
                   ? translate(
                       'auto.components.right.sidebar.AiVaultSessionLimitMenu.recommended',
                       'Recommended'
                     )
-                  : limit === 500
-                    ? translate(
-                        'auto.components.right.sidebar.AiVaultSessionLimitMenu.mayBeSlower',
-                        'May be slower'
-                      )
-                    : translate(
+                  : limit === 'unlimited' || limit === slowestNumericLimit
+                    ? translate(
                         'auto.components.right.sidebar.AiVaultSessionLimitMenu.slowest',
                         'Slowest'
                       )
+                    : translate(
+                        'auto.components.right.sidebar.AiVaultSessionLimitMenu.mayBeSlower',
+                        'May be slower'
+                      )
                 }
               </span>
src/shared/ai-vault-session-depth.test.ts (1)

40-46: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add boundary assertions for depth normalization.

requestedAiVaultSessionDepth floors finite limits and falls back for non-positive or non-finite values. The current tests do not cover those branches, and aiVaultSessionDepthCovers does not test finite equality. Add these cases to prevent normalization regressions. The expected behavior follows src/shared/ai-vault-session-depth.ts:8-17.

Suggested assertions
   it('recognizes which loaded depths cover a request', () => {
+    expect(aiVaultSessionDepthCovers(250, 250)).toBe(true)
     expect(aiVaultSessionDepthCovers(1000, 250)).toBe(true)
     expect(aiVaultSessionDepthCovers(250, 500)).toBe(false)

   it('normalizes default, finite, and unlimited requests', () => {
     expect(requestedAiVaultSessionDepth()).toBe(1000)
     expect(requestedAiVaultSessionDepth({ limit: 500 })).toBe(500)
+    expect(requestedAiVaultSessionDepth({ limit: 500.75 })).toBe(500)
+    expect(requestedAiVaultSessionDepth({ limit: 0 })).toBe(1000)
+    expect(requestedAiVaultSessionDepth({ limit: -1 })).toBe(1000)
+    expect(requestedAiVaultSessionDepth({ limit: Number.NaN })).toBe(1000)
+    expect(requestedAiVaultSessionDepth({ limit: Number.POSITIVE_INFINITY })).toBe(1000)
     expect(requestedAiVaultSessionDepth({ limit: 500, unlimited: true })).toBe('unlimited')
   })

Also applies to: 48-52


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e67c582-6b75-40db-b115-49cad8894eb2

📥 Commits

Reviewing files that changed from the base of the PR and between a26a18eb3fd83f7e7d2db9a6a7c3e02e0f79089a and 8e7355173b8cc3ec601d67e9c52d5b26a4197f87.

📒 Files selected for processing (86)
  • src/main/agent-hooks/wsl-hook-relay-sentinel.test.ts
  • src/main/agent-hooks/wsl-hook-relay-sentinel.ts
  • src/main/ai-vault/ai-vault-scan-cancellation.test.ts
  • src/main/ai-vault/ai-vault-scan-cancellation.ts
  • src/main/ai-vault/ai-vault-scan-coordinator.test.ts
  • src/main/ai-vault/ai-vault-scan-coordinator.ts
  • src/main/ai-vault/cached-session-list.ts
  • src/main/ai-vault/remote-session-content-lines.ts
  • src/main/ai-vault/remote-session-file-stat.ts
  • src/main/ai-vault/remote-session-scan-batching.test.ts
  • src/main/ai-vault/remote-session-scan-batching.ts
  • src/main/ai-vault/remote-session-scan-concurrency.ts
  • src/main/ai-vault/remote-session-scan-issues.ts
  • src/main/ai-vault/remote-session-scanner-codex-index.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/remote-session-scanner-sources.ts
  • src/main/ai-vault/remote-session-scanner-types.ts
  • src/main/ai-vault/remote-session-scanner.test.ts
  • src/main/ai-vault/remote-session-scanner.ts
  • src/main/ai-vault/runtime-session-scanner.test.ts
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ai-vault/session-list-result-validation.test.ts
  • src/main/ai-vault/session-list-result-validation.ts
  • src/main/ai-vault/session-list-results.test.ts
  • src/main/ai-vault/session-list-results.ts
  • src/main/ai-vault/session-scanner-antigravity-parser.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/session-scanner-copilot-parser.ts
  • src/main/ai-vault/session-scanner-cursor-parser.ts
  • src/main/ai-vault/session-scanner-droid-parser.ts
  • src/main/ai-vault/session-scanner-gemini-parsers.ts
  • src/main/ai-vault/session-scanner-graph-parsers.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-bounds.test.ts
  • src/main/ai-vault/session-scanner-opencode-sqlite-list.ts
  • src/main/ai-vault/session-scanner-primary-parsers.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/main/ai-vault/session-scanner.test.ts
  • src/main/ai-vault/session-scanner.ts
  • src/main/ai-vault/ssh-session-list.test.ts
  • src/main/ai-vault/ssh-session-list.ts
  • src/main/ipc/ai-vault-host-discovery.ts
  • src/main/ipc/ai-vault-host-leg-cache.ts
  • src/main/ipc/ai-vault-runtime-scan.ts
  • src/main/ipc/ai-vault-scan-coalescing.test.ts
  • src/main/ipc/ai-vault.test.ts
  • src/main/ipc/ai-vault.ts
  • src/main/ipc/ssh.ts
  • src/main/runtime/rpc/methods/ai-vault.test.ts
  • src/main/runtime/rpc/methods/ai-vault.ts
  • src/main/ssh/ssh-channel-multiplexer.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/relay/ai-vault-handler.test.ts
  • src/relay/ai-vault-handler.ts
  • src/relay/relay.ts
  • src/renderer/src/components/right-sidebar/AiVaultPanel.tsx
  • src/renderer/src/components/right-sidebar/AiVaultPanelControls.tsx
  • src/renderer/src/components/right-sidebar/AiVaultPanelHeader.tsx
  • src/renderer/src/components/right-sidebar/AiVaultScanIssueBanners.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionLimitMenu.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionListStates.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionVirtualList.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-scan-issue-state.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-limit.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-result-cache.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-defaults.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-defaults.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-options-persistence.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-view-options-persistence.ts
  • src/renderer/src/components/right-sidebar/use-persisted-ai-vault-view-options.test.tsx
  • src/renderer/src/components/right-sidebar/use-persisted-ai-vault-view-options.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/ai-vault-session-depth.test.ts
  • src/shared/ai-vault-session-depth.ts
  • src/shared/ai-vault-types.ts
  • src/shared/ssh-ai-vault-relay.ts
  • tests/e2e/ssh-codex-reconnect-replay-driver.ts
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/renderer/src/web/web-preload-api.ts
  • src/main/ai-vault/runtime-session-scanner.test.ts
  • src/shared/ssh-ai-vault-relay.ts
  • src/preload/api-types.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/relay/relay.ts
  • src/main/ai-vault/remote-session-scan-issues.ts
  • src/main/ai-vault/remote-session-scanner-types.ts
  • src/preload/index.ts
  • src/main/ai-vault/remote-session-scanner-discovery.ts
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ssh/ssh-relay-session.ts
  • src/main/ipc/ssh.ts

Comment thread src/main/ipc/ai-vault-runtime-scan.ts Resolved
Comment thread src/main/ipc/ai-vault.ts Resolved
@AmethystLiang

Copy link
Copy Markdown
Contributor Author

@coderabbitai[bot] fixed all comments

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@AmethystLiang Confirmed. All review comments are addressed.

🐇 ✅

You are interacting with an AI system.

AmethystLiang and others added 10 commits August 3, 2026 16:16
Add relay-native aiVault.listSessions scanning that discovers agent
sessions on SSH hosts. Includes fallback to filesystem crawl for
legacy relays, full cancellation support, result validation, and
scan coalescing to reduce redundant work.
- Extract batching logic to `mapRemoteScanBatches` for reuse and proper cancellation checkpoints
- Move `AiVaultScanCoordinator` from relay to main to handle concurrent same-key requests with individual cancellation signals
- Report scope path truncation consistently across relay and SSH fallback paths
- Gracefully degrade relay handler on unsupported platforms instead of aborting startup
- Refactor issue display to separate blocking errors, scope notices, and skipped transcript counts
Swallow async WSL relay stdin EPIPE so the live hook-relay shard no longer
fails after all tests pass. Merge main, resolve scan/relay conflicts, and
align cancellation/host-issue reporting with IPC expectations.
…preemption

Thread the abort signal through every scan and parse path so superseded or
cancelled scans stop promptly instead of parsing every remaining transcript
for a caller that already left.  Replace the fragile message-text relay
timeout check with a typed error code so unrelated errors carrying the
phrase "timed out after" no longer suppress the filesystem fallback.  Fix
scan coordinator preemption so a forced Refresh in one window no longer
re-enters as a spurious cancellation in another.  Add a host-leg cache for
the all-hosts view and cap filesystem concurrency so a single slow remote
home cannot stall the whole merge.

Co-authored-by: Orca <[email protected]>
Drop array-index keys so react-doctor/no-array-index-as-key passes.
Uniqueness comes from host, kind, agent, path, and message.
Implement depth-aware caching and proper scan boundaries to make SSH session
scanning reliable in worktrees. Users can now select between faster (250
sessions) and comprehensive (unlimited) history scans. The scanner:
- Deduplicates scans across relay, host leg, runtime, and renderer layers
- Reuses larger scans to serve smaller depth requests
- Properly bounds in-scope discovery per-limit
- Fixes timeout enforcement when SSH providers ignore abort signals
Keep render pure for React Doctor by deferring ref updates to
a layout effect, which still executes before render-dependent
effects that consume the ref.
Adhoc builds check out arbitrary refs whose package.json often lags
version bumps (e.g. 1.4.165-rc.0 while main is 1.4.168-rc.1). Hourly
always builds main so it already tracks the product line; adhoc now
resolves the base version from origin/main (or ORCA_ADHOC_BASE_VERSION)
so branch builds share that prefix.
…ranch"

This reverts commit a26a18eb3fd83f7e7d2db9a6a7c3e02e0f79089a.
Resolve race where the last waiter leaving could abort an already-settled scan (add `settled` flag). Redesign scoped session backfill to keep searching through newer files until the scope reaches its requested session quota instead of stopping at the candidate limit; out-of-scope files no longer consume the scope budget. Centralize scan limit normalization and fix error classification for cancelled scans using the proper helper instead of checking Error.name. Disambiguate cache keys using JSON and add cancellation check after scope discovery phase.
@AmethystLiang
AmethystLiang force-pushed the scanning-sessions-in-ssh-worktree-does-not-work branch from e32e015 to a286c70 Compare August 3, 2026 23:16
@AmethystLiang
AmethystLiang merged commit d7fe9d6 into main Aug 3, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(ai-vault): support session scanning in SSH worktrees

Add relay-native aiVault.listSessions scanning that discovers agent
sessions on SSH hosts. Includes fallback to filesystem crawl for
legacy relays, full cancellation support, result validation, and
scan coalescing to reduce redundant work.

* fix(ai-vault): scan sessions in SSH worktrees with coordinated cancellat

- Extract batching logic to `mapRemoteScanBatches` for reuse and proper cancellation checkpoints
- Move `AiVaultScanCoordinator` from relay to main to handle concurrent same-key requests with individual cancellation signals
- Report scope path truncation consistently across relay and SSH fallback paths
- Gracefully degrade relay handler on unsupported platforms instead of aborting startup
- Refactor issue display to separate blocking errors, scope notices, and skipped transcript counts

* fix(ai-vault): stabilize SSH session scan CI

Swallow async WSL relay stdin EPIPE so the live hook-relay shard no longer
fails after all tests pass. Merge main, resolve scan/relay conflicts, and
align cancellation/host-issue reporting with IPC expectations.

* fix(ai-vault): harden session scan cancellation, relay timeouts, and preemption

Thread the abort signal through every scan and parse path so superseded or
cancelled scans stop promptly instead of parsing every remaining transcript
for a caller that already left.  Replace the fragile message-text relay
timeout check with a typed error code so unrelated errors carrying the
phrase "timed out after" no longer suppress the filesystem fallback.  Fix
scan coordinator preemption so a forced Refresh in one window no longer
re-enters as a spurious cancellation in another.  Add a host-leg cache for
the all-hosts view and cap filesystem concurrency so a single slow remote
home cannot stall the whole merge.

Co-authored-by: Orca <[email protected]>

* fix(ai-vault): use stable React keys for scan issue banners

Drop array-index keys so react-doctor/no-array-index-as-key passes.
Uniqueness comes from host, kind, agent, path, and message.

* fix(ai-vault): SSH session scanning with configurable depth limits

Implement depth-aware caching and proper scan boundaries to make SSH session
scanning reliable in worktrees. Users can now select between faster (250
sessions) and comprehensive (unlimited) history scans. The scanner:
- Deduplicates scans across relay, host leg, runtime, and renderer layers
- Reuses larger scans to serve smaller depth requests
- Properly bounds in-scope discovery per-limit
- Fixes timeout enforcement when SSH providers ignore abort signals

* Move sessionLimit ref update to useLayoutEffect

Keep render pure for React Doctor by deferring ref updates to
a layout effect, which still executes before render-dependent
effects that consume the ref.

* fix(adhoc): stamp version prefix from main, not the feature branch

Adhoc builds check out arbitrary refs whose package.json often lags
version bumps (e.g. 1.4.165-rc.0 while main is 1.4.168-rc.1). Hourly
always builds main so it already tracks the product line; adhoc now
resolves the base version from origin/main (or ORCA_ADHOC_BASE_VERSION)
so branch builds share that prefix.

* Revert "fix(adhoc): stamp version prefix from main, not the feature branch"

This reverts commit a26a18eb3fd83f7e7d2db9a6a7c3e02e0f79089a.

* fix(ai-vault): fix scoped backfill and coordinator race conditions

Resolve race where the last waiter leaving could abort an already-settled scan (add `settled` flag). Redesign scoped session backfill to keep searching through newer files until the scope reaches its requested session quota instead of stopping at the candidate limit; out-of-scope files no longer consume the scope budget. Centralize scan limit normalization and fix error classification for cancelled scans using the proper helper instead of checking Error.name. Disambiguate cache keys using JSON and add cancellation check after scope discovery phase.

---------

Co-authored-by: Orca <[email protected]>
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