Skip to content

perf(talk): index open voice session lookups - #165546

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-voice-session-indexed-lookups-20260919
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-voice-session-indexed-lookups-20260919

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Talk legacy-client inference and stale-call recovery decoded every retained voice record, including closed history, before checking status. Repeated tool checks also decoded the record's growing effect and consult arrays.

User Impact

Closed history no longer contributes payload decoding to open-call lookups. Ownership, confirmation, transcript, and persisted JSON contracts stay unchanged. Concurrent legacy consults reuse their connection binding, and an explicit close still completes when stale recovery skips a resumed call.

Why This Change Was Made

Two partial expression indexes select open records by agent/session/origin or update time. The existing agent history worker selects and validates candidates; the all-row scanner is deleted. Synchronous tool policy retains at most 128 compact facts per native connection, invalidated by admitted schema, foreign-commit data version, and local mutation revision. Exact-record transaction helpers keep their native preparation/error ordering.

The index-only design is recorded in storage changes. It preserves table shape, schema version, and JSON bytes; no Doctor data conversion is required. Generated columns were avoided because they require a version bump under the storage policy. Writable admission builds the indexes once, and older same-version readers tolerate the additional non-unique indexes.

Production LOC is +273 / −88, net +185 (git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*'). Growth preserves the synchronous tool-policy contract with revision-safe facts and the legacy protocol's validated uniqueness and worker-custody contracts. No scan fallback, second persistence owner, or configuration option is added.

Evidence

A 50,000-record synthetic fixture, 95% closed, contains 171,561,674 JSON bytes. On Blacksmith Testbox tbx_01m45rd64c95hwqn912tjfw512 (openclaw-check, Linux/Node 24.19):

Measurement Before After
Legacy lookup SQL + decode, median 359.08 ms 0.056 ms
Legacy lookup SQL + decode, p95 388.88 ms 0.119 ms
Repeated public open check, median / p95 / maximum — 0.010 / 0.017 / 0.114 ms
Stale payloads decoded All 50,000 eligible records Exactly 2,500 open records
Host record decodes during worker inference Scoped record scan 0

Matching results are identical. Both queries use their partial indexes. The first isolated worker request took 1.75 s to initialize; warm end-to-end inference was 0.96 ms median, with a 50.98 ms maximum over 10 samples. These are synthetic measurements, not production throughput claims. The <=0.5 ms open-check target passed across 1,000 samples.

pnpm test src/talk src/gateway/talk/handlers/index.test.ts src/gateway/talk/handlers/client-native-control.test.ts src/state/sqlite-query-index-repair.test.ts --maxWorkers=1 passed 486 tests in 43 files, including the new concurrent-legacy and close-race regressions. Wrapper wall time was 162.15 s on current head; the new public-handler regression took 0.978 s on prior-head validation. Original-base tests fail on the old host-payload reads; both asynchronous race regressions were observed failing before their fixes.

Prior-head Testbox tbx_01m464c2q8s0vt5s8abh7mzh9q passed 49 tests across all five changed test files. Each ran as pnpm test <file> --maxWorkers=1; serial wall time totaled 133.86 s including startup/compilation:

Changed test file Tests Wall time / single-worker CI seconds
src/talk/client-voice-session.test.ts 18 39.02 s
src/talk/client-voice-session-store.test.ts 9 8.39 s
src/talk/client-voice-session.recovery.test.ts 3 9.84 s
src/state/sqlite-query-index-repair.test.ts 5 8.87 s
src/gateway/talk/handlers/client-native-control.test.ts 14 67.74 s

Independent review returned no actionable P0–P2 findings. Revisions obtained upstream fixes through rebase only; the stable patch ID is unchanged and this PR contains one lane commit across 16 intended files.

Static gate on 86c5cc0c: completed with exit 1 on the isolated Linux rig, using node scripts/check-changed.mjs --staged against an index verified byte-for-byte equal to head 86c5cc0cd38bfcc4833e4015496209d5ba96aed4. All 25 preceding checks passed, including production types and all 27 test typecheck groups; the only failure is the inherited export scan described below. This fallback started after the Testbox lease remained queued for over 20 minutes. Prior-head Testbox lint, max-lines, schema, database-first, media/sidecar, import-cycle, webhook and pairing guards passed.

Historical inherited failure on 86c5cc0c: the global dead-export scan reported BranchSummaryResult, renderRootHelpText, stripEnvelopeFromMessage, and seven media-understanding default exports. The same command reproduces the identical findings in a clean worktree at untouched base 223f6e441ecb9bb80bbd80d885997a8ecc7270db. None of those files is changed here; no suppression or unrelated fix was added. Earlier base failures were obtained as upstream fixes by rebase rather than copied into this branch.

CI recovery: run 37322965820 failed the Madge guard on an inherited 17-file startup/database import cycle. Every cycle file and the detector were byte-identical between CI merge 612ef6e8 and its base d94b8d8a. Main fixed the cycle in 21901766c534 and removed some inherited unused exports in e698b96e7480. This branch was rebased onto 0d9e310d9fe79bd205fd0e83a19b60cb95e11131, yielding head bec2340dab57d2d53706a16f46fed1ce2b5bdec4 with unchanged stable patch ID fa61639ec885c7956702dc720e8ef9844c982267. No upstream fix was copied into the lane. CI run 37324528419 is green on this head, including the required openclaw/ci-gate.

Current-head Testbox proof: blacksmith-testbox / openclaw-check, lease tbx_01m4678767xqnn70w90bxxxhmx, Linux:

  • node --import ./scripts/tsx.mjs scripts/check-madge-import-cycles.ts: passed, zero cycles.
  • pnpm tsgo:core: passed.
  • pnpm test src/talk src/gateway/talk/handlers/index.test.ts src/gateway/talk/handlers/client-native-control.test.ts src/state/sqlite-query-index-repair.test.ts --maxWorkers=1: 486 tests / 43 files passed, 162.15 s.
  • node --import tsx scripts/check-deadcode-exports.mts: fails on renderRootHelpText, resolvePolicyPluginActivationState, and seven media-understanding default exports. An isolated untouched-base worktree at 0d9e310d9fe79bd205fd0e83a19b60cb95e11131 reproduces the identical findings. This standalone inherited failure remains documented; no guard or export baseline was weakened.

The combined command took 424.28 s and returned 1 solely for that export scan. The untouched-base reproduction took 115.94 s. All Testbox leases are stopped, and the completed Linux rig worktree has been removed.

Remote validation and recovery

Runtime tests and benchmarks used the installed Crabbox CLI, provider blacksmith-testbox, profile openclaw-check. Final static validation uses the authorized Linux rig fallback.

  • tbx_01m45n99vd3w5ghe55qpnht17j: Talk suites passed; index-plan fixture sorting was corrected. The initial 50k benchmark passed. Original-base payload-read regressions failed as expected after installing the temporary worktree's dependencies. Gateway handlers passed 117 tests. The close-race regression failed before repair. The first changed-file attempt identified a type-file size limit; declarations moved to the existing sibling. Two subsequent sync attempts timed out before validation. Lease stopped.
  • tbx_01m45rd64c95hwqn912tjfw512: focused tests passed after the close fix. Recovery cases moved into a focused sibling to meet the test-file size cap. Full typechecks and preceding changed-file guards passed; the dead-export failure was reproduced on the untouched base. The legacy race was then reproduced and repaired; final runtime suites passed 486 tests. The benchmark above passed. Post-repair core/Gateway typechecks passed. Remaining lint found mechanical issues, now corrected, before the connection dropped. Lease is completed.
  • tbx_01m45wyff3j2vrjwx14wrmnebe: all typechecks passed. The global dead-export check found two further inherited exports. Changed-file lint, architectural guards, and all 486 tests passed independently. A generated one-line stale-baseline prune was reviewed, then discarded when the same fix arrived on main. The lease was stopped and the branch rebased; its stable patch ID remains unchanged.
  • tbx_01m460eqenqkk9rpamg4temkg6: lease disappeared while queued after more than an hour; no validation command ran. Cleanup completed.
  • tbx_01m464c2q8s0vt5s8abh7mzh9q: final-head changed-file runtime checks passed 49 tests; max-lines, changed-file lint and architectural guards passed. Lease stopped. The dead-export guard failed with the same findings reproduced in a clean worktree at untouched base 223f6e441ecb9bb80bbd80d885997a8ecc7270db.
  • Linux rig: node scripts/check-changed.mjs --staged on an index verified byte-for-byte against head 86c5cc0cd38bfcc4833e4015496209d5ba96aed4; 25 checks passed, inherited export scan failed (exit 1). No guard was skipped.

No production database was copied or mutated, and no live Gateway deployment is included.

Linux rig static-gate summary for prior head 86c5cc0
[check:changed] summary
   2.03s  ok         conflict markers
   1.68s  ok         line-cap growth ratchet
  24.08s  ok         max-lines suppression ratchet
  60.41s  ok         assertion SAFETY comment ratchet
  13.40s  ok         SQLite worker ratchet
   5.97s  ok         test timeout race ratchet
  51.88s  ok         first-party mock export ratchet
   1.03s  ok         changelog attributions
   741ms  ok         doctor deprecation registry
   978ms  ok         guarded extension wildcard re-exports
   935ms  ok         plugin-sdk wildcard re-exports
   1.45s  ok         duplicate scan target coverage
   1.71s  ok         dependency pin guard
   2.56s  ok         format changed files
  17.16s  ok         config docs baseline
   771ms  ok         SQLite sessions/transcripts schema baseline
   7.11s  ok         plugin boundaries
  38.06s  ok         wrapper shadowing
   2.04s  ok         package patch guard
   1.59s  ok         test temp creation report (warning-only)
 454.50s  ok         core tsgo graph boundary
 160.82s  ok         typecheck core
3832.15s  ok         typecheck core tests
  30.09s  ok         coercion helper declaration guard
  18.68s  ok         deprecated API usage
 240.09s  failed:1   dead export scan

@clawsweeper

clawsweeper Bot commented Oct 5, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 5, 2026
@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 Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 10:19 AM ET / 14:19 UTC (Revision 5).

ClawSweeper review

What this changes

Talk voice-call lookups use indexed background reads and revision-bound compact facts, with safeguards for concurrent legacy consults and stale-call recovery.

Merge readiness

✅ Ready for maintainer review

Keep open: current main still performs broad voice-record scans, and this PR provides a useful, validated optimization. No actionable correctness or security findings remain; the previous readiness action is resolved.

Priority: P2
Reviewed head: 86c5cc0cd38bfcc4833e4015496209d5ba96aed4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with strong production-path measurements, useful race and compatibility coverage, and no actionable review findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Captured Testbox measurements exercise the changed SQLite lookup owner, history-worker inference, and public open check against a populated synthetic database with matching results and reduced decoding. Final-head regression runs supplement that evidence; additive-index compatibility is supported by populated admission and preceding-reader checks.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured Testbox measurements exercise the changed SQLite lookup owner, history-worker inference, and public open check against a populated synthetic database with matching results and reduced decoding. Final-head regression runs supplement that evidence; additive-index compatibility is supported by populated admission and preceding-reader checks.
Evidence reviewed 8 items Pinned patch ownership: Reviewed the merge-base-to-head introduced patch. Raw head parent is 223f6e4; the test merge records d94b8d8 followed by the exact PR head. Base-only dependency and updater changes are not attributed to this PR.
Still needed on main and latest release: Fetched main retains readVoiceSessionRecordRows and broad payload selection. GitHub contents inspection at the supplied latest-release commit likewise shows legacy inference and stale recovery calling that scanner. No verified merged replacement was established.
Release source check: The v2026.9.8 source at fc23bc8 calls readVoiceSessionRecordRows at lines 408 and 710. The release blob was inspected through GitHub after its local object was unavailable.
Findings None None.
Security None None.

How this fits together

Talk connects realtime voice clients to OpenClaw agent consults. Its per-agent voice records track call ownership, transcripts, confirmation capability, and closure.

flowchart TD
  A[Realtime voice client] --> B[Talk request handler]
  B --> C[Current session authorization]
  C --> D[Background open-call lookup]
  D --> E[Indexed agent database]
  E --> F[Validated call candidates]
  F --> G[Consult or stale-call close]
  E --> H[Revision-bound tool facts]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +185, Tests +344, Docs +25. Total +554 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 10 273 88 +185
Tests 5 377 33 +344
Docs 1 25 0 +25
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 675 121 +554

Review metrics

Metric Value Why it matters
Production versus test growth Production +273/-88, net +185; tests +377/-33, net +344 The PR explains production growth as preserving synchronous policy, revision-safe facts, and asynchronous lookup ordering.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-schema.sql. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Retain one canonical voice-record store, use indexed worker reads for candidate selection, and preserve synchronous fresh ownership checks and transaction-bound closure.

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

Not applicable as a functional bug reproduction: current-main source establishes the broad scan, and the captured benchmark quantifies its cost without claiming production throughput.

Is this the best way to solve the issue?

Yes. Filtering through derived indexes in the existing reader and retaining revision-bound facts avoids record conversion, a second persistence owner, and configuration growth.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Talk performance improvement with demonstrated synthetic lookup gains and preserved existing contracts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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): Captured Testbox measurements exercise the changed SQLite lookup owner, history-worker inference, and public open check against a populated synthetic database with matching results and reduced decoding. Final-head regression runs supplement that evidence; additive-index compatibility is supported by populated admission and preceding-reader checks.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured Testbox measurements exercise the changed SQLite lookup owner, history-worker inference, and public open check against a populated synthetic database with matching results and reduced decoding. Final-head regression runs supplement that evidence; additive-index compatibility is supported by populated admission and preceding-reader checks.

