Skip to content

fix(runtime): treat an empty completion after tool results as a provider fault - #196

Merged
lg2m merged 2 commits into
fix/eng-940-measured-context-recoveryfrom
fix/eng-952-empty-turn-fault
Sep 26, 2026
Merged

lg2m merged 2 commits into
fix/eng-940-measured-context-recoveryfrom
fix/eng-952-empty-turn-fault

Conversation

@lg2m

@lg2m lg2m commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes ENG-952. Stacked on #195 (ENG-940); merge that first, then this rebases to one commit.

User-visible behavior

A run no longer settles completed when the provider answers fresh tool results with nothing. Two production runs on 2026-09-25/26 did exactly that after a LiteLLM gateway returned a bare [DONE] (no text, no calls, no usage); the user saw only the empty-turn placeholder and had to re-prompt, losing the in-flight work twice.

Cause

ProviderEvent::Completed { usage: None } with no preceding events was classified as a finished answer. The transient-fault path (bounded re-issue → Paused) exists but was never entered.

Design

When a completed turn carries no content, no calls, and no usage, and the previous message holds tool results, the loop records the same transient fault a stream cut short does: retry with backoff up to MAX_TURN_RETRIES, then Paused, never completed. Scoped deliberately: an empty reply to the prompt itself (turn one, no results) still completes so the existing placeholder keeps that transcript well-formed, and a reply with usage is a real (if useless) answer and completes once. No schema or protocol change.

Five test providers used a bare Completed { usage: None } as their "done" signal after tool results; they now say "done", which is what a real model does.

Verification

  • New regression an_empty_completion_without_usage_is_a_transient_fault_not_an_answer: read → empty reply → 5 re-issues → Paused with the fault message; the same reply with usage present completes once. Fails on the base commit (settles completed after one call).
  • cargo test --workspace green (736 qq-core). One headless test (hard_cost_budget_cancels_an_unmetered_looping_child) flaked once under full-workspace load and passed 5/5 in isolation on both this branch and the base; unrelated 2 s timeout.
  • clippy -D warnings clean; fmt clean.

Performance

None: one extra boolean check per completed turn, no allocation.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T19:07:19.191427Z b123ed3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f501d3a7a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/qq-core/src/lib.rs Resolved
Comment thread crates/qq-core/src/lib.rs Resolved
@lg2m
lg2m added this pull request to stack #203 September 26, 2026 06:44
lg2m added a commit that referenced this pull request Sep 26, 2026
…tions (ENG-952)

Review follow-ups on #196. Steering or a checkpoint correction joins the
request as a user message after the tool results, so `messages.last()`
missed them and a bare terminal event still settled `completed`; the fault
predicate now scans every user message since the last assistant turn.
Whitespace-only deltas before that event counted as content although
`has_content` trims them out of the transcript; the predicate trims too.

Tests: the regression runs with no prelude, "\n", and " \n\t"; an "ok"
prelude still completes in two sends; a new test queues steering so the
empty turn's request ends in a user message. Both new checks fail on
3f501d3. Ledger RR4.1 and the ADR-0040 paragraph in architecture.md record
the behaviour.
…der fault (ENG-952)

A gateway that swallows an upstream failure returns a bare terminal event:
no text, no tool call, no usage. The run loop treated that as a finished
answer and settled `completed`, so the user saw only the empty-turn
placeholder and had to re-prompt; two production runs on 2026-09-25/26 lost
their in-flight work this way, each right after delivering ~17 KB of fresh
tool results.

Silence in reply to tool results is not an answer. When a completed turn
carries no content, no calls, and no usage, and the previous message holds
tool results, the loop now records the same transient fault a stream cut
short does: bounded re-issue with backoff, then `Paused`, never
`completed`. An empty reply to the prompt itself (turn one, no results)
still completes; the placeholder keeps that transcript well-formed.

Five test providers that used a bare `Completed { usage: None }` as their
"done" signal after tool results now say "done", which is what a real model
does.

Regression: `an_empty_completion_without_usage_is_a_transient_fault_not_an_answer`
(read → empty reply → MAX_TURN_RETRIES re-issues → Paused; the same reply
with usage present completes once). Fails on the previous code.
…tions (ENG-952)

Review follow-ups on #196. Steering or a checkpoint correction joins the
request as a user message after the tool results, so `messages.last()`
missed them and a bare terminal event still settled `completed`; the fault
predicate now scans every user message since the last assistant turn.
Whitespace-only deltas before that event counted as content although
`has_content` trims them out of the transcript; the predicate trims too.

Tests: the regression runs with no prelude, "\n", and " \n\t"; an "ok"
prelude still completes in two sends; a new test queues steering so the
empty turn's request ends in a user message. Both new checks fail on
3f501d3. Ledger RR4.1 and the ADR-0040 paragraph in architecture.md record
the behaviour.
@lg2m
lg2m force-pushed the fix/eng-952-empty-turn-fault branch from 919c6a8 to b123ed3 Compare September 26, 2026 19:03
@lg2m
lg2m merged commit 25effaa into main Sep 26, 2026
4 checks passed
@lg2m
lg2m deleted the fix/eng-952-empty-turn-fault branch September 26, 2026 19:04
lg2m added a commit that referenced this pull request Oct 5, 2026
…tch bench completes again (#242)

* fix(bench): tool_dispatch completes again; a test runs its fixture

The bench's provider answered the turn after a tool result with a bare
unmetered completion. Since #196 the run loop treats that as a swallowed
gateway fault and retries it, so the bench never finished. The fixture
now answers with text. It moves to tests/support/read_tool.rs, shared with
a new integration test that runs one bench iteration under a 10 s
timeout, so a fixture that stops completing fails CI instead of hanging
the bench.

Linear: ENG-1003

* fix(provider): Bedrock compaction no longer fails once a session has used a tool

Converse rejects any request holding tool-use or tool-result blocks
unless it declares tools: "The toolConfig field must be defined when
using toolUse and toolResult content blocks". Both compaction summarizers
send exactly that: the session's tool history, with no tools. So on
native bedrock/, neither /compact nor automatic in-run compaction worked
for a session that had made one tool call, and long sessions failed once
the context filled.

The Bedrock codec now renders tool blocks as text on a request that
declares no tools, for example "[tool call: read_file {...}]" and
"[tool result from read_file]". The model reads the same history and
cannot call anything. Requests with tools keep their blocks, so the
cached prefix is unchanged. The other codecs are untouched: those APIs
accept tool blocks without tools.

Verified live on bedrock/ Claude Haiku 4.5: one read_file call, then
CompactSession over qq serve. main fails the compaction run with the
error above; this completes it.

Linear: ENG-1002

* docs(provider): place the tool-history rule after the budget-final passage; review nits (ENG-1002)

Review follow-up: the compaction sentence sat inside the budget-final
passage, so its next sentence read as if it applied to summaries.
Stale 'dropping the tools is rejected' reasoning in bedrock.rs and the
ToolChoice doc now names the cached prefix and native tool blocks. Result
labels take the first call with an id. The between-run /compact test
asserts the summary still carries tool blocks. Mantle's Anthropic path,
checked live, accepts tool blocks without tools.

Linear: ENG-1002
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