Skip to content

perf(sessions): reduce stalls when saving large chat messages - #158402

Merged
steipete merged 3 commits into
mainfrom
perf/l07-payload-navigation-inline-20260925
Sep 26, 2026
Merged

steipete merged 3 commits into
mainfrom
perf/l07-payload-navigation-inline-20260925

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes long Gateway stalls when saving large chat messages that compress into transcript storage.

User Impact

Large messages spend substantially less time in synchronous transcript preparation. Canonical transcript bytes, navigation, schemas, and update behavior stay unchanged. This removes the measured SQLite temporary-storage cliff; it does not move the remaining user-turn persistence off the Gateway thread.

Why This Change Was Made

The source CTE carried both full JSON and JSONB into temporary storage. Inline that source while keeping the bounded metadata result materialized. Extend the existing native-JSON parity fixture to a large payload instead of adding a separate test harness.

Evidence

Source microbenchmark on Node 26.9.0/macOS arm64, five warm samples per size, identical FILE TEMP policy. Median milliseconds:

Input Before After
64 KiB 0.94 1.00
512 KiB 2.43 3.14
1 MiB 173.18 5.97
2 MiB 1033.36 14.31

The small-input tradeoff is visible above; the large-input cliff disappears. The shared host was busy, so these are component measurements rather than end-to-end latency predictions. The 2 MiB median process CPU time fell from 119.84 ms to 10.83 ms.

  • Focused test: node scripts/run-vitest.mjs src/config/sessions/transcript-payload.test.ts --maxWorkers=1 passed all 23 tests, including large-payload canonical-byte and duplicate-key/native-projection parity. Wall: 11.69 s; Vitest: 3.80 s. Baseline: 22 tests passed, 35.91 s cold wall.
  • Production LOC: +2 / -2, net 0. Tests: +96 / -89, net +7; most churn is formatter indentation around the extended table.
  • Deslop: inspected the complete diff; no defensive wrappers, casts, or unrelated cleanup added.
  • Original query validation: node scripts/check-changed.mjs passed, including core production and all 25 selected core-test typecheck graphs, lint, export scans, and storage/runtime guards.
  • Original query Codex autoreview: scoped-clean through P2; no accepted/actionable findings. End-to-end Gateway latency was not measured.

CI fixture repair

The original CI job failed the Watch reconnect/invoke test. Full main CI passed on the same main commit, and the Watch owners are byte-identical between the reviewed head and that CI merge tree. A controlled 2,001 ms clock advance after command delivery reproduced a real TIMEOUT response. The original log omitted the error code, so this establishes the fixture's timing failure mechanism without claiming to recover that missing field.

The functional transport fixture now holds its monotonic clock steady and checks that the HTTP result was accepted. The two-second invoke budget, real HTTP/pairing work, authorization checks, and production code stay unchanged.

Linux Node 24.19.0 validation through the task-owned Testbox:

  • Controlled original failed with TIMEOUT; the same probe passed with the fixture repair.
  • pnpm test src/gateway/watch-node-http.test.ts --maxWorkers=1: 20 clean runs, 420 test executions. Median warm wall time 19.40 s (18.59–21.61 s); the initial unchanged-file run was 38.49 s.
  • Original 15-file shard, on verified merge d033b983f3e39416c6570445b0215189a732964c plus the same repair: three clean runs, 226 tests each, with the original eight-worker policy. Wall times: 215.98 s, 182.17 s, and 188.21 s.
  • Registry deadline/policy siblings: 30 selected tests passed; formatting, lint, complete core-test type checks, and diff checks passed.
  • Fresh Codex autoreview of the fixture correction: scoped-clean through P2, with no accepted/actionable findings.

Local shard and standalone attempts did not complete test execution on the busy host. Remote preparation also needed recovery from an interrupted capture, an idle lease expiry, and incomplete workspace dependency links; normal frozen installs resolved the dependency issue. These are setup failures, not passing test evidence. No hosted CI run was blindly retried.

Prior-head CI run 36216113165 failed for fixture commit e54df72d19c3073771fb16525698bb16458a9fff, blocking that head in openclaw/ci-gate.

The single actual test failure was in compact-small-5: update-runner-git-candidate.test.ts, Doctor outcome doctor-error. Its first target-inspection git rev-parse HEAD hit the fixture's 5,000 ms command deadline (exit 124), before the Doctor callback. Other reported failures were cancellation fallout. The tested merge was 975ed433570a9e56d327deec2497cf7e9c46ca61; the relevant test, inspection, and process-runner files match this PR's head. Searches found no matching owning fix. The latest completed full-main run checked, 36215230884, passed.

