feat(session): add lifecycle management — storage reclamation, CLI commands, VACUUM support#16201
Open
guazi04 wants to merge 1 commit intoanomalyco:devfrom
Open
feat(session): add lifecycle management — storage reclamation, CLI commands, VACUUM support#16201guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04 wants to merge 1 commit intoanomalyco:devfrom
Conversation
6 tasks
1998672 to
fe15de5
Compare
e0e6dc1 to
d768138
Compare
6 tasks
…mmands, VACUUM support - Clear tool output/attachments after compaction to reclaim storage (conservative mode, configurable via compaction.reclaim) - Add retroactive reclamation pass for previously-pruned parts - Expose session archive/unarchive in CLI - Add `session stats` command showing DB size and session/message/part counts - Add `session prune` command with --older-than, --children, --vacuum, --dry-run - Add Database.vacuum() and Database.checkpoint() for disk space reclamation - Fix cross-project child session cascade deletion via project-agnostic childrenAll() Closes anomalyco#16101
d768138 to
a54dfdd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Partially addresses #16101 (MVP path: steps 1–4)
Type of change
What does this PR do?
Sessions currently have no lifecycle beyond creation. This PR adds the missing pieces from the MVP path outlined in #16101:
Storage reclamation in compaction —
prune()incompaction.tspreviously markedtime.compactedon tool parts but never cleared the heavyoutputandattachmentsfields. Now it actually clears them (set output to[reclaimed], attachments to[]). A retroactive pass inprocess()catches parts that were marked compacted before this change but still carry stale content. Gated by a newcompaction.reclaimconfig option (default: true). This implements the conservative reclamation level described in #16101.CLI session management — Four new subcommands under
opencode session:archive <id>/unarchive <id>— surfaces the existingsetArchived()API that had no CLI exposurestats— shows DB/WAL file sizes, session counts (root/child/archived), message/part counts via single-query SQL aggregatesprune— bulk cleanup with--older-than(default 30 days),--children,--vacuum,--dry-run. Uses direct Drizzle queries with batch pagination to avoidlistGlobal()ordering bias. Tracks descendants viaSet<string>to prevent double-delete.VACUUM support —
Database.vacuum()does WAL checkpoint (TRUNCATE) + VACUUM;Database.checkpoint()does checkpoint only. Used bysession prune --vacuum.Data integrity fix —
remove()previously calledchildren()which filters by project, causing cross-project child sessions to be orphaned on delete. AddedchildrenAll()that queries byparent_idonly, andremove()now uses it for safe cascade deletion.Not included (future work per #16101):
How did you verify your code works?
opencode session statsagainst a real vault with ~200 sessions — counts match manual spot-checksopencode session prune --dry-run --older-than 7to verify candidate selection, then without--dry-runto confirm deletion + vacuum reclaimed ~40 MBarchive/unarchiveround-trip on multiple sessionsoutputfields correctly replaced with[reclaimed]childrenAll()finds children across projects by creating a child session with a different project contextScreenshots / recordings
N/A — CLI-only changes, no UI modifications.
Checklist