Skip to content

feat(always-on): workspace retention cleanup + test script fix#163

Open
hernandez42 wants to merge 2 commits into
OpenBMB:mainfrom
hernandez42:feat/always-on-retention
Open

feat(always-on): workspace retention cleanup + test script fix#163
hernandez42 wants to merge 2 commits into
OpenBMB:mainfrom
hernandez42:feat/always-on-retention

Conversation

@hernandez42

Copy link
Copy Markdown

Summary

Add workspace retention for Always-On isolated workspaces and fix the test script to expose open handles naturally.

Changes

New file: src/always-on/runtime/AlwaysOnRetention.ts

  • Scans worktrees/ and snapshots/ directories under the Always-On root
  • Deletes workspaces older than retentionDays (default 14 days)
  • When no old workspaces exist, keeps only the maxRetainedWorkspaces newest (default 8)
  • Protects workspaces currently in active/applying/applied cycle status
  • Protects active run context working directories
  • Best-effort: errors logged but never block Always-On startup
  • Does NOT touch .apex-mem — persistent memory data is preserved

New file: src/always-on/runtime/AlwaysOnRetention.test.ts

  • Tests: old workspace deletion, active cycle protection, maxRetainedWorkspaces limit, cwd protection

Modified: src/always-on/runtime/AlwaysOnRuntime.ts

  • start() now calls runRetentionCleanup() before scheduler.start()
  • Retention only runs when config.workspace.retention.enabled is true
  • Reads cycle index to protect active workspace IDs
  • Collects protected cwds from active run contexts
  • retentionConfig fields: enabled, retentionDays, maxRetainedWorkspaces

Modified: package.json

  • test script now runs without --test-force-exit — open handles are naturally exposed
  • Added test:force as the explicit --test-force-exit mode (legacy behavior)

Why this matters

  1. Workspace bloat: Over time, Always-On worktrees and snapshots accumulate. Retention keeps disk usage bounded.
  2. Memory data safety: .apex-mem (database, index, vector store) is explicitly preserved — only workspace directories are cleaned.
  3. Open handle detection: --test-force-exit was masking resource leaks. Natural exit in npm test now catches them.
  4. Startup safety: Retention failures are best-effort — they never block Always-On startup.

Verification

npm test        # natural exit, exposes open handles
npm run test:force  # legacy --test-force-exit mode

Config example

alwaysOn:
  workspace:
    retention:
      enabled: true
      retentionDays: 14
      maxRetainedWorkspaces: 8

Co-authored-by: Xuanji xuanji@ouvaton.org

Xuanji added 2 commits June 5, 2026 08:43
- Add AlwaysOnRetention: cleanup old worktrees/snapshots workspaces
  - retentionDays (default 14) + maxRetainedWorkspaces (default 8)
  - Protects active cycle workspaces and run context cwds
  - Best-effort: errors logged but never block Always-On startup
  - Does NOT touch .apex-mem (persistent memory data)

- Integrate AlwaysOnRetention into AlwaysOnRuntime.start()
  - Runs before scheduler.start()
  - Reads WorkCycleStore cycle index to protect active workspaces
  - Protects active run context cwds

- Fix package.json test script
  - Default 'test' now runs WITHOUT --test-force-exit
  - Open handles naturally exposed in CI
  - 'test:force' preserves the --test-force-exit mode

Co-authored-by: Xuanji <xuanji@ouvaton.org>
@Gucc111 Gucc111 self-requested a review June 5, 2026 03:49
@Gucc111

Gucc111 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

The current design guarantees at most one isolated workspace per project. So workspace accumulation shouldn't happen under normal operation.

Are you seeing orphaned workspaces that weren't cleaned up properly? That would help clarify what this retention mechanism is meant to address.

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.

2 participants