Repository navigation
perf(sessions): index pending conversation replies - #127182
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 11:06 PM ET / September 5, 2026, 03:06 UTC. ClawSweeper reviewWhat this changesIndex pending conversation replies by agent and outbound message ID to avoid scanning unrelated waiters while preserving reply matching and cleanup. Merge readiness⛔ Blocked before merge - 1 item remains The bottleneck remains on current main and v2026.9.1. The production caller resolves the prior ordering concern, and no actionable correctness findings remain. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway registers a waiter when an agent sends a conversation message and requests its reply. Incoming channel messages pass through correlation and durable capture before either completing that waiter or continuing ordinary dispatch. flowchart TD
A[Conversation turn request] --> B[Register waiter and outbound ID]
B --> C[Exact reply index]
D[Incoming channel reply] --> C
C --> E{Eligible live waiter?}
E -->|Yes| F[Durable reply capture and cleanup]
F --> G[Reply returned to waiting agent]
E -->|No| H[Ordinary inbound dispatch]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +34, Tests +145. Total +179 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep the index in the pending-turn lifecycle owner; its additional state enables exact lookup while the primary registry preserves cancellation by turn ID. Do we have a high-confidence way to reproduce the issue? Yes, from current source: completing N distinct pending turns enumerates N(N+1)/2 registry entries. The supplied owner-level run corroborates this; no runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? Yes. Indexing at the shared waiter owner removes the bottleneck for every caller and keeps cleanup centralized; a channel-local cache would duplicate ownership, and removing sorting would still scan unrelated waiters. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 790fbf0304a6. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
The indexed reply lookup fixes the reported quadratic work at the pending-turn lifecycle owner. In a direct source-level run of 1,000 correlated replies, main visited 500,500 registry entries and the candidate visited zero; all replies matched correctly and both registries were empty after completion and restart. The measured claim/complete loop was 31.66 ms versus 2.47 ms on this run; the deterministic visit counts are the performance proof, not a general latency guarantee. Source imports were redirected only to isolated copies of the same normalization and singleton helpers for this harness. Independent lifecycle review and fresh Codex autoreview found no actionable P0-P2 findings. The index is maintained during outbound-ID replacement and removed through the shared settle owner on completion, timeout, cancellation and abort. Canonical object checks preserve turn-ID reuse; released claims remain retryable. Agent, session, conversation and thread eligibility and transcript-durability waits remain unchanged. ClawSweeper's equal-timestamp reverse-assignment finding and its two rank-up moves were checked against the sole production registrar. Best-fix verdict: the owner-level secondary index is the appropriate repair. A linear scan without sorting still visits every unrelated waiter; a cache or index in individual channels would duplicate lifecycle policy. Production +51/-17 (net +34), tests +145. The additional production state is required to index exact reply identities and clean it up without a global scan. No database/schema change is involved. The old failed CI job was the portal retry-page test using a released ephemeral port (expected 502, observed 401). Main already fixes that race in 9177024 (#130920). The branch refresh will retain that correction before current-head validation. |
648a5b2 to
be9686c
Compare
|
@clawsweeper re-review Refreshed onto main without changing the reviewed patch. All 83 focused tests and changed-file checks pass. The PR body now records the 1,000-reply failing/passing regression, cleanup proof, independent review, and the production-caller evidence resolving the equal-timestamp assignment concern. Current head: be9686c. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
The fresh review's remaining data-model flag does not apply to this change: Upgrade/restart compatibility follows the existing waiter lifecycle: process shutdown discards these registries, and the registered close/restart drain settles primary waiters and clears the secondary index. The 1,000-reply owner proof verified both maps empty after completion and after an explicit restart drain. The primary registry and durable conversation-delivery records keep their existing roles. No data migration is needed. The rebased exact head |
|
Merged via squash.
|
Co-authored-by: Amp <[email protected]>
* refs/remotes/origin/main: (602 commits) fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746) perf(sqlite): reuse compiled plugin state point reads (openclaw#138758) refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793) ci: reduce Doctor test startup and core lint jobs (openclaw#138796) feat(update): retain run history and share outcome reports (openclaw#138690) chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500) fix: preserve global board ownership from pinning to notifications (openclaw#138675) fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674) perf(sessions): index pending conversation replies (openclaw#127182) perf(auth): reuse ordered provider alias entries (openclaw#138805) docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804) perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766) fix: allow older source on newer Testbox checkouts (openclaw#138782) fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785) perf(codex): reduce rollout tail scan CPU (openclaw#138784) perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655) fix(build): bound native declaration inputs to checkout (openclaw#138742) fix(cli): preserve foreground Gateway argument handling (openclaw#138765) fix(ui): align task toolbar with side-panel tabs (openclaw#138769) fix(logbook): drain accepted work before closing SQLite (openclaw#138754) ... # Conflicts: # src/agents/embedded-agent-runner/compact.queued.ts
What Problem This Solves
Fixes #127173. Every exactly correlated conversation reply previously copied, filtered, and sorted the process-wide pending-turn registry before matching its outbound message ID. Completing N unique pending turns visited N(N+1)/2 entries synchronously on the Gateway ingress thread.
Why This Change Was Made
Index pending turns by the exact agent and outbound message ID at the existing pending-turn lifecycle owner. Maintain collision buckets during outbound-ID replacement, and remove membership on completion, timeout, cancellation, and abort. Select the oldest eligible reply from its bucket while preserving agent, session, conversation, thread, claim, and transcript-durability checks.
The primary registry still owns cancellation by turn ID. The secondary index is bounded by active waiters and is cleared through their existing settlement and Gateway restart lifecycle. No configuration or storage-schema change is involved.
User Impact
Correlated reply bursts avoid global scans and temporary arrays/sorts, reducing synchronous ingress work and allocation pressure. Reply routing, cancellation, retry behavior, and durable capture remain unchanged.
Evidence
Rebased head:
be9686c20bdccf1e00042b85a492d68d8424db0e.git range-diffconfirms the original patch is unchanged; the production owner is byte-identical to the reviewed source.83 focused tests passed across pending-turn correlation, reply capture, Gateway turn execution, Gateway methods, and portal HTTP proxy coverage:
Changed-file formatting, production/test typechecks, lint, boundary/storage guards, dead-export scans, and import-cycle checks passed:
Direct source-level 1,000-reply regression: main visits 500,500 global registry entries; the candidate visits zero. All replies match correctly, and both registries are empty after completion and restart. The zero-scan assertion fails on main and passes on the candidate. The harness redirects imports only to isolated copies of the same normalization/singleton helpers; it is an owner-level runtime proof, not a live-channel run.
Fresh independent Codex autoreview: no actionable P0-P2 findings. Independent lifecycle review also found no blocker.
The old failed CI job used a released ephemeral port in an unrelated portal test. This rebase includes its canonical repair in fix: keep portal retry-page tests on an owned target port #130920; the portal suite now passes.
ClawSweeper findings and rank-up moves
The equal-timestamp reverse-assignment concern was checked against the sole production registrar in
src/gateway/conversation-turn.ts: it registers and immediately assigns the prepared outbound ID without an intervening await, and never reassigns it. A transport ID mismatch cancels the turn. Bucket insertion therefore retains registration order in the real flow. An extra registration ordinal and reverse-assignment-only test are intentionally skipped; existing collision, replacement, and lifecycle coverage remain.Production: +51/-17, net +34. Tests: +145. The added state is the lifecycle-owned index needed to avoid global scans; a channel-local cache or linear scan would not fix the owning bottleneck.