Files
ironclaw/tests
firat.sertgoz fbb904116c fix(web): prevent user messages from vanishing on thread switch (#2409) (#2498)
* fix(web): prevent user messages from vanishing during safety-pipeline window (#2409)

When loadHistory() re-renders the chat (thread switch, SSE reconnect,
page reload), user messages that haven't been persisted yet disappear
because the agent loop persists them after safety checks (100ms-1s
delay). This fix tracks pending messages client-side and re-injects
them into the DOM when loadHistory() doesn't find them in the DB yet.

- Add _pendingUserMessages Map with 60s TTL
- Record pending messages in sendMessage() before the fetch call
- Clear pending entries when SSE events confirm agent processing
- Re-inject non-persisted pending messages in loadHistory() fresh path
- Suppress welcome card when pending messages exist

Purely frontend fix — no backend changes, no safety pipeline bypass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* test(e2e): add Playwright tests for pending message persistence (#2409)

Six scenarios covering the frontend fix for disappearing user messages:
- User message visible immediately after send (optimistic display)
- Pending message survives SSE reconnect (re-injected by loadHistory)
- Pending messages cleared after agent response (no stale entries)
- No duplicates when DB already has the message
- Welcome card suppressed when pending messages exist
- Full round-trip message survives page reload (DB persistence)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(e2e): use domcontentloaded for reload test — SSE blocks networkidle

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): address review — remove SSE early-clear race, use frequency map for pending dedup (#2498)

Remove _pendingUserMessages.delete() from response/tool_started/stream_chunk
SSE handlers to prevent race condition when user sends multiple messages
in quick succession. Replace Set-based dedup in loadHistory with a
frequency map so duplicate-content messages ("ok", "ok") are tracked
correctly. Simplify welcome-card guard using hoisted freshPending.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(web): clear pending entry on turn completion — address henrypark133 review (#2498)

* fix(web): address review — remove pending on send fail, Map for dedup, improve reconnect test (#2498)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: remove unused imports in pending message test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* ci: retrigger checks against updated staging base

* fix(web): preserve images in pending messages, harden tests (#2498)

Address remaining review feedback:
- Capture attached image data URLs in optimistic display and in the
  _pendingUserMessages entry so a thread switch / SSE reconnect re-injects
  thumbnails alongside the text instead of just an "(images attached)"
  placeholder.
- Rewrite the SSE-reconnect test to drive the real production path: stub
  apiFetch so /api/chat/send hangs, send via the real UI, force a
  reconnect, and assert the message survives — instead of manually
  pre-populating the pending map.
- Add coverage for the .catch() cleanup branch in sendMessage so a
  rejected /api/chat/send leaves _pendingUserMessages clean.
- Add a FIFO-assumption comment on the response-handler shift() and
  drop the leading underscore on the function-local `pending` (the
  underscore convention in this file is for module-level state).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Illia Polosukhin <ilblackdragon@gmail.com>
2026-04-18 01:26:35 +09:00
..