Skip to content

perf(relay): release canceled AI Vault startup requests - #23027

Merged
nwparker merged 4 commits into
mainfrom
nwparker/perf-09-25-ai-vault-ready-retention
Sep 26, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/perf-09-25-ai-vault-ready-retention

Conversation

@nwparker

@nwparker nwparker commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​203
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​149 $\color{#cf222e}{\Huge{\mathbf{−}}}$​80 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69

Historical release-test CI prerequisite

The CI merge base advanced the package version beyond a historical release fixture: the test expected 1.4.203 but read today’s 1.4.214 package. The build-identity helper now accepts an optional package version alongside its existing release inputs, and that test supplies its historical 1.4.201 version. Normal callers still read package.json. Both original version/build-number assertions remain; all 16 tests pass, and two exact before/after comparisons confirm unchanged default output. Targeted lint, including the no-module-mocking rule, passes. Application and native terminal code are unchanged; fresh CI remains required.

ELI5

Canceled requests no longer leave their luggage behind while the background scanner starts. Live requests still wait for the scanner and run normally.

What Changed

Repeatedly canceling AI Vault title lookups during remote scanner startup now releases their request data immediately. The client uses existing detachable promise waiters instead of adding an undetachable callback for every call. Disposing the client also settles and clears startup readiness.

Each startup attempt has its own counter so a delayed failure cannot reject a request already retried on another attempt. The existing timeout arming moved beside cancellation timer handling to keep the client within its file-size limit.

Why

Canceling freed the active lane but left its request captured by the shared startup promise, bypassing the 16-call admission bound for retained data. Reusing the existing waiter utility removes that retention without canceling the shared scanner or changing live request deadlines.

Linked Issue

Fixes #23024

Visual Proof

N/A — startup memory ownership only. No visual or interaction behavior change; no app/window launched.

Performance proof

Production-module synthetic cold-start fixture: hold readiness, issue/cancel 1,000 title calls with 50 distinct paths each, then force GC. Retained canceled arrays: 1,000 → 0 before ready. Incremental Node heap was 34,771,464 → 492,504 bytes in the recorded run (includes runtime noise).

The normal startup deadline remains 5s. This measures adverse cold-start churn, not typical frequency, UI latency, or all scanner memory. Disposal retention is covered separately.

Testing

  • Canceled-payload and disposed-client regressions both fail on baseline and pass after the fix.
  • 38 tests/six suites pass, covering readiness, live successor delivery, same-turn abort, startup retries, cancellation acknowledgements, idle retirement, handler behavior and spawning contracts.
  • Independent review adds three adverse scenarios. It found a failed-spawn/second-lane race in the first prototype; attempt ownership fixes it and a permanent regression now covers it.
  • Node typecheck, focused lint/format, changed-code quality and reliability manifest validation pass.
  • Reproduce: ORCA_BACKGROUND_LAUNCH=1 pnpm test src/relay/ai-vault-service-ready-retention.test.ts src/relay/ai-vault-service-client.test.ts src/shared/promise-settlement-waiters.test.ts.
  • macOS Node with fake children and real forced GC; native Windows/Linux and real SSH were not run.

Review

Merge risk: low to moderate. Asynchronous startup, retry and cancellation ownership are the sensitive paths. The gate manifest addition may need a simple merge resolution with other audit PRs.

Negative user-facing trade-offs: none identified. Same call caps, deadlines, lane ordering, cancellation acknowledgements and wire messages. Only abandoned owners release earlier.

Reliability: experimental gate relay-performance.ai-vault-ready-ownership. Invariant: canceled/disposed readiness owners release payloads while live calls still deliver exactly once. Failure source: cancellation churn during slow startup. Oracle: GC, request counts, zero cleanup timers, cold-start and failed-spawn races. No new polling, process starts or deadline timers.

Agent skill upstream boundary

  • Not applicable; no agent skill source changed.

Notes

The shared diff-note catalog prerequisite is now in main and has dropped out of this branch’s diff.

Scanner work stays on the execution host. Local/daemon PTYs, WSL shell selection and mobile terminal streams are unaffected. No process-death inference, Git/provider routing, folder-workspace assumption or protocol change.

Checklist

  • Focused fix; mechanism, rationale, ELI5, proof, risks and trade-offs included.
  • Independent review finding resolved and regression added.
  • Visual proof marked N/A; platform gaps explicit.
  • Full application/platform suite; targeted checks above passed.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The AI Vault client now uses cancellable waiters for child readiness. Call state tracks startup attempts and uses a shared helper to arm operation-specific timeouts. Regression tests cover cancellation, disposal, readiness races, and startup retry. The reliability-gates configuration adds a gate for AI Vault readiness ownership; changes to existing gate arrays only reformat their values. The hourly-build version test mocks package-file reads and sets a fixed package version.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to 40453

The new tests do not exercise delayed startup failure during retry, so a regression in recovery could go unnoticed. This is a bounded coverage gap.

Architecture Summary

Architecture risk: 🔵 Low · up to 40453

The change affects 2 systems.

Changed systems: src, config

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 3 changed files map to changed impact.
  • observed — config (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/relay/ai-vault-service-client-state.ts: Adds armRelayAiVaultCallTimeout, selecting the scan timeout for list requests and the title timeout otherwise, then invoking onExpired with the selected duration when the timer expires.
  • observed — Modified behavior in src/relay/ai-vault-service-client-state.ts: New relay service calls initialize startAttempt to 0.
  • observed — Modified behavior in src/relay/ai-vault-service-client-state.ts: RelayAiVaultServiceCall adds the numeric startAttempt field.
  • observed — Modified behavior in src/relay/ai-vault-service-client.ts: Imports PromiseSettlementWaiters for managing readiness waiters.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The AI Vault client, state, regression tests, and reliability-gate entry support the PR scope. config/reliability-gates.jsonc also reformats the existing workspace-hooks.execution-host-ownership a… Revert the formatting-only changes to the existing workspace-hooks.execution-host-ownership arrays. Keep the AI Vault reliability-gate entry and related AI Vault changes.
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 7 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue [#23024] is closed and completed, so it supplies historical context only. No active directly linked issue supplies coding requirements. The reported AI Vault changes and focused tests remain rel…
Title check ✅ Passed The title clearly and concisely describes the main change: releasing canceled AI Vault startup requests in the relay path.
Description check ✅ Passed The description is mostly complete. It includes the required change summary, rationale, linked issue, visual-proof explanation, testing evidence, review risks, platform notes, and checklist status. Th…
Full details: Out of Scope Changes check

Explanation

The AI Vault client, state, regression tests, and reliability-gate entry support the PR scope. config/reliability-gates.jsonc also reformats the existing workspace-hooks.execution-host-ownership arrays as single-line arrays without changing their values. This formatting-only change has no demonstrated connection to AI Vault startup request retention. The current head still contains this change, and no incremental diff removes it.

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

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

ℹ️ No blocking issues. One scope question about the sibling local scanner client, plus a trivial nit.

Reviewed changes

  • Canceled readiness owners release their payloads — RelayAiVaultServiceClient.pump() now waits on the shared readiness through PromiseSettlementWaiters.wait({ signal, onFulfilled: sendCall }), so an aborted waiter is removed and its captured call/request array is freed before the sidecar is ready (src/relay/ai-vault-service-client.ts:136).
  • Disposal settles readiness — dispose() calls readyReject?.(error) and clears ready before settling active/queued calls (src/relay/ai-vault-service-client.ts:77).
  • Per-attempt ownership — new RelayAiVaultServiceCall.startAttempt, bumped in pump(), and the failure handler bails when the captured attempt is stale (src/relay/ai-vault-service-client.ts:134, :143).
  • Timeout arming extracted — armRelayAiVaultCallTimeout moved to src/relay/ai-vault-service-client-state.ts:31; behavior unchanged, keeps the client under its line budget.
  • Regression coverage + gate — src/relay/ai-vault-service-ready-retention.test.ts (1000-call WeakRef/GC retention, disposal, cancel-on-ready turn, spawn-failure two-lane retry) and experimental gate relay-performance.ai-vault-ready-ownership.

I re-ran the focused suites (19/19 pass), check-reliability-gates (127 gates), oxlint, and pnpm tc:node; all clean.

ℹ️ Sibling local scanner client has the same readiness capture

The fix lands only in the relay client. The parallel main-process client, AiVaultScannerServiceClient, still attaches a permanent .then reaction to its shared readiness promise in pump(), capturing the same call/request payload (src/main/ai-vault/session-scanner-service-client.ts:142). A call canceled before its child is ready is deleted from active, but its closure stays on readyWaiter.promise until ready resolves — and this client's dispose() never settles that promise, so the capture can outlive disposal entirely. Issue #23024 is written generically ("Canceled AI Vault title requests ... captured by reactions on the shared pending sidecar readiness promise"), so it is worth confirming whether the local path is deliberately out of scope or tracked separately. The two clients also both sit under the same 16-call admission bound, which is the bound the issue says retention bypasses.

Technical details
# Same retention in the local AI Vault scanner client

## Affected sites
- `src/main/ai-vault/session-scanner-service-client.ts:142` — `void this.ensureChild().then((child) => sendAiVaultServiceCall(child, call, ...), ...)`; the `onFulfilled` arrow captures `call`, whose `request` holds the payload array. On abort, `cancelAiVaultServiceCall` (`src/main/ai-vault/session-scanner-service-client-state.ts:139`) deletes the call from `active` but the reaction on `readyWaiter.promise` remains until the child is ready.
- `src/main/ai-vault/session-scanner-service-client.ts:111` — `dispose()` calls `retireChild()` but never rejects `readyWaiter.promise`, so pending reactions are not settled at disposal.
- Compare the fix under review: `src/relay/ai-vault-service-client.ts:136` and `:77`.

## Required outcome
- Decide whether canceled-request retention during readiness applies to the local execution host too; if so, the local client should use a detachable wait (e.g. `PromiseSettlementWaiters`) and dispose should settle the readiness promise, mirroring this PR.

## Open questions for the human
- Is the local `AiVaultScannerServiceClient` intentionally out of scope for #23024, or is a follow-up planned?

ℹ️ Nitpicks

  • src/relay/ai-vault-service-ready-retention.test.ts:117 re-invokes vi.useFakeTimers(...) even though beforeEach at line 35 already installs the same fake-timer set; the extra call is a no-op.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-09-25-ai-vault-ready-retention branch from 861b85b to 4304f33 Compare September 26, 2026 19:56
@nwparker

Copy link
Copy Markdown
Contributor Author

Reviewed the local scanner sibling: this PR deliberately covers RelayAiVaultServiceClient only. The unchanged main-process AiVaultScannerServiceClient still has the same readiness-promise capture; this change does not claim to fix it. It is recorded as remaining local scanner work in the audit, without creating a GitHub issue.

The redundant vi.useFakeTimers call in the retry test is removed; the shared beforeEach already installs those timers. The relay ownership/restart/cancellation/waiter suites passed 38 tests across six suites on the reviewed head.

The generic docstring percentage suggestion is declined under this repository’s instruction to keep comments concise and limited to non-obvious reasoning. Existing comments describe the ownership decisions; no runtime change is needed for that style warning.

Published fix: 4304f3376d20; the 38 focused tests pass after rebasing.

@nwparker
nwparker force-pushed the nwparker/perf-09-25-ai-vault-ready-retention branch from 4304f33 to 4784437 Compare September 26, 2026 20:07

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

ℹ️ No code issues in this delta. One merge-hygiene note: the PR currently conflicts with main, and the catalog entries it restores have already landed there with different Japanese/Korean wording.

Reviewed changes

  • Relocated the AI Vault reliability gate — relay-performance.ai-vault-ready-ownership moves from the last entry in gates to the first, and the adjacent workspace-hooks.execution-host-ownership arrays were compacted to single lines. Gate content is unchanged and check:reliability-gates passes (129 gates).
  • Restored the diff-note localization catalog — added f6c449191e, 5fa4bfebaa, and 5e9b3d0c2e to all six locale files and reworded the Japanese/Korean f6c449191e value so the AI is the recipient. All six JSONs parse; verify:localization-catalog and verify:localization-runtime-catalog pass.
  • No relay-service changes — the retention fix and its tests are untouched by these commits.

ℹ️ The restored catalog entries conflict with main instead of dropping out

The PR description expects the restored catalog entries to "drop out of this diff once they land on main." They have already landed on origin/main, but the branch's base predates that and the Japanese/Korean f6c449191e values differ, so GitHub reports the PR CONFLICTING / DIRTY. Merging needs those two lines reconciled (presumably keeping this PR's AI 向けの… / AI에게 전달할… wording per the #23256 correction) rather than a clean drop-out.

Technical details
# Restored i18n entries already exist on main with different values

## Affected sites
- `src/renderer/src/i18n/locales/ja.json:15500` — `f6c449191e`: this branch `"AI 向けのメモを追加"` vs `origin/main` `"AI に関するメモを追加"`.
- `src/renderer/src/i18n/locales/ko.json:15500` — `f6c449191e`: this branch `"AI에게 전달할 메모 추가"` vs `origin/main` `"AI에 대한 메모 추가"`.
- The `en` / `es` / `fr` / `zh` additions are byte-identical to `origin/main` and merge cleanly.

## Required outcome
- On rebase/merge, keep the recipient-oriented Japanese/Korean wording and drop the duplicated additions so the branch carries no i18n churn.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker force-pushed the nwparker/perf-09-25-ai-vault-ready-retention branch from 4a6e2eb to 70b3c13 Compare September 26, 2026 21:23
@nwparker

Copy link
Copy Markdown
Contributor Author

The merge-hygiene finding is addressed in 70b3c136640f: this branch is rebased onto main, has no localization delta, and retains the corrected Japanese/Korean values from main. The AI Vault gate is inserted at a separate internal boundary to avoid the competing prepend. All 130 existing main gates and this gate’s contents are preserved. The two runtime modules and their test are byte-identical to the reviewed head. Gate validation, formatting, and all four localization checks pass; fresh CI remains required.

@nwparker

Copy link
Copy Markdown
Contributor Author

The formatting-only gate-array warning is declined: these lines are the repository formatter’s output. Every preexisting gate object, including workspace-hooks.execution-host-ownership, was compared by parsed value and preserved unchanged. Reverting the formatter output would restore formatting drift without changing scope or behavior. The generic docstring threshold is also declined under AGENTS.md’s concise, non-obvious-comments-only policy. The historical hourly-version test prerequisite is now disclosed in the description; it changes only the fixture input and keeps the original assertions.

@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)
src/relay/ai-vault-service-ready-retention.test.ts (1)

116-152: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Cover the delayed startup failure ordering.

The added retry test only simulates a synchronous processFactory throw. It does not create an earlier child whose failure is handled after the replacement attempt starts. Its toContainEqual assertions also allow duplicate requests.

The existing cold-start test emits the first child’s exit before advancing the retry timer. Its failure handler therefore runs before the replacement child is created. Add a test that delays the earlier attempt’s rejection until after the replacement starts, then assert that the replacement remains active and sends the later call exactly once.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e4ec1f06-a7a3-4e0f-ae75-1ea3689661b7

📥 Commits

Reviewing files that changed from the base of the PR and between 70b3c13 and 404535b.

📒 Files selected for processing (1)
  • config/scripts/hourly-build-version.test.mjs

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

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

✅ No new issues found in the new commits.

Reviewed changes

  • Pinned the historical hourly package version — getHourlyBuildIdentity now accepts an optional packageVersion, and the September 14 regression passes 1.4.201 instead of reading the live package.json (now 1.4.214), so the test is deterministic again; production callers omit it, so release behavior is unchanged.
  • Repositioned the AI Vault reliability gate — the rebase moves relay-performance.ai-vault-ready-ownership among the other gates and compacts adjacent arrays; gate content is unchanged and check:reliability-gates passes (131 gates).
  • Dropped the locale churn — the diff-note catalog entries now live on main, so the branch no longer touches the six locale JSONs.
  • Relay retention fix untouched — ai-vault-service-client.ts, ai-vault-service-client-state.ts, and the retention test are byte-identical to the prior reviewed revision.

Verified locally: hourly-build-version.test.mjs 16/16 pass.

ℹ️ Nitpicks

  • The PR description still says the test's "package read" is pinned to the 1.4.201 fixture; the final commits instead thread a packageVersion option through the build. Worth a wording update so the description matches the code.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Addressed the delayed-startup coverage note in 993aa36. The new test synchronously advances the restart timer before the old readiness rejection microtasks run, starts the second lane on the replacement child, and asserts the complete sent-message arrays: one initialization per child and exactly one request per lane. Both requests must resolve, the factory must remain at two calls, and disposal must leave no timers.

The five focused suites pass (27 tests). As a negative control, removing the startAttempt check makes this new test fail because the old rejection incorrectly rejects the restarted list request. Production code is unchanged; focused lint and formatting pass.

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

✅ No new issues found in the new commit.

Reviewed changes

Since the prior pullfrog review (b4e61dd), one commit landed:

  • Added delayed-readiness-rejection regression — src/relay/ai-vault-service-ready-retention.test.ts gains ignores an earlier readiness rejection after a replacement startup begins: it lets the first attempt's readiness rejection settle only after the scheduled restart has begun a replacement on the same lane, then asserts the replacement sends list and titles exactly once and both calls resolve. The production files are byte-identical to the prior review.

This test is not theatre: I re-ran the file with the call.startAttempt !== attempt clause removed from pump()'s failure handler and only this test failed (list rejected with the stale Relay AI Vault service exited (1).), so it genuinely covers the startAttempt ownership half of the guard rather than just the active.get(lane) check. All 5 tests in the file pass with the guard intact. It also answers the CodeRabbit request for delayed-failure ordering coverage.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 34d055c into main Sep 26, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Release canceled AI Vault requests during sidecar startup

1 participant