Repository navigation
perf(state): keep plugin and GitHub reads off the writer queue - #173534
Conversation
Route five pure plugin-state operations and GitHub publication queries through the existing shared-state reader pool. Preserve mutation ordering, read-after-write visibility, authority checks, and typed failures; remove the retired writer handlers.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Add an opt-in synthetic plugin metadata and GitHub options workload to the existing owned Gateway restart driver. Capture authenticated Prometheus queue totals at five minutes and document its observation limits.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fdac91c67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: needs changes before merge. What this changesThis PR moves pure plugin-state and GitHub publication reads from the shared writer queue to the existing reader pool. Example: A reconnect reads plugin namespace restart-catalog while unrelated writes are queued.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the reader cutover is useful, but one remaining writer caller breaks an existing session-list test. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway and plugin callers submit typed state requests; reader workers return committed rows, while the existing writer owner retains mutations, admission, and publication receipts. flowchart TD
A[Gateway and plugin callers] --> B[Typed state facade]
B --> C[Namespace write settlement]
C --> D[Shared reader pool]
B --> E[Shared writer queue]
D --> F[Canonical state database]
E --> F
Technical reviewBest possible solution: Complete the reader cutover by migrating the remaining session-list test caller and excluding pure reads from the shared writer contract. Do we have a high-confidence way to reproduce the issue? Source inspection establishes that the existing session-list test submits a command rejected by the new writer guard; no target code or tests were executed during this read-only review. Is this the best way to solve the issue? Reusing the existing reader pool and namespace settlement owner is appropriate; completing the caller and type-contract migration is preferable to restoring a parallel writer read path. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3f99631b7ea2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +69, Tests +61, Docs +14, Other +55. Total +199 across 24 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 15, 2026, 7:37 PM ET / 23:37 UTC. |
…law#173534) * perf(state): keep plugin and GitHub reads off the writer queue Route five pure plugin-state operations and GitHub publication queries through the existing shared-state reader pool. Preserve mutation ordering, read-after-write visibility, authority checks, and typed failures; remove the retired writer handlers. * test(perf): measure writer reads during reconnect bursts Add an opt-in synthetic plugin metadata and GitHub options workload to the existing owned Gateway restart driver. Capture authenticated Prometheus queue totals at five minutes and document its observation limits. * fix(state): finish plugin reader contract cutover * fix(state): preserve plugin reader admission errors * fix(state): exclude pure plugin reads from writer contract
What Problem This Solves
Uncached plugin-state reads and GitHub publication status queries occupy the shared SQLite writer queue during startup and UI reconnects, delaying unrelated writes and attachment metadata.
User Impact
Plugin-state and GitHub discovery reads stop delaying unrelated SQLite writes during reconnects. The measured GitHub-options cold-start timeout regression remains an explicit limitation below; this PR does not claim all RPCs are faster. No configuration or schema migration is required.
Why This Change Was Made
Move the five pure plugin-state reads (
lookup,lookupMany,entries, key-range entries,count) and the GitHub publication read registry to the existing shared-state reader pool. Remove their writer registrations and dispatch branches. Plugin reads still observe preceding namespace mutations; mutations retain FIFO ordering. Overlapping reads do not reserve writer positions. Comparison observations and actual mutations remain with the writer, including their authority checks.The runtime delta is +69 lines: the GitHub portion removes 11 lines; the plugin cutover adds 80 because typed error envelopes, missing-store behavior, and namespace-cache publication must cross the reader transport. The retired writer read path is deleted. No schema, configuration, cache, or timer is added.
Attribution
executeincludes the generic GitHub publication read operations used by status discovery and reconciliation. Reconciliation starts immediately and repeats every minute; UI discovery also invokes those reads per session.plugin_stateincluded uncached keyed reads and catalog snapshots as well as real persistence. This change removes the pure reads from that class; actual catalog persistence and compound/compare operations remain writes.githubRepositoryincluded thepersonalPendingread called bysessions.github.options. That old writer command is removed; the existing publication read registry now owns it.Coarse production request-class metrics and logs cannot assign exact operation counts to individual callers. The comparison below isolates these paths through real Gateway RPCs with synthetic state.
Measurement
Baseline source:
2aca37525ff0804790c29d9ab6fea1bb9e5f700e. Measured reader-cutover source:735f802912798910e01a1eaff00a214d87ac33dc. The subsequent repair narrows the writer type contract and migrates one missed test caller; the measured reader path is unchanged. Both use the same final benchmark driver. Each run starts from independently generated state: 5,000 sessions, 6,000 retained runs, 200 approvals, 100 cron jobs, 12 projects with real worktrees, and a 4,641,595,392-byte agent database. All accounts, tokens, sessions, and model responses are synthetic.The driver pairs 150 devices in batches before the measured crash, holds 30 real agent requests, kills its own Gateway, then starts all 150 reconnect clients concurrently. It polls session/sidebar, catalog, project, and GitHub-option RPCs for five minutes from restart spawn. Connection refusals/retries and RPC errors stay in the results. The synthetic catalog exercises real plugin-state lookup and session metadata without provider scans or external network latency.
Five-minute target-class writer queue results:
executeplugin_stategithubRepositoryAll 150 clients connected in both runs. Readiness was effectively unchanged (20.491 → 20.577 s). Successful RPCs increased from 31,953 to 32,095; total RPC errors fell from 151 to 55. HTTP 503 connection refusals before successful retries were 165 → 41. An unchanged-baseline repeat produced 470.019 s of target writer wait and 23,553 target requests.
sessions.listsessions.catalog.listprojects.listsessions.github.optionsAdverse result and follow-up: GitHub-options cold-start latency/timeouts worsened in the final run. All 55 timed-out calls started before 25 seconds from restart; none timed out after the initial burst. Clients also began polling earlier (first-150 polling-start median 29.50 → 26.91 s). The repeated baseline had one GitHub timeout, so this is not dismissed as proven noise. The catalog errors were initially empty metadata results.
A separate, temporary stage trace on final code using the reused synthetic fixture located its observed timeout in session preparation (6,227 ms), before publication reads began. Other traced slow calls spent about 1,850 ms in session preparation; personal-pending reads took at most 6 ms, shared-publication reads 273 ms, and identity discovery 52 ms. This identifies a remaining cold-session readiness bottleneck, but the different diagnostic run does not conclusively attribute all 55 original timeouts. No diagnostic instrumentation is included in this PR. The change removes target writer contention; it does not claim a universal RPC latency improvement. Medians increased in this run even where p99 improved.
The scrape occurs at five minutes from restart spawn. Counters cover events observed after exporter initialization; work still waiting at the cutoff is counted only when it starts. This is a cold-start comparison, not a statistical latency study or a production deployment claim.
Evidence
Focused local files passed with one worker: plugin-state-worker (20 tests), plugin-state-publication (15), plugin-state-store (23), shared-state summary (5), shared-state imports (6), GitHub pending-publication (6), and persisted session-list worker (3). Changed-file formatting/lint and diff checks passed. Broad validation belongs to PR CI.
The plugin regression fails on old routing with five writer requests, then passes with five reader requests and zero writer requests while preserving prior-write visibility. The GitHub regression fails on old routing when writer dispatch is unavailable, then passes after the reader cutover. Existing quarantine, corruption, cache invalidation, and authority tests remain in force.
CI and review caught and drove repairs for stale cache-dispatch assertions, a contract import cycle, quarantine error classification, the worker-entry boundary, and one remaining test caller of the retired writer read. That session-list test failed before its caller migration and passes afterward. The shared writer type now excludes all five read operations. The final dispatcher lives in the existing worker module; no guard allowance was added.
Independent subagent review (autoreview route unavailable) found no actionable P0/P1/P2 findings, including the CI repairs and final writer-contract/caller repair. Operator configuration was not changed. No Testbox/Crabbox lease was used. Runtime benchmark builds ran only in the isolated Linux sandbox. Local validation used focused test files and changed-file lint/format. An initial lint invocation entered dependency-artifact preparation and was stopped; the corrected core-only lint passed. No local test suite or standalone repository-wide typecheck/build was run.
Final CI
CI run 38826388682 passed on final head
df6ff99bf4a107f472a127a20b060cb1471a7bd7, including the test shards, architecture checks, production/test types, lint, builds, PostgreSQL conformance, and SQL ratchet. The final contract/caller repair independently passed the persisted session-list worker file (3 tests) and plugin-state worker file (20 tests), changed-file lint/format, and independent review.The PR-description check initially rejected the nonstandard “Proof” heading. The body was corrected to the required “Evidence” heading, and its replacement check passed on the same head. Earlier-head CI caught the source repairs documented above and had two pre-checkout action-download failures; final CI has no failed shards. No CI rerun or branch update was requested to chase green.
The benchmark sandbox has been removed after verifying all task processes stopped. Cold-session GitHub-options readiness remains the explicit performance gap described above; the separate diagnostic does not conclusively explain the final measured timeout increase. No user-profile code or production state was changed.