Opus flagged a tool-card-frame-loss edge in the segment-only swap: the premise of #3877 is that the live DOM can be AHEAD of S.messages, so a tool/worklog group can land in the live turn between the last throttled persist and a mid-stream rebuild. The rebuild (built from the lagging S.messages) would then lack that group, and a segment-only swap would drop it for a frame (empirically confirmed: a live-only tool card present before the rebuild was absent after). Fix: count structural blocks ([data-live-assistant=1] + tool/worklog/thinking groups) on both turns. Segment-swap only when the rebuild is the structural SUPERSET (rebuilt >= preserved); otherwise restore the WHOLE preserved turn so live-only structure the user already saw never vanishes. Verified live: tool-card- ahead → whole-turn restore keeps the card + parser; single-segment tie → segment swap, parser connected; multi-live-segment tail → tail parser connected, both segments kept. Also addresses Opus's dead-code note implicitly — the dataset.sessionId stamp now matters on the whole-turn restore path (it's the branch that actually inserts the preserved wrapper). |
||
|---|---|---|
| .. | ||
| vendor | ||
| apple-touch-icon.png | ||
| boot.js | ||
| commands.js | ||
| favicon-32.png | ||
| favicon-192.png | ||
| favicon-512.png | ||
| favicon-512.svg | ||
| favicon.ico | ||
| favicon.svg | ||
| i18n.js | ||
| icons.js | ||
| index.html | ||
| login.js | ||
| manifest.json | ||
| messages.js | ||
| onboarding.js | ||
| outline.js | ||
| panels.js | ||
| pwa-startup.js | ||
| sessions.js | ||
| style.css | ||
| sw.js | ||
| terminal.js | ||
| ui.js | ||
| workspace.js | ||