Bounded reproduction on macOS/Node 26.9.0, rather than CI's Linux/Node 24.19.0:

  • The original two-group, 90-file selection was stopped after 684.09 s because local runtime was disproportionate. It recorded 1,604 passes, including the original Doctor case (3.586 s). A different candidate-Node fallback case failed with an empty message; interruption prevented its final stack report.
  • The focused original Doctor case passed: one selected test, 60 filtered, 12.908 s test time and 208.106 s command wall including worker compilation.

These passing replays do not prove a fix. The reason for the original Git stall remains unknown, and no safe repair was established. No updater source, command deadline, or assertion was changed, and no hosted CI rerun was requested. That run remained failed and was not rerun.

Required main refresh

Merged current main ceac53a0feaf75eb599e4c310fbd7e35923ba9cf into the stale branch without rebasing or changing the reviewed PR delta. Merge head: 82d5b9af62a9b9b3c0258ee44262d98ee19cfb67.

The requested local rerun passed: 23 transcript-payload tests and 21 Watch fixture tests, using node scripts/run-vitest.mjs src/config/sessions/transcript-payload.test.ts src/gateway/watch-node-http.test.ts --maxWorkers=1 (184.90 s including worker preparation). Fresh exact-head CI run 36219424661 passed on 82d5b9af62a9b9b3c0258ee44262d98ee19cfb67. The Doctor failure did not recur. The prior Doctor timeout remains historical evidence, not a claimed repair.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 25, 2026 22:31
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 1:10 AM ET / 05:10 UTC (Revision 3).

ClawSweeper review

What this changes

The branch changes how SQLite prepares navigation metadata for large saved chat messages, extends transcript parity coverage, and steadies a Watch HTTP test fixture.

Merge readiness

✅ Ready for maintainer review

Current main still materializes the large transcript input, so this PR addresses a remaining performance problem. The source review found no introduced correctness defect.

Priority: P2
Reviewed head: 82d5b9af62a9b9b3c0258ee44262d98ee19cfb67

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused query change has useful component-level before/after measurements and behavioral parity coverage, with no identified patch defect.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR reports a real Node/macOS benchmark exercising transcript preparation with the changed SQLite query and an observed large-payload improvement, supported by a parity test and repeated Watch fixture runs. It does not claim full Gateway latency proof; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR reports a real Node/macOS benchmark exercising transcript preparation with the changed SQLite query and an observed large-payload improvement, supported by a parity test and repeated Watch fixture runs. It does not claim full Gateway latency proof; no stored-data contract changes.
Evidence reviewed 8 items Introduced query-plan change: The pinned PR delta changes the source CTE from materialized to not materialized while retaining the materialized, size-bounded metadata result.
Current main still has the performance cliff's query shape: Fetched main still explicitly materializes the source CTE; this PR's central change is not already present there.
Existing storage contract: Agent schema 23 stores exact original event JSON either as text or compressed bytes with bounded navigation metadata. The PR changes preparation SQL, not that persisted format.
Findings None None.
Security None None.

How this fits together

OpenClaw prepares chat messages for per-agent SQLite transcript storage. It saves the original message bytes or a compressed representation with bounded navigation metadata, which session history and model-context reads later consume.

flowchart LR
A[Chat message] --> B[Transcript preparation]
B --> C{Compression eligible?}
C -->|Yes| D[Compressed event and navigation metadata]
C -->|No| E[Original JSON event]
D --> F[Session history and model context]
E --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +7. Total +7 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 2 96 89 +7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 98 91 +7

Review metrics

Metric Value Why it matters
2 MiB preparation median 1033.36 ms before → 14.31 ms after The submitted component benchmark measures the large-message SQLite cliff targeted by this PR; it is not an end-to-end Gateway latency measurement.

Technical review

Best possible solution:

Keep transcript bytes exact and navigation metadata bounded while avoiding the large temporary SQLite source; investigate remaining Gateway turn stalls separately if users still observe them.

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

Yes, at the component boundary: current main materializes the large JSON source, and the PR reports a before/after benchmark with large payloads and the same SQLite temporary-storage policy. No full Gateway turn-latency reproduction was supplied.

Is this the best way to solve the issue?

