Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/cli/src/ui/utils/todoSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ function makeGeminiHistoryItem(text: string, id: number): HistoryItem {
};
}

function makeUserHistoryItem(text: string, id: number): HistoryItem {
return {
type: 'user',
id,
text,
};
}

describe('getStickyTodos', () => {
it('returns the latest todo snapshot from history', () => {
const history = [
Expand Down Expand Up @@ -211,6 +219,38 @@ describe('getStickyTodos', () => {
expect(getStickyTodos(history, [])).toBeNull();
});

it('hides sticky todos when a new user message starts after the snapshot', () => {
// Simulates: turn N creates todos → turn N ends → turn N+1 user message
// The stale todo list from turn N should not resurface.
const history = [
makeUserHistoryItem('Do the tasks', 1),
makeTodoToolGroup('task from turn N', 2),
makeGeminiHistoryItem('Working on it', 3),
makeGeminiHistoryItem('Done with turn N', 4),
makeUserHistoryItem('/stats', 5),
] as HistoryItem[];

expect(getStickyTodos(history, [])).toBeNull();
});

it('shows sticky todos when no new user message follows the snapshot', () => {
// Normal case: todo snapshot is from the current turn.
const history = [
makeUserHistoryItem('Do the tasks', 1),
makeTodoToolGroup('current task', 2),
makeGeminiHistoryItem('Working on it', 3),
makeGeminiHistoryItem('Still working', 4),
] as HistoryItem[];

expect(getStickyTodos(history, [])).toEqual([
{
id: 'todo-current task',
content: 'current task',
status: 'pending',
},
]);
});

it('keeps sticky todos hidden for a completed pending snapshot', () => {
const history = [
makeTodoToolGroup('older history task', 1),
Expand Down
23 changes: 23 additions & 0 deletions packages/cli/src/ui/utils/todoSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ function isRecentHistoryTodoSnapshot(
return historyItemsAfterSnapshot < MIN_HISTORY_ITEMS_AFTER_TODO_BEFORE_STICKY;
}

/**
* Returns true when a user message exists after the given index, meaning the
* todo snapshot belongs to a previous turn. The sticky panel should not
* resurface stale todos from an earlier turn when the user starts a new one.
*/
function hasUserMessageAfter(
items: readonly HistoryLikeItem[],
afterIndex: number,
): boolean {
for (let i = afterIndex + 1; i < items.length; i++) {
if (items[i].type === 'user') {
return true;
}
Comment on lines +133 to +135

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful read — declining this one, because the suggested guard would regress the exact case this PR fixes.

Verified at the reviewed commit: local slash commands keep sentToModel: false (slashCommandProcessor.ts:857-860 initializes it false and only flips it to true when the command yields a submit_prompt; UI-only commands like /stats, /about, /exit never do), while regular user messages leave it undefined (types.ts:124-131). Steers are also false (useGeminiStream.ts:2576-2582). So sentToModel !== false cannot separate a mid-turn steer from a local slash command — and applying it would stop /stats (the command in the #7061 screenshot) from hiding the stale panel, re-breaking #7061. This lines up with @wenshao's independent E2E on 090ad18, which confirmed /stats triggers the boundary today.

The sentToModel !== false pattern elsewhere answers "did this reach the model?" (rewind/telemetry/turn rendering); hasUserMessageAfter answers "did the user start any new interaction?", which intentionally includes local slash commands — so the omission is deliberate. The steer case is real but minor and self-healing (next todo_write re-snapshots), already accepted by the author and @wenshao; a precise fix needs streaming state in this pure function, out of scope here.

To make sure the naive guard can't be applied silently, I added a regression test (hides sticky todos when a local slash command starts after the snapshot) using a faithful sentToModel: false fixture — it passes now and fails if the guard is added.

中文说明

感谢细致的审查 —— 这一条予以拒绝,因为建议的判断条件会让本 PR 修复的场景重新回归。

已在被审查的 commit 上核实:本地斜杠命令保持 sentToModel: false(slashCommandProcessor.ts:857-860 初始化为 false,仅当命令产生 submit_prompt 时才改为 true;/stats、/about、/exit 等纯 UI 命令从不触发),而普通用户消息保持 undefined(types.ts:124-131)。Steer 同样是 false(useGeminiStream.ts:2576-2582)。因此 sentToModel !== false 无法区分轮内 steer 与本地斜杠命令 —— 应用它会导致 /stats(#7061 截图中的命令)不再隐藏过期面板,重新破坏 #7061。这与 @wenshao 在 090ad18 上的独立 E2E 验证一致:他确认当前 /stats 能触发边界。

其他地方的 sentToModel !== false 模式回答的是"这条是否发给了模型?"(rewind/telemetry/turn 渲染);而 hasUserMessageAfter 回答的是"用户是否开启了任何新交互?",这有意包含本地斜杠命令 —— 所以这里的省略是刻意的。Steer 场景确实存在但影响很小且可自愈(下一次 todo_write 重建快照),作者与 @wenshao 均已接受;精确修复需要在这个纯函数中引入 streaming 状态,超出本次范围。

为防止该朴素判断被悄悄应用,我新增了一个回归测试(hides sticky todos when a local slash command starts after the snapshot),使用忠实的 sentToModel: false fixture —— 当前通过,加上该判断后会失败。

}
return false;
}

export function getStickyTodos(
history: readonly HistoryItem[],
pendingHistoryItems: readonly HistoryItemWithoutId[],
Expand All @@ -143,6 +160,12 @@ export function getStickyTodos(
return null;
}

// If a new user message appeared after the todo snapshot, the snapshot
// belongs to a previous turn. Do not resurface stale todos.
if (hasUserMessageAfter(history, historySnapshot.itemIndex)) {
return null;
}

if (areAllTodosCompleted(historySnapshot.todos)) {
return null;
}
Expand Down
Loading