Skip to content

refactor(media): track generated-HTML provenance through the shared-state worker - #164424

Merged
steipete merged 3 commits into
mainfrom
dbasync/htmlprov
Oct 4, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/htmlprov

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Generated-HTML staging, reload checks, and scheduled cleanup performed shared-state SQLite work on the Gateway main thread.

Why This Change Was Made

Move provenance lookup, upsert, selection, and cleanup into the existing shared-state reader/writer registries. Capture the physical store and marker bytes before filesystem waits, retain synchronous worker transactions and live transaction/commit grants, and reconcile acknowledged native receipts without replaying unknown outcomes. Cleanup compares the complete selected row inside its transaction, preserving markers updated while file inspection waits.

Realpath/outbound-root validation, link restrictions, SHA-256/size matching, and fail-closed lookup behavior remain at the existing media boundary. The scheduler retains accepted cleanup through the real Gateway close prelude before database teardown; the lifecycle regression starts the real Gateway and drives its actual close order.

The released zero-argument pruneStaleTrustedGeneratedHtmlMarkers(): Promise<void> declaration is preserved. Internal cleanup callers pass their captured context directly to the private provenance owner. An exact type regression caught the optional-argument declaration leak before this repair and passes afterward. There is no deprecated alternate implementation or changed released signature.

User Impact

No change to which HTML is trusted, media API signatures, schemas, retention, durability, or update behavior. No new worker service, persistent cache, or OPENCLAW_* environment name. All six host SQL sites are cut over, with no retained synchronous provenance path and no added host SQL in grant callbacks.

Final production diff against integrated main 7b9615fc20fe61de6d32cb77bf5b2f0f3bed5e5a: +314 / -101 / net +213. Tests/test support add 430 lines; docs add 10. T1 inventory at the original merge base 4ab382220e2cca1deedb2c2549982f91c0fb5c64: 1,233 → 1,227.

Bounded recent-PR overlap review found no competing provenance migration. The image optimize/load/filename hunks in #120119 are untouched. #162530 adds a separate media stream helper; #163296 adds a separate worker domain. #164391's shared error-identity functions are untouched. #162433 remains the explicitly excluded umbrella draft.

Evidence

Final reviewed head: 563ce35fbcc48c850a967d972198e7f877d7bc57. Main was integrated with merge commit 8ddd9a236ee7d60ef44ee1c916ff7440f63fbb97 to obtain the SDK tooling fix from #164466; compatibility repair 563ce35 preserves the released declaration.

  • 79 tests across 9 files passed after the compatibility repair, using node scripts/run-vitest.mjs <files> --maxWorkers=1: 669.28 s wall, including 150.168 s one-time compiled-worker preparation. Covers the real staging/reload flow, both cleanup entry points, zero caller-thread provenance SQL, transaction/commit refusal and error identity, known-commit lost replies, unknown-outcome non-replay, store/byte capture, concurrent-upsert preservation, real Gateway close, and the SDK type contract.
  • Explicit shared-registry checks pass: test/scripts/runtime-process-build-graph.test.ts, src/auto-reply/reply/get-reply.imports.test.ts, src/state/openclaw-state.worker.imports.test.ts, and src/worker/worker.runtime-imports.test.ts.
  • New SDK type regression: 12.86 s wall / 0.001 s test time standalone. Gateway close regression: 200.03 s wall / 32.441 s test time standalone on the loaded host. Its real Gateway, scheduler, worker, and database teardown contract requires this integration layer; a helper-only test cannot prove CLOSE-PRELUDE ordering. The tests use deferred gates/fake timers rather than sleeps or retry-based assertions.
  • SDK test typecheck, targeted formatting/lint, and git diff --check pass. Production, full-tree, and script unused-export scans pass with zero findings. Fresh independent Codex P2 autoreview of the staged repair is scoped-clean, with no actionable findings.
  • Earlier whole-PR proof before the compatibility-only repair: 82 tests across 9 files passed in 151.30 s; Madge found zero cycles; the database-worker ratchet, core and all 27 test typecheck graphs passed. node scripts/check-changed.mjs --base 4ab382220e2cca1deedb2c2549982f91c0fb5c64 passed in 1,964.85 s, including type-aware lint, unused-export scans, cycles, schema/storage guards, and policy guards. Only pre-existing max-lines warnings were reported.
  • Negative control against the original web-media.ts and store.ts: all four selected regressions failed for the intended caller-SQL, store/byte capture, concurrent-upsert cleanup, and original-store cleanup reasons (77.95 s wall); the candidate passes all four. The SDK exact-signature type test independently failed before the compatibility repair with TS2741 and passes afterward.

Released-SDK attribution on the final head: zero changes introduced by this PR. The fixed tool from #164466 compared integrated main 7b9615fc20fe61de6d32cb77bf5b2f0f3bed5e5a to 563ce35fbcc48c850a967d972198e7f877d7bc57: 0 added/removed entrypoints and 0 affected exports. Independently verified report digest: ff7b090f43d2d90e4cd883d95840d6b752475a7a1769e295fb4cbb558a6ffb64. This resolves the accidental declaration leak; the earlier unrepaired comparison reported 124 reachable-export changes.

The local v2026.9.8 → final-head report is complete. Source bindings: release fc23bc864e4553c2d215e479eeec47b67a0bf943, head 563ce35fbcc48c850a967d972198e7f877d7bc57, fixed tooling 7b9615fc20fe61de6d32cb77bf5b2f0f3bed5e5a. Status: checked; independently recomputed digest: 3a7f33365263f2f8a0b7f87101697cd3781ff8ce34dfc84d9754ed9d14a68878. Release-wide results: 1 entrypoint added, 8 removed; 2,219 affected exports (1,098 reachable declarations, 55 signatures, 59 additions, 1,007 removals). These are inherited main differences: the separate comparison from integrated main to this exact head is empty. The release-wide surface is not claimed unchanged. No SDK change is introduced by this PR, and the report prerequisite is satisfied. Main-relative comparison exited 0 in 970 s including cleanup; the released comparison exited 0 in 954 s, with all temporary SDK checkouts and owned processes cleaned up.

Final-head CI passed: run 37161192927, head 563ce35fbcc48c850a967d972198e7f877d7bc57; the exact-head watcher finished GREEN. No failed final-head checks or reruns. The CI job API reports 11,630 total job-seconds for this run (aggregate workflow cost, not isolated new-test time). Final-head ClawSweeper review completed at 2026-10-03T23:33:52Z: durable review. No correctness or security findings; the signature and attribution concerns are resolved. Its sole remaining request was to record the final released-SDK report, now supplied above. The initial, earlier PR-context failure was corrected by using the repository template headings.

…workers

Move lookup, upsert, and stale-marker cleanup to the existing shared-state reader and writer registries. Capture the physical store before filesystem waits, preserve exact-byte HTML trust and conditional cleanup, and reconcile native commit receipts without replaying unknown outcomes.

Keep media APIs asynchronous and preserve schema, retention, durability, and update behavior. Verify zero caller-thread SQL, transaction and commit refusal, lost-reply settlement, import boundaries, and the real Gateway close prelude.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 3, 2026
@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. labels Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 7:58 PM ET / 23:58 UTC (Revision 9).

ClawSweeper review

What this changes

Moves generated-HTML trust-marker reads, writes, and cleanup into the existing shared-state database workers while preserving public media signatures.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and has no identified blocking correctness or security findings. The final SDK report resolves the previous review’s sole remaining hold.

Priority: P2
Reviewed head: 563ce35fbcc48c850a967d972198e7f877d7bc57

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent worker migration with strong boundary evidence, preserved SDK declarations, and no identified blocking defects.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Reported final-head execution exercises real media staging/reload, SQLite worker transport with injected refusal and lost replies, and actual Gateway shutdown with observed committed cleanup before database teardown. Source inspection confirms those entrypoints; the unchanged stored row format requires no migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Reported final-head execution exercises real media staging/reload, SQLite worker transport with injected refusal and lost replies, and actual Gateway shutdown with observed committed cleanup before database teardown. Source inspection confirms those entrypoints; the unchanged stored row format requires no migration.
Evidence reviewed 8 items Pinned introduction and preserved trust boundary: Inspected the introduced delta from the pinned merge base to the exact head. Store and byte capture precede filesystem waits; outbound containment, link restrictions, marker kind/version, SHA-256, size matching, and fail-closed lookup remain enforced.
Worker transaction and settlement ownership: The worker uses synchronous transactions with transaction and commit grants. Cleanup compares all six selected row fields, preserving concurrent updates; the host accepts matching acknowledged commit receipts and does not replay unknown outcomes.
Production boundary proof: The captured PR body reports 79 passing final-head cases and baseline negative controls. Inspected tests exercise actual staging, reload, SQLite workers, lost replies, refusal, concurrent cleanup, and the real Gateway close prelude. The close fixture calls startGatewayServerCore and verifies cleanup commits before the shared database closes. No tests were executed during this read-only review.
Findings None None.
Security None None.

How this fits together

OpenClaw stages generated HTML for outbound delivery and records which exact bytes are trusted. Media reload and cleanup consume those records before allowing delivery or removing stale markers.

flowchart TD
  A[Generated HTML] --> B[Outbound staging]
  B --> C[Shared-state workers]
  C --> D[SQLite trust markers]
  D --> E[Path and byte validation]
  E --> F[Allowed media delivery]
  D --> G[Conditional stale-marker cleanup]
  H[Gateway shutdown] --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +213, Tests +430, Docs +10. Total +653 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 9 314 101 +213
Tests 4 430 0 +430
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 754 101 +653

Review metrics

Metric Value Why it matters
Production and regression growth production +314/-101, net +213; tests/support +430 Production growth implements worker contracts and settlement handling; distinct regressions protect SQL placement, concurrency, shutdown, and the released signature.

Technical review

Best possible solution:

Keep provenance persistence with the existing shared-state workers and retain exact-byte trust validation at the media boundary.

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

Not applicable as a refactor; current-main source establishes caller-thread SQL, and reported negative controls exercise the changed production boundaries.

Is this the best way to solve the issue?

Yes. Reusing the existing reader/writer registries removes the synchronous path without adding a competing storage owner or changing the released media contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal database-worker migration without an established 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 (terminal): Reported final-head execution exercises real media staging/reload, SQLite worker transport with injected refusal and lost replies, and actual Gateway shutdown with observed committed cleanup before database teardown. Source inspection confirms those entrypoints; the unchanged stored row format requires no migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. Reported final-head execution exercises real media staging/reload, SQLite worker transport with injected refusal and lost replies, and actual Gateway shutdown with observed committed cleanup before database teardown. Source inspection confirms those entrypoints; the unchanged stored row format requires no migration.

Evidence

What I checked:

  • Pinned introduction and preserved trust boundary: Inspected the introduced delta from the pinned merge base to the exact head. Store and byte capture precede filesystem waits; outbound containment, link restrictions, marker kind/version, SHA-256, size matching, and fail-closed lookup remain enforced. (src/media/web-media.ts:350, 563ce35fbcc4)
  • Worker transaction and settlement ownership: The worker uses synchronous transactions with transaction and commit grants. Cleanup compares all six selected row fields, preserving concurrent updates; the host accepts matching acknowledged commit receipts and does not replay unknown outcomes. (src/media/generated-html-provenance.worker.ts:51, 563ce35fbcc4)
  • Production boundary proof: The captured PR body reports 79 passing final-head cases and baseline negative controls. Inspected tests exercise actual staging, reload, SQLite workers, lost replies, refusal, concurrent cleanup, and the real Gateway close prelude. The close fixture calls startGatewayServerCore and verifies cleanup commits before the shared database closes. No tests were executed during this read-only review. (src/gateway/server-close.media-provenance.test.ts:22, 563ce35fbcc4)
  • Previous SDK hold resolved: The captured body, sourceRevision aadc283c6332b4cbd3c914e34ead042d795c3d37e8b0e4df86c093bdb215719c, records the completed v2026.9.8-to-final-head report with digest 3a7f33365263f2f8a0b7f87101697cd3781ff8ce34dfc84d9754ed9d14a68878. Its separate integrated-main comparison reports zero introduced SDK changes. This addresses the retained previous rank-up move; release-wide inherited changes are explicitly distinguished. (563ce35fbcc4)
  • Released cleanup signature checked: The released source declares the same zero-argument Promise<void> cleanup function preserved at the head. The added exact parameter/return type regression guards the earlier declaration leak. (src/media/web-media.ts:423, fc23bc864e45)
  • Still necessary on current main: Fetched main still contains synchronous provenance lookup, upsert, selection, and deletion in web-media.ts. The related merged worker and SDK-tooling PRs address different responsibilities and do not implement this migration. (src/media/web-media.ts:298, ccc0020633ba)

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 (8 earlier review cycles)
  • reviewed 2026-10-03T17:41:59.197Z sha 1903df6 :: needs changes before merge. :: none
  • reviewed 2026-10-03T17:48:39.569Z sha 1903df6 :: needs changes before merge. :: none
  • reviewed 2026-10-03T18:05:04.736Z sha 1903df6 :: blocked before merge. :: none
  • reviewed 2026-10-03T19:39:51.606Z sha 1903df6 :: needs changes before merge. :: none
  • reviewed 2026-10-03T22:21:18.604Z sha 8ddd9a2 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-03T22:52:57.820Z sha 8ddd9a2 :: blocked before merge. :: none
  • reviewed 2026-10-03T23:21:17.507Z sha 563ce35 :: blocked before merge. :: none
  • reviewed 2026-10-03T23:33:52.436Z sha 563ce35 :: needs changes before merge. :: none

@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 3, 2026
Keep context-aware pruning in the private provenance owner so captured stores survive filesystem waits without changing the released zero-argument cleanup declaration carried by SDK types. Gate the real shutdown regression at that owner and protect the parameter and return contract with a type test.
@steipete

steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 3, 2026
@steipete
steipete merged commit a8eb0b5 into main Oct 4, 2026
171 checks passed
@steipete
steipete deleted the dbasync/htmlprov branch October 4, 2026 00:11
@steipete

steipete commented Oct 4, 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 4, 2026
…tate worker (openclaw#164424)

* refactor(media): move generated-HTML provenance through shared-state workers

Move lookup, upsert, and stale-marker cleanup to the existing shared-state reader and writer registries. Capture the physical store before filesystem waits, preserve exact-byte HTML trust and conditional cleanup, and reconcile native commit receipts without replaying unknown outcomes.

Keep media APIs asynchronous and preserve schema, retention, durability, and update behavior. Verify zero caller-thread SQL, transaction and commit refusal, lost-reply settlement, import boundaries, and the real Gateway close prelude.

* fix(media): preserve the cleanup SDK declaration

Keep context-aware pruning in the private provenance owner so captured stores survive filesystem waits without changing the released zero-argument cleanup declaration carried by SDK types. Gate the real shutdown regression at that owner and protect the parameter and return contract with a type test.
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