Skip to content

[bugfix] agent: finish persistence failure can silently report success and continue queued turns #502

Backlog

Description

@yefuyou

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:

  1. Accept a Turn and persist its initial assistant reply as streaming.
  2. Let the runtime produce an answer, then fail Conversations.update(..., finish=...) with OSError or an injected lock/transaction exception.
  3. In apps/api/src/opendirector_api/agent.py, produce_one() catches the write failure (around lines 733–741), logs it and sets saved = None, but leaves error = None and status = 'complete'.
  4. run_chain() sends an end frame with conversation: null and error: null (around lines 792–793). The client has no explicit indication that the reply was not persisted. The durable reply may still show streaming.
  5. Because status remains complete, 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() and release_agent_session() share one try: a non-OSError timing exception can skip session release, leaving a lease row until expiry.
  • The chain's CancelledError path can overwrite a previously recorded runtime/persistence error with None.
  • 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 end reports 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 complete status.
  • 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.

Related: #381, #469, #476.

Activity

  1. added
    area:agent
    on Nov 25, 2026
  2. changed the title [-][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[/+] on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions