Skip to content

refactor(transcripts): move durable mirror corrections to workers - #165541

Merged
steipete merged 7 commits into
mainfrom
dbasync/w4mirrors
Oct 5, 2026
Merged

steipete merged 7 commits into
mainfrom
dbasync/w4mirrors

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Delivery-mirror and media corrections still scanned and rewrote durable transcripts with SQLite on the Gateway thread.

User Impact

Saved reply corrections keep their existing selection, refusal, and concurrency behavior while durable database work runs in workers. Schemas, retention, durability, configuration, and released SDK call shapes are unchanged.

This is the correction-only part of W4-01. Locked mirror appends, SDK callback adapters, and feedback persistence remain in the stacked follow-up; full W4-01 is not complete. Native maintenance and incognito adapters remain, and P7 remains inactive.

Why This Change Was Made

Reuse the existing transcript history reader and canonical agent writer. Retain the captured physical source through preparation, exact-row commit, and cleanup, separately from logical session identity. The writer checks generation and original stored bytes; tail-selected corrections also check the full version, while indexed-media corrections allow unrelated later appends. Transaction and commit grants recheck current authority, and accepted corrections settle before Gateway database shutdown.

Production delta: +300 / -53 / net +247, seven production files. 0 new OPENCLAW_* names. The original pinned-base inventory remains T1 883 → 883 because shared native/SDK kernels remain counted.

Overlap: #162433 (session ownership), #165401 (transcript hydration), and #165028 (session authority). Integration with #165490 uses the canonical extracted transcript-conflict error owner. Hunks remain within correction callers and their existing owners.

Evidence

  • Final candidate: 05984c525627f694092dbbc36b842a6fe97b1c44. Main was integrated with merge commits, preserving ancestry.
  • Real-entry Gateway-thread SQL calls against pinned baseline e78e965a55e2: keyed correction 55 → 0, source-mirror correction 59 → 0, indexed-media correction 45 → 0. These measure the correction entry points, not whole-chat throughput.
  • Refreshed correction/lifecycle/build-graph/import batch at 05984c525627f: 27 tests passed. The 13-case correction shard took 146.58 s; graph/import shards took 9.62 s and 16.34 s. The prior full command measured 940.56 s wall on the loaded development host and covers physical ownership, generation/byte refusal, exact media selection, tail refusal, intervening rewrite/revocation, unrelated appends, and real Gateway close settlement. Commands use node scripts/run-vitest.mjs ... --maxWorkers=1; isolated CI timing for these focused runtime cases is not claimed.
  • Planner/watch routing: 124 tests passed, 439.55 s wall. Both original routing failures reproduced 5/5 on the prior PR head and passed 5/5 on the merge base; removing one stale Gateway route repaired them without changing assertions. After main integration, both affected routing guards passed again (2 passed, 122 skipped; 52.91 s wall). The earlier 68 indirect dispatch/commentary/cancellation cases remain applicable because their inputs are unchanged.
  • Runtime-process build graph and get-reply/history-reader/reconcile import-closure guards passed. Madge: 0 cycles after taking main’s repair 21901766c534. Fresh independent Codex review through P2: scoped-clean.
  • Released SDK boundary checked against v2026.9.8. The API report adds only optional eventJson?, afterSeq?, and includeEventJson? fields, with no new entrypoints or direct exports. Existing sync/async signatures remain accepted, so no deprecation adapter is needed. The refreshed local report against integrated main completed successfully: no added/removed entrypoints or direct signatures; JSON SHA256 1e026d9bf215163daafe2e6c29510ca1cc7076af76868099f4bb256208defc57 (acknowledgement e3e9c76e).
  • Published-driver upgrade proof on final head 05984c525627f: full cell passed, using published driver 2026.9.8, Node 24.21.0 and pnpm 12.5.1. Cell exit 0 in 492.271 s, update in 407.718 s; durable update finished successfully, readyz 200, exact candidate build running, durable history retained, incognito history cleared. Final stop exited 0 in 628 ms, within the unchanged 5000 ms limit. The proof uses synthetic state and preserves cleanup assertions. This proves upgrade compatibility without a schema, retention, or serialized-format change. Candidate tarball SHA256: ef30d3ff071f17ed0f6a8ad20fcf726b564a86c99dd5500651cf1a61620d48ef.
  • The prior cleanup failure was isolated to fixture background work. The manual-RPC fixture now disables default heartbeat, matching sibling fixtures; no deadline or assertion changed. The effective 0m cadence was independently observed. The exact earlier cron job ID was not captured.
  • Completed trusted ClawSweeper review on 05984c525627f at 2026-10-05 14:36 UTC found no introduced correctness/security defect. Its two remaining proof requests—complete published-driver cleanup and upgrade compatibility—are satisfied by the passed cell above.
  • CI run 37319251718 at 3c9a7900bea7 had 50 successful jobs and one root type error plus the aggregate gate: an untouched RPC exporter fixture assigned input descriptors without required profileAccess. The exact error independently reproduced on main bfe92816. Main subsequently fixed it in b9f2ea649750; that fix is integrated in merge commit 05984c525627f. The exact failing type stripe now passes locally (21.2 s). Current-head CI passed: 52 successful jobs, 23 skipped, no failures or cancellations, including security-fast and openclaw/ci-gate. The final published-driver cell also passed; no admin exception is needed. Fresh complete-delta P2 review is scoped-clean.

Earlier failures were addressed at their owners: a stale conflict-error import after main integration, duplicate commentary-media test routing, and an independently reproduced main Madge cycle. The first two were repaired here; main’s cycle fix was merged before the final green run. The later inherited RPC-exporter type error was resolved by taking main’s fix.

Read correction snapshots through the retained history owner and commit exact
rows through the canonical agent writer. Preserve source-tail restrictions,
indexed generation refusals, unrelated later appends, and shared-store identity.

Release-note context: durable delivery-mirror and media corrections no longer
perform their transcript SQL on the Gateway thread. Stored formats and SDK
entrypoints remain unchanged. Locked mirror appends and feedback remain separate.
@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
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

Moves saved reply and media corrections into existing transcript workers, preserves their selection and concurrency checks, and disables background heartbeat in the upgrade fixture.

Merge readiness

✅ Ready for maintainer review

This remains useful work: current main still performs these corrections through synchronous transcript access. No introduced correctness or security defect was found, and the recorded final-head upgrade run resolves the previous review’s shutdown and cleanup blocker.

Priority: P2
Reviewed head: 05984c525627f694092dbbc36b842a6fe97b1c44

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported ownership refactor with no actionable defect and the previous qualification gap resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded real correction-entry measurements exercise the changed reader/writer path and show zero Gateway-thread SQL after the cutover. Final-head boundary coverage includes revoked authority and Gateway close settlement; the completed published-2026.9.8 update cell preserves durable state and finishes shutdown and cleanup. No stored-format change is introduced, and existing-state compatibility is demonstrated.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real correction-entry measurements exercise the changed reader/writer path and show zero Gateway-thread SQL after the cutover. Final-head boundary coverage includes revoked authority and Gateway close settlement; the completed published-2026.9.8 update cell preserves durable state and finishes shutdown and cleanup. No stored-format change is introduced, and existing-state compatibility is demonstrated.
Evidence reviewed 9 items Pinned introduced changes: Reviewed the merge-base-to-head delta, including correction callers, worker commands, hydration fields, regression coverage, fixture configuration, and test routing. The supplied test merge is stale and was not used to infer removal of current-main behavior.
Current main still needs this cutover: Fetched main retains withTranscriptWriteLock for keyed and source-mirror corrections and synchronous watermark/row reads for indexed-media corrections. The related merged header and conflict fixes do not implement this correction cutover.
Physical source and live authority: Correction preparation retains the physical history source, captures its original event bytes, and composes source currency with the caller’s owned write assertion. The existing writer admission owner invokes that assertion at transaction and commit grants.
Findings None None.
Security None None.

How this fits together

The Gateway updates saved assistant replies after delivery and media preparation. Transcript readers supply the original records, and the agent database writer commits corrections before updated history is published.

