Repository navigation
fix(orchestration): avoid full message scans on working terminal titles - #19390
Conversation
📝 WalkthroughWalkthroughAdds conditional creation of the partial Merge Risk: 🟡 Moderate · up to Existing databases already at the current schema version will miss the new lookup index, leaving the main-thread cleanup performance issue unresolved. Index repair should run for current-version databases before merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
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/orchestration/db/schema/migrate.ts (1)
18-20: 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick winInstall indexes when the schema version is already current.
Lines 18-20 return before
createMailboxDeliveryIndexesIfPossible()runs. This PR does not changeSCHEMA_VERSION, so databases created before this PR already have the current version but lackidx_messages_pending_pointer_pty. The cleanup query then continues to scanmessages. Thecurrentfixture insrc/main/runtime/orchestration/mailbox-pointer-release-query.test.tsreproduces this case.Invoke index repair before this return, or invoke it during current-schema initialization.
Proposed fix
if (current >= SCHEMA_VERSION) { + this.createMailboxDeliveryIndexesIfPossible() return }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: f712975c-5982-4594-acf1-a57a87feec6e
📒 Files selected for processing (4)
src/main/runtime/orchestration/db/schema/migrate.tssrc/main/runtime/orchestration/db/schema/schema-column-probes.tssrc/main/runtime/orchestration/mailbox-pointer-release-query.test.tssrc/main/runtime/orchestration/orchestration-version-skew-migration.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Adds a per-PTY partial index —
initializeMailboxDeliveryIndexesIfPossiblenow also createsidx_messages_pending_pointer_pty ON messages(pointer_pty_id) WHERE pointer_enter_pending > 0, givingreleasePendingMailboxPointerForPty's cleanupUPDATEa direct seek instead of a fullSCAN messages. - Runs index init after migration —
migrate()now callscreateMailboxDeliveryIndexesIfPossible()at the end of the chain, so databases migrating up from pre-pointer schemas get the index on first open (columns are added inmigrateMailboxPointerEnterV33, aftercreateTables()already ran). - Adds regression coverage — a query-plan assertion that the cleanup uses the new index (and no
SCAN messages), a settlement-semantics test covering reserved/written/entered/already-read rows, and existing-database reopen tests for both current and pre-pointer-column databases.
The index selector and predicate match the cleanup WHERE clause exactly, so this changes only the access path, never delivery/status semantics. The partial index is correctly left out of POST_V6_INDEXES / VERSIONED_POST_V6_INDEX_PREDICATES (those gate migration-start detection and would otherwise force a full re-migration); creation is idempotent and converges on every-open via createTables() and post-migration.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Review status: LANDI completed the requested review/fix loop against The fix addresses the root cause at the database boundary: Validation completed:
The automated concern that current-version databases miss the index does not apply: The requested supervised Grok Electron worker was launched, but Grok's weekly provider quota blocked it before execution. I recorded and stopped that exact worker, then collected the Electron evidence directly. This is a process gap rather than a code or validation finding. No mobile-facing, wire, provider, SSH, WSL, path, shell, or platform-specific behavior changed. The branch matches its remote and is mergeable/clean. Recommendation: land. |


ELI5
An agent's working-title updates repeatedly scanned the entire message history, blocking Orca's main thread. Give the cleanup query a direct lookup for the terminal it is cleaning.
What Changed
messages(pointer_pty_id) WHERE pointer_enter_pending > 0through existing index initialization.Why
applyTrackedPtyTitle→observeAgentWorking→releasePendingMailboxPointerForPtyruns even for repeated working titles with no reservations. On a database with approximately 45,400 messages, SQLite choseSCAN messages; the no-op UPDATE took 13–17 ms. The existing mailbox index excludes read rows and cannot serve this cleanup, which intentionally includes them.The partial PTY index removes history-sized work without changing delivery behavior, status-transition handling, retention, or the schema version. Both the caller and query originated in #16904 (
06a607a1d71).Linked Issue
Fixes #19389
Visual Proof
N/A — database access-path change; no UI layout or interaction semantics change. Live macOS profiling provides the performance evidence:
Applied the same additive index to the running installed profile without restarting processes or deleting data. CPU figures are supporting observations under a changing workload, not a controlled throughput benchmark. Raw samples and the private database copy remain local.
Testing
pnpm tc:node, changed-file oxlint, formatting, andgit diff --checkpass. Commit hooks also pass.Review
The index covers already-read reservations as required. Tests retain reserved/write-attempted/enter-attempted settlement behavior and leave other PTYs/history unchanged. No TTL, status-only gate, process cleanup, or new cache is introduced.
Agent skill upstream boundary
Checklist