Skip to content

perf(gateway): acknowledge idle chat after one durable input commit - #170376

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-chat-send-ack-e2e-20260919
Oct 13, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-chat-send-ack-e2e-20260919

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fresh idle chat.send requests waited for two durable writes before acknowledging one message: pending-input custody, then the transcript and restart-recovery claim.

User Impact

Eligible idle sends now acknowledge after the existing atomic transcript/recovery commit. The response still proves durable acceptance. Existing queued inputs, active/steered sends, and sends outside restart-safe admission retain their custody path. Current authority, retry identity, and message order remain enforced.

Why This Change Was Made

Use the admitted input actor's existing, writer-invalidated snapshot to select the custody path. A fresh input goes directly to canonical transcript admission. A pending row left by an older Gateway still goes through its original recovery owner, preserving both the original message identity and approval. No new cache, configuration, schema, or migration.

Production delta: +50 lines. The routing change retains the real crash/upgrade contract for already-durable pending rows; deleting staging wholesale would strand them. The existing authority guard construction moves intact into the work-admission owner to keep the handler within its line limit. The handler itself shrinks by 12 lines.

Evidence

The initial direct-admission patch relied on the staging path for ordinary idle-send ACL checks. Direct-idle negative controls exposed that gap. Fresh admission now rechecks the retained, current session authorization inside the existing composed commit assertion. The original source preparation stays unchanged, preserving history-independent ACKs; the owner invokes the assertion at fresh transaction admission and commit.

chat-send-preparation-ack.test.ts passes all 11 tests, including real request-dispatch and SQLite coverage that pauses immediately before the transcript owner:

  • Unchanged session and selected profile: success, one transcript append and restart claim, provider dispatch.
  • Selected profile replaced: denied, no transcript append, restart claim, pending staging, or provider dispatch.
  • Shared session becomes a draft belonging to another person: denied with the same absence of side effects.
  • Redundant staging is refused while unrelated history is blocked: ACK still observes durable transcript, restart claim, and message sequence.
  • Older queued input: recovered exactly once with its original identity and approval.

Focused terminal result (synthetic fixtures):

PASS rechecks unchanged before committing unhooked idle input
PASS rechecks selected profile before committing unhooked idle input
PASS rechecks session access before committing unhooked idle input
chat-send-preparation-ack.test.ts: 11 passed
chat-send-profile-binding.test.ts: 15 passed

Changed-file formatting and lint pass. The focused preparation file passed in 54.22 s wall. Independent review of the complete corrected patch found no actionable P0–P2 findings. The profile-binding sibling passed all 15 tests after the correction (38.94 s runner wall). Previous retry and work-admission focused checks also passed. No Testbox/Crabbox was used.

Measurements

Final head 15bcdee97467655bc0e4dbd17cd4c17913935856 versus baseline ed97ab7d2c749b945bdaaf67475fd87cc0d6ff5f, in an isolated Linux sandbox: four ABBA blocks, 320 measured ACKs per variant (640 total), all followed by successful final replies. Each Gateway has 5,000 synthetic sessions; 20 WebSocket clients send the next turn after its final reply. Both instances stay warm. Each leg contains 40 ACKs. The configured openai/gpt-5.6-luna label targets a synthetic loopback provider with 100 ms chunks; no real model is called; loopback clients use operator scopes and auth-none. No production data or services were used.

Metric Before After Change
ACK p50 1,401 ms 1,209 ms 13.7% lower
ACK p99 3,565 ms 1,693 ms 52.5% lower
Pending-input staging, mean per ACK 303 ms 0 ms removed for fresh input
Transcript acceptance, mean per ACK 309 ms 158 ms
ABBA block Before p50 / p99 After p50 / p99
1 1,000 / 3,758 ms 1,066 / 1,763 ms
2 1,446 / 1,952 ms 1,135 / 1,681 ms
3 1,218 / 2,096 ms 1,041 / 1,494 ms
4 1,220 / 1,991 ms 1,367 / 1,693 ms

