Repository navigation
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 77409208d8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: found issues before merge. Reviewed September 2, 2026, 2:11 PM ET / 18:11 UTC. ClawSweeper reviewWhat this changesThe PR prevents cleanup from deleting managed attachments still reachable through transcript branches and checkpoints by adding retention-aware transcript snapshots and a revalidation fence. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessThe retention repair remains necessary and the checkpoint fence addresses the prior finding, but the new read-only snapshot opens the writable agent database on cleanup and artifact-read paths. That reintroduces lease, WAL, schema, and cached-handle lifecycle work for a read-only operation. Priority: P1 Review scores
Verification
How this fits togetherManaged attachments are stored alongside transcript/session state and served through artifact URLs. Gateway cleanup and artifact reads consult transcript history to decide whether those media bytes remain reachable. flowchart LR
A[Transcript and checkpoint state] --> B[Retention snapshot]
B --> C[Managed attachment index]
C --> D[Gateway cleanup]
C --> E[Artifact download]
D --> F[Keep or delete media]
E --> G[Serve retained media]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +561, Tests +1617. Total +2178 across 12 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep the retention and fence logic, but run both snapshot and fence reads through the canonical read-only session database owner. Do we have a high-confidence way to reproduce the issue? Yes: a cold or evicted agent database followed by managed-media cleanup reaches the introduced snapshot, whose direct writable open has observable lifecycle effects; this read-only review did not execute the scenario. Is this the best way to solve the issue? No: the retention fence is the right deletion-boundary repair, but the new read-only reader must use the canonical read-only database owner before it is the best complete solution. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1212f991db46. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (23 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
@clawsweeper re-review |
0469ce3 to
2d04e11
Compare
|
Rebased and re-proved. New head [P1] Preserve the compatibility owner before destructive cleanup - preserved. [P1] Publish the managed record only after media preparation succeeds - preserved. [P1] Retain the checkpoint expected-state mutation fence - preserved. [P1] Keep the message-cut expected-state fence during the rebase - preserved. The optimistic-concurrency validation in [P1] Resolve merge risk (mechanical merge would reintroduce the above) - resolved by not taking a mechanical merge. The conflicts in [P1] Resolve merge risk (dirty branch, stale required checks) - the branch now applies cleanly to [P1] The isolated autoreview helper could not run from a grafted checkout - not author-actionable, and the underlying reason is gone: this head has a real merge base on Two suites added to Proof repeated on the exact head. The PR body carries a fresh before/after captured on pristine One environment limit to name. Root-cause cluster is unchanged and still accurate. Current @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
…anches Rewinding or resetting a conversation could permanently delete generated media that was no longer on the active transcript path but was still reachable through an inactive branch or a live compaction checkpoint. Cleanup treated absence from the active projection as proof the media was orphaned, deleted the SQLite record and the backing file, and a later branch or checkpoint restore brought back a message whose bytes were gone. Managed-media lookup is now split into restorable and retained modes. HTTP serving and artifact download stay on the immediate restorable projection. Destructive cleanup asks the session owner for the retained event set, walking complete canonical paths for every live transcript tip including reset-hidden ancestry that remains checkpoint-reachable, and fails closed when checkpoint retention is incomplete, legacy file-backed, or unreadable. The retention snapshot and the irreversible delete were also separated by an unfenced window, because checkpoint publication commits through a session write path that the cleanup queue does not serialize. The session owner now derives a retention fence from the transcript generation, the maximum sequence, and the published checkpoint set inside the same deferred transaction that produces the snapshot. Cleanup carries that fence to the point of deletion and revalidates it there, retaining the record when the fence moved or cannot be read. Integration with current main preserves every newer safeguard on these surfaces rather than reasserting this branch's older shape: compatibility owner resolution for destructive cleanup, publication of the managed record only after media preparation succeeds, the checkpoint expected-state conflict fence, read-only database reads for the transcript watermark, the canonical transcript projection helper, and the separation of display media from model history in the attachment index. The tri-state session-store availability read still retains a record when reachability cannot be determined, and an aged transient record is still retained while its session has an active run. Co-authored-by: Vincent Koc <[email protected]>
2d04e11 to
ff07bd2
Compare
|
Rebased and re-proved. New head Answering the verdict at [P1] Fence deletion against checkpoint publication - fixed. Interleaving regressions added:
Coverage gap on the pre-seeded checkpoint test - addressed. The new cases above interleave publication with the retention decision instead of pre-seeding an already-persisted checkpoint. Residual, and it is a maintainer call. The fence closes the snapshot-to-delete window, which is where the reported loss happens. It does not make deletion atomic with respect to checkpoint publication: a checkpoint committing between the fence revalidation and the [P1] Branch is dirty against current main - cleared. Rebased onto
Scope reduction. The earlier revision also routed Not superseded. #119764 (merged) covers uncommitted generated media while a session run is live, a liveness dimension, and its Proof in the body is regenerated against this exact head: on pristine main the rewind sweep deletes the inactive-branch record and its bytes and the restored branch answers 404; with this patch the same sweep retains, the restored branch serves the bytes with status 200, and media referenced by no branch is still deleted. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing this while it sits assigned, stale, and conflicting. The defect is unchanged on current @vincentkoc you are the assignee here. The branch |
What Problem This Solves
Rewinding or resetting a conversation could permanently delete generated media that was no longer on the active transcript path but was still reachable through an inactive branch or a live compaction checkpoint.
Cleanup treated absence from the active projection as proof that the media was orphaned. It deleted the SQLite record and the backing file. Restoring the branch or the checkpoint brought the message and its URL back, but the bytes were already gone.
Root Cause
Managed-media cleanup, HTTP serving, and artifact download shared one attachment index built from the active/restorable message projection. That projection is correct for what the operator can open immediately, but it is not the lifecycle owner for destructive retention.
The session owner already records the facts retention needs: the full SQLite transcript event tree, reset and compaction boundaries, live compaction checkpoint source sessions and fork boundaries, and the transcript rewrite generation and maximum sequence. The bug was using a consumer projection as a garbage-collection authority instead of asking the session owner which messages can become reachable again.
Canonical Fix
restorableandretainedmodes. HTTP serving and artifact download stay on the immediate restorable projection.No schema, config, migration, protocol, or changelog change is required.
Fencing Deletion Against Checkpoint Publication
The previous review found a real P1 on top of the retention change: the retention snapshot and the irreversible delete were separated by an unfenced window. Checkpoint publication commits through
updateSessionEntry, which the cleanup queue does not serialize, so a snapshot that reported media unreferenced could be obsolete by the time the record and file were removed.The session owner now derives a retention fence inside the same deferred transaction that produces the retention snapshot, from the transcript generation, the maximum sequence, and the published checkpoint set. Destructive cleanup carries that fence to the point of deletion and revalidates it there, retaining the record when the fence moved or cannot be read. This reuses the optimistic-concurrency shape already used by the checkpoint and message-cut expected-state fences rather than introducing a second independent guard.
Scope note for the maintainer: this fences the snapshot-to-delete window, which is where the reported loss occurs. It does not make deletion atomic with respect to checkpoint publication; a checkpoint committing between the fence revalidation and the
unlinkremains theoretically possible. Closing that last gap requires the session owner to own media deletion inside its own write transaction, which is a lifecycle redesign beyond this fix.Safety Guards Preserved From Current Main
Every newer safeguard on the surfaces this touches is carried into the resolved integration rather than replaced.
resolveManagedSessionOwnerAgentIdplustryResolveSessionCompatibilityOwnerAgentIdremain the owner resolver for cleanup, the attachment index, and artifact download.insertManagedImageRecordstill runs after the fallible playback and mode preparation.restoreCompactionCheckpointSessionandbranchCompactionCheckpointSessionkeep the requiredexpectedStateparameter and theconflictresult.recordMatchesTranscriptMessagestill returnsmatch/missing/unavailable, retained mode included, and cleanup deletes only onmissing.hasActiveSessionRunpredicate still guards the aged-transient branch.readSessionTranscriptWatermarkkeeps main'swithOpenClawAgentDatabaseReadOnlyshape; this branch's atomic generation-and-sequence pair is applied inside it rather than replacing it.projectSqliteHistoryEventsinstead of the helpers that refactor removed.listSessionBranchesthrough the new shared branch-tip selector; that changed which rows count as branches and broke the large-shared-graph assertion added by that commit, so it is dropped. Retention no longer depends on it.Verification
Run from the rebased worktree at head
ff07bd20f864bdfc8a85d77cdb69bd6c751e4e4d, base1623683f478b1e4a2e3d5632585f006ea142e08c:node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-restorable-messages.test.ts src/config/sessions/transcript-tree.test.ts src/config/sessions/session-accessor.sqlite-message-cut.test.ts- 3 files, 50 tests passed.node scripts/run-vitest.mjs src/gateway/managed-image-attachments.branch-retention.test.ts src/gateway/managed-image-attachments.test.ts- 2 files, 132 tests passed.oxfmton the 12 changed files - clean.oxlint --tsconfig config/tsconfig/oxlint.core.jsonon the 12 changed files - clean.Real behavior proof
Behavior addressed: after
sessions.rewind, managed media still referenced by the inactive transcript branch is permanently deleted by managed-media cleanup, so switching back to that branch restores a message whose bytes no longer exist.Real environment tested: the real production entry points driven end to end against one temporary state directory with a real SQLite session store, on pristine
main1623683f478b1e4a2e3d5632585f006ea142e08cand on the rebased headff07bd20f864bdfc8a85d77cdb69bd6c751e4e4d. RealupsertSessionEntryCoreandappendTranscriptMessagebuild the transcript, realrewindSessionToMessage,listSessionBranchesandswitchSessionBranchdrive the branch lifecycle, realcleanupManagedOutgoingMediaRecordsperforms the sweep, realresolveManagedOutgoingMediaArtifactDownloadmints the scoped URL, and the bytes are fetched over a real loopback HTTP server running the realhandleManagedOutgoingMediaHttpRequest. Nothing is stubbed; the only synthetic input is the seeded conversation.Exact steps or command run after this patch: seed a six-turn session whose assistant turn carries a managed image, commit the managed record and its file, rewind to the user turn before it, sweep, switch back to the inactive branch leaf, mint an artifact URL and fetch it over authenticated loopback HTTP, publish a compaction checkpoint and re-read the session retention fence, then sweep a second record referenced by no branch at all.
Evidence after fix:
Observed result after fix: on pristine main the rewind sweep destroys the inactive-branch record and its bytes, and the later branch switch restores a message whose artifact URL can no longer be minted and whose bytes answer 404; with this patch the same sweep keeps the record and the file, the restored branch mints a scoped URL and serves the bytes over authenticated loopback HTTP with status 200, the session retention fence visibly moves when a compaction checkpoint is published so a stale retention verdict is detectable at the point of deletion, and media referenced by no branch at all is still removed, so the change does not over-retain.
What was not tested: no live model provider or network media generation; the full production build and the complete repository suite were not run, only the affected suites; the residual window between fence revalidation and file removal is argued from the code path rather than observed, because forcing that interleaving deterministically would require a test-only hook in the cleanup loop.