#23179: fix: resolve defects in parallel sessions implementation
size: XL
Cluster:
Test Coverage Enhancements
## Summary
Improves PR #22962 (`feat/parallel-sessions-memory` by @jaredtribe) by fixing all 9 identified defects — 3 runtime-blocking, 2 high, 4 medium — and adding comprehensive test coverage.
### Defects Fixed
| # | Severity | File | Description |
|---|----------|------|-------------|
| 1 | **BLOCKER** | `shared-memory-backend.ts` | Replaced `better-sqlite3` with `node:sqlite` (`requireNodeSqlite()`) to match repo convention |
| 2 | **BLOCKER** | `parallel-session-manager.ts` | Fixed config schema mismatch — import Zod-inferred `ParallelSessionsConfig` type instead of flat interface |
| 3 | **BLOCKER** | `parallel-session-manager.ts` | Wired `SharedMemoryBackend` into manager for real hibernation persistence |
| 4 | **HIGH** | `parallel-session-manager.ts` | Added bounded eviction (500 session memories, 100 global knowledge entries) |
| 5 | **HIGH** | `parallel-session-manager.ts` | Used `config.memory.autoPromoteThreshold` instead of hardcoded `8` |
| 6 | **MEDIUM** | `parallel-sessions-config.ts` | Fixed default paths: `~/.clawdbot` → `~/.openclaw` |
| 7 | **MEDIUM** | `parallel-session-manager.ts` | Wrapped idle check `setInterval` in try-catch |
| 8 | **MEDIUM** | `shared-memory-backend.ts` | Eliminated SQL injection via `${SCHEMA_VERSION}` template literal |
| 9 | **MEDIUM** | `index.ts` | Fixed barrel exports to avoid re-exporting existing modules |
### Bug Found During E2E Testing
E2E tests with real SQLite uncovered an additional concurrency bug: **reactivating a hibernated session bypassed the `maxConcurrent` limit**, allowing more active sessions than configured. Fixed by extracting `enforceSessionLimit()` and calling it before both new session creation AND hibernated session reactivation.
### Test Coverage
- **41 unit tests** (3 new files) — mocked SQLite backend for fast isolated testing
- **17 end-to-end tests** — real `node:sqlite` `DatabaseSync` against temp directories
- Full lifecycle: create → save → briefing → hibernate → resume
- Cross-session knowledge sharing via auto-promotion
- Concurrent session limits with disk-backed hibernation
- Per-chat and per-peer isolation modes
- Memory eviction under load (505 entries)
- Data durability across backend close/reopen
- WAL mode verification
- Concurrent write safety
All **63 tests pass**, 0 TypeScript errors, 0 lint errors.
## Test plan
- [x] `npx vitest run src/sessions/` — 63/63 pass
- [x] `tsc --noEmit` — 0 errors
- [x] `oxlint src/sessions/` — 0 warnings, 0 errors
- [x] E2E tests verify real SQLite persistence, not just mocks
- [x] E2E tests caught a real concurrency bug (now fixed)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Most Similar PRs
#4664: fix: per-session metadata files to eliminate lock contention
by tsukhani · 2026-01-30
68.1%
#20496: test(utils): add comprehensive unit tests for utility functions
by masifislamm · 2026-02-19
68.0%
#21054: fix(cli): fix memory search hang — close undici pool + destroy QMD ...
by BinHPdev · 2026-02-19
67.8%
#18179: CLI: add sessions --json-debug diagnostics
by p6l-richard · 2026-02-16
67.7%
#20148: fix(memory): persist session dirty state and fix reindex gate
by togotago · 2026-02-18
67.4%
#19418: feat(persist-postgres): PostgreSQL persistence plugin + session dat...
by supmo668 · 2026-02-17
66.8%
#15569: test: comprehensive test coverage expansion (57 new test files)
by tangcruz · 2026-02-13
66.8%
#11710: fix: security hardening — exec blocking, auth validation, timing-sa...
by zendizmo · 2026-02-08
66.8%
#10367: CLI/Ops: resilient browser fill + failover hardening + operations t...
by cluster2600 · 2026-02-06
66.7%
#16542: fix(sessions): use atomic temp+rename write on Windows
by aldoeliacim · 2026-02-14
66.6%