Skip to content

perf(sessions): reuse admitted transcript encoding - #169624

Merged
steipete merged 28 commits into
mainfrom
dbasync/t1cut-s8-encoding
Oct 12, 2026
Merged

steipete merged 28 commits into
mainfrom
dbasync/t1cut-s8-encoding

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Transcript payload preparation discovers database text encoding with synchronous SQL on the caller thread. SQLite encoding is immutable after schema creation and belongs with the database's admitted facts.

Design

Capture encoding with admitted schema facts and transfer it through the existing worker admission contract. Payload preparation consumes the admitted value. Pre-admission migration uses the shared native metadata helper. The old per-handle encoding cache and repeated SQL read are removed.

UTF-8 and UTF-16 payload behavior is preserved. There is no stored-format, retention, or schema-version change. Boot admission and explicit pre-admission migration metadata reads remain permitted native work.

Removed check and accepted edge: payload preparation trusts admission's encoding; replacing a database outside the Gateway owner's lifecycle is unsupported.

Evidence

  • Two Codex review rounds completed with no actionable P0/P1 findings.
  • Changed-file oxfmt, oxlint and git diff --check pass. Broad checks run in PR CI under RELAXED TESTING v6.
  • First CI found raw test handles missing schema admission, the historical schema-read count missing the new encoding field, and a cold-writer fixture that incorrectly warmed its database before exercising discovery. These fixtures are corrected; their data, snapshot and lost-write assertions remain intact. The later full CI found the same missing admission on the competing media writer; that fixture now opens through the tracked native owner and admits before the snapshot exercise.
  • Owned lexical T1 sites: 23 → 22; the removed payload encoding query is one source site. Boot admission/migration metadata reads are explicit exceptions.
  • One live baseline/candidate pair completed: base d23ecfbd6fe8691909e8c25445df2258de353106, candidate 5ec1a5d67afa2bb4f70ae56d8d1e369efaa6f224. Later changes are test-only fixes and conflict-free integration. Both runs completed all 13 turns, child execution, every RPC, cron, compaction, and shutdown.
Metric Base Candidate
Warmed all-thread statements/turn 343.6 333.2
Warmed requests/turn 105.4 101.7
Warmed MAIN statements/turn 0.4 0
Whole-workload statements 9,607 9,653 (+0.48%)
Whole-workload requests 1,942 1,943 (+0.05%)
Whole-workload MAIN statements 1,988 1,990

The payload encoding SELECT ran 3 times on the base and 0 on the candidate. Shared admission added 16 encoding reads (4 boot, 7 connect, 5 first-turn startup); 2 were permitted MAIN boot reads and 14 ran in workers/helpers. Net: +13 cold statements, no new requests, no new warmed reads. The whole-workload increase is within the T1 MOVE exception with warmed counts lower. The remaining variation comes from unchanged background owners; no causal warmed saving or runtime speedup is claimed. Warmed duration ratio was 0.943.

  • Published-driver × candidate update cell passed in combined CI 38217360424, job 114712232724: published driver 2026.10.2 updated to candidate 3254d6171c275, then readiness returned 200 and the running version matched. Later changes are test-only. Update artifact. It is required because this changes migration implementation, despite preserving storage format and version.
  • Final static CI 38217360424 passed types, lint, source contracts, database ratchets, SDK API diff (digest 5ff6265e) and Madge. Knip reports the exact same untouched UI exports as main run 38216343022; it is inherited. SDK surface check and runtime API guardrail tests passed on the earlier measured head 95d395c19a94; the lane inputs for both checks remain unchanged, so that proof is reused.
  • Integrated-head CI 38223201252, at 4faaed07c01bb, passed production/test types, lint, source contracts, Madge, and database/worker/dialect ratchets. Its one failed test root is the inherited type-suppression inventory assertion (18 expected, 19 actual): main added the annotation in scripts/lib/managed-cleanup-handoff.mts at 04cfcd8e25871; both the script and test are byte-identical on the integrated main and PR head. Security-sensitive review and dependency review are green. The authorized inherited-failure landing route applies.
  • Knip reuse: main scheduled run 38220958692, job 114717131950, reports the same renderPublicSessionCardSvg unused export. This PR changes neither that owner nor its consumers or Knip configuration; its only new production export, readSqliteTextEncoding, is used by the migrated payload and migration readers. The later combined child scan also reports the inherited gateway-prewarm.mjs unused file. These findings do not arise from the encoding-only diff.
  • Main integration at 4faaed07c01bb preserves the exact encoding-only diff. The only conflict kept the two imports used by the admitted competing-writer fixture; local format/lint/diff checks pass. Earlier production, SDK and update proof remains applicable.
  • Current encoding-only diff against its parent: 20 files, +144 / −78 lines.

Parent #169523 is merged. This PR now targets main; the review diff contains only encoding changes and their fixture corrections.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review 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 commands Command implementations size: S labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR records SQLite text encoding during database admission and reuses it when preparing transcript payloads.

Example: Save a 7 KiB transcript event to an admitted UTF-16le database.

  • Before: The newly used handle queries its encoding and stores the event as identity text.
  • After: Preparation consumes the admitted encoding and stores the same identity text.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, worthwhile consolidation with preserved storage contracts, resolved prior findings, and applicable shipped-entry-point upgrade evidence.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The supplied baseline/candidate Gateway workload exercises transcript preparation and reports encoding discovery removed from payload preparation. The verified successful published-driver job exercises the real update CLI and post-restart history through the inspected harness; its production modules match this head. Artifact contents could not be downloaded because the review environment blocks their storage host.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Preparing transcripts on newly used handles performs avoidable synchronous encoding discovery on the caller thread.
Reason: The established feature owner proposes a focused consolidation that preserves storage behavior and removes redundant metadata discovery without adding configuration.

Merge readiness

✅ Ready for maintainer review

Keep this useful maintainer-authored optimization open. Prior fixture findings are resolved, and no introduced correctness or security defect remains; current-head CI is still running with an unrelated tooling inventory failure.

Priority: P2
Reviewed head: 4faaed07c01bbf46165f0a2ee16f65f78540e6ad

Before merge

None.

Findings

None.

Agent review details

How this fits together

Physical-database admission publishes schema facts to handles and workers; transcript preparation consumes encoding to select identity text or compressed UTF-8 storage.

flowchart TD
 A[SQLite database] --> B[Schema admission]
 B --> C[Published encoding facts]
 C --> D[Handles and workers]
 D --> E[Transcript preparation]
 E --> F[Identity or compressed payload]
Loading

Technical review

Best possible solution:

Keep encoding with the existing physical-database admission owner while preserving encoding-specific transcript bytes.

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

Current main directly shows first-use encoding SQL on each handle; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

