Repository navigation
fix(gateway): images on a rewound branch are deleted before switching back to it - #160471
masatohoshino wants to merge 1 commit into
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 maintainer review before merge. Reviewed September 28, 2026, 12:37 PM ET / 16:37 UTC (Revision 2). ClawSweeper reviewWhat this changesGateway media cleanup now retains attachments referenced by inactive conversation branches while downloads continue to follow the active branch. Merge readiness✅ Ready for maintainer review This PR addresses the still-open inactive-branch media loss reported in the linked issue. Current main still uses active-history visibility to decide cleanup, while the proposed change has focused regression coverage and a convincing Gateway before/after trace. Priority: P0 Review scores
Verification
How this fits togetherThe Gateway stores conversation events and managed media separately. Transcript reads tell cleanup which files to retain, while download requests check which attachments are visible in the current conversation. flowchart LR
A[Conversation events] --> B[Active branch]
A --> C[Inactive branches]
B --> D[Download visibility]
B --> E[Retention read]
C --> E
E --> F[Media cleanup]
F --> G[Retained files]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +58, Tests +7. Total +65 across 5 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep download authorization tied to visible history and let the session transcript reader supply the broader restorable set to destructive cleanup. Do we have a high-confidence way to reproduce the issue? Yes. The PR records an isolated Gateway before/after rewind, restart, and branch-switch run, and fetched main still has the source-level deletion path; this read-only review did not execute that run on current main. Is this the best way to solve the issue? Yes. The patch changes cleanup's retention read at the existing session-reader boundary while preserving active-history checks for downloads. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ad7669535c37. 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)
|
## What Problem This Solves Finishes four small helper cleanups found during the maintainer-requested eighth config sweep. ## User Impact No user-visible change. Config schemas, defaults, environment handling, migration decisions, refusal order, and persisted session keys stay the same. ## Why This Change Was Made - Remove the unused `DiscoveryToggleConfig` type left after its model discovery fields were retired. It has no repository consumers or public SDK export; the still-used Bedrock type remains. - Re-export the docs baseline functions directly through the existing lazy runtime facade, preserving names and dependency order. - Let the canonical main-session-key builder perform main-key normalization once. - Classify cron ownership once instead of allocating two filtered arrays and repeating the same lookups. Production diff: 23 added / 40 removed, **17 net lines removed**. No tests changed. ## Evidence - Independent review found no actionable P0-P2 findings. - Blacksmith Testbox `tbx_01m3sxdrf1qfe6fc408sjgf0bf`, [run 36767521248](https://github.com/openclaw/openclaw/actions/runs/36767521248), verified the four source hashes against base `3c0ae56c634e664ff12cfc2664bcdb9cf330ce5f`. - 63 tests passed across docs baseline, cron ownership, session key, session path, and filesystem import-boundary suites. - Generated config docs hashes/counts, core typechecking, and changed-file lint passed. - Both import-cycle checks reported zero cycles. - No schema, generated snapshots, dependencies, or protected SQLite accessor files changed. ### Config compatibility assessment The review's requested compatibility assessment is complete. This changes no schema, default, environment variable, migration marker, redaction rule, or stored format. The docs facade exposes the same five operations in the same dependency order. Main-key normalization remains with `buildAgentMainSessionKey`, which already calls `normalizeMainKey`; persisted keys are unchanged. Cron classification preserves both predicates, counts, refusal order, and the existing repair/recheck path. The removed type has no consumers and is absent from public SDK exports. No updater or live-upgrade execution is claimed. ### Exact-head hosted CI [Run 36769831270](https://github.com/openclaw/openclaw/actions/runs/36769831270) completed on `91162736eeb2b9660af6c7c48ab32438ed70c23a`: 143 jobs passed, 22 skipped, two test jobs failed, and the CI gate failed downstream. Security-fast, dependency review, security-sensitive review, all selected types/lint/build checks, and architecture checks passed. `checks-node-changed-compact-large-26` ([job 110073528939](https://github.com/openclaw/openclaw/actions/runs/36769831270/job/110073528939)) fails `setup-inference.first-signin.integration.test.ts:420:38`: expected `confirm`, received `note`, in the same-owner sign-in/revoked-retry case. The identical failure is present on unrelated PR #162093, head `be4f3855425d239b494f77e308881b2b0c7a3157`, [run 36769218900 / job 110071456815](https://github.com/openclaw/openclaw/actions/runs/36769218900/job/110071456815). That PR changes only `src/agents/apply-patch-paths.ts`. The assertion was introduced by #162020, which is already this PR's base; no Gateway/authentication source or test changes here. `checks-node-changed-compact-small-4-1` ([job 110073535262](https://github.com/openclaw/openclaw/actions/runs/36769831270/job/110073535262)) fails `server.catalog-startup.test.ts:86:3`, “starts with provider settings without model rows when a channel is auto-enabled,” with `Test timed out in 90000ms`. The same case/error appears in the latest CI for unrelated PR #160471's still-current head `f007e2c16e02455a3ace3d5e803af02bccac4130`: [September 28 run 36428787158 / job 108950748546](https://github.com/openclaw/openclaw/actions/runs/36428787158/job/108950748546). This is independent current-PR evidence, not a claim that the latest hourly main reproduced the timeout. The docs facade is only loaded by docs baseline generation, the removed type has no runtime effect, and the session helper still applies the same canonical normalization. The cron change only combines synchronous classification; it adds no await, retry, startup operation, or changed refusal decision. The startup fixture has no legacy cron jobs. Gateway/catalog/auth source and both failing tests are unchanged by this PR. These inherited failures remain with the main-CI coordinator; no retry, timeout increase, assertion change, or main repair is included. The maintainer-authorized exception is pinned to the exact tested head and does not describe the hosted run as green. The catalog-startup test has identical Git blob `d60a895ece760b2cfb5f066acf0787a8a2ee4f11` at this PR's base/head and the independent PR head above.
## What Problem This Solves Finishes four small helper cleanups found during the maintainer-requested eighth config sweep. ## User Impact No user-visible change. Config schemas, defaults, environment handling, migration decisions, refusal order, and persisted session keys stay the same. ## Why This Change Was Made - Remove the unused `DiscoveryToggleConfig` type left after its model discovery fields were retired. It has no repository consumers or public SDK export; the still-used Bedrock type remains. - Re-export the docs baseline functions directly through the existing lazy runtime facade, preserving names and dependency order. - Let the canonical main-session-key builder perform main-key normalization once. - Classify cron ownership once instead of allocating two filtered arrays and repeating the same lookups. Production diff: 23 added / 40 removed, **17 net lines removed**. No tests changed. ## Evidence - Independent review found no actionable P0-P2 findings. - Blacksmith Testbox `tbx_01m3sxdrf1qfe6fc408sjgf0bf`, [run 36767521248](https://github.com/openclaw/openclaw/actions/runs/36767521248), verified the four source hashes against base `c3dd660f699728d5ba714e447f8484590d085f5d`. - 63 tests passed across docs baseline, cron ownership, session key, session path, and filesystem import-boundary suites. - Generated config docs hashes/counts, core typechecking, and changed-file lint passed. - Both import-cycle checks reported zero cycles. - No schema, generated snapshots, dependencies, or protected SQLite accessor files changed. ### Config compatibility assessment The review's requested compatibility assessment is complete. This changes no schema, default, environment variable, migration marker, redaction rule, or stored format. The docs facade exposes the same five operations in the same dependency order. Main-key normalization remains with `buildAgentMainSessionKey`, which already calls `normalizeMainKey`; persisted keys are unchanged. Cron classification preserves both predicates, counts, refusal order, and the existing repair/recheck path. The removed type has no consumers and is absent from public SDK exports. No updater or live-upgrade execution is claimed. ### Exact-head hosted CI [Run 36769831270](https://github.com/openclaw/openclaw/actions/runs/36769831270) completed on `91162736eeb2b9660af6c7c48ab32438ed70c23a`: 143 jobs passed, 22 skipped, two test jobs failed, and the CI gate failed downstream. Security-fast, dependency review, security-sensitive review, all selected types/lint/build checks, and architecture checks passed. `checks-node-changed-compact-large-26` ([job 110073528939](https://github.com/openclaw/openclaw/actions/runs/36769831270/job/110073528939)) fails `setup-inference.first-signin.integration.test.ts:420:38`: expected `confirm`, received `note`, in the same-owner sign-in/revoked-retry case. The identical failure is present on unrelated PR openclaw#162093, head `be4f3855425d239b494f77e308881b2b0c7a3157`, [run 36769218900 / job 110071456815](https://github.com/openclaw/openclaw/actions/runs/36769218900/job/110071456815). That PR changes only `src/agents/apply-patch-paths.ts`. The assertion was introduced by openclaw#162020, which is already this PR's base; no Gateway/authentication source or test changes here. `checks-node-changed-compact-small-4-1` ([job 110073535262](https://github.com/openclaw/openclaw/actions/runs/36769831270/job/110073535262)) fails `server.catalog-startup.test.ts:86:3`, “starts with provider settings without model rows when a channel is auto-enabled,” with `Test timed out in 90000ms`. The same case/error appears in the latest CI for unrelated PR openclaw#160471's still-current head `f007e2c16e02455a3ace3d5e803af02bccac4130`: [September 28 run 36428787158 / job 108950748546](https://github.com/openclaw/openclaw/actions/runs/36428787158/job/108950748546). This is independent current-PR evidence, not a claim that the latest hourly main reproduced the timeout. The docs facade is only loaded by docs baseline generation, the removed type has no runtime effect, and the session helper still applies the same canonical normalization. The cron change only combines synchronous classification; it adds no await, retry, startup operation, or changed refusal decision. The startup fixture has no legacy cron jobs. Gateway/catalog/auth source and both failing tests are unchanged by this PR. These inherited failures remain with the main-CI coordinator; no retry, timeout increase, assertion change, or main repair is included. The maintainer-authorized exception is pinned to the exact tested head and does not describe the hosted run as green. The catalog-startup test has identical Git blob `d60a895ece760b2cfb5f066acf0787a8a2ee4f11` at this PR's base/head and the independent PR head above.
|
Closing as superseded: #163043 (merged 2026-10-02) fixes the same defect on |
Closes #139670
What Problem This Solves
Fixes: generated images, audio, video, and documents are permanently deleted by routine cleanup after a rewind moves their message to an inactive branch, so switching back to that branch shows the message with a dead link.
User Impact
Users can rewind a conversation, let the Gateway restart or run maintenance, and later switch back to the earlier branch with its attachments intact. While the branch is inactive, its attachments stay unavailable for download (unchanged); they are served again as soon as the branch is active.
Why This Change Was Made
Rewind and branch switch keep every branch in the session transcript and only move the active leaf. Managed media cleanup decided deletion from the visible active-path history, so a message on an inactive branch read as unreferenced and its record and file were deleted.
This PR keeps two sets apart, the split the review on #139670 calls sound:
retainedmode next tofull; the extra rows come from one query in the session projection reader (transcript_eventsrows with nosession_transcript_active_eventsentry), read inside the same snapshot and in the same history worker as today. The reset-archive fallback for empty history still depends on visible history alone.Deliberate limits:
The existing
inactive-branchcase inmanaged-image-attachments.sqlite-visibility.test.tsexpected cleanup to delete the media. It now expects cleanup to keep it; its assertions that downloads return nothing for inactive branches stay the same. Production code grows by about 45 lines, mostly the new query and its comment.Evidence
Tested at
e102ebccea1(baseupstream/main733ceac1a7e). The headf007e2c16e0differs only in how the new query'sNOT EXISTSfilter is written (method-call form for the linter); the SQL and behavior are the same, and the focused test file passes on the head.Both builds ran with
pnpm build, then an isolated Gateway (own state directory, loopback port, token auth, channels skipped) with a local OpenAI-compatible mock model whose reply attaches a synthetic PNG through aMEDIA:line. A driver ran the same steps against each build through the built CLI (openclaw gateway call) and HTTP GETs: send a plain turn, send a turn that attaches the image, GET it,sessions.rewindto the second user message, GET again, restart the Gateway (startup maintenance runs managed media cleanup),sessions.branches.switchback to the old tip, readchat.history, GET again.Before (base
733ceac1a7e):After (this PR):
Observed result: on the base, cleanup deletes the original while its branch is inactive and the restored message's image returns 404. With this PR, the original survives cleanup, the inactive branch still returns 404, and the restored branch returns 200.
Not covered: the run uses a mock model and a single image; other media kinds share the same record and cleanup path. The hourly maintenance run was not waited for; it calls the same cleanup that runs at startup.
Focused tests and checks:
pnpm test <file> --maxWorkers=1wallf007e2c16e0src/gateway/managed-image-attachments.sqlite-visibility.test.tsinactive-branchcase fails on the base (cleanup deletes the record) and passes with this PR; the other 24 cases in the file pass unchanged, including the fresh-history, reset-only, and corrupt-row cases.oxfmt --checkandoxlinton the changed files pass;pnpm check:changedresults are below.autoreviewskill ran on the branch. One finding was fixed (inactive rows could have suppressed the empty-history reset-archive fallback; the fallback now looks at visible history only). One was kept on purpose: a corrupt inactive row makes cleanup reject (see the limits above). The final run is clean.CI checks on
f007e2c16e0Two
checks-node-changedjobs failed (CI run); neither failure comes from this change.test/e2e/qa-lab/runtime/gateway-agent-artifact-apis.e2e.test.tsfails at line 403 withexpected Promise{…} to be true. The test callsattachManagedOutgoingMediaToMessage(...)withoutawait, but that function has returnedPromise<boolean>since improve: reduce Gateway blocking during image delivery #159348, andmainstill has the same unawaited assertion, so it fails regardless of this change. (A local rerun was not possible: the e2e setup refuses to rebuild while a Gateway runs on the test host.) This PR does not change that function or the test; its edit tomanaged-image-attachments.tsonly puts the e2e file in this PR's changed-test selection.src/gateway/server.catalog-startup.test.ts("starts with provider settings without model rows when a channel is auto-enabled") hit its 90 s timeout. The same test timed out the same day in unrelated PRs, for example feat(queue): tell the sender whether a busy-time message steered the running turn #160405 (job), fix: deliver final replies after unrelated plugin reloads #160009 (job), and fix(gateway): failed visible tasks leave a stranded child session for write-only operators #160046 (job). On this branch the file passes locally (3 tests, 51 s wall).