Skip to content

fix(runner): fail the turn instead of answering with a lost conversation - #5493

Merged
bekossy merged 3 commits into
feat/sessions-storage-reworkfrom
fix/sessions-fail-on-lost-records
Jul 28, 2026
Merged

fix(runner): fail the turn instead of answering with a lost conversation#5493
bekossy merged 3 commits into
feat/sessions-storage-reworkfrom
fix/sessions-fail-on-lost-records

Conversation

@mmabrouk

Copy link
Copy Markdown
Member

The problem

Two silent failure modes that both end with the agent answering as though the conversation never happened.

An unreadable record log looked like success. fetchSessionRecords catches every error, logs one line to stderr, and returns null. The caller treated null as "keep the inbound history", which was safe while the client still sent the whole conversation. Once the client sends only its last message, the inbound history is one message. So a failed query produced a model turn with no prior context at all, and answered confidently. Nothing on the wire said anything went wrong: no error frame, no retry, no signal to the caller.

A dropped record was counted and then ignored. takePersistFailures had no caller outside the unit tests. Its own docstring says the turn-end drain uses it to decide "whether the durable history is complete enough to reconstruct model context from", and nothing did that. So when durable ingest exhausted its retries, the count went into a map nothing read, the client still discarded its history on the next turn, and reconstruction rebuilt a conversation with a hole in it.

Reported by Codex; confirmed by reading the call graph.

The fix

Consume the drop count at the turn-end drain, which is where the docstring already claimed it happened, and mark the session's log as incomplete.

Then make reconstruction refuse rather than guess. When the client sent only its last message there is no history to fall back on, so an unreadable log or a session known to have lost a record fails the turn and the caller sees an error instead of a wrong answer delivered with confidence.

Requests that still send their own history never reach this path and are unaffected.

Before / after

Before After
Record query fails Answers with no memory, no error Turn fails with a stated reason
A record was dropped Reconstructs from an incomplete log Turn fails, session marked

Testing

Two new cases assert the turn rejects on an unreadable log and on a session marked incomplete, and that the second case never issues a query. Full runner unit suite green. Context: QA results.

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jul 28, 2026 1:58pm

Request Review

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ef5c1ca3-47db-40af-a9c7-e24b93c258cb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sessions-fail-on-lost-records

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Two silent failure modes met in the same place. `fetchSessionRecords` returned
null on any error and the caller treated that as "keep the inbound history";
once the client sends only its last message, that history is one message, so an
unreadable log produced an agent that answered as if the user had just arrived,
with no error anywhere on the wire. Separately, `takePersistFailures` had no
caller outside the tests, so a dropped record was counted into a map nothing
read, and the next turn reconstructed from a log with a hole in it.

Consume the drop count at the turn-end drain, where the docstring already said
it happened, and mark the session. Reconstruction now fails the turn for an
unreadable log or a session known to have lost a record, so the caller sees an
error rather than a confident wrong answer. Requests that still send their own
history are unaffected: they never reach this path.

Claude-Session: https://claude.ai/code/session_01KM69J7uHafgciiN5zfG7qR
@mmabrouk
mmabrouk force-pushed the fix/sessions-config-attached branch from 3286a79 to 5a00886 Compare July 24, 2026 22:10
@mmabrouk
mmabrouk force-pushed the fix/sessions-fail-on-lost-records branch from 8f19a97 to f621400 Compare July 24, 2026 22:10
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 24, 2026
@mmabrouk
mmabrouk changed the base branch from fix/sessions-config-attached to fix/sessions-no-duplicate-prompt July 24, 2026 22:10
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 24, 2026
@mmabrouk
mmabrouk requested a review from ardaerzin July 24, 2026 22:10
@bekossy
bekossy changed the base branch from fix/sessions-no-duplicate-prompt to feat/sessions-storage-rework July 27, 2026 19:26
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 28, 2026
@bekossy
bekossy merged commit d08d7f5 into feat/sessions-storage-rework Jul 28, 2026
24 of 25 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-production-9241.up.railway.app/w
Project agenta-oss-pr-5493
Image tag pr-5493-3cac32b
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-07-28T14:10:57.924Z

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

Labels

Backend lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants