chore: scene-close-on-cancel — strengthen regression test + document rationale (T108)

Investigation surfaced a transactional bug in the cancel path: when the
primary stream raises asyncio.CancelledError mid-stream, post_turn
re-raises at end-of-function, and open_db's dependency teardown skips
conn.commit() — rolling back ALL post-cancel writes including the
scene_closed event. The existing T74.3 regression test only passes
because asyncio is not imported at module scope, so CancelledError
becomes NameError (caught by except Exception, leaves cancelled=False).
Documented in turns.py + test docstring; deferred for triage.
This commit is contained in:
Joseph Doherty
2026-04-27 04:47:26 -04:00
parent a06f90a164
commit baffeb3a44
2 changed files with 48 additions and 0 deletions
+14
View File
@@ -873,6 +873,20 @@ async def post_turn(
# mid-stream still meant to close the scene — the cancelled bot
# beat doesn't invalidate that intent. Pinned by
# test_cancelled_turn_still_closes_scene_when_user_prose_signals_close.
#
# T108 NOTE — the in-memory append order is correct, but the cancel
# path re-raises ``CancelledError`` at the end of ``post_turn``
# (see step 11 below). The ``open_db`` dependency teardown skips
# ``conn.commit()`` when the consumer raises, which means in
# production a genuine cancel currently rolls back ALL post-cancel
# writes — including this scene_closed event, the truncated
# assistant_turn record, edge updates, and per-POV summaries. The
# T74.3 regression test passes only because of a missing
# ``import asyncio`` in the test module: the inline mock raises
# ``NameError`` instead of ``CancelledError``, which is caught by
# the ``except Exception:`` branch and leaves ``cancelled=False``,
# so the function returns 204 normally and the commit fires. This
# is a transactional bug deferred for triage (T108 report).
if scene is not None and prose.strip():
container = None
if scene.get("container_id") is not None: