Skip to content

chore: classify worker-owned transcript SQLite calls - #174572

Merged
steipete merged 2 commits into
mainfrom
dbasync/t1trace-transcript
Oct 16, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/t1trace-transcript

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The main-thread SQLite inventory counts five transcript SQL calls whose execution is confined to workers or explicit maintenance. Correct those classifications without hiding the shared native paths.

User Impact

No runtime behavior, public API, schema, stored data, or SQL changes. This is a source-reachability audit, not a runtime performance improvement. Transcript main-thread debt is reduced in the inventory, not eliminated.

Why This Change Was Made

Use the inventory's existing operation/guard classifiers for mixed modules and its worker-module list for the single-operation incremental reader. Keep the shared header, append, replacement, index, and SDK paths visible. No new owner, worker protocol, fallback, or compatibility API is introduced.

Four assigned calls are worker-only: incremental event reads; message presence reads; the actor-window timestamp UPDATE; and the native lock's replacement transaction. The public SDK lock projectors do not expose the replacement method. One active-entry identity query serves workers and explicit maintenance; its apparent Gateway native caller is incognito-only and the database opener rejects that sentinel before SQL.

No paranoid checks were removed in this classification-only change, so there are no newly accepted runtime edge cases. Existing delivery authority and destructive compaction authority checks protect real effects and are retained.

Evidence

Base: f90f26f638091ef505ebd7b96201b8c32a0d5cc0. Counts below are static SQL call expressions, not statements per turn.

Scope Before After Disposition
Assigned transcript T1 calls 67 62 Four worker-only; one worker/maintenance
Global T1 calls 224 219 Full source inventory
Runtime statements / requests / MAIN Not measured Not measured Runtime source is unchanged; no harness or speedup claim

All 67 assigned calls were traced. Class (a): four reclassified worker calls. Class (e): one worker/maintenance call. Classes (b)/(c): no runtime cutover or deletion in this PR. The remaining 62 retain released compatibility and/or the real-effect authority paths described below; they are not declared worker-only. No schema, SDK, update, Doctor, plugin loading, or service lifecycle changes, so SDK API diff and update-cell proof do not apply.

Validation: changed-file oxfmt and oxlint, git diff --check; independent Codex source review (no findings); complete base census and regenerated inventory. Independent generated-document review also passed (no P0/P1 findings). Final-head CI 38953368492 passed (31 successful jobs): changed-file format/type-aware lint, production/test types, source/export-collision contracts, Madge (zero cycles), T1/dialect ratchets, docs, and selected tests including all eight worker-ratchet cases. CI omitted Knip, so the exact-head local export scan ran through the campaign proof slot. It reported 11 production, five full-tree, and two script findings, all reproduced by scheduled main dependency job 117157269800 at d401ad3409e4d0f19a7740568cd7a5536fd9d30d; all 13 finding-source, scan-rule/config, and lockfile blobs match. No changed-file finding. The authorized inherited-static exception is used and the evidence is routed to the campaign's red-main owner. LOC: 31 source lines added for evidence; zero production/test lines changed; generated document +143/-141 (mostly table padding and stale baseline line metadata). The generator also refreshes four already-moved boot calls: the actual base has T2=392/W=1325, while the old committed document still said T2=396/W=1321. This PR itself moves four calls to W and one to T3.

Complete assigned-file trace and retained boundaries

All paths below are under src/config/sessions/. sqlite-* denotes the session-accessor.sqlite-* family. These are call-site totals; shared kernels can have both worker and native callers.

File T1 before → after Execution evidence
sqlite-suffix-read 4 → 4 Bounded suffix reads (3) and previous-indexed-event read (1): released synchronous SessionManager.removeTrailingEntries runs the native suffix generator; async removal uses the maintenance worker.
sqlite-transcript-anchor 2 → 1 Active identity (1) serves worker current-turn/anchor/activity/patch readers and native maintenance patches. The incognito Gateway branch cannot open SQLite. Anchor facts (1) remain reachable through released synchronous anchor/turn/agent-end APIs.
sqlite-transcript-identity 2 → 2 Idempotency owner and message-identity lookup feed native append/deduplication, including the live delivery-authority path below.
sqlite-transcript-incremental-read 1 → 0 Anchor kernel worker roots, or sqlite-read wrapper called only by correction's runNative under !isMainThread.
sqlite-transcript-metadata-read 2 → 1 Message presence (1) has only anchor/history worker callers. Header (1) remains reachable through released synchronous entry freshness.
sqlite-transcript-mirror 2 → 2 Projection and facts reads remain exposed by native SDK lock callbacks; ordinary mirror reads use workers.
sqlite-transcript-parent 5 → 5 Active parent (2), ancestor (1), identity (1), and visible tail (1): native append and released SessionManager snapshot/validation paths.
sqlite-transcript-presence 1 → 1 Header creation and native session-window preparation call stored-event presence.
sqlite-transcript-sequences 1 → 1 Native appendMessageWithMessageSequence remains exposed by the released Codex mirror lock callback. Pure in-memory sequence accessors do not make this query worker-only.
sqlite-transcript-state 14 → 13 Actor-window UPDATE (1) is worker-only: only session-actor.worker installs transaction facts. Generation read/write (2), root setup (5), next sequence (1), unbound timestamp UPDATE (1), event DELETEs (2), and reaction pruning (2) remain reachable through native append, manual compaction, or SDK suffix removal. The existing migration exception is separate.
sqlite-transcript-store 1 → 1 Idempotency-owner relocation remains reachable through released SessionManager.persist with caller-checked idempotency.
sqlite-transcript-suffix-idempotency 2 → 2 Native suffix removal prepares idempotency ownership through the released synchronous SessionManager method.
sqlite-transcript-suffix-write 1 → 1 Released synchronous suffix method executes this transaction.
sqlite-transcript-suffix 12 → 12 Storage row read (1), incremental preparation (4), replacement writes (7): same released native suffix contract.
sqlite-transcript-turn 2 → 2 Scheduled/delivery-attempt source replies still select native turn preparation/commit through an opaque live authority callback.
sqlite-transcript-watermark 1 → 1 Released onAgentRunStart callback can omit prepared transcript facts and select native watermark fallback; other native entry/replacement bookkeeping shares it.
sqlite-transcript-write-snapshot 1 → 1 Released synchronous SessionManager.persist and appendMessageToTranscript retain native snapshot persistence.
sqlite-transcript-write 3 → 2 Replacement transaction (1) is only consumed by worker correction; public SDK projections omit it. Native append (1) and sequenced append (1) remain exposed by released lock callbacks.
session-transcript-fts 1 → 1 Native manual compaction/full replacement reaches index deletion/rebuild and its FTS delete.
session-transcript-index 6 → 6 Rebuild decision, projection state, index status, active-row deletion, index deletion remain shared with native append/full replacement. Suffix index replacement retains the synchronous SDK suffix caller.
session-transcript-projection-rebuild 2 → 2 Unclassified-event detection feeds native append; projection-session reads feed native replacement/reconcile.
session-transcript-retained-data 1 → 1 Native replacement/suffix paths copy retained payloads. SQL-side payload copying stays in SQL; materializing large values is not a safe substitute.

Worker anchor-kernel entry points are session-entry-read.worker, session-entry-cohort.worker, session-transcript-hydration-read.worker, session-history-read-operation.worker, and openclaw-agent-execution-operations registered in openclaw-agent-execution.worker.

Real-effect authority follow-ups

  1. Scheduled source replies: src/infra/outbound/message-action-runner.ts wraps persistence with withSessionTranscriptWriteAssertion(..., () => assertMessageDeliveryCurrent(input), ...). captureExternalSessionCommitGuard marks that plain callback native/opaque. Replay and fresh append in src/gateway/internal-source-reply-persistence.ts retain it, so appendPreparedSessionTranscriptTurn deliberately rejects its worker route. The delivery owner must supply equivalent worker-compatible prepared authority before this native family can be removed. Stripping the callback or its native marker would weaken a real effect boundary.
  2. In-process manual compaction: sessions.compact retains native request authority for supported in-process dispatch. The compaction adapter selects native commit for opaque authority and reaches full transcript replacement, event deletion, reaction pruning, and index rebuild. This public dispatch API is not deprecated. Its request-authority owner must provide equivalent prepared authority before deleting the native adapter; compaction modifies retained user data.
  3. Incognito active-leaf fallback: an obsolete branch in chat-send-active-leaf.ts attempts a native relation read for incognito. Admission rejects the sentinel before SQLite. Its behavior is a separate cleanup; this PR only records that it does not execute the counted SQL.

Released compatibility verification

Verified from stable tag v2026.10.4 in the full repository: agent-sessions exports SessionManager, including synchronous persist, appendMessageToTranscript, removeTrailingEntries, appendMessageWithTranscriptAnchor, and resolveCurrentTurnEntryId; agent-harness-runtime exports runAgentEndSideEffects; session-transcript-runtime exports the lock and append APIs with synchronous preparation callbacks; codex-session-transcript-runtime exports the mirror lock with sequenced append; channel runtime exposes synchronous resolveEntryResetFreshness; and reply-runtime exports the older GetReplyOptions.onAgentRunStart signature without transcript facts. Their removal belongs to the separate SDK compatibility work. Retained shared kernels are not automatically relabeled T1-compat because callback escapes and native authority consumers remain.

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T19:16:50.446996Z b43d957 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: XS labels Oct 16, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR classifies four transcript SQLite calls as worker-only and one as worker/maintenance, then refreshes the generated inventory.

