Repository navigation
refactor(gateway): await managed media ownership reads - #163049
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:56 PM ET / 22:56 UTC (Revision 2). ClawSweeper reviewWhat this changesMove 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +297, Tests +210, Docs +3, Other 0. Total +510 across 8 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
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.
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, andsession-entry-readworker 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
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.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 nativecreateChangedCheckPlanthroughrunManagedCommand; 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.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, andresolveExistingAgentSessionStoreTargetsReadOnlyResultexports 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
recordMatchesTranscriptMessageto retain media on inactive transcript branches during cleanup. This PR leaves that matcher, the cleanup transaction inmanaged-image-record-store.kernel.ts, and scheduled GC unchanged. The suspected GC reference race remains a separate follow-up.