flowchart TD
  A[Prepared reply or media] --> B[Select saved reply]
  B --> C[Retained transcript reader]
  C --> D[Prepare corrected display]
  D --> E[Check current authority and original rows]
  E --> F[Agent database writer]
  F --> G[Publish updated history]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +247, Tests +433, Docs +11, Other +1. Total +692 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 300 53 +247
Tests 3 434 1 +433
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 12 746 54 +692

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +300/-53; tests +429/-0 Production growth supports retained-source preparation and exact worker commits; the added tests exercise distinct concurrency and lifecycle contracts.

Stored data model

Persistent data-model change detected: migration/backfill/repair: scripts/e2e/lib/upgrade-survivor/published-driver.mjs. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep durable corrections under the existing transcript reader and agent writer, preserving current authority, exact-row refusal, and shutdown settlement.

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

Not applicable as a new bug report; current-main source confirms synchronous correction access, and the recorded paired entry-point measurements demonstrate the intended worker cutover.

Is this the best way to solve the issue?

Yes. Reusing the existing reader, writer, byte codec, and admission checks is a focused way to move durable SQL off the Gateway thread.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime performance and ownership improvement with no demonstrated urgent user-facing regression.
  • 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): Recorded real correction-entry measurements exercise the changed reader/writer path and show zero Gateway-thread SQL after the cutover. Final-head boundary coverage includes revoked authority and Gateway close settlement; the completed published-2026.9.8 update cell preserves durable state and finishes shutdown and cleanup. No stored-format change is introduced, and existing-state compatibility is demonstrated.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real correction-entry measurements exercise the changed reader/writer path and show zero Gateway-thread SQL after the cutover. Final-head boundary coverage includes revoked authority and Gateway close settlement; the completed published-2026.9.8 update cell preserves durable state and finishes shutdown and cleanup. No stored-format change is introduced, and existing-state compatibility is demonstrated.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head delta, including correction callers, worker commands, hydration fields, regression coverage, fixture configuration, and test routing. The supplied test merge is stale and was not used to infer removal of current-main behavior. (05984c525627)
  • Current main still needs this cutover: Fetched main retains withTranscriptWriteLock for keyed and source-mirror corrections and synchronous watermark/row reads for indexed-media corrections. The related merged header and conflict fixes do not implement this correction cutover. (src/gateway/server-methods/chat-transcript-persistence.ts:400, bb3a8a9ac304)
  • Physical source and live authority: Correction preparation retains the physical history source, captures its original event bytes, and composes source currency with the caller’s owned write assertion. The existing writer admission owner invokes that assertion at transaction and commit grants. (src/config/sessions/session-transcript-correction.ts:83, 05984c525627)
  • Exact-row concurrency contract: The worker checks writer fences and generation, checks the full version for tail-selected corrections, resolves original row identities, and delegates byte comparisons and generation rotation to the existing transactional rewrite owner. Indexed corrections preserve unrelated later appends. (src/config/sessions/session-message-rewrite.worker.ts:168, 05984c525627)
  • Meaningful boundary regressions: Inspected tests cover all three correction entry points without caller-thread SQL, shared physical-store ownership, tail refusal, exact media selection, generation loss, intervening rewrite/revocation, unrelated appends, and accepted correction settlement through real Gateway close. Tests were not executed during this read-only review. (src/gateway/server-methods/chat-transcript-persistence.mirrors.test.ts:127, 05984c525627)
  • Recorded runtime and completed upgrade proof: Captured PR body sourceRevision b3b1a53993d775b88f7ea7e10e7f04d8962b8a1e20b97df05ea7595947cd5e19 records correction-entry Gateway SQL reductions of 55→0, 59→0, and 45→0. It records the final-head published-2026.9.8 driver cell passing in 492.271 seconds, readyz 200, exact candidate running, durable history retained, incognito history cleared, and final stop succeeding in 628 ms under the unchanged 5000 ms bound. This satisfies the prior completed review’s sole rank-up request. (05984c525627)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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 (8 earlier review cycles)
  • reviewed 2026-10-05T11:19:45.931Z sha fe5decc :: needs changes before merge. :: none
  • reviewed 2026-10-05T11:24:37.746Z sha fe5decc :: needs changes before merge. :: none
  • reviewed 2026-10-05T11:32:29.469Z sha fe5decc :: blocked before merge. :: none
  • reviewed 2026-10-05T11:52:56.795Z sha 761270d :: needs changes before merge. :: none
  • reviewed 2026-10-05T12:23:03.422Z sha 2d0aec3 :: needs changes before merge. :: none
  • reviewed 2026-10-05T13:08:05.215Z sha 947f695 :: needs changes before merge. :: none
  • reviewed 2026-10-05T13:52:37.236Z sha 3c9a790 :: blocked before merge. :: none
  • reviewed 2026-10-05T14:36:57.833Z sha 05984c5 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 5, 2026
