Repository navigation
fix(media): keep the ttl sweep out of the managed outgoing tree - #119127
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 9:13 AM ET / 13:13 UTC. ClawSweeper reviewWhat this changesThe PR excludes SQLite-managed outgoing attachments from the general TTL sweep, gives their record-aware cleanup an independent gateway lifecycle, and retains media when session state cannot be read safely. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open for maintainer review: the exact head repairs a still-current P0 data-loss path with no actionable source finding, but intentionally narrows the existing TTL retention contract for managed outgoing media. Priority: P0 Review scores
Verification
How this fits togetherGateway maintenance periodically prunes staged media and managed outgoing attachments under the OpenClaw state directory. General TTL cleanup removes ordinary staged files, while managed outgoing cleanup consults SQLite session and transcript state before deciding whether an attachment can be deleted. flowchart LR
A[Attachment TTL setting] --> B[Gateway maintenance]
B --> C[General staged-media sweep]
B --> D[Managed outgoing reaper]
D --> E[Session and transcript state]
C --> F[Expired staged media removed]
D --> G[Referenced attachments retained]
H[Gateway shutdown] --> I[Cleanup drain fence]
I --> E
Decision needed
Why: The source and proof support the data-loss repair, but this deliberately changes what an existing configured retention setting governs. Before merge
Agent review detailsSecurityNone. PR surfaceSource +514, Tests +987. Total +1501 across 22 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Adopt managed outgoing media as the sole record-aware retention owner and keep attachments.ttlHours limited to general staged media after a maintainer accepts that corrected upgrade contract. Do we have a high-confidence way to reproduce the issue? Yes: current main directly walks media/outgoing under the configured recursive TTL sweep, and the PR body supplies exact-head filesystem, gateway, and real-SQLite evidence for the repaired boundary. Is this the best way to solve the issue? Yes: the generic sweep cannot determine SQLite-backed transcript ownership, so isolating the managed subtree and using its existing record-aware reaper is the narrowest maintainable fix. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 36ee98d815db. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (28 earlier review cycles; latest 8 shown)
|
|
Both findings landed in 18c170fe94:
Real behavior proof on this exact head (18c170fe94): a harness runs the real maintenance timers against a temp @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
The check-lint red was real: my maintenance-timer edit missed an oxfmt pass on the dynamic import, fixed in 0e4137ce80. The other three failures in that run do not touch this change: build-artifacts died on gateway connect/request timeouts in its own harness, and checks-node-compact-large-3 failed a doctor open-policy test in an untouched tree. Expect them to settle on the rerun. |
|
Maintainer proof update for rebased exact head The managed outgoing reaper is lifecycle-owned independently of Exact-head proof:
The exact recorded The PR body contains the durable runtime, lifecycle, and CI evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head source-blind runtime proof and the unrelated CI-timeout verification are now in the PR body and maintainer proof comment. @clawsweeper re-review |
Co-authored-by: Yufeng He <[email protected]>
|
Frozen landing head @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: Yufeng He <[email protected]>
|
@steipete thanks for taking the implementation over and doing it properly at the accessor boundary. I read through the result: the availability reason now survives One addition in 03a3ec1bf2, keeping to the case your review named: an end-to-end regression that seeds a real database, drops |
Co-authored-by: Yufeng He <[email protected]>
The exact case the review called out: a real seeded database loses its session_nodes table, the global sweep runs, and the record plus its original bytes must survive. A control case keeps the healthy path honest: a dereferenced record still gets deleted when the store reads fine. Fails against the pre-guard code, passes with it.
03a3ec1 to
2c66ffb
Compare
|
Converged exact head @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: Yufeng He <[email protected]>
Co-authored-by: Yufeng He <[email protected]>
|
Final exact head @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer decision: accept the corrected retention boundary. The remaining optional rebase/rank-up move is intentionally skipped under the frozen-baseline policy: exact head |
|
Merged via squash.
|
Fixes #119088.
What Problem This Solves
Fixes an issue where operators who configured
attachments.ttlHourscould lose generated attachments referenced by chat history. The generic mtime sweep enteredmedia/outgoing, deleting the only original while its SQLite history record remained, and could remove legacyoutgoing/records/*.jsonmetadata that intentionally blocks destructive orphan cleanup until Doctor imports it.Why This Change Was Made
The generic TTL sweep now stays out of the managed outgoing subtree. That subtree remains owned by its SQLite- and transcript-aware reaper, which runs independently at gateway startup and hourly even when the configurable TTL is disabled, fails, or is still in flight. Playback cache retention remains a separate fixed owner lifecycle.
The maintenance owner now keeps its interval private and exposes one asynchronous stop operation. Gateway shutdown and startup-race disposal stop future runs and normally drain any in-flight configured sweep, playback cleanup, and managed outgoing cleanup before closing shared state. The drain is bounded at five seconds: a stuck operation records an operator-visible warning and cannot block restart forever. Unresolved drains are tracked process-wide across gateway generations; shared SQLite remains open until every prior-generation drain settles, and the attached all-settled observers handle late outcomes. This lifecycle is independently required by the new always-on managed reaper; it is not a workaround for the separate loaded-shard Doctor timeout.
The transcript-aware reaper also preserves session-store availability as a first-class result. Confirmed missing databases/sessions may be treated as absent, while schema/table unavailability retains history records and originals instead of converting an operational failure into deletion. Serving remains fail-closed while storage is unavailable.
The config help describes the actual boundary:
attachments.ttlHourscontrols the general mtime sweep, while generated chat attachments use managed outgoing retention.User Impact
Generated attachments retained by chat history and pre-SQLite migration metadata are no longer deleted by
attachments.ttlHours. Transient managed outgoing media still expires on its own startup/hourly lifecycle without requiring achat.historyread or the optional general TTL setting. Gateway shutdown and restart no longer let media maintenance continue against retired state.Evidence
Exact rebased head:
2f7699dccfac436e1a81b7ed3600883d1069740a.session_nodesGC regression is included.attachments.ttlHours, survives a failed or hung general sweep, and skips overlap.pnpm buildandpnpm deadcode:full— passed.tsgo, targeted oxlint/oxfmt, andgit diff --check— passed. The broad local changed wrapper later stopped on an unrelated current-main max-lines baseline shrink; its earlier exact touched-surface run had passed all related gates.origin/mainbaseline — clean, no P0/P1 findings; patch correct at 0.87 confidence.Source-blind exact-head runtime behavior proof
The source-blind validator built and ran exact head
2f7699dccfac436e1a81b7ed3600883d1069740aagainst an isolated state directory and loopback gateway withattachments.ttlHours=1:inbound,downloads,uploads,browser, andtemp, while preserving fresh controls in all five trees.media/outgoing/originals,legacy-metadata.json, and.migration-barrierthrough the post-ready maintenance pass; repeated-restart preservation was also observed on the immediately preceding behavior-identical heads.GET /healthreturned{"ok":true,"status":"live"}. After a 15-second post-ready maintenance window, SIGTERM shutdown completed cleanly in 6 seconds.chat.history/SQLite attachment reference could not be provisioned through the isolated no-provider public workflow; the exact-head real filesystem/SQLite regression covers that boundary.chmod 000did not establish a permission fault for the validator process on this host, so the permission-fault clause was not claimed as a pass.Anti-cheat probes used distinct expired and fresh files, inspected disk state instead of trusting logs, restarted the same isolated state, and rejected the permission test when the intended fault did not take effect. The predecessor source-blind run remains supplementary evidence for the SQLite-reference and permission-fault scenarios, but is not presented as exact-head proof.
Loaded-shard Doctor timeout reclassification
The exact logged
core-unit-fast-2CI process was reproduced locally with the CI runner, recorded include list,--isolate=false, three workers, and matching environment. It reproduced the same synchronous Discord Doctor timeout while neither PR media test was part of that process.The identical timeout also occurred on unrelated PR #119331 at head
13110081850da0e43b6c9e32f30d08a6c68698d6: https://github.com/openclaw/openclaw/actions/runs/30969952001/attempts/1. Latest main's matching shard passed at22de30f998216c0c480b8858f9185d9829d90bae: https://github.com/openclaw/openclaw/actions/runs/30970858385/job/92194836323. Current main now includes the separate Doctor runtime-load repair from #119391, which this branch picked up during rebase.The isolated Doctor file passes 10/10 on the rebased head. The loaded-shard regression is tracked separately and is not attributed to this media PR.