Skip to content
Closed
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
75 changes: 75 additions & 0 deletions packages/web-shell/client/components/MessageList.dom.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ vi.mock('./MessageItem', async () => {
assistantTurnFooterInfo,
sendFailed,
onRetrySend,
onEditUserMessage,
}: {
message: Message;
showAssistantActions?: boolean;
Expand All @@ -63,6 +64,7 @@ vi.mock('./MessageItem', async () => {
assistantTurnFooterInfo?: WebShellAssistantTurnFooterRenderInfo;
sendFailed?: boolean;
onRetrySend?: () => void;
onEditUserMessage?: () => void;
}) => {
if (message.role === 'tool_group') {
messageItemTestState.toolArrays.push(message.tools);
Expand Down Expand Up @@ -107,6 +109,17 @@ vi.mock('./MessageItem', async () => {
'data-testid': `disclosure-${message.id}`,
})
: null,
onEditUserMessage
? React.createElement(
'button',
{
'data-testid': `edit-${message.id}`,
onClick: onEditUserMessage,
type: 'button',
},
'edit',
)
: null,
showAssistantBranch
? React.createElement('button', {
'data-testid': `branch-${message.id}`,
Expand Down Expand Up @@ -353,6 +366,7 @@ function mount(
pendingApproval?: PermissionRequest | null;
failedPromptMessageId?: string;
onRetryFailedPrompt?: () => void;
onEditUserMessage?: (targetTurnIndex: number, content: string) => void;
} = {},
): HTMLElement {
const container = document.createElement('div');
Expand Down Expand Up @@ -392,6 +406,7 @@ function mount(
onCanScrollToBottomChange={opts.onCanScrollToBottomChange}
failedPromptMessageId={opts.failedPromptMessageId}
onRetryFailedPrompt={opts.onRetryFailedPrompt}
onEditUserMessage={opts.onEditUserMessage}
/>
</TranscriptRenderModeProvider>
</CompactModeContext.Provider>
Expand Down Expand Up @@ -6505,3 +6520,63 @@ describe('MessageList — turn collapse (DOM)', () => {
expect(parallelAgentsSummary(c)).toBeNull();
});
});

describe('user message edit affordance (issue #10385)', () => {
function clickEdit(container: HTMLElement, messageId: string): void {
const button = container.querySelector(`[data-testid="edit-${messageId}"]`);
expect(button).not.toBeNull();
act(() => {
(button as HTMLButtonElement).dispatchEvent(
new MouseEvent('click', { bubbles: true }),
);
});
}

it('does not offer editing while older history is unloaded', () => {
const onEditUserMessage = vi.fn();
// Session-global history has more user turns than the loaded window:
// only the last two user messages are rendered. The window-local ordinal
// of the last message (1) is not its session-global turn index, so the
// edit affordance must not be offered while the window is incomplete.
const c = mount([userMsg('u4'), asstMsg('a4'), userMsg('u5')], undefined, {
hasOlderHistory: true,
onLoadOlderHistory: async () => {},
onEditUserMessage,
});
expect(c.querySelector('[data-testid="edit-u5"]')).toBeNull();
expect(c.querySelector('[data-testid="edit-u4"]')).toBeNull();
expect(onEditUserMessage).not.toHaveBeenCalled();
});

it('does not offer editing when older history was dropped for window capacity', () => {
const onEditUserMessage = vi.fn();
const c = mount([userMsg('u4'), asstMsg('a4'), userMsg('u5')], undefined, {
historyCapacityReached: true,
onEditUserMessage,
});
expect(c.querySelector('[data-testid="edit-u5"]')).toBeNull();
expect(onEditUserMessage).not.toHaveBeenCalled();
});

it('offers editing only for the last user message when the window is complete', () => {
const onEditUserMessage = vi.fn();
const c = mount([userMsg('u1'), asstMsg('a1'), userMsg('u2')], undefined, {
onEditUserMessage,
});
expect(c.querySelector('[data-testid="edit-u1"]')).toBeNull();
clickEdit(c, 'u2');
expect(onEditUserMessage).toHaveBeenCalledTimes(1);
expect(onEditUserMessage).toHaveBeenCalledWith(1, 'q');
});

it('does not count user_shell echoes when numbering user turns', () => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed real at the reviewed head, but escalating instead of fixing in this pass — the correct fix exceeds the 3-file budget for this worker and needs a design decision.

Verified evidence:

  1. Snapshots skip local commands: Session.ts (~5232) places makeSnapshot after the slash-command/hook early returns, with a comment stating locally handled commands must not create phantom snapshots that desync the snapshot index.
  2. Echo path: echoLocalCommandIfIdle (App.tsx:7356; call sites 10498/10514 for /stats, /status, /about) → store.appendLocalUserMessage(text) with no meta → adapter renders role: 'user' (transcriptToMessages.ts:470-483 lifts meta.source when present) → counted by editableUserTurn (MessageList.tsx:2892, counts every role === 'user').
  3. /stats//status//about//context are absent from VSCODE_HIDDEN_SLASH_COMMANDS (EmbeddedApp.tsx:83-103).
  4. Rejected-send entrance confirmed: on a definite admission rejection the optimistic block persists with attachments stripped (actions.ts ~929-941) and no user.text.delta ever merges into it.

Design questions blocking a worker-pass fix:

  • Tagging surface spans ≥4 files: App.tsx echo wrapper, ChatPane.tsx direct echoes (/goal ~780, /context ~1054 — the latter is a toolbar button, not a rare path), the editableUserTurn producer in MessageList.tsx, plus tests.
  • Marker mechanism matters: appendTextDelta merges event meta into the existing block meta (existing.meta = { ...existing.meta, ...event.meta }), so tagging optimistic prompt blocks would survive daemon admission and wrongly skip admitted turns from numbering. Only never-dispatched blocks may be tagged, which argues for per-call-site tagging or an SDK-level local-origin flag (API change).
  • Semantics decision: skip-and-renumber vs fail-closed-while-present for the echo case, and how the rejected-send entrance should interact with the retry affordance.

Leaving unresolved for maintainer decision.

Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Re-assertion of the open R1-2 thread (PRRT_kwDOPB-92c6dRhRj) — same file, same echo-skew finding, unchanged at this head. The author already responded there (3884091068) and the fix is deliberately human-gated: per-call-site tagging vs. an SDK-level flag spans >3 files and needs a design call before code lands. Tracking continues in the original thread; this duplicate stays open but unactioned until that decision is made.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Same blocker as the original R1-2 thread (PRRT_kwDOPB-92c6dRhRj), where the author has already responded. The fix remains human-gated: tagging local-echo/rejected-send blocks and skipping them in the editableUserTurn producer is a >3-file design decision spanning the sdk-typescript transcript store (appendLocalUserTranscriptMessage), the client adapter, and the test suite. The branch is being actively revised by the PR team (head 14cfa47 merged today); keeping this open until that work lands. No code changes from our side this round.

const onEditUserMessage = vi.fn();
const c = mount(
[userMsg('u1'), userShellMsg('s1'), asstMsg('a1'), userMsg('u2')],
undefined,
{ onEditUserMessage },
);
clickEdit(c, 'u2');
expect(onEditUserMessage).toHaveBeenCalledWith(1, 'q');
});
});
11 changes: 11 additions & 0 deletions packages/web-shell/client/components/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5437,6 +5437,15 @@ export const MessageList = memo(
onEditUserMessage={
onEditUserMessage &&
!isResponding &&
// Rewind snapshots are indexed session-globally, but the
// rendered transcript is a capped/paginated window. While
// older history is still unloaded (hasOlderHistory) or was
// dropped for window capacity (historyCapacityReached), the
// window-local user-turn ordinal is not the session-global
// turn index, so offering edit here would rewind to the
// wrong snapshot (or none at all). Fail closed (#10385).
!hasOlderHistory &&
!historyCapacityReached &&
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
displayItem.message.role === 'user' &&
editableUserContent !== undefined &&
displayItem.message.id === editableUserTurn.lastId
Expand Down Expand Up @@ -5512,6 +5521,8 @@ export const MessageList = memo(
onInsightReportOpen,
onEditUserMessage,
editableUserTurn,
hasOlderHistory,
historyCapacityReached,
Comment thread
yiliang114 marked this conversation as resolved.
Resolved
generateContent,
headerOffset,
visibleItems,
Expand Down
Loading