Evidence

What I checked:

  • Pinned patch ownership: Reviewed the merge-base-to-head introduced patch. Raw head parent is 223f6e4; the test merge records d94b8d8 followed by the exact PR head. Base-only dependency and updater changes are not attributed to this PR. (86c5cc0cd38b)
  • Still needed on main and latest release: Fetched main retains readVoiceSessionRecordRows and broad payload selection. GitHub contents inspection at the supplied latest-release commit likewise shows legacy inference and stale recovery calling that scanner. No verified merged replacement was established. (src/talk/client-voice-session-store.ts:154, e698b96e7480)
  • Release source check: The v2026.9.8 source at fc23bc8 calls readVoiceSessionRecordRows at lines 408 and 710. The release blob was inspected through GitHub after its local object was unavailable. (src/talk/client-voice-session.ts:408, fc23bc864e45)
  • Freshness and authorization: Compact facts are bounded to 128 entries per native connection and invalidated by schema facts, foreign-commit data version, and local mutation revision. Transactions, snapshots, and authorizers bypass reuse. The handler revalidates session authority after inference, and stale recovery rereads ownership and cutoff inside the close transaction. (src/talk/client-voice-session-store.ts:175, 86c5cc0cd38b)
  • Stored-state compatibility: Only two nonunique derived indexes are added; table shape, record serialization, and schema version remain unchanged. The existing admission owner repairs indexes. Changed regression coverage checks populated fresh, missing, and drifted index states, unchanged rows/version, repeated reopening, and preceding-reader tolerance. (src/state/sqlite-query-index-repair.test.ts:203, 86c5cc0cd38b)
  • Production-path benchmark and final-head validation: The captured PR body reports real SQLite and history-worker execution on isolated Linux/Node 24.19 with 50,000 synthetic records: identical lookup results, partial-index use, zero host payload decodes during inference, and a 0.010 ms median repeated public open check. It separately reports 49 final-head tests passing across all five changed test files and an inherited dead-export failure reproduced on the untouched base. These are contributor-reported observations, not reviewer-executed tests; the captured body identity is 15cff63b35b8ca6f267c02c14e6c64aabb3fb9f65631540403b344973a2d81e2. (86c5cc0cd38b)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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 (4 earlier review cycles)
  • reviewed 2026-10-05T11:34:44.487Z sha 3baecb8 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T11:42:23.220Z sha 3baecb8 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T12:43:55.691Z sha 86c5cc0 :: needs changes before merge. :: none
  • reviewed 2026-10-05T14:03:24.749Z sha 86c5cc0 :: needs changes before merge. :: none

@steipete
steipete force-pushed the steipete/perf-micro-voice-session-indexed-lookups-20260919 branch from 3baecb8 to 86c5cc0 Compare October 5, 2026 12:26
@steipete
steipete marked this pull request as ready for review October 5, 2026 14:13
@steipete
steipete enabled auto-merge (squash) October 5, 2026 14:16
Filter and validate legacy and stale candidates in the agent reader, retain revision-bound tool facts, and preserve close and legacy-binding ordering across reader waits. Keep voice JSON bodies and schema version unchanged with additive partial indexes.
@steipete
steipete force-pushed the steipete/perf-micro-voice-session-indexed-lookups-20260919 branch from 86c5cc0 to bec2340 Compare October 5, 2026 14:24
@steipete
steipete merged commit 495c243 into main Oct 5, 2026
138 of 139 checks passed
@steipete
steipete deleted the steipete/perf-micro-voice-session-indexed-lookups-20260919 branch October 5, 2026 14:37
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
Filter and validate legacy and stale candidates in the agent reader, retain revision-bound tool facts, and preserve close and legacy-binding ordering across reader waits. Keep voice JSON bodies and schema version unchanged with additive partial indexes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation 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: L 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