Yes. Changing this query plan targets the measured SQLite bottleneck without adding a storage format, setting, or parallel implementation, and the extended parity case checks the resulting data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8279835741d0.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Large-message transcript preparation can cause noticeable Gateway stalls, but the affected payload range limits its blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR reports a real Node/macOS benchmark exercising transcript preparation with the changed SQLite query and an observed large-payload improvement, supported by a parity test and repeated Watch fixture runs. It does not claim full Gateway latency proof; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports a real Node/macOS benchmark exercising transcript preparation with the changed SQLite query and an observed large-payload improvement, supported by a parity test and repeated Watch fixture runs. It does not claim full Gateway latency proof; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed September 25, 2026, 6:52 PM ET / 22:52 UTC sha unknown :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T04:01:04.964Z sha e54df72 :: needs maintainer review before merge. :: none

Keep pairing-worker latency from exhausting the reconnect fixture's invoke
budget. Preserve the two-second timeout and all transport and authority
assertions, and verify that the HTTP result was accepted.

A controlled clock advance reproduced TIMEOUT through the real result path.
Validation: 20 full Watch runs, three original 15-file CI cohorts, selected
registry deadline/policy tests, core-test types, lint, and P2 review.
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 26, 2026
@steipete
steipete merged commit 7bad1cb into main Sep 26, 2026
207 checks passed
@steipete
steipete deleted the perf/l07-payload-navigation-inline-20260925 branch September 26, 2026 05:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 26, 2026
* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...
vincentkoc added a commit that referenced this pull request Sep 26, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '66b812f26e725cd709e08860d2cb46ba496cd308': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (#158689)
  fix(gateway): reset staged headers on authority errors (#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (#158612)
  fix(ui): keep automation starter prompts out of startup (#158482)
  fix(cli): distinguish configuration read failures from invalid input (#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (#158662)
  fix(daemon): keep native service checks within their timeout (#154565)
  fix(test): restore gateway steering fixture contracts (#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (#158633)
  perf(gateway): release event payloads from live text guards (#158643)
  perf(sessions): reduce stalls when saving large chat messages (#158402)
  fix(qa): reject history-bearing utility requests without session affinity (#158496)
  test: allow intentional progress snapshot coercion
  ...

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…aw#158402)

* perf(sessions): avoid spilling transcript navigation inputs

* test(gateway): control the Watch invoke fixture clock

Keep pairing-worker latency from exhausting the reconnect fixture's invoke
budget. Preserve the two-second timeout and all transport and authority
assertions, and verify that the HTTP result was accepted.

A controlled clock advance reproduced TIMEOUT through the real result path.
Validation: 20 full Watch runs, three original 15-file CI cohorts, selected
registry deadline/policy tests, core-test types, lint, and P2 review.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
* fix(test): verify followup completion ordering

Exercise the real presentation settlement helper with asynchronous cleanup, preserve continuation and admission semantics, and unconditionally release and join the held work. Remote proof covers the strengthened ordering contract and both missing-await faults.

* fix(test): verify followup completion ordering

* chore: retain followup test branch ancestry

The current-main reconstruction preserves the original reviewed scope and supersedes its stale base. Keep the remotely qualified candidate tree unchanged while retaining the original PR ancestry for a non-force branch update.

* commit 'ff35145de21cf6296bec05e86bee37b5ed53bcb8':
  fix(test): verify followup completion ordering

* test(auto-reply): signal queued presentation entry

* chore: refresh followup test on boundary fix

* commit '622be54be3ffe0fce27d6a4b147c76d4b19c528c': (70 commits)
  fix(gateway): preserve typed boxed-number coercion
  chore(ui): refresh control ui locales (openclaw#158689)
  fix(gateway): reset staged headers on authority errors (openclaw#158669)
  fix(workers): keep inbound staging stable during quota scans
  fix: preserve Telegram delivery after bot identity changes (openclaw#158612)
  fix(ui): keep automation starter prompts out of startup (openclaw#158482)
  fix(cli): distinguish configuration read failures from invalid input (openclaw#158671)
  test: remove retired progress coercion suppression allowance
  refactor(gateway): schedule worker placement maintenance (openclaw#158662)
  fix(daemon): keep native service checks within their timeout (openclaw#154565)
  fix(test): restore gateway steering fixture contracts (openclaw#158478)
  fix(acpx): use SDK filesystem publication boundary
  fix(agentsapi): load OpenClaw persona and workspace context (openclaw#158328)
  fix(gateway): drop progress snapshot coercion suppression
  fix(qa): accept native Codex truncation in cache evidence (openclaw#158454)
  fix(gateway): keep chat subscriptions stable during unrelated approvals (openclaw#158633)
  perf(gateway): release event payloads from live text guards (openclaw#158643)
  perf(sessions): reduce stalls when saving large chat messages (openclaw#158402)
  fix(qa): reject history-bearing utility requests without session affinity (openclaw#158496)
  test: allow intentional progress snapshot coercion
  ...

Co-authored-by: Vincent Koc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant