Skip to content

refactor(gateway): await managed media ownership reads - #163049

Merged
steipete merged 2 commits into
mainfrom
dbasync/s08b
Oct 2, 2026
Merged

steipete merged 2 commits into
mainfrom
dbasync/s08b

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Managed media retrieval still resolved durable session ownership and availability with SQLite on the Gateway thread, even though transcript message matching already used the history worker. Moving those probes across awaits must preserve the selected source and current caller authority.

Why This Change Was Made

Reuse the existing session-target-inventory, session-exact-entries, and session-entry-read worker operations for serving. Retain discovery aliases and physical reader ownership through ticket or HTTP response publication, preserving the supplied state directory, shared and retired stores, ambiguity refusals, and unavailable-versus-missing behavior. Recheck caller authority after reads and before publishing media. Process-held incognito reads keep their existing native owner.

Extract the existing serving ticket and URL builders to satisfy the oversized-file ratchet, and replace the relocated JSON assertion with record validation. The assertion baseline shrinks by one.

User Impact

  • Measured HTTP ownership path: 19 main-thread SQLite calls → 0. Real shared-store, retired-owner, and supplied-state retrievals also assert zero host SQL.
  • Targeted static inventory: T1 10 → 10 (session-accessor.sqlite-entry-availability.ts: 4; session-accessor.sqlite-exact-read.ts: 5; targets-read-availability.ts: 1). Their excluded cleanup and other existing callers remain; no inventory classification was changed.
  • Production LOC: +561 / −264 / net +297. Measured against integrated main; the lane-only delta is also +297 against the original pinned base before integration. Tests, test support, docs, and the assertion baseline are excluded. This is within the approved wave-8 LOC tolerance.
  • No new worker operation, broker change, cache, configuration option, or public SDK change.

Evidence

Baseline: 4f0541eb4691d155027d4febbe9e304a6e947127. Integrated main: 61485d58172b637ae2f73fd80d627e5fdf8c0f45. Final tested head: ccee0e06ccb9f9c4687253dcf5e1bf4beca231b2.

  • node scripts/worktree-setup.mjs gateway — completed.
  • node scripts/database-worker-inventory.mjs --json — before/after counts above, filtered to the three owner files.
  • OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/gateway/managed-image-attachments.authority.test.ts --maxWorkers=1 — 11 passed; 755.35 s command wall (530.98 s Vitest duration, including compiler preparation).
  • OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/gateway/managed-image-attachments.sqlite-visibility.test.ts --maxWorkers=1 — 21 passed; 564.95 s command wall (533.40 s Vitest duration).
  • OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=1800000 pnpm test src/gateway/managed-image-attachments.test.ts --maxWorkers=1 -t 'ticket|thumbnail' — 2 passed, 54 intentionally unselected; 264.62 s command wall (221.10 s Vitest duration).
  • node scripts/check-changed.mjs --base 4f0541eb4691d155027d4febbe9e304a6e947127 -- config/assertion-safety-baseline.txt docs/reference/database-schemas/worker-access.md src/gateway/managed-image-attachments.ts src/gateway/managed-image-session-read.ts src/gateway/managed-image-tickets.ts src/gateway/managed-outgoing-artifact-id.ts src/gateway/managed-image-attachments.authority.test.ts src/gateway/managed-image-attachments.sqlite-visibility.test.ts — selected core, core-test, and docs gates. After correcting a test close-promise annotation, reused the successful prefix and ran every remaining command from the native createChangedCheckPlan through runManagedCommand; all selected gates passed.
  • pnpm check:database-worker-ratchet --base 4f0541eb4691d155027d4febbe9e304a6e947127 — passed on the integrated head.
  • pnpm check:madge-import-cycles — passed on the integrated head, zero cycles.
  • Autoreview, Codex with high reasoning, branch mode against the integrated merge base — scoped clean at P0/P1, no actionable findings.

The original HTTP regression failed with 19 observed native SQL calls before the cutover. Coverage includes delayed real worker replies, rejection without native fallback, requester revocation, reader retirement, schema unavailability, shared/retired/supplied-state sources, invalid and ambiguous ownership, archive fallback, and corrupt history. No sleeps or polling were added. Production and Gateway test types were also refreshed successfully after main integration. The real-worker suites exceed the usual time target on the heavily loaded host; their wall times include cold compiler preparation and verification, plus native reader startup/retirement needed to prove the thread and custody boundaries. Automatic PR CI timings are not available yet; no CI runs were dispatched for proof.

Compatibility retained

The synchronous loadExactSessionEntryReadOnlyResult, resolveSessionEntry, and resolveExistingAgentSessionStoreTargetsReadOnlyResult exports remain unchanged because the existing cleanup path is explicitly outside this cutover. The original matcher also remains the native incognito path: those process-held databases cannot be reopened in a worker by path. Other existing SDK, transaction, and Doctor callers are untouched. No synchronous compatibility alias was added; no export was deleted.

Update behavior

No schema, stored-state format, retention, durability, configuration, or migration change. Retrieval stays existing-only and read-only. Installed-updater and Doctor behavior is unchanged.

Overlapping open PRs and GC follow-up

#160471 changes recordMatchesTranscriptMessage to retain media on inactive transcript branches during cleanup. This PR leaves that matcher, the cleanup transaction in managed-image-record-store.kernel.ts, and scheduled GC unchanged. The suspected GC reference race remains a separate follow-up.

Retain worker-selected session sources through managed media publication and recheck caller authority after asynchronous reads. Keep cleanup and process-held incognito under their existing owners; the GC reference-race follow-up is separate.
@clawsweeper

clawsweeper Bot commented Oct 1, 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: XL labels Oct 1, 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 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:56 PM ET / 22:56 UTC (Revision 2).

ClawSweeper review

What this changes

Move managed-media session ownership reads into existing database workers, retain selected readers through publication, and extract ticket and URL helpers.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and the latest release still perform synchronous managed-media ownership reads. The pinned diff preserves existing access boundaries, and no actionable introduced defect was found.

Priority: P2
Reviewed head: ccee0e06ccb9f9c4687253dcf5e1bf4beca231b2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker cutover with relevant regression coverage, explained growth, and no blocking correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported runs exercise production ownership workers and serving code, with mocked HTTP authentication and transcript matching; they are supplemental boundary evidence. No unresolved new authority grant was identified, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported runs exercise production ownership workers and serving code, with mocked HTTP authentication and transcript matching; they are supplemental boundary evidence. No unresolved new authority grant was identified, and no stored-data contract changes.
Evidence reviewed 10 items Pinned change ownership: Reviewed the merge-base-to-head introduced delta. The verified test-merge metadata identifies the same eight changed paths; unrelated endpoint drift was excluded.
Current main still needs the cutover: The current-main transcript matcher still calls synchronous store discovery and exact-entry readers. Serving callers continue using that matcher.
Latest release retains synchronous serving reads: The v2026.9.7 source still imports synchronous ownership readers and invokes the transcript matcher from media-serving paths. The local release blob was unavailable, so its contents were inspected through GitHub instead.
Findings None None.
Security None None.

How this fits together

The Gateway serves attachments referenced by session transcripts. It checks the owning session and current request access before returning download tickets, thumbnails, or media bytes.

flowchart TD
  A[Attachment request] --> B[Request access check]
  B --> C[Worker session ownership read]
  C --> D[Transcript attachment match]
  D --> E[Current access and reader checks]
  E --> F[Download ticket or media response]
  E --> G[Refuse unavailable or revoked request]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +297, Tests +210, Docs +3, Other 0. Total +510 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 561 264 +297
Tests 2 216 6 +210
Docs 1 5 2 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 8 783 273 +510

Review metrics

Metric Value Why it matters
Production versus test growth production net +297 lines; tests net +210 lines Production growth is explained by retained worker custody and helper extraction; tests exercise source selection and refusal boundaries.

Technical review

Best possible solution:

Use the existing history-worker owner for durable serving reads while preserving current access checks, incognito ownership, and the separate cleanup contract.

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

Yes, source inspection establishes that current serving paths invoke synchronous SQLite ownership readers; the PR reports a baseline HTTP measurement of 19 host SQL calls. This review did not execute that measurement.

Is this the best way to solve the issue?

Yes, reusing the existing worker operations and retaining their readers through consumption is a focused solution; no competing store, cache, public API, or migration is introduced.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Gateway performance and lifecycle improvement without an established urgent user-facing regression.
  • 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. Not applicable: The verified repository-admin author is exempt from ordinary contributor proof. Reported runs exercise production ownership workers and serving code, with mocked HTTP authentication and transcript matching; they are supplemental boundary evidence. No unresolved new authority grant was identified, and no stored-data contract changes.

Evidence

What I checked:

  • Pinned change ownership: Reviewed the merge-base-to-head introduced delta. The verified test-merge metadata identifies the same eight changed paths; unrelated endpoint drift was excluded. (ccee0e06ccb9)
  • Current main still needs the cutover: The current-main transcript matcher still calls synchronous store discovery and exact-entry readers. Serving callers continue using that matcher. (src/gateway/managed-image-attachments.ts, 2558513216f8)
  • Latest release retains synchronous serving reads: The v2026.9.7 source still imports synchronous ownership readers and invokes the transcript matcher from media-serving paths. The local release blob was unavailable, so its contents were inspected through GitHub instead. (src/gateway/managed-image-attachments.ts:1031, c074824a27c9)
  • Retained source and refusal behavior: The new serving scope retains discovery and physical readers, checks database identity after awaits, refuses invalid or ambiguous ownership, and restricts runtime fallback when a separate state directory was supplied. (src/gateway/managed-image-session-read.ts:76, ccee0e06ccb9)
  • Publication authority: HTTP serving rechecks request authority and ticket expiry after record reads and composes those checks with reader custody before protected response publication. Ticket extraction preserves the existing signing and attachment-binding contract. (src/gateway/managed-image-attachments.ts:1488, ccee0e06ccb9)
  • Focused regression evidence: Inspected tests cover zero host SQL, delayed real ownership-worker replies, requester revocation, reader retirement, rejection without native fallback, and shared, retired, supplied-state, invalid, and ambiguous sources. The HTTP suite mocks authentication, transcript matching, and its response transport; the PR body reports passing runs, which were not rerun during this read-only review. (src/gateway/managed-image-attachments.authority.test.ts:85, ccee0e06ccb9)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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 (1 earlier review cycle)
  • reviewed 2026-10-01T22:44:32.785Z sha ccee0e0 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 9dd0f4b into main Oct 2, 2026
136 of 138 checks passed
@steipete
steipete deleted the dbasync/s08b branch October 2, 2026 00:09
@steipete

steipete commented Oct 2, 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 2, 2026
Retain worker-selected session sources through managed media publication and recheck caller authority after asynchronous reads. Keep cleanup and process-held incognito under their existing owners; the GC reference-race follow-up is separate.
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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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