Skip to content

fix(chat): rollback session on pre-stream failure log commit error - #97

Open
fredifo wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
fredifo:fix/pre-stream-failure-rollback
Open

fredifo wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
fredifo:fix/pre-stream-failure-rollback

Conversation

@fredifo

@fredifo fredifo commented Sep 14, 2026

Copy link
Copy Markdown

Orca-Code-Review — push 1

Severity Count
P0 0
P1 0
P2 0
P3 0

✅ no blocking findings

When _log_pre_stream_failure fails to commit the request log row (e.g. transient SQLite busy error), the request-scoped session is left dirty with the pending INSERT still attached. Any subsequent DB operation on that session then fails with InvalidRequestError — a secondary failure caused by our own error handling, not the original upstream error.

The streaming _finalize path already handles this correctly (its _commit_row does rollback on failure), but the pre-stream path was missing the same guard.

Fix: add await db.rollback() in the except clause so the session is clean for any subsequent operations (streaming _finalize, blocking path commit).

Files changed:

  • app/routes/chat.py — rollback in _log_pre_stream_failure except clause
  • tests/unit/test_pre_stream_rollback.py — regression test

When _log_pre_stream_failure fails to commit the request log row, the
request-scoped session is left in a dirty state with the pending INSERT
still attached. The next DB operation on that session then fails with
InvalidRequestError — a secondary failure caused by our own error
handling, not the original upstream error.

Add a rollback in the except clause so the session is clean for any
subsequent operations (streaming _finalize, blocking path commit).

@orcacode-review orcacode-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐳 OrcaCode Review

No findings — nothing to flag in this PR. Great work!

OrcaCode Review — Route Smarter. Ship Safer. Spend Less.
Engine-reported: 376 calls · 22.8M tokens · 98% cached

❤️ Share · Install OrcaCode Review

Free on GitHub — the review runs on your own OrcaRouter key. If it helped, a shout-out goes a long way.

Share: X · Reddit · LinkedIn
Follow: X · Discord · LinkedIn · OrcaRouter

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.

1 participant