Repository navigation
refactor: move managed media session selection off the Gateway thread - #169140
Conversation
|
🦞👀 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 changes before merge. What this changesThis PR moves managed-media cleanup session selection into the existing worker-backed reader and removes the duplicate native selector. Example: Cleanup examines fixture.png after its owning message disappears from current session history.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: current main still needs this focused shared-reader cutover, and no actionable introduced defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway maintenance and media downloads consume session ownership and transcript facts to decide whether to retain, delete, or disclose managed attachment bytes. flowchart TD
A[Gateway maintenance] --> C[Retained session reader]
B[Media download] --> C
C --> D[Durable read workers]
C --> E[Bound incognito actor]
D --> F[Ownership and transcript facts]
E --> F
F --> G[Retention or authorized disclosure]
Technical reviewBest possible solution: Complete the shared-reader cutover while preserving conservative retention, physical-source custody, and current disclosure authority. Do we have a high-confidence way to reproduce the issue? Current main directly exposes synchronous cleanup ownership reads, and the PR reports a baseline failure with three host queries; this read-only review ran no target code. Is this the best way to solve the issue? Reusing the existing retained reader removes competing selection policy and preserves unreadable-versus-missing ownership semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3529142cc84f. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -143, Tests +13, Docs +14, Other +11. Total -105 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 11, 2026, 11:30 AM ET / 15:30 UTC (Revision 3). |
…openclaw#169140) * refactor: read managed media session ownership in workers * fix: retain managed media when worker metadata reads fail
What Problem This Solves
Managed outgoing-media cleanup still selected session ownership on the Gateway main thread, despite the existing worker-backed reader used for serving. Its separate selector repeated entry/participant reads and maintained its own discovery cache.
User Impact
Media cleanup and serving share the existing retained worker/actor reader. Cleanup still retains files when the session store is unavailable, invalid, or ambiguous. No schema, retained-data, permission, SDK, or update contract changes.
This is a bounded result of the sessclass-a audit, not a claim that the lane reached zero T1. All 63 selected A–R files were traced: the remaining 201 sites share real synchronous SDK, opaque-callback, unbound incognito, or native maintenance owners. Their kernels cannot honestly be classified as worker-only; their owner cutovers remain follow-up work under the requested escape hatch.
Why This Change Was Made
Delete the native managed-image selector and its separate caches; use
withManagedImageSessionReadfor cleanup and serving. Preserve unavailable versus missing results so an unreadable owner cannot become deletion evidence. Keep live disclosure checks at the reader/effect boundary.T1 for the original selected session files: 203 → 202 (63 files). On the final integrated base
c3a682c836325, it is 202 → 201 (62 files): main independently removed the T1 site insession-accessor.sqlite-entry-snapshot.ts. The contribution of this PR remains one reclassification, not two deletions. One raw-row assertion is reclassified as a Doctor-only T2 exception, since only Doctor constructsexpectedRawEntryJson. No whole module is reclassified W. One real Gateway caller family moves to workers; its shared kernels remain T1 because other native callers still exist. No SQL statement is deleted from those kernels.Removed checks / accepted edge cases:
Evidence
Measured pinned base
8234359c0b163f24002fef11b163fbdffae25459against corrected candidatebbc91c1429b21a9c27ad554694ac168e9509daf4on one Testbox, in M,C,M,C,M,C order. The subsequent merges of main only required resolving generated inventory documentation; the media source did not change. Final conflict-only head:7db128b05af188df8333aa3418d9a436774988b8; media source and regression are byte-identical to the fully tested head1ade03971ba09.run.mtsandobserver.cjsare byte-identical to the shared harness. Counts include every thread; warmed figures are per-run means over ten turns, reported as median [min–max].Warm duration ratio: 1.015; first-turn ratio: 1.126; full-workload ratio: 1.024. No duration-skew rejection. The freshly measured baseline is already below the planning estimate; this PR does not claim a warmed-turn query saving.
The request increase triggered one extra M,C pair. It measured full-workload statements 9741 → 9737, requests 1696 → 1698, MAIN 2052 → 2051; warmed statements 335.7 → 336.8, requests 89.4 → 89.5, MAIN 0 → 0. Warm duration ratio 1.001. The 0.33% warmed statement variation and 0.45% original request variation are within the noise floor, in unchanged session corpus/actor/facts operations. The extra pair's two full-workload requests are a 0.12% difference, likewise in unchanged session operations; no additional media request occurs in warmed turns.
Attribution: 131
database.domain.publishstatements and 31database.prepareWritestatements shift from first-turn to connect in the original medians; their workload totals stay 130 requests/677 statements and 3 requests/63 statements, respectively. Startup media inventory is unchanged:managedImages.entries1 request/1 statement,managedImages.originalMediaIds1/1,deliveryQueue.mediaRetentionSnapshot1/6, andlifecycle-artifact-plan1/7 (medians). The fixed harness contains no attachment fixture and records no node-artifact owner execution; nonempty media ownership is proven by the focused tests, not this workload.check:changedand CI encounter unchanged UI tab-type errors; Knip reports unrelated existing exports. On mainaec89935b8f4cea399aed02b710567e571842a3f, the same six TS2322/TS2717 errors reproduce inbrowser-panel-render.tsx,panel-elements.ts,panel-tab-strip-solid.tsx, andterminal-panel-view.tsx. Candidate and main Knip each report exactly the same 69 file/symbol entries (zero candidate-only entries). CI run 38146031712 fails on this inherited UI typing work. Landing uses the explicitly authorized relaxed exception; no static failure was hidden and no baseline was raised.Per-file A–R caller audit and retained ownership boundaries
This table records the original 63-file audit against the measurement base; the final main integration independently removed the entry-snapshot T1 site, leaving 201. These are call-expression counts, not runtime execution counts. No file below is claimed worker-only. Native compatibility/uncaptured incognito paths need an owning-contract cutover before their shared kernels can move; effect guards remain where they protect disclosure or user data.
src/config/sessions/session-accessor.sqlite-entry-read.tsconversation-registry.tsgoals-operations-read.tsgoals-operations.tssession-accessor.sqlite-acp-provenance.tssession-accessor.sqlite-active-context.tssession-accessor.sqlite-active-events.tssession-accessor.sqlite-active-projection.tssession-accessor.sqlite-archive-read.tssession-accessor.sqlite-archive-store-kernel.tssession-accessor.sqlite-archive-transaction.tssession-accessor.sqlite-branch-rewrite.tssession-accessor.sqlite-compaction.tssession-accessor.sqlite-conversation-read.tssession-accessor.sqlite-conversation.tssession-accessor.sqlite-creation.tssession-accessor.sqlite-delete-snapshot.tssession-accessor.sqlite-deletion.tssession-accessor.sqlite-display-position.tssession-accessor.sqlite-entry-availability.tssession-accessor.sqlite-entry-cache-projection.tssession-accessor.sqlite-entry-cache.tssession-accessor.sqlite-entry-identity.tssession-accessor.sqlite-entry-inventory.tssession-accessor.sqlite-entry-list.read.tssession-accessor.sqlite-entry-snapshot.tssession-accessor.sqlite-entry-store.tssession-accessor.sqlite-entry.tssession-accessor.sqlite-exact-read.tssession-accessor.sqlite-history-input-visibility.tssession-accessor.sqlite-history-interval.tssession-accessor.sqlite-history-projection.tssession-accessor.sqlite-history-query.tssession-accessor.sqlite-history-recency.tssession-accessor.sqlite-history-source.tssession-accessor.sqlite-history.tssession-accessor.sqlite-initial-entry.tssession-accessor.sqlite-involvement.tssession-accessor.sqlite-lifecycle-artifacts.tssession-accessor.sqlite-lifecycle-state.tssession-accessor.sqlite-lifecycle.tssession-accessor.sqlite-maintenance-store.tssession-accessor.sqlite-maintenance-transaction.tssession-accessor.sqlite-maintenance.tssession-accessor.sqlite-model-context.tssession-accessor.sqlite-node-artifacts.tssession-accessor.sqlite-owner.tssession-accessor.sqlite-parent-session.tssession-accessor.sqlite-participant-projection.tssession-accessor.sqlite-participant-read.tssession-accessor.sqlite-participants.native.tssession-accessor.sqlite-pending-input-receipts.tssession-accessor.sqlite-pending-inputs-repair.tssession-accessor.sqlite-pending-inputs.tssession-accessor.sqlite-projection-read.tssession-accessor.sqlite-projection.tssession-accessor.sqlite-provenance.tssession-accessor.sqlite-raw-delta-read.tssession-accessor.sqlite-read.tssession-accessor.sqlite-reclamation.tssession-accessor.sqlite-replacement-projection.tssession-accessor.sqlite-replacement-read.tssession-accessor.sqlite-reset-window.tsNo schema or owner redesign was undertaken for the retained contracts. No synchronous SDK API was changed to return a Promise, no alternate state owner was introduced, and no real user-data/disclosure guard was reclassified as bookkeeping.
Final landing checks
On head
1ade03971ba09, the four media suites passed again (65.50 s), as did type-aware core/script lint, export collisions, Madge, inventory, T1, and dialect checks. Final Knip reports seven unrelated exports, reproduced exactly on basec3a682c836325: six in Telegram native-command runtime and one in the subagent registry. Candidate-only set is empty.CI run 38151048234 failed only
checks-ui-e2e (1/2)and its aggregate gate. The exact base reproduces the same failure inchat-panel-layout.e2e.test.ts:379: the terminal canvas stays hidden and times out after 30 seconds. The focused base run has one failure and one pass; this mocked-Gateway UI test does not execute managed-media cleanup. This replaces the older UI-typing attribution for current-head CI. No CI rerun or baseline change was used.Native prepare completed. Native merge admission rejected twice before dispatch; landing uses the explicitly authorized v4 head-pinned REST squash fallback after generated-inventory-only integration. No pending or uncertain merge request exists. ClawSweeper's current review has no product/security findings; its requested CI attribution is provided above. Nonempty live-Gateway media maintenance remains a separate proof follow-up; this PR's nonempty media proof uses real worker-backed production cleanup tests.
Final integration preserves the exact tested media source. The generated inventory and its source lint, T1 ratchet, dialect ratchet, and whitespace checks passed after resolving the inventory conflict.