Merge main to resolve the shared worker-test routing conflict while preserving both routing additions. Follow the canonical transcript mutation conflict error owner extracted on main.\n\nValidation: 27 correction, lifecycle, runtime build-graph, and import-closure checks passed in 539.68s; independent P2 review is scoped-clean. Published-driver qualification remains a pre-merge gate.
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: XL and removed size: L labels Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Remove the stale Gateway database-worker entry after moving the suite to the isolated core owner. Both ownership assertions failed in five runs on the prior head and passed in five runs on the merge base. The repaired planner and watch suites pass all 124 cases; P2 review is scoped-clean.
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Merge main after its deferred-migration read-registry cycle fix landed, preserving the correction implementation and unique worker test routing. The focused correction, lifecycle, build-graph and import suite passed all 27 tests; Madge reports zero cycles and the fresh P2 review is scoped-clean. Published-driver qualification remains required before merge.
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed scripts Repository scripts size: XL labels Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

The RPC-only update fixture left default heartbeat enabled, and a real run reached cleanup with unrelated cron and session work active. Use the existing disabled cadence already used by neighboring update fixtures. Keep every assertion and deadline unchanged. Syntax, the disabled-monitor contract, and P2 review pass; the exact cron job identity was not captured.
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 5, 2026
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Integrate the main fix for the independently reproduced RPC exporter fixture error. Preserve the correction-only worker cutover and stacked branch ancestry.
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The prior candidate's published-driver cell passed fully, including cleanup. Main has since fixed the independently reproduced RPC-exporter type error; merge commit 05984c5 incorporates that fix without conflicts or correction changes. Fresh P2 review is clean and the repaired typecheck passes. Runtime/import proof and the new SDK report are refreshing; a full published-driver cell for this integrated candidate is running because imported shutdown and incognito inputs changed.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 602b940 into main Oct 5, 2026
149 checks passed
@steipete
steipete deleted the dbasync/w4mirrors branch October 5, 2026 15:08
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…enclaw#165541)

* refactor(transcripts): move durable mirror corrections to workers

Read correction snapshots through the retained history owner and commit exact
rows through the canonical agent writer. Preserve source-tail restrictions,
indexed generation refusals, unrelated later appends, and shared-store identity.

Release-note context: durable delivery-mirror and media corrections no longer
perform their transcript SQL on the Gateway thread. Stored formats and SDK
entrypoints remain unchanged. Locked mirror appends and feedback remain separate.

* test(transcripts): satisfy mirror fixture lint

* fix(test): give commentary media one worker route

Remove the stale Gateway database-worker entry after moving the suite to the isolated core owner. Both ownership assertions failed in five runs on the prior head and passed in five runs on the merge base. The repaired planner and watch suites pass all 124 cases; P2 review is scoped-clean.

* fix(test): disable heartbeat in published-driver fixture

The RPC-only update fixture left default heartbeat enabled, and a real run reached cleanup with unrelated cron and session work active. Use the existing disabled cadence already used by neighboring update fixtures. Keep every assertion and deadline unchanged. Syntax, the disabled-monitor contract, and P2 review pass; the exact cron job identity was not captured.
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. scripts Repository scripts 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