All four blocks improve p99; block 1 and block 4 medians regress by 6.6% and 12.1%. The pooled tail improvement is 2.1×, with a smaller median win. The <50 ms p50 / <300 ms p99 targets were missed. Gateway main-thread utilization remains 84–88%; run admission and idempotency/pre-admission still dominate, averaging 561 ms and 240 ms respectively after the change. Actor acquisition remains under 3 ms p99 and response serialization/send under 1.1 ms p99. This is synthetic comparative evidence, not a production latency claim.

Request attribution

A separate correlated trace of 40 ACKs per variant confirms 80 → 40 session.actor.acceptInput writes before ACK. This trace ran on the final source after the timed ABBA campaign, with additional FIFO/worker instrumentation.

A representative corrected request took 765 ms from RPC receipt to ACK, with 754 ms inside the ACK timer:

Span Elapsed
Gateway admission, including dispatch queue 31 ms (12 ms queue)
Authority checks 20 ms
Session resolve 27 ms
Idempotency/pre-admission 246 ms
Run admission 99 ms
Input actor read 65 ms
Pending-input staging 0 ms
Transcript acceptance 297 ms
Response serialization/send 0.5 ms

The request spent 673 ms waiting in the outer database FIFO, with 565 ms of main-thread active time during those waits. The actor read waited 61 ms and held admission for 3 ms; transcript acceptance waited 277 ms and held admission for 16 ms. Actual worker execution was 2.0 ms and 13.6 ms, with worker-broker queueing below 0.02 ms each. The idempotency read alone waited 245 ms in the outer FIFO.

This attributes the remaining delay to outer admission/main-thread contention, not slow SQL execution or response serialization. Phase spans can overlap; main-thread active time includes work for other requests and must not be summed as per-request CPU time. This trace is attribution evidence, separate from the 640-ACK latency comparison.

PR CI

Exact-head PR CI passed on 15bcdee97467655bc0e4dbd17cd4c17913935856: 613 s wall, 6,864 successful-job seconds; no failed jobs or retries. Typecheck, changed lanes, broad suites, and UI end-to-end checks ran in PR CI. The PR-context check initially rejected a renamed Evidence heading; restoring the required heading cleared that check without rerunning the CI suites.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Oct 12, 2026
@steipete
steipete marked this pull request as ready for review October 12, 2026 23:21
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Eligible idle chat sends acknowledge after one atomic transcript and restart-claim commit while existing pending inputs retain their recovery path.

Example: An idle conversation receives “Hello” with run ID chat-42.

  • Before: The Gateway commits pending-input custody and then the transcript and restart claim before acknowledging.
  • After: Fresh input needs only the transcript and restart-claim commit; an older pending row still uses staged recovery.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation and supplied runtime measurements support the optimization, but the prior direct-path authority-proof request remains unresolved.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: An idle chat message waits through redundant durable staging before the Gateway acknowledges acceptance.
Reason: The maintainer-directed change removes a durable round trip through existing owners, with a meaningful improvement in the supplied matched workload.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: it provides a focused, maintainer-directed latency improvement, and source review found no concrete introduced bug.

Priority: P2
Reviewed head: b1afa47463fb77f00f8de1273d962c884ce7a100

Before merge

  • Add real behavior proof - Authority-chain proof required: the supplied Linux public-WebSocket workload exercises successful idle sends and final replies, but does not show an unhooked idle send rejected after session-access revocation or selected-profile replacement before transcript commit and provider dispatch; provide redacted terminal output or logs without credentials, IPs, phone numbers, or non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security review attention item - No concrete authorization bypass was found, but the changed authority path still needs final-effect negative controls.
  • Resolve merge risk - Direct idle admission replaces staged-custody authorization with fresh-transcript authorization; equivalence under session-access revocation and selected-profile replacement remains unverified.

Findings

None.

Tests

  • Missing end-to-end proof: Supply direct idle-admission evidence showing allowed input succeeds and revocation or profile replacement prevents transcript commit and provider dispatch.
Agent review details

How this fits together

Gateway chat admission receives authenticated chat.send requests, selects input custody, durably records the user turn and recovery claim, and acknowledges acceptance before detached dispatch.

