Skip to content

Commit d65ba38

Browse files
grimmerkclaude
andcommitted
docs: add complexity analysis + file cleanup to design doc
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cac7530 commit d65ba38

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

docs/session-status-hooks-design.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,30 @@ Status hooks are an **additional layer** on top of the existing detection system
158158
| Hook script execution | ~5ms (bash + write file) | Per Claude Code turn (~1-5/min) |
159159
| fs.watch notification | ~0ms (OS-level, no polling) | Per status file change |
160160
| Status file read | ~1ms | Per fs.watch event |
161-
| Startup JSONL scan | ~1ms per session (tail 50 lines) | Once on CodeV launch |
161+
| Startup JSONL scan | ~1ms per session (tail 100 lines) | Once on CodeV launch |
162162
| Total CPU when idle | ~0% ||
163163

164+
### Complexity analysis
165+
166+
All operations are O(n) or better (n = number of active sessions):
167+
168+
| Step | Complexity | Notes |
169+
|---|---|---|
170+
| readAllStatuses() | O(n) | readdir + read each file |
171+
| detectActiveSessions() | O(n) | readdir sessions/*.json |
172+
| Filter sessions without status | O(n) | filter on Map |
173+
| scanInitialStatuses() | O(m) parallel | m = sessions without status file, each `tail + grep` |
174+
| cleanupStaleStatuses() | O(n) | readdir + Set.has() |
175+
| fs.watch callback | O(n) | readAllStatuses() once |
176+
177+
**Note:** `get-session-statuses` uses `allSessions.find()` per session without status → O(m×s) where m = sessions without status, s = total sessions in history.jsonl. In practice m ≈ 0 after first startup (scan results are persisted to files), and s is cached with 5s TTL.
178+
179+
### File accumulation prevention
180+
181+
Two mechanisms prevent status files from growing indefinitely:
182+
1. **SessionEnd hook** — removes `{sessionId}.json` when session ends normally
183+
2. **cleanupStaleStatuses()** — runs on each `get-session-statuses` call (startup + window focus), deletes files for sessions no longer in active set (handles crash/SIGKILL cases)
184+
164185
### Architecture note: `get-session-statuses` and duplicate detection
165186

166187
The `get-session-statuses` IPC handler internally calls `detectActiveSessions()` and `readClaudeSessions(500)` to find sessions without status files for JSONL scanning. This duplicates work the renderer already does.

0 commit comments

Comments
 (0)