The existing admission owner is the appropriate place for immutable encoding metadata, and the explicit migration argument preserves preparation before admission completes.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Transcript compression and encoding cache keeps the original intent (c659113: Compact eligible UTF-8 events while preserving canonical bytes and identity storage for UTF-16 and exceptional payloads.)
  • Encoding consumed by worker hydration keeps the original intent (dbd3bf7: Hydrate canonical records through the history worker using their database encoding.)
  • Shared physical-database admission keeps the original intent (bb7d32e: Reuse completed admission across workers and reopened handles instead of repeating validation.)
  • Existing storage regression coverage keeps the original intent (706e08c: Remove redundant variants while retaining distinct storage, migration, security, and lifecycle contracts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +11, Tests +47, Docs +8. Total +66 across 20 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 30 19 +11
Tests 15 106 59 +47
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 20 144 78 +66

Review metrics

Metric Value Why it matters
Production versus test changes Production +30/-19; tests and test support +106/-59. The small production growth extends existing admission facts while removing a separate cache; test changes adapt fixtures and preserve both encoding directions.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This focused internal storage optimization has no established urgent production impact.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

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

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-12T05:19:18.688Z sha fc8dc00 :: blocked before merge. :: [P2] Admit the remaining payload test fixtures before using them | [P2] Update the native snapshot admission expectation
  • reviewed 2026-10-12T05:57:43.538Z sha 9f23775 :: blocked before merge. :: [P2] Admit the remaining payload test fixtures before using them | [P2] Update the native snapshot admission expectation
  • reviewed 2026-10-12T06:53:14.264Z sha 5ec1a5d :: blocked before merge. :: [P2] Open both remaining fixture writers through the tracked SQLite owner
  • reviewed 2026-10-12T07:13:01.478Z sha 8a74a41 :: blocked before merge. :: none
  • reviewed 2026-10-12T07:36:03.956Z sha 3254d61 :: blocked before merge. :: [P2] Admit the managed attachment snapshot fixture writer

Reviewed October 12, 2026, 4:31 AM ET / 08:31 UTC (Revision 6).

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 12, 2026
Base automatically changed from dbasync/t1cut-s8 to main October 12, 2026 08:16
…t1cut-s8-encoding

# Conflicts:
#	src/gateway/managed-image-attachments.sqlite-visibility.test.ts
@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete
steipete merged commit 19f46de into main Oct 12, 2026
146 of 151 checks passed
@steipete
steipete deleted the dbasync/t1cut-s8-encoding branch October 12, 2026 08:48
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
## What Problem This Solves

Transcript payload preparation discovers database text encoding with synchronous SQL on the caller thread. SQLite encoding is immutable after schema creation and belongs with the database's admitted facts.

## Design

Capture encoding with admitted schema facts and transfer it through the existing worker admission contract. Payload preparation consumes the admitted value. Pre-admission migration uses the shared native metadata helper. The old per-handle encoding cache and repeated SQL read are removed.

UTF-8 and UTF-16 payload behavior is preserved. There is no stored-format, retention, or schema-version change. Boot admission and explicit pre-admission migration metadata reads remain permitted native work.

Removed check and accepted edge: payload preparation trusts admission's encoding; replacing a database outside the Gateway owner's lifecycle is unsupported.

## Evidence

- Two Codex review rounds completed with no actionable P0/P1 findings.
- Changed-file oxfmt, oxlint and `git diff --check` pass. Broad checks run in PR CI under RELAXED TESTING v6.
- First CI found raw test handles missing schema admission, the historical schema-read count missing the new encoding field, and a cold-writer fixture that incorrectly warmed its database before exercising discovery. These fixtures are corrected; their data, snapshot and lost-write assertions remain intact. The later full CI found the same missing admission on the competing media writer; that fixture now opens through the tracked native owner and admits before the snapshot exercise.
- Owned lexical T1 sites: **23 → 22**; the removed payload encoding query is one source site. Boot admission/migration metadata reads are explicit exceptions.
- One live baseline/candidate pair completed: base `d23ecfbd6fe8691909e8c25445df2258de353106`, candidate `5ec1a5d67afa2bb4f70ae56d8d1e369efaa6f224`. Later changes are test-only fixes and conflict-free integration. Both runs completed all 13 turns, child execution, every RPC, cron, compaction, and shutdown.

| Metric | Base | Candidate |
| --- | ---: | ---: |
| Warmed all-thread statements/turn | 343.6 | 333.2 |
| Warmed requests/turn | 105.4 | 101.7 |
| Warmed MAIN statements/turn | 0.4 | 0 |
| Whole-workload statements | 9,607 | 9,653 (+0.48%) |
| Whole-workload requests | 1,942 | 1,943 (+0.05%) |
| Whole-workload MAIN statements | 1,988 | 1,990 |

The payload encoding SELECT ran 3 times on the base and 0 on the candidate. Shared admission added 16 encoding reads (4 boot, 7 connect, 5 first-turn startup); 2 were permitted MAIN boot reads and 14 ran in workers/helpers. Net: **+13 cold statements, no new requests, no new warmed reads**. The whole-workload increase is within the T1 MOVE exception with warmed counts lower. The remaining variation comes from unchanged background owners; no causal warmed saving or runtime speedup is claimed. Warmed duration ratio was 0.943.

- Published-driver × candidate update cell passed in combined CI 38217360424, job 114712232724: published driver `2026.10.2` updated to candidate `3254d6171c275`, then readiness returned 200 and the running version matched. Later changes are test-only. [Update artifact](https://github.com/openclaw/openclaw/actions/runs/38217360424/artifacts/11734172334). It is required because this changes migration implementation, despite preserving storage format and version.
- Final static CI 38217360424 passed types, lint, source contracts, database ratchets, SDK API diff (digest `5ff6265e`) and Madge. Knip reports the exact same untouched UI exports as main run 38216343022; it is inherited. SDK surface check and runtime API guardrail tests passed on the earlier measured head `95d395c19a94`; the lane inputs for both checks remain unchanged, so that proof is reused.
- Integrated-head CI [38223201252](https://github.com/openclaw/openclaw/actions/runs/38223201252), at `4faaed07c01bb`, passed production/test types, lint, source contracts, Madge, and database/worker/dialect ratchets. Its one failed test root is the inherited type-suppression inventory assertion (18 expected, 19 actual): main added the annotation in `scripts/lib/managed-cleanup-handoff.mts` at `2efdcb956c136`; both the script and test are byte-identical on the integrated main and PR head. Security-sensitive review and dependency review are green. The authorized inherited-failure landing route applies.
- Knip reuse: main scheduled run [38220958692](https://github.com/openclaw/openclaw/actions/runs/38220958692), job `114717131950`, reports the same `renderPublicSessionCardSvg` unused export. This PR changes neither that owner nor its consumers or Knip configuration; its only new production export, `readSqliteTextEncoding`, is used by the migrated payload and migration readers. The later combined child scan also reports the inherited `gateway-prewarm.mjs` unused file. These findings do not arise from the encoding-only diff.
- Main integration at `4faaed07c01bb` preserves the exact encoding-only diff. The only conflict kept the two imports used by the admitted competing-writer fixture; local format/lint/diff checks pass. Earlier production, SDK and update proof remains applicable.
- Current encoding-only diff against its parent: **20 files, +144 / −78 lines**.

Parent openclaw#169523 is merged. This PR now targets main; the review diff contains only encoding changes and their fixture corrections.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations 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: M 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