Skip to content

[bugfix] agent: report a failed finish write instead of ending silently (#502) - #512

Draft
yefuyou wants to merge 5 commits into
ThinkFlowLab:mainfrom
yefuyou:fix/502-finish-failure-end-event
Draft

yefuyou wants to merge 5 commits into
ThinkFlowLab:mainfrom
yefuyou:fix/502-finish-failure-end-event

Conversation

@yefuyou

@yefuyou yefuyou commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #502.

After #381 refactored the assistant into produce_one() / run_chain(), an unsuccessful final conversation write could still produce an SSE end with error: null and conversation: null. The assistant reply remained streaming on disk, while the client saw no persistence error. Because the in-memory Turn status stayed complete, the chain could also start the next queued message.

This PR fixes the silent false-success terminal state, not the older no-end behavior (which was superseded by #381).

Changes

  • On a failed final Conversations.update(..., finish=...), report a localized reply could not be saved error in the terminal SSE event; preserve a preceding runtime error alongside it.
  • Mark an otherwise complete Turn as interrupted so an unsaved reply cannot authorize the next queued Turn.
  • Keep chain-local unsaved/error state from bleeding across Turns, including the cancellation path.
  • Separate best-effort timing-ledger writes from Agent session lease release, so a ledger exception cannot skip release.
  • Add Python fault-injection regressions, a TypeScript SSE contract test, and a fixture-based browser scenario showing the error, retaining partial text, and restoring controls.

Evidence

The isolated tests use real FastAPI TestClient and real conversation persistence with a simulated Agent runtime; no paid providers or generation Jobs are invoked.

  • Before fix (clean upstream main): 10/12 new Python checks failed, covering incorrect end.error, combined errors, queued execution after an unsaved finish, and lease cleanup; 2/12 existing-behavior checks passed.
  • After fix: 12/12 new Python checks passed; six related assistant test files: 90 passed.
  • TypeScript: npm test 998 passed.
  • lint-imports (4 contracts), tsc, build, i18n, browser manifest and locale checks passed.
  • Existing assistant_sessions.mjs with the added mocked-SSE regression passed twice.
  • An independent code-and-test review reported APPROVED.

Boundaries and known limitations

  • Stop during an in-flight asyncio.to_thread finish write is not resolved. Cancelling the await cannot cancel the underlying write thread. Under forced races, the final SSE end.error can still be null and the disk reply may remain streaming after a failed write. This is explicitly not claimed fixed here.
  • Database lock/authorization failure cases were injected at the call boundary rather than caused by a real contended lock.
  • The browser regression mocks SSE and verifies the UI contract, not the real backend-to-browser transport.
  • Runtime tests do not exercise the Generation Tool Gateway; they do not establish cross-Turn exactly-once Job submission.
  • An observer that disconnects and never reconnects cannot be guaranteed receipt of an SSE terminal event.
  • A queued Turn currently inherits the existing Chinese-only persistence-error message when no Accept-Language is carried into its plan.
  • No scheduler, general replay mechanism, automatic side-effect retry or Job submission logic is added.

Related work

No real provider calls or project data changes were involved in verification.

…inkFlowLab#502)

When the final Conversations.update(finish=...) fails, produce_one() now
ends the turn with a localized "reply could not be saved" error (kept
beside any earlier runtime error), marks the turn interrupted so
run_chain() does not dispatch a queued message behind it, and carries
that error through the CancelledError path. Timing ledger writes and
agent session release run in separate try blocks so a ledger failure
cannot leave the project lease behind. chain.last is reset per turn.

Tests: fault-injected finish OSError, lock/authorization failures,
runtime + finish failure, queued turn, ledger/release failures, Stop,
stream detach and English locale; a TS SSE test and a browser check in
assistant_sessions.mjs prove end.error leaves the running state and
shows the error with the partial reply.

Fixes ThinkFlowLab#502

yefuyou commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @FayeSpica, could you please rerun the failed browser (isolated) job for #512 when convenient? Our linked GitHub integration receives HTTP 403 when attempting a rerun.

The failure is in tests/browser/canvas_progressive_load.mjs:107: the selected node's 720 panorama toolbar intercepts clicks on Switch project (29/30 isolated browser workflows passed). This is the same signature seen during #422. We investigated #512 head and upstream main in isolated environments; the canvas code is unchanged by #512, and the affected issue is tracked separately in #513. We could not reproduce the exact 20-second CI sequence locally, so we're keeping that limitation explicit.

The Agent-related checks, including browser (assistant) and Python, passed. No unrelated canvas changes or CI-bypass commits have been added to #512.

Failing job: https://github.com/ThinkFlowLab/OpenDirector/actions/runs/45604025737/job/139170443880

Thanks!

yefuyou pushed a commit to yefuyou/OpenDirector that referenced this pull request Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants