perf(views): yield execution candidate reads #2039
<!-- coderabbit-ai-generated:v1 -->
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- review_stack_entry_start -->
<a href="https://app.coderabbit.ai/change-stack/mvschwarz/openrig/pull/2039?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a>
<!-- review_stack_entry_end -->
<!-- recent_review_start -->
No actionable comments were generated in the recent review.
<details>
<summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary>
<dl>
<dd>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary>
<dl>
<dd>
e6d39f49-86dc-4bd6-be3c-3a80af769e2d</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary>
<dl>
<dd>
Reviewing files that changed from the base of the PR and between 00e2c8066d87200506ea7e3d768b5aae513c382b and 3973c4c0b7ee3d87094e585dbbc1d5f518e277b5.
</dd>
</dl>
</details>
<details>
<summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 4</strong></summary>
<dl>
<dd>
packages/daemon/src/domain/execution-candidate-reader.ts
packages/daemon/src/domain/execution-view.ts
packages/daemon/src/domain/view-projector.ts
packages/daemon/test/execution-candidate-reader.test.ts
</dd>
</dl>
</details>
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
</dd>
</dl>
</details>
<!-- recent_review_end -->
<!-- walkthrough_start -->
<details>
<summary><strong>Walkthrough</strong></summary>
<dl>
<dd>
Execution-view candidate reads use a cooperative reader when the database is outside a transaction and uses WAL. Other cases retain synchronous reads on the main handle. The projector serializes execution-view builds outside transactions, while builds inside transactions run immediately.
Changes: Execution-view reads
|Layer / File(s)|Summary|
|:---|:---|
|Cooperative reader and eligibility <br> packages/daemon/src/domain/execution-candidate-reader.ts, packages/daemon/test/execution-candidate-reader.test.ts|Adds eligibility checks for WAL-backed database files and a readonly cursor that yields after 64 rows or 8 ms. Tests cover ordering, yielding, snapshots, errors, cleanup, and fallback cases.|
|Execution-view candidate query <br> packages/daemon/src/domain/execution-view.ts|Uses cooperative reads for eligible databases. Runs the same candidate query synchronously on the main handle otherwise.|
|Execution build ordering <br> packages/daemon/src/domain/view-projector.ts, packages/daemon/test/execution-candidate-reader.test.ts|Serializes execution-view builds outside transactions and continues the queue after a failed build. Tests also cover immediate builds inside transactions and memory/WAL document parity.|
<!-- change_assessment_start -->
<strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong>
Estimated code review effort: 3 (Moderate) | ~25 minutes
<!-- change_assessment_commit:"3973c4c0b7ee3d87094e585dbbc1d5f518e277b5" -->
Change: Refactor
<!-- change_assessment_end -->
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant ViewProjector
participant buildExecutionView
participant readRowsCooperatively
participant ReadonlySQLiteConnection
Caller->>ViewProjector: Request execution view
ViewProjector->>buildExecutionView: Start build after prior build settles
buildExecutionView->>readRowsCooperatively: Read candidates for eligible WAL database
readRowsCooperatively->>ReadonlySQLiteConnection: Query rows in slices
ReadonlySQLiteConnection-->>readRowsCooperatively: Return rows
readRowsCooperatively-->>buildExecutionView: Return complete row set
buildExecutionView-->>ViewProjector: Return projected view
ViewProjector-->>Caller: Return execution view
Possibly related PRs
Suggested reviewers: rudycelekli
</dd>
</dl>
</details>
<!-- walkthrough_end -->
<details>
<summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>3973c</code></summary>
<dl>
<dd>
<!-- final_review_risk_start -->
<!-- final_review_risk_label
Merge Risk: ⚪ Minimal · up to 3973c
-->
<!-- final_review_risk_coverage:{"sourceCommitId":"3973c4c0b7ee3d87094e585dbbc1d5f518e277b5","coveredCommitId":"3973c4c0b7ee3d87094e585dbbc1d5f518e277b5","kind":"reviewed"} -->
The reviewed change is mergeable after normal checks; no actionable risk remains established.
<!-- final_review_risk_end -->
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_start -->
<details>
<summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary>
<dl>
<dd>
<strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong>
| Check name | Status | Explanation | Resolution |
| :---------------- | :----------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
| Docstring Coverage | !Warning | Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
<details>
<summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary>
<dl>
<dd>
| Check name | Status | Explanation |
| :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------- |
| Description Check | !Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | !Passed | The title clearly and concisely describes the main change: yielding during execution candidate reads to reduce event-loop blocking. |
| 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. |
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary><strong>Finishing Touches: 💡 1</strong></summary>
<dl>
<dd>
<!-- finishing_touch_suggestion:docstrings -->
<details open>
<summary><strong>📝 Generate docstrings: 💡</strong></summary>
<dl>
<dd>
</dd>
</dl>
</details>
<details open>
<summary><strong>🧪 Generate unit tests (beta)</strong></summary>
<dl>
<dd>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- autopilot:start -->
<!-- autopilot:end -->
<!-- tips_start -->
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.
<details>
<summary><strong>❤️ Share</strong></summary>
<dl>
<dd>
</dd>
</dl>
</details>
<sub>Comment @coderabbitai help to get the list of available commands.</sub>
<!-- tips_end -->
Approved at 3973c4c0b7ee3d87094e585dbbc1d5f518e277b5, recording the completed independent source reviews and QA rather than claiming a new test run. I verified the four-file port and stable patch identity, prerequisite inclusion, clean current-main composition, and all eight required exact-head CI checks. The retained evidence covers complete-result parity and health-handler progress during cursor reads; it does not establish an overall request-time speedup or eliminate remaining synchronous work.
— orch-lead@v-openrig-build
openrig-review
mvschwarz
Large execution views collect candidate rows in one synchronous SQLite call, making health checks and unrelated requests wait for seconds. Read WAL candidates through a request-owned readonly cursor that yields between slices, and serialize complete execution builds per projector. Transactions, memory and non-WAL databases retain synchronous main-handle reads.
SQL, bindings, row order and complete results are preserved. Candidates use one committed snapshot; later history reads can observe writes committed during yields. Native steps can still block, and queued execution requests can exceed the existing client deadline.
Validation: 138 focused tests, two independent transaction/cleanup adverses, and a matched source-built full-request case confirming complete-result parity apart from build identity and health-handler progress during the cursor read. This does not establish an overall request-time speedup.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Performance
Execution views can now yield between batches of database reads, helping keep the application responsive during larger reads.
Execution view updates are processed in order and continue after a failed update.
Reliability
Reads within an active transaction continue to use that transaction, preserving its data consistency.
Execution views show the same results across supported database configurations, aside from live disk-availability data.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->