flowchart TD
  A[Chat request] --> B[Session and caller admission]
  B --> C[Input actor snapshot]
  C --> D[Existing pending input recovery]
  C --> E[Fresh transcript admission]
  D --> F[Atomic transcript and restart claim]
  E --> F
  F --> G[Acknowledge and dispatch]
Loading

Technical review

Best possible solution:

Retain the existing transcript owner and older pending-row recovery path, with current authority enforced before transcript commit and provider dispatch.

Do we have a high-confidence way to reproduce the issue?

Current main visibly performs staging before transcript acceptance, and the supplied matched WebSocket workload measures its latency cost; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Reusing the existing atomic transcript transaction is focused and preserves durable acceptance before ACK, while retaining staging for older pending rows avoids stranding approved input.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e4f463159d0a.

Merge-risk options

Maintainer options:

  1. Verify direct-admission revocation (recommended)
    Exercise unhooked idle sends through the production owners and show that session-access revocation or selected-profile replacement prevents transcript commit and provider dispatch.

Provenance checked

  • Pending-input custody before acknowledgment changes intended behavior with a stated reason (5f0aa4f: Retain accepted browser follow-ups across restarts instead of acknowledging memory-only custody.)
  • Direct atomic transcript and restart-claim admission changes intended behavior with a stated reason (9658ea8: Remove redundant fresh-session input staging while preserving durable acceptance before ACK; this PR extends that mechanism to eligible idle chat.)
  • Staging authority guard construction keeps the original intent (38d1253: Carry prepared sharing and custody facts while preserving original-caller validation; the extracted construction retains those checks.)

Testing

Proof path: shipped entry point.

Security

Needs attention: No concrete authorization bypass was found, but the changed authority path still needs final-effect negative controls.

Evidence

What I checked:

PR surface

Source +51, Tests +84. Total +135 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 101 50 +51
Tests 1 84 0 +84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 185 50 +135

Review metrics

Metric Value Why it matters
Production versus test growth Production +51 lines; tests +84 lines Production growth preserves recovery for existing durable rows and relocates unchanged authority guards; tests cover direct durable acceptance and older-row consumption.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This reduces idle-chat acknowledgment latency without establishing an urgent user-facing outage.
  • merge-risk: 🚨 security-boundary: Skipping staged custody changes the authorization path protecting accepted input, and existing negative controls select the staged path.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof that session-access revocation and selected-profile replacement reject an unhooked idle send before transcript commit and provider dispatch.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-12T23:29:48.775Z sha b1afa47 :: needs real behavior proof before merge. :: none

Reviewed October 12, 2026, 7:49 PM ET / 23:49 UTC (Revision 2).

Recheck retained current session authority at fresh transcript admission and commit. Cover unhooked idle sends with profile replacement and session access revocation before the durable effect.
@steipete

Copy link
Copy Markdown
Contributor Author

The direct-idle authority gap is fixed in 15bcdee. Fresh transcript admission now rechecks the retained current session authorization at the transaction/commit boundary without reopening history preparation.

The added unhooked-idle controls exercise the real request route and SQLite transcript owner. Unchanged authority succeeds. Replacing the selected profile or revoking access rejects the send with no transcript append, restart claim, pending staging, or provider dispatch. All 11 preparation/ACK tests and all 15 profile-binding tests pass. The ACL-revocation control failed against the earlier direct-admission patch, exposing the missing check.

The PR body now includes the terminal result, final-source ABBA measurements, correlated FIFO attribution, limitations, and passing exact-head CI. The independent review of the complete corrected patch is clean at P0–P2.

@steipete
steipete merged commit 768fc78 into main Oct 13, 2026
135 of 138 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-send-ack-e2e-20260919 branch October 13, 2026 00:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…penclaw#170376)

* perf(gateway): acknowledge idle chat after one durable input commit

* fix(gateway): retain idle chat admission authority

Recheck retained current session authority at fresh transcript admission and commit. Cover unhooked idle sends with profile replacement and session access revocation before the durable effect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant