Commit d90a605
fix(#1298): preserve user message on cancel + persist activity-panel expand
Two distinct bugs reported by @YanTianlong-01 in #1298 against v0.50.240.
## Issue 2: Stop/Cancel deletes the user's typed message (data loss)
When a user clicked Stop while the agent was streaming, `cancel_stream()`
in `api/streaming.py` cleared `s.pending_user_message` before the streaming
thread had merged the user turn into `s.messages`. The session was saved
with neither the pending field nor a corresponding message — the user's
typed text was permanently lost from the session JSON, not just the
in-memory client copy. Reload didn't recover it.
The fix runs inside the existing post-cancel session lock and synthesizes
a user turn into `s.messages` from `pending_user_message` when the latest
user message isn't already that turn. Content-match guards against
double-append when the streaming thread won the race and merged before
cancel got the lock. Pending attachments are preserved.
## Issue 1: Activity panel auto-collapses while user is reading it
`ensureActivityGroup()` (`static/ui.js`) creates the live activity group
with `tool-call-group-collapsed` whenever it's missing, and
`finalizeThinkingCard()` force-adds that class on every tool boundary.
The user's manual expand state lives only on the DOM class list, so
every thinking → tool → thinking transition (which destroys and recreates
the group) wipes the expand and snaps the panel shut.
Adds a per-turn singleton `_liveActivityUserExpanded` that tracks the
user's last explicit toggle (set by an inline `_onLiveActivityToggle()`
hook in the summary button's onclick). `ensureActivityGroup()` consults
it when re-creating the live group; `finalizeThinkingCard()` skips the
force-collapse when the user has explicitly expanded.
`clearLiveToolCards()` resets the tracker between turns so the next turn
starts at the default collapsed state.
## Tests
- `tests/test_issue1298_cancel_and_activity.py` — 9 tests:
- 4 server-side: cancel synthesises user message, doesn't double-append,
preserves attachments, no-ops when there's no pending
- 5 client-side: source-level guards on `_liveActivityUserExpanded`,
`ensureActivityGroup`, `finalizeThinkingCard`, the inline onclick,
and `clearLiveToolCards`
All adjacent suites still pass (test_cancel_interrupt,
test_session_sidecar_repair, test_streaming_race_fix, test_regressions).
Closes #1298
Co-authored-by: YanTianlong-01 <[email protected]>1 parent 3f838fc commit d90a605
4 files changed
Lines changed: 419 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2576 | 2576 | | |
2577 | 2577 | | |
2578 | 2578 | | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
2579 | 2628 | | |
2580 | 2629 | | |
2581 | 2630 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2530 | 2530 | | |
2531 | 2531 | | |
2532 | 2532 | | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
2533 | 2557 | | |
2534 | 2558 | | |
2535 | 2559 | | |
| |||
2538 | 2562 | | |
2539 | 2563 | | |
2540 | 2564 | | |
2541 | | - | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
2542 | 2570 | | |
2543 | 2571 | | |
2544 | 2572 | | |
2545 | 2573 | | |
2546 | | - | |
| 2574 | + | |
2547 | 2575 | | |
2548 | 2576 | | |
2549 | 2577 | | |
| |||
3462 | 3490 | | |
3463 | 3491 | | |
3464 | 3492 | | |
| 3493 | + | |
| 3494 | + | |
| 3495 | + | |
3465 | 3496 | | |
3466 | 3497 | | |
3467 | 3498 | | |
| |||
4141 | 4172 | | |
4142 | 4173 | | |
4143 | 4174 | | |
4144 | | - | |
4145 | | - | |
4146 | | - | |
| 4175 | + | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
4147 | 4184 | | |
4148 | 4185 | | |
4149 | 4186 | | |
| |||
0 commit comments