fix(rag): stop the per-run blocks from folding — the container is the one disclosure
Build and Push Containers / build-and-push-app (push) Successful in 1m43s
Build and Push Containers / build-and-push-db (push) Successful in 15s

The owner refinement (2026-10-06): the per-run thinking and tool-call
blocks inside the Reasoning bubble were individually collapsible
details elements — a fold inside the fold. A tool frame closed the
previous thinking block, so the visible thinking vanished mid-turn;
and the pinned-tail follow died on the append of every run after the
first (the pin was captured AFTER the new block's height growth
contaminated the 32px reading).

- app.js: the in-container runs are now plain divs —
  createThinkingRunEl (div.thinking + static .thinking-summary label +
  .thinking-text) and createToolRunEl (div.tool-calls-disclosure +
  static .tool-calls-summary label + the .tool-calls list); they never
  open or fold (the container is the ONE open/fold control, open
  through the turn, folded at settle — unchanged); the pin capture
  moves BEFORE ensureThinkingRun/ensureToolRun append (plus the
  first-frame edge: no container yet -> always pinned);
  closeCurrentRun just ends the run; closeAllRuns stays the defensive
  legacy guard; restoreTimeline/addSegments (shared.js) use the div
  builders; the legacy no-segments restore path keeps the old
  details-based blocks byte-identical
- styles.css: the in-container runs are distinct by label + rail
  (brand-ink Thinking label on a brand-soft rail; accent-ink
  Tool call(s) (N) label on a neutral rail); the interactive
  treatment (cursor + chevron) is scoped to the legacy <summary>; the
  inner windows stay disabled (the container's .reasoning-body is the
  ONE live scroll surface)
- unit + E2E: the D5-refinement contract is pinned — one
  details.reasoning disclosure, per-run blocks as plain divs, zero
  nested <details> inside the container, the container as the only
  open/fold control, the .reasoning-body window auto-follows the
  tail while streaming

unit+integration 3738 passed (coverage 99%), ruff + pyright clean, all
five affected E2E suites pass in isolation (reasoning_bubble 6,
thinking_timeline 6, thinking_display 5, thinking_scroll 8,
tool_call_compact 4), verified live: the follow holds through a long
thinking stream, the tool-frame transition, and the second thinking
run; restore renders the div structure without client-side errors

LLM-Generated: true
This commit is contained in:
2026-10-06 14:44:41 -04:00
parent 051f62deb7
commit 690fd98036
15 changed files with 941 additions and 609 deletions
+74 -54
View File
@@ -11,7 +11,7 @@ regression test (scenario 4) — the deterministic mock's ``think out loud``
trigger (mock_llm.py) keeps all five scenarios reproducible.
Test → story mapping (Playwright Mapping Rule):
1. ``test_thinking_block_streams_open_then_collapses``
1. ``test_thinking_block_streams_in_the_open_container``
2. ``test_thinking_toggle_after_done``
3. ``test_thinking_restored_after_reload``
4. ``test_no_thinking_block_without_trigger``
@@ -123,12 +123,15 @@ def send_and_wait(page: Page, question: str) -> None:
# ---------------------------------------------------------------------------
# 1. Streaming: the block attaches OPEN at the first thinking event, then
# auto-collapses when the first answer token lands
# 1. Streaming: the block attaches at the first thinking event (nested
# in the open reasoning container — D1); the container STAYS OPEN
# through the first answer token (D2) and the block is ALWAYS
# visible (the D5 refinement — a plain div, not collapsible); the
# container folds at done.
# ---------------------------------------------------------------------------
def test_thinking_block_streams_open_then_collapses(
def test_thinking_block_streams_in_the_open_container(
page: Page, app_url: str, seeded_kb: None
) -> None:
page.set_default_timeout(30_000)
@@ -137,25 +140,35 @@ def test_thinking_block_streams_open_then_collapses(
page.evaluate("() => document.querySelector('#composer').requestSubmit()")
expect(page.locator(".msg.user .bubble").last).to_contain_text(THINK_QUESTION)
# The block attaches at the FIRST thinking event — before any answer
# token — and is created OPEN.
details = page.locator(".msg.brain").last.locator("details.thinking")
details.wait_for(state="attached", timeout=10_000)
# The ~2 700-char thinking stream (≈4.5s, phase 21) keeps the block
# open right after attach — assert while it is still streaming.
expect(details).to_have_attribute("open", "")
expect(details.locator(".thinking-text")).not_to_have_text("")
# The block attaches at the FIRST thinking event — before any
# answer token — nested in the container created OPEN (D1).
block = page.locator(".msg.brain").last.locator("div.thinking")
block.wait_for(state="attached", timeout=10_000)
container = page.locator(".msg.brain").last.locator("details.reasoning")
expect(container).to_have_attribute("open", "")
# The ~2 700-char thinking stream (≈4.5s, phase 21) keeps the
# container open right after attach — assert while it is still
# streaming (the D5 refinement: the container is the ONE open
# disclosure — zero <details> inside it).
expect(container).to_have_attribute("open", "")
expect(
page.locator(".msg.brain").last.locator("details.reasoning details")
).to_have_count(0)
expect(block.locator(".thinking-text")).not_to_have_text("")
# First answer token: the block auto-collapses and stays closed.
# First answer token: the container STAYS OPEN (D2 — the mid-round
# delta does not fold it; only done / stop / the failed-turn
# funnel do).
bubble = page.locator(".msg.brain .bubble").last
expect(bubble).not_to_have_text("", timeout=30_000)
expect(details).not_to_have_attribute("open")
expect(container).to_have_attribute("open", "")
# Settled: full scratchpad, grounded mock answer, ZERO citation
# chips (phase 119, LOCKED A1 — the zero-read turn chips nothing;
# the retired phase-118 A4 union is gone), and the re-enabled send
# button.
expect(details.locator(".thinking-text")).to_contain_text(THINKING_FRAGMENT)
# Settled: the container FOLDS (done); the block is not
# collapsible (a div — the D5 refinement); the full scratchpad is
# intact, the grounded mock answer is present, ZERO citation chips
# (phase 119, LOCKED A1), and the re-enabled send button.
expect(container).not_to_have_attribute("open")
expect(block.locator(".thinking-text")).to_contain_text(THINKING_FRAGMENT)
expect(bubble).to_contain_text(MOCK_ANSWER_MARKER)
expect(page.locator(".msg.brain .source-chip")).to_have_count(0)
expect(page.locator("#send-btn")).to_be_enabled()
@@ -163,13 +176,12 @@ def test_thinking_block_streams_open_then_collapses(
# ---------------------------------------------------------------------------
# 2. Toggle: after settle the block is closed; the summary re-opens it
# (a real keyboard-focusable control) and closes it again.
# Phase 161 (D2): at rest the run sits INSIDE the folded reasoning
# container — the container's summary is the at-rest focusable
# surface (native <details> nesting semantics: a closed details
# hides its content, so the inner summary is focusable only after
# the container opens).
# 2. Toggle: after settle the container is folded; its summary
# re-opens it (a real keyboard-focusable control) and closes it
# again. The D5 refinement (owner 2026-10-06): the inner run is a
# plain div — NOT collapsible — so the container's summary is the
# ONE toggle (the per-run "summary" click is gone; the block is
# always visible once the container opens).
# ---------------------------------------------------------------------------
@@ -179,12 +191,14 @@ def test_thinking_toggle_after_done(page: Page, app_url: str, seeded_kb: None) -
send_and_wait(page, THINK_QUESTION)
last = page.locator(".msg.brain").last
details = last.locator("details.thinking")
expect(details).to_have_count(1)
expect(details).not_to_have_attribute("open") # auto-collapsed at first token
block = last.locator("div.thinking")
expect(block).to_have_count(1)
# The D5 refinement: the inner run is not a <details> at all (zero
# <details> inside the container — the block is a plain div).
expect(last.locator("details.reasoning details")).to_have_count(0)
# Phase 161 (D2): the run nests in the reasoning container, which
# folds at done (the at-rest focusable surface is the container's
# summary — open it to reach the inner run's summary).
# summary — the ONE toggle).
container = last.locator("details.reasoning")
expect(container).to_have_count(1)
expect(container).not_to_have_attribute("open")
@@ -193,21 +207,18 @@ def test_thinking_toggle_after_done(page: Page, app_url: str, seeded_kb: None) -
container.locator("summary.reasoning-summary").click()
expect(container).to_have_attribute("open", "")
# The inner run's summary is a real, keyboard-focusable control.
details.locator("summary").focus()
assert page.evaluate("() => document.activeElement.tagName") == "SUMMARY"
# Open: the full scratchpad is visible.
details.locator("summary").click()
expect(details).to_have_attribute("open", "")
text_el = details.locator(".thinking-text")
# Open: the full scratchpad is visible — ONE toggle (the D5
# refinement — no second, per-run toggle; the block is always
# visible once the container opens).
text_el = block.locator(".thinking-text")
expect(text_el).to_be_visible()
expect(text_el).to_contain_text(THINKING_FRAGMENT)
expect(text_el).to_contain_text("nothing is invented")
# Closed again — user control in both directions.
details.locator("summary").click()
expect(details).not_to_have_attribute("open")
# Closed again — user control in both directions (the container's
# summary hides the always-visible block with it).
container.locator("summary.reasoning-summary").click()
expect(container).not_to_have_attribute("open")
expect(text_el).not_to_be_visible()
@@ -222,11 +233,12 @@ def test_thinking_restored_after_reload(page: Page, app_url: str, seeded_kb: Non
login(page, app_url, next="/")
send_and_wait(page, THINK_QUESTION)
# The live block is collapsed; capture what it shows and what the
# turn persisted (raw text, same as what was rendered).
details = page.locator(".msg.brain").last.locator("details.thinking")
expect(details).not_to_have_attribute("open")
captured = details.locator(".thinking-text").text_content()
# The live block is a plain div (the D5 refinement — always visible
# while the container is live-open); capture what it shows and what
# the turn persisted (raw text, same as what was rendered).
block = page.locator(".msg.brain").last.locator("div.thinking")
expect(block).to_have_count(1)
captured = block.locator(".thinking-text").text_content()
assert captured
# The persisted raw text is the same scratchpad (renderMarkdown turns
# the line breaks into <br>, which textContent drops — compare without
@@ -239,9 +251,15 @@ def test_thinking_restored_after_reload(page: Page, app_url: str, seeded_kb: Non
page.reload()
expect(page.locator("#empty-state")).to_be_hidden()
restored = page.locator(".msg.brain").last.locator("details.thinking")
restored = page.locator(".msg.brain").last.locator("div.thinking")
expect(restored).to_have_count(1)
expect(restored).not_to_have_attribute("open") # restored COLLAPSED
# Restored COLLAPSED — the at-rest fold is the container's (the
# D5 refinement — the inner block is not a <details> at all).
restored_wrap = page.locator(".msg.brain").last
expect(
restored_wrap.locator("details.reasoning")
).not_to_have_attribute("open")
expect(restored_wrap.locator("details.reasoning details")).to_have_count(0)
expect(restored.locator(".thinking-text")).to_have_text(captured)
# Answer bubble is intact after the restore (phase-14 restore path)
@@ -264,7 +282,7 @@ def test_no_thinking_block_without_trigger(page: Page, app_url: str, seeded_kb:
send_and_wait(page, PLAIN_QUESTION)
# No trigger → no thinking events → no block anywhere on the page.
expect(page.locator("details.thinking")).to_have_count(0)
expect(page.locator(".thinking")).to_have_count(0)
# The turn itself is complete and grounded, exactly as before phase
# 17 — with ZERO citation chips (phase 119, LOCKED A1: the zero-read
@@ -293,8 +311,10 @@ def test_thinking_with_deflection(page: Page, app_url: str, seeded_kb: None) ->
expect(chips.first).to_be_visible()
assert chips.count() >= 2
# And the thinking block came along, closed, with its scratchpad.
details = last.locator("details.thinking")
expect(details).to_have_count(1)
expect(details).not_to_have_attribute("open")
expect(details.locator(".thinking-text")).to_contain_text(THINKING_FRAGMENT)
# And the thinking block came along — a plain div (the D5
# refinement — not collapsible; the container is the ONE fold) —
# with its scratchpad.
block = last.locator("div.thinking")
expect(block).to_have_count(1)
expect(last.locator("details.reasoning details")).to_have_count(0)
expect(block.locator(".thinking-text")).to_contain_text(THINKING_FRAGMENT)