Repository navigation
perf(channels): batch durable ingress admission and health reads - #175183
Conversation
|
🦞👀 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f68cf25a50
ℹ️ 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".
| ); | ||
| admitOptions.onDurablyAdmitted(); | ||
| results[resultIndex] = { kind: "durable", queueResult }; | ||
| await options.onDurableAdmission?.(raw, { |
There was a problem hiding this comment.
Run every callback after committing a batch
When enqueueBatch is used and an earlier onDurableAdmission callback rejects, this await exits the loop even though every item was already committed, so later durable items never receive their callback. A permanently failing first item can therefore starve per-event acknowledgments or hooks on every replay; invoke all post-commit callbacks while retaining the first failure so every committed admission is observed.
AGENTS.md reference: src/plugin-sdk/AGENTS.md:L1-L3
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesBatches durable channel admission and ingress-health reads, with Telegram polling acknowledging each response after its batch commits. Example: Telegram returns updates 42 and 44 in one getUpdates response.
Review scores
ProductKind: Performance · Worth it: Yes Merge readiness⛔ Needs changes before merge - 1 item remains This PR provides a useful, maintainer-directed optimization, but a callback failure can leave later committed events without their admission hooks. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherChannel transports submit events to the shared ingress monitor, which persists them through the state writer before acknowledgment and agent dispatch; read-only workers supply queue diagnostics to Gateway health. flowchart TD
A[Telegram response] --> B[Polling worker]
B --> C[Shared ingress monitor]
C --> D[SQLite writer]
D --> E[Shared drain]
E --> F[Agent delivery]
D --> G[Read-only health worker]
G --> H[Gateway health]
Technical reviewBest possible solution: Keep batching in the existing queue owner and finish every committed event's admission callback before releasing the claim lock. Do we have a high-confidence way to reproduce the issue? A two-event batch with an onDurableAdmission callback that rejects for the first event deterministically commits both rows but skips the second callback; this review executed no target code. Is this the best way to solve the issue? The existing writer transaction and receipt-invalidated health cache are appropriate owners, but post-commit callback processing must continue across individual failures. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6485b1906e73. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +188, Tests +187, Docs +19. Total +394 across 26 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 17, 2026, 2:04 AM ET / 06:04 UTC. |
Give the prepared array its existing element contract so declaration and type checks pass. The emitted JavaScript is unchanged.
Use void Promise executors and explicit empty Node Worker transfer lists.
|
The batch callback finding is valid and remains a follow-up: if A and B are durably enqueued together and A's This P2 limitation is accepted for this PR under the requested two-round review limit and relaxed landing policy. It is not reported as fixed. The existing ACK-failure regression proves durable queue recovery, not callback completion for every item. |
…nclaw#175183) * perf(channels): batch durable ingress admission and health reads * test(channels): group batch admission with claim ownership proof * fix(channels): type prepared ingress batch entries Give the prepared array its existing element contract so declaration and type checks pass. The emitted JavaScript is unchanged. * test(telegram): fix polling batch fixture lint Use void Promise executors and explicit empty Node Worker transfer lists. * fix(channels): preserve ingress result type compatibility
What Problem This Solves
Channel ingress makes a separate durable-admission request for each event even when a transport already provides a batch. Cold health collection also requests two ingress aggregates independently.
User Impact
Telegram polling durably admits the complete response before advancing its offset. Duplicate IDs retain the first payload, queue ordering and album/forward coalescing remain intact, and committed messages remain recoverable after an acknowledgment failure. Health RPCs use the queue owner's cached facts.
Design
The existing enqueue command accepts a batch, inserts up to 100 unique IDs per statement with
ON CONFLICT DO NOTHING RETURNING, and retrieves retained duplicates together inside the existing writer transaction. Single-event admission uses the same implementation. Telegram passes each completegetUpdatesresponse through that path. Plugin-supplied queues may implement optionalenqueueBatch; existing individual-only queues remain supported.Ingress health fetches missing failed-count and pressure facts in one request, preserving each diagnostic's outcome and write-receipt/claim-expiry invalidation. This changes no schema, migration, coalescing window, or state owner. Immediate singleton enqueue/claim fusion is a separate follow-up; terminal settlement of a burst is not claimed to use a constant number of requests.
Removed checks and accepted edges:
UPDATE RETURNINGinstead of rereading its own write; the returned row inside the transaction is authoritative.Measurements
Completed three alternating pairs (M1, C1, M2, C2, M3, C3): base
1a2494eaff8650466a90d1e0a86abdf3f0bf9eba→ candidate701a6c37c55acd4ecac9f34b6d137091dfbb2453. All six arms completed with zero native SQL errors and independently reconciled wire-request counts. Warm ranges cover all 30 turns per side; whole-workload and phase ranges cover the three complete arms. Counts include transaction-envelope statements. No latency or PostgreSQL performance claim is made.Fixed monitor/Telegram flows count enqueue, direct claim, and completion. Independent queue controls use claimNext (including claimSnapshot), which explains their higher unchanged cost. One monitor batch of ten reduces admission alone from 30 SQL / 10 requests to 3 / 1. Claim and completion still happen per event, so its fixed enqueue/claim/complete cost is 63 / 21; this is constant-request batch admission, not constant-request end-to-end settlement. Ten independent enqueue calls remain unchanged, as does individual monitor admission. The polling response
[42, 42, 44]retains the first duplicate payload, invokes each unique handler once, and advances offset to 45 after durable intake. Album/forward coalescing probes enter through separate individual admissions; their fixed 18 / 6 cost is unchanged.The shared Gateway workload does not send inbound channel messages. Its changed ingress runtime work is the health cache miss at connect and restart-connect: the same two aggregate SQL statements use one worker request instead of two. The ingress area has zero T1 calls on both exact revisions; the complete T1 inventory remains 182 → 182.
Phase and shared-owner attribution
Connect's raw median rises by 11 SQL while its requests fall by one. The extra phase-local SQL is unchanged startup work (standing-intent expiry/listing, session-key/window projections, cache/config reads, quarantine admission, and envelopes), with corresponding reductions in the first-turn window. Boot+connect SQL by arm is M=[588,585,584], C=[564,596,602]: median 585 → 596 (+1.88%); combined request medians are 116 → 116. Boot+connect+first SQL is M=[912,910,949], C=[900,903,927]: median 912 → 903; requests are M=[214,215,220], C=[212,211,218]: median 215 → 212. The cron median's extra SQL is one PASSIVE WAL checkpoint. Restart-connect's +2 SQL stays within the non-turn absolute allowance. The causal first-turn +1 SQL/+1 request is one ACP metadata cache miss through unchanged chat admission, seen on both revisions; raw first-turn medians stay 325 SQL / 100 requests.
All five shared-read family medians remain unchanged, with no higher ranges; overlapping family requests are not additive. The first-turn one-read variation comes from the unchanged ACP metadata path (
chat-send-admission.ts→readAcpSessionMetaForEntries): it uses published facts when present and otherwise performs one worker read. Raw first/warm MAIN placement includes 13 unchanged background plugin-startup lease reads (plugin-lifecycle-lease.tsvia registry startup). Causal warmed MAIN remains zero; the raw range must not be read as every warmed window being MAIN-free. No touched-owner statement/request increase or shared-family increase is observed.Telegram whole-test totals include setup, verification, teardown, and 10 ms polling of list/stale-claim state. Those timer-sensitive totals are retained separately from fixed per-message costs. Direct SQL used only to verify the polling fixture is process-main work, not Gateway MAIN. These measurements cover this batch-admission/health change only; they do not measure the separate singleton enqueue/claim follow-up.
Proof status
The final candidate's
qaRuntimebuild and scoped SDK compatibility proof passed. Final CI run 39019147689 passed all nine changed test files, production/test type checks, lint stripes, source contracts, and architecture checks. Its terminal result is 58 successful jobs, 25 skipped, and two failures (the Telegram job below and its aggregate gate). Madge found zero cycles. Its global live T1 ratchet is 182 → 182, and all three changed-file dialect groups are 0 → 0; the exact-revision ingress-area inventory is 0 → 0.The same run has a failure in
checks-node-changed: the full Telegram ingress-coalescing file passed 21 tests and failed “preserves retry policy and ordering for a young session-start conflict.” The observed queue contained the first retried message but lacked the expected second pending message. The exact failure reproduces on pinned main revision7de7f398b4e98a00cd6bd87772c391450617fc53, an ancestor of this comparison base, with matching affected test/owner/fixture source. Its failure block is identical after clock and log-format normalization. This qualifies as inherited; it does not establish the follower message’s final state or the precise cause. No redundant baseline/candidate replay is scheduled. This is not reported as a green CI run. SDK exports, surface checks, and the runtime API guardrail test passed. Canonical Knip exits 1 with 17 findings, all attributed to exact observed-main scan/file/symbol matches: 14 in main run39017848352, and the remaining three test-support exports in the completed canonical scan at main59b215bc5279. Relevant source, consumers, scanner config and dependencies match. This is an inherited-static exception; Knip is not reported green. PostgreSQL conformance was path-skipped, not passed.Owner regressions cover first-payload deduplication during competing admission, recovery of a committed batch after acknowledgment failure, a real polling Worker over loopback before offset advancement, malformed-response rejection, and health cache reuse/invalidation/partial failure. The live Telegram album attempt failed before Gateway readiness and before any scenario message or model request: its task-local fixture supplied the obsolete
streaming: "off"shape instead ofstreaming: { mode: "off" }. Full channel validation rejects that fixture on unchanged base/head schema code. Native cleanup completed and no owned listener or credential scratch remains. The corrected live Telegram Test Server run passed on the exact final candidate: two photos arrived in one polling response, the batch was spooled before offset advancement, the model prompt included both images, and the bot returned the exact requested marker. Five provider requests were observed in total, including the main response request; the rest were ancillary recap/embedding work. Native lease cleanup completed, credential/Gateway scratch was removed, and both owned listeners were absent. This proves the live polling album path; the initial failed fixture attempt remains recorded.Two scoped Codex review rounds found no actionable P0–P2 defects on their supplied revisions; they did not execute tests. The subsequent main integration and type-only correction have their own build/compiler/CI evidence and are not relabeled as another formal review. A later P2 review finding is accepted as a follow-up: a throwing post-commit callback prevents later callbacks in that batch from running during the same attempt, although all rows remain durable and recoverable. The ACK-failure regression covers recovery, not completion of every callback. See the follow-up acknowledgment.
SDK evidence: the exact integrated comparison (
1a2494eaff865→701a6c37c55a) completed using the repository's native declaration emitter. Both arms cover all 155 public roots and 13,452 emitted modules; ten declarations changed, none were added/removed, and public-root export modules are unchanged. The complete delta was manually reviewed: optionalenqueueBatchis additive; the named admission-result alias preserves readonly fields and optional undefinedqueueResult; remaining changes are internal worker/health contracts. The exact-head public-factory consumer also compiles successfully. Compatibility is accepted. The stock semantic renderer did not finish or produce an artifact after 36 minutes; it remains explicitly incomplete. The complete native declaration comparison is the documented fallback, not a claim that the stock renderer passed.Current integrated diff: production +418/−221, tests +304/−113, docs +23/−4. No update/Doctor/schema/plugin-loading/service-lifecycle change is included, so the published-driver update cell is not applicable.