Example: A maintainer consults the SQLite migration inventory.

  • Before: Five worker or maintenance calls contribute to the 224 T1 calls.
  • After: Those calls are classified separately, leaving 219 T1 calls without changing runtime execution.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused maintenance correction supported by caller inspection and successful exact-head gates; no target code was executed during this review.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored inventory correction changes no runtime behavior; classification evidence was checked against production caller paths.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: Maintainers see worker-owned transcript calls incorrectly listed as outstanding main-thread migration work.
Reason: The maintainer-authored change corrects actionable inventory evidence using existing mechanisms and preserves unresolved native debt.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR corrects five inventory classifications while preserving mixed native paths; no actionable defects were found.

Priority: P3
Reviewed head: b43d957dd5e96df8ebfe536e81a5e102f51af6f2

Before merge

None.

Findings

None.

Agent review details

How this fits together

The developer inventory scans SQL call expressions and combines lexical operations with reviewed caller evidence to generate migration documentation and support the main-thread SQLite ratchet.

flowchart LR
  A[Repository source] --> B[SQL call scanner]
  C[Reviewed caller classifications] --> B
  B --> D[Worker access inventory]
  B --> E[SQLite growth ratchet]
Loading

Technical review

Best possible solution:

Merge the focused inventory correction through the normal repository gates.

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

Current-main classification rules leave the five audited sites in T1; source traces establish their worker or maintenance execution paths without running target code.

Is this the best way to solve the issue?

The existing operation, guard, and worker-module classifiers provide a narrow correction that keeps shared native queries and SDK callback paths visible.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Operation-scoped transcript classifications keeps the original intent (2086a7f: Classify verified worker and maintenance operations while retaining mixed native and compatibility paths.)
  • Generated boot inventory refresh keeps the original intent (1b9731a: Move Gateway boot history operations off the main thread; regeneration reflects that existing source change.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

  • Pinned introduction: The introduced script changes add operation-scoped classifications and one worker-module entry; runtime source, SDK contracts, and SQL remain unchanged. (scripts/database-worker-inventory.mjs:951, b43d957dd5e9)
  • Worker-only correction and SDK projection: Correction invokes its native incremental reader and full replacement path only under !isMainThread. Public transcript callbacks omit replaceEvents; the Codex projector adds sequenced append without exposing replacement. (src/config/sessions/session-transcript-correction.ts:190, b43d957dd5e9)
  • Maintenance and incognito boundaries: The native entry-patch predicate follows the !useWorker branch; durable execution is disabled only under maintenance or cleanup custody. The incognito database sentinel is rejected before SQLite opens. (src/state/openclaw-agent-db-admission.ts:116, b43d957dd5e9)
  • Existing classification intent: The earlier classification work explicitly preserves mixed native siblings and scopes reviewed exceptions to operations and guards. This PR extends that approach. Older follow-history inspection encountered an unavailable promisor object; recent history and the relevant source blobs were available. (scripts/database-worker-inventory.mjs:1096, 2086a7f39fb2)
  • Exact-head checks: The reviewed head has successful ci-gate, dependency-review, and security-sensitive-review statuses. The only nonpassing check runs are two cancelled auto-response jobs; no failing required check was observed. (b43d957dd5e9)

Likely related people:

  • Peter Steinberger: Raw commit 2086a7f adds scripts/database-worker-inventory.mjs:810 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2086a7f39fb2; files: scripts/database-worker-inventory.mjs)

PR surface

Docs +2, Other +31. Total +33 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 1 143 141 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 31 0 +31
Total 2 174 141 +33

Labels

Label changes:

  • add P3: This improves developer migration metadata without changing user-facing runtime behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This improves developer migration metadata without changing user-facing runtime behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

Reviewed October 16, 2026, 3:28 PM ET / 19:28 UTC.

@steipete
steipete merged commit 057f2ba into main Oct 16, 2026
111 of 113 checks passed
@steipete
steipete deleted the dbasync/t1trace-transcript branch October 16, 2026 19:41
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
Record caller evidence for four worker-only transcript SQL calls and one worker/maintenance call. Reduce the assigned static T1 count from 67 to 62 and global T1 from 224 to 219.

Preserve native delivery/compaction authority paths and released synchronous SDK contracts. No production runtime, schema, SQL, or public API changes.
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XS 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