[PR #8818] [MERGED] fix(dottore): resend an empty max_tokens reply instead of failing the review #8825

Closed
opened 2026-11-07 17:39:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8818
Author: @SpicyMarinara
Created: 11/4/2026
Status: ✅ Merged
Merged: 11/4/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/dottore-empty-capped-reply


📝 Commits (2)

  • 5e8b659 fix(dottore): resend an empty max_tokens reply instead of failing the review
  • 8e09386 fix(dottore): count empty capped replies and keep a scout's places when its call fails

📊 Changes

3 files changed (+155 additions, -25 deletions)

View changed files

📝 .github/dottore-review/README.md (+7 -4)
📝 .github/dottore-review/dottore_review.py (+58 -21)
📝 scripts/regressions/dottore-stream-progress.regression.mjs (+90 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #8817

Why this change

Dottore Review has been failing whole reviews with "the finder reply reached its 64000-token output cap" on small diffs (#8800 and Agents #2100 today). The calls never came near the cap: the gateway returned a reply with stop_reason=max_tokens and 0 output tokens 5 to 15 seconds after the request. claude_reply marked any max_tokens stop as capped, so run_agent resent it once at a lower effort and then failed the review when the second reply came back empty too. The retry built for transient gateway faults (RETRY_DELAYS, same effort) never ran. Every such failure costs a manual /dottore rerun and leaves the PR blocked in the meantime.

What changed

  • A Claude reply that stops at max_tokens with 0 output tokens is a gateway fault: claude_reply raises ResponseFailed with no error code, which transient_error already retries, so chat() resends at the same effort after RETRY_DELAYS (15 s, then 45 s). It counts toward MAX_ROLE_FAILURES only when every resend fails. The message says "the gateway ended the reply at max_tokens before Claude wrote anything". usage.output_tokens is the signal because it is the SDK's billed total (it counts thinking even when only a summary is relayed); the real API cannot stop at max_tokens with 0 output tokens.
  • A reply that did write output and hit its cap keeps the existing behaviour: one resend at the next lower effort.
  • responses_reply applies the same rule to a response.incomplete that reports 0 output tokens, and names the incomplete reason. The output cap, or no reason, is retried; another reason, such as content_filter, fails at once with that reason instead of a lower-effort resend and a misleading "output cap" error. A response without usage keeps the old path.
  • The prompt tokens of those empty replies are charged to DOTTORE_COST_LIMIT_USD and the role's telemetry (model_calls, prompt_tokens, usd) through one charge() helper shared with the success path, so the cost limit does not undercount while a gateway repeats the fault.
  • A keep run (the scout) whose call still fails after its resends, or trips the role's failure breaker, returns the places it had already kept instead of dropping them; the stop is counted as stop_error. A run that has kept nothing still raises.
  • .github/dottore-review/README.md (role limits and cost limit) and the ResponseFailed / run_agent docstrings describe the new behaviour.
  • Regression: scripts/regressions/dottore-stream-progress.regression.mjs drives run_agent and chat() with stub Claude and Responses streams: an empty capped reply then a tool call succeeds at the same effort after one 15 s wait; a capped reply with output drops one effort level; three empty replies end in a transient ResponseFailed with waits [15, 45] and every attempt charged; the Responses reasons; and a scout keeping its places. The new cases fail on staging's dottore_review.py and on the first commit, and pass with the fix.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify, after this merges and Dottore's pinned tooling moves to it, that the next review whose log shows completion_tokens=0; ... stop_reason=max_tokens continues with a Dottore call retry: ... the gateway ended the reply at max_tokens before Claude wrote anything line at the same effort instead of "reached its N-token output cap".
  • Manually verify in a review's telemetry line that review_spent_usd and the role's model_calls include those retried attempts.
  • Manually verify that a normal review (no gateway fault) still completes with the same findings and a similar cost.

Agent-run checks (for reference):

  • node scripts/regressions/dottore-stream-progress.regression.mjs: passed (15 tests); on staging's dottore_review.py 5 failures, on the first commit 3 failures and 3 errors (copies restored, cmp identical)
  • node ./scripts/run-regressions.mjs --filter dottore: 8/8 passed
  • python3 -m py_compile .github/dottore-review/dottore_review.py: ok
  • git diff --check: clean
  • Probes driving run_agent / chat / claude_reply through stub streams: three empty replies record 3 calls and their prompt tokens; a scout tripped mid-run returns its kept place

Independent adversarial review: changes (1 medium, 1 low), both fixed in 8e09386365. One part was kept as designed: an empty reply that fails every resend counts toward the role's failure breaker, which is the dead-endpoint case the breaker exists for; the harm the reviewer showed (a scout losing its kept places) is fixed. A suggestion to print prompt tokens on each retry line was not taken (diagnostics only; the error text already says no output was written).

Known limits and risks:

  • The rule trusts the gateway's output_tokens. A gateway that always reported 0 would turn a real cap into up to three same-effort resends instead of one lower-effort one; such a gateway already shows completion_tokens=0 and $0 on every call.
  • On the Claude path, a reply with 0 output tokens is treated as empty even if the gateway relayed some content, because output_tokens is the billed total.
  • Not run against the real anthropic/openai SDKs or linkapi.ai: the pinned SDKs need a newer Python than the local 3.9.6, so the tests use stubs with the same attribute shapes. The first real run is the first review after Dottore's pinned tooling includes this change.
  • This PR is itself reviewed by the currently pinned Dottore, so it can still hit the fault it fixes.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8818 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/4/2026 **Status:** ✅ Merged **Merged:** 11/4/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/dottore-empty-capped-reply` --- ### 📝 Commits (2) - [`5e8b659`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5e8b659fd9908bb158a7a5bbb6af545fa4faeda6) fix(dottore): resend an empty max_tokens reply instead of failing the review - [`8e09386`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8e0938636536541f4806aa13e86e424ee9afc05c) fix(dottore): count empty capped replies and keep a scout's places when its call fails ### 📊 Changes **3 files changed** (+155 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `.github/dottore-review/README.md` (+7 -4) 📝 `.github/dottore-review/dottore_review.py` (+58 -21) 📝 `scripts/regressions/dottore-stream-progress.regression.mjs` (+90 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #8817 ## Why this change Dottore Review has been failing whole reviews with "the finder reply reached its 64000-token output cap" on small diffs (#8800 and Agents #2100 today). The calls never came near the cap: the gateway returned a reply with `stop_reason=max_tokens` and **0** output tokens 5 to 15 seconds after the request. `claude_reply` marked any `max_tokens` stop as capped, so `run_agent` resent it once at a lower effort and then failed the review when the second reply came back empty too. The retry built for transient gateway faults (`RETRY_DELAYS`, same effort) never ran. Every such failure costs a manual `/dottore` rerun and leaves the PR blocked in the meantime. ## What changed - A Claude reply that stops at `max_tokens` with 0 output tokens is a gateway fault: `claude_reply` raises `ResponseFailed` with no error code, which `transient_error` already retries, so `chat()` resends at the same effort after `RETRY_DELAYS` (15 s, then 45 s). It counts toward `MAX_ROLE_FAILURES` only when every resend fails. The message says "the gateway ended the reply at max_tokens before Claude wrote anything". `usage.output_tokens` is the signal because it is the SDK's billed total (it counts thinking even when only a summary is relayed); the real API cannot stop at `max_tokens` with 0 output tokens. - A reply that did write output and hit its cap keeps the existing behaviour: one resend at the next lower effort. - `responses_reply` applies the same rule to a `response.incomplete` that reports 0 output tokens, and names the incomplete reason. The output cap, or no reason, is retried; another reason, such as `content_filter`, fails at once with that reason instead of a lower-effort resend and a misleading "output cap" error. A response without usage keeps the old path. - The prompt tokens of those empty replies are charged to `DOTTORE_COST_LIMIT_USD` and the role's telemetry (`model_calls`, `prompt_tokens`, `usd`) through one `charge()` helper shared with the success path, so the cost limit does not undercount while a gateway repeats the fault. - A keep run (the scout) whose call still fails after its resends, or trips the role's failure breaker, returns the places it had already kept instead of dropping them; the stop is counted as `stop_error`. A run that has kept nothing still raises. - `.github/dottore-review/README.md` (role limits and cost limit) and the `ResponseFailed` / `run_agent` docstrings describe the new behaviour. - Regression: `scripts/regressions/dottore-stream-progress.regression.mjs` drives `run_agent` and `chat()` with stub Claude and Responses streams: an empty capped reply then a tool call succeeds at the same effort after one 15 s wait; a capped reply with output drops one effort level; three empty replies end in a transient `ResponseFailed` with waits [15, 45] and every attempt charged; the Responses reasons; and a scout keeping its places. The new cases fail on staging's `dottore_review.py` and on the first commit, and pass with the fix. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify, after this merges and Dottore's pinned tooling moves to it, that the next review whose log shows `completion_tokens=0; ... stop_reason=max_tokens` continues with a `Dottore call retry: ... the gateway ended the reply at max_tokens before Claude wrote anything` line at the same effort instead of "reached its N-token output cap". - Manually verify in a review's telemetry line that `review_spent_usd` and the role's `model_calls` include those retried attempts. - Manually verify that a normal review (no gateway fault) still completes with the same findings and a similar cost. Agent-run checks (for reference): - `node scripts/regressions/dottore-stream-progress.regression.mjs`: passed (15 tests); on staging's `dottore_review.py` 5 failures, on the first commit 3 failures and 3 errors (copies restored, `cmp` identical) - `node ./scripts/run-regressions.mjs --filter dottore`: 8/8 passed - `python3 -m py_compile .github/dottore-review/dottore_review.py`: ok - `git diff --check`: clean - Probes driving `run_agent` / `chat` / `claude_reply` through stub streams: three empty replies record 3 calls and their prompt tokens; a scout tripped mid-run returns its kept place Independent adversarial review: changes (1 medium, 1 low), both fixed in 8e09386365. One part was kept as designed: an empty reply that fails every resend counts toward the role's failure breaker, which is the dead-endpoint case the breaker exists for; the harm the reviewer showed (a scout losing its kept places) is fixed. A suggestion to print prompt tokens on each retry line was not taken (diagnostics only; the error text already says no output was written). Known limits and risks: - The rule trusts the gateway's `output_tokens`. A gateway that always reported 0 would turn a real cap into up to three same-effort resends instead of one lower-effort one; such a gateway already shows `completion_tokens=0` and $0 on every call. - On the Claude path, a reply with 0 output tokens is treated as empty even if the gateway relayed some content, because `output_tokens` is the billed total. - Not run against the real anthropic/openai SDKs or linkapi.ai: the pinned SDKs need a newer Python than the local 3.9.6, so the tests use stubs with the same attribute shapes. The first real run is the first review after Dottore's pinned tooling includes this change. - This PR is itself reviewed by the currently pinned Dottore, so it can still hit the fault it fixes. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8825
No description provided.