Repository navigation
improve(agents): speed up subagent capability lookups - #152263
Conversation
Replace whole-store capability reads with per-resolution keyed reads and reuse synchronous prepared session entries. Preserve legacy whitespace-padded IDs with a trimmed query only after an exact current-ID miss. No schema change; a normalized-ID index is deferred.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 18, 2026, 7:56 PM ET / 23:56 UTC. ClawSweeper reviewWhat this changesReplace whole-store subagent capability reads with memoized session and ancestor lookups, preserve whitespace-padded legacy IDs, and reuse session metadata already read by the Gateway. Merge readiness⛔ Blocked before merge - 1 item remains This optimization remains useful: current main still materializes the session store for capability lookups. No actionable introduced correctness or security defect was found. Priority: P2 Review scores
Verification
How this fits togetherSubagent capability resolution combines persisted session lineage with configured depth limits and inherited tool restrictions. Its results determine delegation permissions and the tool inventory shown by the Gateway. flowchart TD
A[Session key and configuration] --> B[Capability resolution]
C[Gateway session metadata] --> B
B --> D[Per-resolution lookup cache]
D --> E[SQLite session reader]
E --> F[Session and ancestor metadata]
F --> B
B --> G[Depth limits and tool restrictions]
G --> H[Delegation and tool inventory]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +163, Tests +397. Total +560 across 14 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep session selection and validation in the existing accessor, with resolution-local memoization preserving lineage and inherited restrictions. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: this is a performance optimization, and current-main source confirms the whole-store materialization it targets. Is this the best way to solve the issue? Yes. Keyed reads through the existing session owner remove unnecessary materialization without adding persistent state or another policy implementation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e623bcd437da. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* commit 'ca69b4d25dfcd488acc6ba1d878e4b4252f40cd2': (325 commits) perf(gateway): streamline config reload comparison (#152279) fix(xai): reject invalid UTF-8 OAuth responses (#111737) fix(release): accept waived advisory performance evidence for stable publication (#152290) fix: deliver watcher results while other sessions are busy (#152287) perf(media): reuse attachment filename classification (#152274) refactor(build): reuse forwarded option scanning (#152293) chore(diagnostics-otel): revert unapproved duration-bucket merge (#152292) fix: stop chat media reads after access changes (#152219) fix(test): use Gateway WebSocket transport in network fixtures (#152143) improve: retain quota refresh evidence from successful CI runs (#152173) improve(gateway): reduce memory used by session selection (#152260) perf(agents): use keyed subagent capability lookups (#152263) refactor(matrix): centralize media metadata assembly (#149128) chore(ui): refresh control ui locales (#152276) feat: open Crabbox apps beside the conversation (#152094) refactor: simplify worker and model fallback handling (#152268) perf(codex): reconcile session catalogs incrementally (#152257) fix(ui): keep submitted prompts visible across session startup (#152241) perf(sessions): move automatic maintenance database work to workers (#148630) fix: preserve reply metadata through outbound preparation (#152231) ...
Replace whole-store capability reads with per-resolution keyed reads and reuse synchronous prepared session entries. Preserve legacy whitespace-padded IDs with a trimmed query only after an exact current-ID miss. No schema change; a normalized-ID index is deferred.
What Problem This Solves
Repeated subagent capability and tool-policy checks rebuild the entire agent session store to find one session and its ancestors, adding avoidable work as session history grows.
User Impact
Capability and tool-policy resolution reads the requested session and its ancestry without materializing thousands of unrelated entries. Whitespace-padded legacy session IDs retain their depth, leaf restrictions, and inherited tool policy.
No schema change; index deferred. This change adds no index, migration, configuration, or operator action. A legacy ID miss can still scan the current-ID column for that one normalized ID; ordinary exact-key and exact-ID hits do not scan. Database formats, upgrade behavior, and writes are unchanged.
Why This Change Was Made
The session accessor owns current-ID selection and validation. Lookups try the exact session key, then the existing indexed current ID. Only if no visible exact-ID match exists does a SQLite trimmed comparison recover a padded legacy ID. Its whitespace set matches JavaScript
String.trim(), including tabs, newlines, and Unicode whitespace. Exact IDs take precedence over padded duplicates; matches within each query retain session-key listing order. The reader excludes hidden entries and retained transcript generations and validates selected rows.A lazy capability-store adapter memoizes keyed reads and misses within each synchronous resolution, then follows the existing cycle-checked parent chain. Explicit in-memory records retain their comparison semantics. The whole-store materializer is removed. The synchronous
tools.effectiverequest reuses its already-read exact-key entry; callers crossing asynchronous waits keep fresh reads.Evidence
canSpawn=false).EXPLAIN QUERY PLANverifies the exact-ID query uses the existing current-ID index.node scripts/check-changed.mjspassed, including oxfmt, production/core-test tsgo, lint, dead-export, storage, and import-cycle checks.git diff --checkpassed.No live Gateway or full release validation was run. No deployment was performed.