unbridled-41 opened a new pull request, #5070:
URL: https://github.com/apache/rocketmq-dashboard/pull/5070

   ## Problem
   
   The AI history modal (会话历史) keeps a ticked row after the row has left the 
visible list, so the batch delete acts on a conversation the operator can no 
longer see.
   
   `ConversationListPanel` owns `selectedRowKeys` 
(`ConversationListModal.tsx:170`) and only ever prunes the keys whose delete 
failed (`:224`), while the toolbar's destructive button is rendered on the 
selection alone (`:427`), confirming with `remove(selectedRowKeys.map(Number))` 
(`:434`) — and antd renders the checkbox column for the rows it is given 
(`rowSelection={{ selectedRowKeys, onChange: setSelectedRowKeys }}`, `:483`).
   
   Four ways a row leaves the visible set, all of which used to keep its tick:
   
   | the row leaves because | was the tick dropped? |
   |---|---|
   | the page changes (`pagination.onChange: list.setPage`, `:491`) | no |
   | the search changes (`onSearch`, `:411`) | no |
   | the active/archived scope changes (`Segmented.onChange`, `:416`) | no |
   | the row is archived (or unarchived) out of the scope (`toggleArchive` → 
`reload()`) | no |
   
   Concretely: tick row A on page 1, click page 2. Page 2 shows nothing ticked, 
but the toolbar still reads `删除 (1)`; confirming it issues `DELETE 
/api/ai/conversations/{A}` for a row on another page. The delete is a hard 
delete — it stops any active run, clears three tables and unlinks the agent 
workspace. Same for a ticked row that is then archived: it disappears from the 
table while the toolbar keeps offering to delete it.
   
   The component's own comment two lines above that button states the property 
the code was breaking: "the checkbox column antd renders selects the current 
page only — so the two never disagree about what 'all' means" (`:424-426`).
   
   ## Evidence
   
   Pre-fix, on base `a562601d`, with the three page/search/scope tests in place 
and only `ConversationListModal.tsx` at its base revision (the fourth test was 
written afterwards, when the audit below found the archive path):
   
   ```
   $ cd web && npx vitest run 
src/pages/ai/components/__tests__/ConversationListModal.test.tsx
    × dropsTheSelectionWhenThePageChangesTest
    × dropsTheSelectionWhenTheSearchChangesTest
    × dropsTheSelectionWhenTheScopeChangesTest
    Test Files  1 failed (1)
         Tests  3 failed | 19 passed (22)
   
   FAIL  … > dropsTheSelectionWhenThePageChangesTest
   Error: expect(element).not.toBeInTheDocument()
   expected document not to contain element, found <button
     class="ant-btn … ant-btn-dangerous …"
     data-testid="ai-conversation-selected-delete"
     type="button"><span>删除 (1)
   ```
   
   The fourth path needed the first commit to be in place to be visible at all 
(that commit clears the other three), so it is demonstrated against `ba0e28c7` 
— the branch with only the page/search/scope clearing — with the same test:
   
   ```
   $ cd web && npx vitest run 
src/pages/ai/components/__tests__/ConversationListModal.test.tsx \
         -t dropsTheSelectionWhenARowIsArchivedOutOfTheListTest
   FAIL  … > dropsTheSelectionWhenARowIsArchivedOutOfTheListTest
   Error: expect(element).not.toBeInTheDocument()
   expected document not to contain element, found <button
     class="ant-btn … ant-btn-dangerous …"
     data-testid="ai-conversation-selected-delete"
     type="button"><span>删除 (1)</span>
   ```
   
   Reachability is a plain user path on `/ai` → 历史: tick a row, then page, 
search, switch to 已归档, or archive the ticked row itself, and press the red 
button.
   
   ## Root cause
   
   The selection survived every change of what the list shows. The panel 
cleared it after a delete and for the conversation it knows left the list, but 
the four paths above — the three query-identity setters and the archive 
mutation that removes the row — did not.
   
   ## Fix
   
   `clearSelection` is called from the three scope setters, and `toggleArchive` 
drops just the archived row's key on success (commits `ba0e28c7` and 
`8e6657d8`), mirroring the merged fix for the same defect class on the topic 
and consumer group lists (commit `1172d859`, "#4473 clear hidden resource 
selections", issue #4465). Dropping only that one key on archive is deliberate: 
the operator's other ticks still refer to rows that are on screen, so they stay.
   
   ## Score
   
   `PRIORITY = 72` (impact 30: a hard delete of conversations the operator 
cannot see, irreversible and stopping a running agent run; scope 12: one page's 
modal, but every user of the AI console; reproducibility 18: the four tests 
decide it deterministically; maintenance value 12: the same defect class was 
already fixed twice in this repository, and the file's own comment pins the 
invariant).
   `FIX_CONFIDENCE = 88`.
   
   ## Tests
   
   ```
   $ cd web && npx vitest run 
src/pages/ai/components/__tests__/ConversationListModal.test.tsx   # post-fix
    ✓ src/pages/ai/components/__tests__/ConversationListModal.test.tsx (23 
tests)
    Test Files  1 passed (1)
         Tests  23 passed (23)
   
   $ cd web && npx tsc --noEmit -p tsconfig.json      # no output, exit 0
   $ cd web && npx eslint src/pages/ai/components/ConversationListModal.tsx \
         src/pages/ai/components/__tests__/ConversationListModal.test.tsx       
   # exit 0
   ```
   
   Four tests, one per path in the table above, each asserting both that the 
toolbar button is gone and that the new page's row checkbox is unticked — so 
every write path the fix touches is asserted rather than one representative. 
The two pre-fix runs quoted under Evidence cover all four.
   
   ## Risk
   
   Low. The only behaviour change is that a selection does not outlive the rows 
it refers to, which is what the button's own copy ("删除本页全部 N 条会话?" / "删除 (N)") 
already implies. The after-delete pruning is untouched, so "keeps the rows 
whose delete failed selected" still holds (its test passes unchanged), and 
archiving keeps the *other* ticks. No API, hook or payload change.
   
   ## Dedup
   
   - `gh search issues --repo apache/rocketmq-dashboard "clear hidden resource 
selections"` → #4465 (closed, Topic/Consumer), #2427/#2428 (closed, instance 
list); `gh search prs` → #4473/#2433 (merged, 
`pages/instance/{topic,consumer}.tsx` only), #4471 (closed).
   - `gh search prs "conversation list selection"`, `"delete selected 
conversations"` → no results.
   - `grep -F ConversationListModal /tmp/open_pr_files.txt 
/tmp/frun1na_files.txt /tmp/my_open_pr_files.txt` (the file lists of all 231 
open PRs) → no match.
   - `git log --oneline a562601d -- 
web/src/pages/ai/components/ConversationListModal.tsx` → `1ef5d860` (console 
polish) and `5b761df8` (introduction); neither touches the selection.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to