Skip to content

fix(chat): report compaction instead of "waiting for model" during auto-compaction - #1008

Merged
agegr merged 3 commits into
mainfrom
claude/pr-963-compaction-status
Sep 30, 2026
Merged

agegr merged 3 commits into
mainfrom
claude/pr-963-compaction-status

Conversation

@agegr

@agegr agegr commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Replaces #963 by @jokinas. Their commit is kept as is. This branch adds one review fix on top and merges current main.

What

Auto-compaction starts in the middle of a turn, so two things went wrong while it ran:

  • The status line kept saying "Waiting for model…", because phaseLabel() only looked at the stale waiting_model phase.
  • The compaction control is gated on !isStreaming, so it never rendered. The user only had the generic Stop, which drops the whole turn.

Changes

  • From fix(chat): 自动压缩时显示压缩状态与「停止压缩」,而非「正在等待模型」 #963:
    • phaseLabel() moves to lib/chat-phase-label.ts and reports "Compacting…" while isCompacting is true.
    • The compaction control renders when !isStreaming || isCompacting, so Stop compaction (abort_compaction, which also aborts auto-compaction in the SDK) is reachable mid-turn.
  • Review fix: revert the edits to demo/components/ChatInput.tsx and demo/components/ChatWindow.tsx. The demo resolves @/lib against demo/lib, which has no chat-phase-label module, so those edits would break the Pages build on main. The demo is synced separately (demo/README.md).

Verification

tsc --noEmit, eslint, and the full unit suite (1328/1328) pass on this branch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ


Generated by Claude Code

jokinas and others added 3 commits September 24, 2026 19:43
…to-compaction

Auto-compaction can hold a turn for a while before the next token arrives.
While it runs, the chat UI reported "Waiting for model..." and offered only a
generic Stop button, which reads as a hang and gives the user the wrong control.

## What was wrong

`agentPhase` is set once when the prompt is sent (handleSend sets
`waiting_model`) and nobody updated it when compaction began. `phaseLabel()`
only looked at the phase, so it kept reporting the stale `waiting_model`.

The compaction control was worse. It is guarded by:

    {!isStreaming && onCompact && ( ... )}

Manual compaction starts from an idle session, so the button is already
rendered and simply flips to "Stop compaction" when `isCompacting` turns true.
Auto-compaction starts *mid-turn*, where `sessionBusy` is already true, so the
button never rendered at all and only the generic Stop remained. That guard
also contradicted the button's own `disabled={isStreaming && !isCompacting}`,
which only makes sense if the button is meant to be reachable while streaming.

Manual compaction therefore looked correct and auto-compaction did not, which
is why this went unnoticed.

## What changed

`phaseLabel()` takes `isCompacting` and returns the compaction label ahead of
the phase, so the status names the activity that is actually blocking the turn.
The render condition accepts a missing phase while compacting.

The compaction control guard becomes `(!isStreaming || isCompacting)`, so the
control is reachable mid-turn. Both actions stay available: "Stop compaction"
sends `abort_compaction` and skips the compaction so the turn continues, while
Stop sends `abort` and drops the whole turn. The now-unreachable
"streaming but not compacting" branches (disabled, dimmed opacity, not-allowed
cursor, the hover early-return) are removed rather than left as dead code.

`phaseLabel()` moved to lib/chat-phase-label.ts so it can be unit tested;
importing ChatWindow.tsx in a test pulls in next/image and the whole component
tree, so it cannot be loaded in node.

## Result

| | before | after |
|---|---|---|
| auto-compaction status | Waiting for model... | Compacting… |
| auto-compaction control | Stop | Stop compaction (+ Stop) |
| idle / manual | unchanged | unchanged |

## Verification

- tsc: 0 errors from this change (the 2 remaining are pre-existing SDK drift)
- lint: clean
- tests: 1308 pass / 4 fail — the same 4 fail on upstream main
- 5 new tests: phase label per phase, compaction precedence, and the control
  guard reaching mid-turn
The demo resolves @/lib against demo/lib, which has no chat-phase-label
module, so importing it there breaks the Pages build. The demo keeps its
own copies and is synced separately (demo/README.md).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ
@agegr
agegr merged commit 2e66e40 into main Sep 30, 2026
2 checks passed
@agegr
agegr deleted the claude/pr-963-compaction-status branch October 1, 2026 13:28
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…#907 agegr#941 agegr#946 agegr#961 agegr#968 agegr#969 agegr#1007 agegr#1008 agegr#1009 agegr#1010)

上游已把我们提前摘取的 agegr#884 / agegr#871 / agegr#996 / agegr#961 原样合并(agegr#961 逐字节相同),
agegr#967 与 agegr#963 由上游的 agegr#1009 / agegr#1008 接管。

冲突解决:
- demo/ 对齐上游 fe288c0,撤销 agegr#963 对 demo 的两处改动(`@/lib/chat-phase-label`
  在 demo/lib 下不存在,会打断 Pages 构建)。
- AGENTS.md:保留我们的 default-project 条目,open-folder 换成上游的
  open-in-explorer。
- MessageView.tsx / SessionSidebar.tsx / FileExplorer.tsx:以上游为准,
  DismissButton 采用上游的独立文件,保留我们的思考卡片与文件管理改动。
