A form's handler answers its own request, and a finished reply is finished
Two regressions, one of them much older than it looked. htmx events bubble, and the composer's form declares `hx-on::after-request` so it can clear itself after sending. Six things inside that form make requests -- the two scope switches, "ask me about these again", the agent mode select, the effort select, and the jobs chip -- and every one of their afterRequest events was reaching that handler. So changing the mode, or the effort, or toggling a tool called `this.reset()` on a composer somebody was typing in and dragged the view to the bottom. That has been true for as long as those controls have existed. The jobs chip did not introduce it; it polls, so it made it happen every five seconds, and that is the only reason it was ever noticed. `event.target === this` is the whole fix, and it is what the attribute always meant. Moving the chip out of the form would have left the other five. The second: `steps.for_message` marked its trailing prose step as still being written, so every finished reply ending in prose carried `msg__body--live` and blinked a caret at the reader for ever. One flag was doing two jobs -- emit the tail, and mark it live -- and a stored reply wants the first without the second. They are separate arguments now. Note what the existing test for that did: it asserted the caret was on the *right* step, through `for_message`, and passed. It never asked whether a finished reply should have one at all. It is driven through the live path now, and the stored path has its own assertion. The composer handler is driven under a DOM stub -- extract the body from the template, fire the event from a descendant and from the form -- because a source assertion can only say the guard is present, not what it does. Checked against the bug before being kept: without the guard the stub reports the text wiped and the thread scrolled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+56
-10
@@ -103,16 +103,20 @@ def test_thinking_is_sliced_per_round_and_the_column_stays_whole():
|
||||
|
||||
def test_only_the_trailing_prose_is_marked_live():
|
||||
"""`--live` draws the caret, and a caret after every paragraph that happened
|
||||
to precede a tool call is not where the reply is being written."""
|
||||
built = steps.for_message(
|
||||
_message(
|
||||
content="before after",
|
||||
events=[{"name": "a"}],
|
||||
marks=[{"round": 0, "thinking_to": 0, "text_to": 6, "tools_to": 1}],
|
||||
)
|
||||
to precede a tool call is not where the reply is being written.
|
||||
|
||||
Driven through the *live* path deliberately. This used to go through
|
||||
`for_message` and pass, which is precisely how a stored reply came to blink
|
||||
a cursor for ever: the test asserted the caret was in the right place
|
||||
without ever asking whether it should be there at all.
|
||||
"""
|
||||
generation = _generation(
|
||||
content=["before after"],
|
||||
tool_events=[{"name": "a"}],
|
||||
steps=[{"round": 0, "thinking_to": 0, "text_to": 6, "tools_to": 1}],
|
||||
)
|
||||
|
||||
assert [s.open for s in built if s.kind == "text"] == [False, True]
|
||||
assert [s.open for s in _live_steps(generation) if s.kind == "text"] == [False, True]
|
||||
|
||||
|
||||
def test_a_step_with_nothing_in_it_produces_nothing():
|
||||
@@ -189,8 +193,7 @@ def test_a_fence_left_open_is_closed_and_reopened_around_the_tool_call():
|
||||
)
|
||||
)
|
||||
|
||||
first = next(s for s in built if s.kind == "text" and not s.open)
|
||||
last = next(s for s in built if s.kind == "text" and s.open)
|
||||
first, last = (s for s in built if s.kind == "text")
|
||||
# `code-block`, not the literal source: the fence renderer highlights, so
|
||||
# `x = 1` comes back as a run of spans.
|
||||
assert "code-block" in first.html
|
||||
@@ -300,3 +303,46 @@ def test_a_reply_with_no_marks_has_everything_in_its_tail():
|
||||
generation = _generation(content=["all of it"], reasoning=["thinking"])
|
||||
|
||||
assert steps.tail(generation) == ("thinking", "all of it")
|
||||
|
||||
|
||||
# --- Finished means finished ---------------------------------------------------
|
||||
def test_a_stored_reply_marks_nothing_as_still_being_written():
|
||||
"""`msg__body--live` draws the blinking caret. `include_open` used to do two
|
||||
jobs -- emit the trailing step, and mark it live -- so every finished reply
|
||||
ending in prose blinked a cursor at the reader for ever."""
|
||||
built = steps.for_message(
|
||||
_message(
|
||||
content="before after",
|
||||
events=[{"name": "a"}],
|
||||
marks=[{"round": 0, "thinking_to": 0, "text_to": 6, "tools_to": 1}],
|
||||
)
|
||||
)
|
||||
|
||||
assert [s.open for s in built] == [False] * len(built)
|
||||
|
||||
|
||||
def test_a_stored_reply_with_no_marks_marks_nothing_either():
|
||||
"""The compatibility branch had its own copy of the same flag, so every row
|
||||
written before the marks existed blinked too -- which is most of them."""
|
||||
built = steps.for_message(_message(content="An older answer."))
|
||||
|
||||
assert [s.open for s in built] == [False]
|
||||
|
||||
|
||||
def test_a_running_reply_still_marks_its_tail():
|
||||
"""The other half: the caret has to be somewhere while the reply is being
|
||||
written, or there is no sign it is still going."""
|
||||
generation = _generation(content=["still going"])
|
||||
|
||||
assert [s.open for s in _live_steps(generation)] == [True]
|
||||
|
||||
|
||||
def _live_steps(generation):
|
||||
from lembas.services.steps import _build
|
||||
|
||||
return _build(
|
||||
text=generation.text,
|
||||
thinking=generation.thinking,
|
||||
events=list(generation.tool_events),
|
||||
marks=list(generation.steps),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user