Repository navigation
Description
Current status (updated after #381 merged)
Confirmed on upstream main b9b7e587 (2026-11-25). This issue was originally reported against the earlier single-turn produce() implementation. PR #381 has since refactored it into produce_one() and run_chain(). The original symptom, no SSE end at all, is no longer the primary reproducible failure: run_chain() now queues end in its finally.
The remaining bug is a false, silent terminal outcome after finish persistence fails, with associated queue and cleanup hazards. This is an existing bug on main, not introduced by #476.
Current reproduction and observed effects
Using FastAPI TestClient, a simulated Agent runtime and fault injection around the real conversation persistence path:
- Accept a Turn and persist its initial assistant reply as
streaming. - Let the runtime produce an answer, then fail
Conversations.update(..., finish=...)withOSErroror an injected lock/transaction exception. - In
apps/api/src/opendirector_api/agent.py,produce_one()catches the write failure (around lines 733–741), logs it and setssaved = None, but leaveserror = Noneandstatus = 'complete'. run_chain()sends anendframe withconversation: nullanderror: null(around lines 792–793). The client has no explicit indication that the reply was not persisted. The durable reply may still showstreaming.- Because
statusremainscomplete, the chain may dispatch a queued message (around lines 772–784) after a failed finish write.
Additional current-main failure paths observed under targeted fault injection:
agent_timing.write()andrelease_agent_session()share onetry: a non-OSErrortiming exception can skip session release, leaving a lease row until expiry.- The chain's
CancelledErrorpath can overwrite a previously recorded runtime/persistence error withNone. - This issue does not claim that an SSE event queued by the producer is guaranteed to reach a disconnected client.
Expected behavior / acceptance criteria
- On finish-write failure, the SSE
endreports a nonempty, localized persistence error; it must not claim successful persistence or expose a fabricated successful conversation. - Preserve the original runtime failure and the finish failure when both occur, without revealing private internal paths or secrets.
- A queued subsequent Turn must not be dispatched based on the falsely retained
completestatus. - Separate best-effort timing persistence from lease release, so the former cannot suppress the latter.
- Stop/cancellation must not silently discard a known relevant error; preserve correct chain-local terminal data.
- Exactly one terminal event is queued on successful/failed attached-stream paths; reconnect uses existing cursor semantics. Do not claim delivery to a disconnected client.
- Successful turns, cancellation, original Turn identity and Job idempotency semantics remain unchanged. Do not automatically retry uncertain side-effectful operations.
- Regression tests use fault injection and include normal path, finish OSError, lock/transaction failures, combined runtime + finish failures, queued turns, best-effort timing exceptions, Stop and stream detach. Browser behavior should be verified or marked untested.
Original reproduction (historical, before #381)
The first report against the older produce() implementation reproduced three times that a failed final durable_json write skipped the end enqueue entirely. That evidence explained the old control flow, but is superseded by #381's new run_chain() finalizer. The underlying inability to report an unsaved terminal reply safely remains.
Scope and ownership
Minimal failure-finalization correction only. No new scheduler, replay engine, side-effect retry, or redesign of Begin / Finish.
A local, independently reviewed candidate fix exists as of 2026-11-25, but it is not yet committed or published as a PR; all descriptions above refer to reproducible current-main behavior, not a merged fix.
Activity
[-][bugfix] agent: a failed finish write can leave SSE without an end event[/-][+][bugfix] agent: finish persistence failure can silently report success and continue queued turns[/+]