Commit 48c25c0
authored
🤖 Fix auto-compact-continue regression (#417)
## Problem
Auto-compact-continue feature stopped working after compaction
completed. The hook that automatically sends follow-up messages wasn't
detecting the compacted state, breaking conversation flow in
long-running sessions.
## Root Cause
The `useAutoCompactContinue` hook checked `messages[0]` for the
`isCompacted` flag, but `messages[0]` is the `workspace-init` UI
metadata message, not the compacted assistant message. The check always
failed because workspace-init has no `isCompacted` flag.
**What the code was doing:**
```typescript
const isSingleCompacted =
state.messages.length === 1 && // ❌ Includes workspace-init
state.messages[0]?.type === "assistant" && // ❌ False - it's workspace-init
state.messages[0].isCompacted === true;
```
**State after compaction:**
- `messages[0]` = workspace-init (UI metadata)
- `messages[1]` = compacted assistant message ✅
## Solution
Filter out `workspace-init` messages before checking compaction state:
```typescript
// Filter to conversation messages only
const cmuxMessages = state.messages.filter((m) => m.type !== "workspace-init");
const isSingleCompacted =
cmuxMessages.length === 1 && // ✅ Only conversation messages
cmuxMessages[0]?.type === "assistant" &&
cmuxMessages[0].isCompacted === true;
```
## Additional Improvements
**Type Safety**: Added `isCmuxMessage()` type guard following existing
pattern. Replaced manual `"role" in data && !("type" in data)` checks
that were causing regressions.
**Better Logging**: Added workspace `name` to `WorkspaceState` for
debugging. Removed verbose debug logs after fix confirmed.
## Testing
- All 763 tests passing ✅
- Manual verification: Compaction now triggers auto-continue as expected
_Generated with `cmux`_1 parent 110962b commit 48c25c0
File tree
4 files changed
+39
-27
lines changed- src
- hooks
- stores
- types
- utils/messages
4 files changed
+39
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
44 | 46 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | 79 | | |
83 | 80 | | |
84 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
| |||
335 | 337 | | |
336 | 338 | | |
337 | 339 | | |
| 340 | + | |
338 | 341 | | |
339 | 342 | | |
| 343 | + | |
340 | 344 | | |
341 | 345 | | |
342 | 346 | | |
| |||
730 | 734 | | |
731 | 735 | | |
732 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
733 | 740 | | |
734 | 741 | | |
735 | 742 | | |
| |||
958 | 965 | | |
959 | 966 | | |
960 | 967 | | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
976 | 987 | | |
977 | | - | |
978 | 988 | | |
979 | 989 | | |
980 | 990 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
152 | 157 | | |
153 | 158 | | |
154 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
| |||
0 commit comments