Commit 01e48c6
authored
🤖 feat: idle compaction for inactive workspaces (#1160)
## Summary
Automatically compacts workspaces that have been inactive for a
configurable period. Runs eligibility checks hourly after an initial
60-second delay on startup.
Closes #714.
## Configuration
- **Per-project setting**: `idleCompactionHours` (null = disabled,
number = hours threshold)
- **UI**: Settings → Project → Idle Compaction (checkbox + hours input)
- **Slash command**: `/idle <hours>` or `/idle off`
## UX Invariants
Two critical behaviors to preserve sidebar ordering and provide
feedback:
1. **Compaction preserves recency** — Idle compaction does not make a
workspace appear "recently used" in the sidebar. The
`computeRecencyFromMessages()` function calculates recency from the last
user message or last user-initiated compaction, explicitly filtering out
idle compaction requests.
2. **Sidebar shows status during compaction** — The compaction request
includes `displayStatus` in metadata, which the
`StreamingMessageAggregator` reads to show "Idle Compacting..." in the
sidebar. Status clears when the `idleCompacted: true` summary message
arrives.
## Eligibility Checks
A workspace is eligible for idle compaction when:
- Has at least one message
- Idle time ≥ configured threshold (based on
`computeRecencyFromMessages`)
- Not currently streaming
- Not already compacted (last message is not a compaction summary)
- Last message is not from user (not awaiting a response)
## Visual Indicators
- Regular compaction badge: `📦 compacted`
- Idle compaction badge: `💤📦 idle-compacted`
## Architecture
```
Backend (hourly check) Frontend
────────────────────── ────────
IdleCompactionService.checkAllWorkspaces()
│
├─► checkEligibility()
│
└─► emitIdleCompactionNeeded(workspaceId)
│
▼
WorkspaceService → session stream
│
══════════════════════════════════════════════►
│
useIdleCompactionHandler hook ◄─┘
│
▼
executeCompaction({ source: "idle-compaction" })
│
│ Adds: model, gateway, thinkingLevel
│ (from localStorage)
▼
CompactionHandler.performCompaction()
│
└─► recency = computeRecencyFromMessages()
(preserves original timestamp)
```
### Why the frontend relay?
The backend cannot currently construct compaction requests because it
lacks access to user preferences:
- **Preferred compaction model** — stored in localStorage
- **Gateway routing** — which models should use the mux gateway vs
direct API
These preferences live in the browser and are assembled by
`buildSendMessageOptions()` when sending any message. Until we persist
these preferences to backend-accessible storage, the frontend must relay
compaction requests.
## Known Limitation
**Requires frontend to be running.** Since compaction requests are
relayed through the frontend, a standalone `mux server` instance cannot
perform idle compaction. This will be resolved once user preferences are
persisted to the backend.
## Future: Backend-Only Architecture
Once compaction preferences are persisted to backend-accessible storage
(per-workspace or per-project config file), the entire flow can happen
on the backend:
```
Backend (hourly check)
──────────────────────
IdleCompactionService.checkAllWorkspaces()
│
├─► checkEligibility()
│
└─► WorkspaceService.sendMessage() directly
│
│ Reads: model, gateway, thinkingLevel
│ (from persisted config)
▼
CompactionHandler.performCompaction()
```
**Migration path:**
1. Persist compaction preferences (model, gateway, thinking level) to
backend config
2. Have `IdleCompactionService` call `WorkspaceService.sendMessage()`
directly
3. Remove `useIdleCompactionHandler` hook (~40 lines) and
`idle-compaction-needed` event type
This will enable standalone `mux server` deployments to perform
auto-compaction without any frontend involvement.
---
_Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking:
`high`_1 parent e793c89 commit 01e48c6
File tree
35 files changed
+1536
-50
lines changed- .storybook/mocks
- src
- browser
- components
- ChatInput
- Messages
- Settings/sections
- hooks
- stores
- stories
- utils
- messages
- slashCommands
- common
- constants
- orpc/schemas
- types
- utils
- node
- orpc
- services
35 files changed
+1536
-50
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
191 | 195 | | |
192 | 196 | | |
193 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
202 | 203 | | |
203 | 204 | | |
204 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
987 | 1039 | | |
988 | 1040 | | |
989 | 1041 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
119 | 122 | | |
120 | 123 | | |
121 | 124 | | |
| |||
Lines changed: 94 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
198 | 209 | | |
199 | 210 | | |
200 | 211 | | |
| |||
206 | 217 | | |
207 | 218 | | |
208 | 219 | | |
209 | | - | |
210 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 | | |
212 | 227 | | |
213 | | - | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
380 | 395 | | |
381 | 396 | | |
382 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
383 | 421 | | |
384 | 422 | | |
385 | 423 | | |
| |||
417 | 455 | | |
418 | 456 | | |
419 | 457 | | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
420 | 510 | | |
421 | | - | |
| 511 | + | |
422 | 512 | | |
423 | 513 | | |
424 | 514 | | |
| |||
0 commit comments