Skip to content

feat(session): add lifecycle management — storage reclamation, CLI commands, VACUUM support#16175

Closed
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:feat/session-lifecycle
Closed

feat(session): add lifecycle management — storage reclamation, CLI commands, VACUUM support#16175
guazi04 wants to merge 1 commit intoanomalyco:devfrom
guazi04:feat/session-lifecycle

Conversation

@guazi04
Copy link

@guazi04 guazi04 commented Mar 5, 2026

Summary

Implements Session Lifecycle Management (MVP path from #16101). Sessions now have a lifecycle — not just a birth.

What's new

Post-compaction storage reclamation (compaction.ts)

  • prune() now clears output and attachments from ToolStateCompleted parts after marking time.compacted — previously it only marked but never reclaimed
  • Added retroactive reclamation pass in process() that catches previously-pruned parts with unreclamed content
  • Gated by new compaction.reclaim config option (default: true)

CLI session management commands (cli/cmd/session.ts)

  • opencode session archive <id> / unarchive <id> — surfaces existing setArchived() functionality that was API-only
  • opencode session stats — shows DB/WAL file size, session counts (root/child/archived), message/part counts via efficient SQL aggregates
  • opencode session prune — bulk cleanup with --older-than (default 30 days), --children, --vacuum, --dry-run

VACUUM support (storage/db.ts)

  • Database.vacuum() — WAL checkpoint (TRUNCATE) + VACUUM to actually free disk space
  • Database.checkpoint() — WAL checkpoint only

Data integrity fix (session/index.ts)

  • Added childrenAll() that queries children by parent_id only (no project filter)
  • remove() now uses childrenAll() for cascade deletion, fixing cross-project child session orphaning

Design decisions

  • Conservative reclamation: Only clears parts already marked as compacted — doesn't touch active/recent content
  • Direct Drizzle queries for prune: Avoids listGlobal() ordering bias that would skip the oldest sessions
  • Descendant tracking: Prune uses Set<string> to prevent double-delete when --children includes both parent and child
  • Vacuum safety: Wrapped in try/catch with user-friendly "DB busy" message

Files changed

File Change
packages/opencode/src/session/compaction.ts Storage reclamation in prune + process
packages/opencode/src/config/config.ts New compaction.reclaim option
packages/opencode/src/cli/cmd/session.ts 4 new CLI commands
packages/opencode/src/session/index.ts childrenAll() + safer remove()
packages/opencode/src/storage/db.ts vacuum() + checkpoint()

Not included (future work per #16101)

  • Auto-archival for inactive sessions
  • Aggressive reclamation mode
  • TUI integration for archive/stats
  • Child session retention period

Closes #16101

…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
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 5, 2026
@github-actions github-actions bot closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Session Lifecycle Management — unified storage reclamation, auto-archival, and child session cleanup

1 participant