- SessionSidebar 移除引用已删函数的旧 agegr#951 工作区按钮(agegr#951 的其他入口另行收尾)。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
agegr#967 / agegr#963 已由上游的 agegr#1009 / agegr#1008 落地,agegr#961 上游原样合并(逐字节相同),
agegr#951 已收敛到上游的 agegr#907,agegr#960 上下游都拒绝——这些都与上游一致,按台账规则删行。
agegr#899 上游关闭但本地保留,状态注明为永久分叉。
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…to-compaction (agegr#1008)

* fix(chat): report compaction instead of "waiting for model" during auto-compaction

Auto-compaction can hold a turn for a while before the next token arrives.
While it runs, the chat UI reported "Waiting for model..." and offered only a
generic Stop button, which reads as a hang and gives the user the wrong control.

## What was wrong

`agentPhase` is set once when the prompt is sent (handleSend sets
`waiting_model`) and nobody updated it when compaction began. `phaseLabel()`
only looked at the phase, so it kept reporting the stale `waiting_model`.

The compaction control was worse. It is guarded by:

    {!isStreaming && onCompact && ( ... )}

Manual compaction starts from an idle session, so the button is already
rendered and simply flips to "Stop compaction" when `isCompacting` turns true.
Auto-compaction starts *mid-turn*, where `sessionBusy` is already true, so the
button never rendered at all and only the generic Stop remained. That guard
also contradicted the button's own `disabled={isStreaming && !isCompacting}`,
which only makes sense if the button is meant to be reachable while streaming.

Manual compaction therefore looked correct and auto-compaction did not, which
is why this went unnoticed.

## What changed

`phaseLabel()` takes `isCompacting` and returns the compaction label ahead of
the phase, so the status names the activity that is actually blocking the turn.
The render condition accepts a missing phase while compacting.

The compaction control guard becomes `(!isStreaming || isCompacting)`, so the
control is reachable mid-turn. Both actions stay available: "Stop compaction"
sends `abort_compaction` and skips the compaction so the turn continues, while
Stop sends `abort` and drops the whole turn. The now-unreachable
"streaming but not compacting" branches (disabled, dimmed opacity, not-allowed
cursor, the hover early-return) are removed rather than left as dead code.

`phaseLabel()` moved to lib/chat-phase-label.ts so it can be unit tested;
importing ChatWindow.tsx in a test pulls in next/image and the whole component
tree, so it cannot be loaded in node.

## Result

| | before | after |
|---|---|---|
| auto-compaction status | Waiting for model... | Compacting… |
| auto-compaction control | Stop | Stop compaction (+ Stop) |
| idle / manual | unchanged | unchanged |

## Verification

- tsc: 0 errors from this change (the 2 remaining are pre-existing SDK drift)
- lint: clean
- tests: 1308 pass / 4 fail — the same 4 fail on upstream main
- 5 new tests: phase label per phase, compaction precedence, and the control
  guard reaching mid-turn

* fix(demo): leave the demo copies of ChatInput/ChatWindow untouched

The demo resolves @/lib against demo/lib, which has no chat-phase-label
module, so importing it there breaks the Pages build. The demo keeps its
own copies and is synced separately (demo/README.md).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

---------

Co-authored-by: jokin <[email protected]>
Co-authored-by: Claude <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…to-compaction (agegr#1008)

* fix(chat): report compaction instead of "waiting for model" during auto-compaction

Auto-compaction can hold a turn for a while before the next token arrives.
While it runs, the chat UI reported "Waiting for model..." and offered only a
generic Stop button, which reads as a hang and gives the user the wrong control.

## What was wrong

`agentPhase` is set once when the prompt is sent (handleSend sets
`waiting_model`) and nobody updated it when compaction began. `phaseLabel()`
only looked at the phase, so it kept reporting the stale `waiting_model`.

The compaction control was worse. It is guarded by:

    {!isStreaming && onCompact && ( ... )}

Manual compaction starts from an idle session, so the button is already
rendered and simply flips to "Stop compaction" when `isCompacting` turns true.
Auto-compaction starts *mid-turn*, where `sessionBusy` is already true, so the
button never rendered at all and only the generic Stop remained. That guard
also contradicted the button's own `disabled={isStreaming && !isCompacting}`,
which only makes sense if the button is meant to be reachable while streaming.

Manual compaction therefore looked correct and auto-compaction did not, which
is why this went unnoticed.

## What changed

`phaseLabel()` takes `isCompacting` and returns the compaction label ahead of
the phase, so the status names the activity that is actually blocking the turn.
The render condition accepts a missing phase while compacting.

The compaction control guard becomes `(!isStreaming || isCompacting)`, so the
control is reachable mid-turn. Both actions stay available: "Stop compaction"
sends `abort_compaction` and skips the compaction so the turn continues, while
Stop sends `abort` and drops the whole turn. The now-unreachable
"streaming but not compacting" branches (disabled, dimmed opacity, not-allowed
cursor, the hover early-return) are removed rather than left as dead code.

`phaseLabel()` moved to lib/chat-phase-label.ts so it can be unit tested;
importing ChatWindow.tsx in a test pulls in next/image and the whole component
tree, so it cannot be loaded in node.

## Result

| | before | after |
|---|---|---|
| auto-compaction status | Waiting for model... | Compacting… |
| auto-compaction control | Stop | Stop compaction (+ Stop) |
| idle / manual | unchanged | unchanged |

## Verification

- tsc: 0 errors from this change (the 2 remaining are pre-existing SDK drift)
- lint: clean
- tests: 1308 pass / 4 fail — the same 4 fail on upstream main
- 5 new tests: phase label per phase, compaction precedence, and the control
  guard reaching mid-turn

* fix(demo): leave the demo copies of ChatInput/ChatWindow untouched

The demo resolves @/lib against demo/lib, which has no chat-phase-label
module, so importing it there breaks the Pages build. The demo keeps its
own copies and is synced separately (demo/README.md).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q8e4GL1QSNFveKtnFfP3FZ

---------

Co-authored-by: jokin <[email protected]>
Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants