Skip to content

fix(agents): silently retry unfinished-step turns before surfacing them to the user (ENG-18893) - #183

Closed
convyusboy wants to merge 3 commits into
boonfrom
ridho/eng-18893-gemstone-industrial-proposal-generation-generic-one-step
Closed

convyusboy wants to merge 3 commits into
boonfrom
ridho/eng-18893-gemstone-industrial-proposal-generation-generic-one-step

Conversation

@convyusboy

@convyusboy convyusboy commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Today, when a Boon Agent turn produces a real reply but a recoverable exec-class tool call didn't cleanly resolve, the turn ends with "N steps didn't finish (... completed): — . The reply may be incomplete — ask me to redo it if something looks off." plus a manual "Retry" button, and just stops. The user has to notice, click Retry (or type /retry), and wait through another full turn themselves — on live customer calls this reportedly happens at least once per session (Arief, ENG-18893).

Why This Change Was Made

The recovery text already exists and is proven: /retry (src/auto-reply/reply/commands-retry.ts) just re-sends "Please look at what didn't finish in your last reply and redo it." as a new turn, and booneval's own CI regression harness (eval/agent-regression) already auto-sends this exact nudge up to 2 times to get scenarios green — production has no equivalent, so the same self-fixable stall that CI silently recovers from reaches the user instead.

This change moves that proven recovery inside the harness itself: run.ts's existing internal silent-retry loop (the same one already used for empty-response, reasoning-only, and compaction-interrupted turns) now also retries when payloads.ts classifies the turn as a non-terminal tool-error warning (isReplyPayloadNonTerminalToolErrorWarning) — i.e. exactly the condition that produces today's "N steps didn't finish" note. Bounded to 2 attempts, matching booneval's own cap, and skipped for aborted/externally-aborted/timed-out attempts. When the retry succeeds, the user never sees a stall at all; when it doesn't, today's note + Retry button still fires unchanged as the fallback.

The decision logic is extracted as a small pure helper (shouldRetryUnfinishedSteps in run/incomplete-turn.ts) alongside its siblings, per this directory's own guidance to keep the expensive run.ts integration surface thin and push decisions into unit-testable helpers.

User Impact

Applies to every channel (Slack, Teams, webapp, etc.) since the fix lives in the shared core run loop, not a per-channel surface. A turn that hits a self-fixable partial tool failure now silently finishes instead of stopping and waiting for the user to click Retry — no visible change when the retry succeeds; identical behavior to today when the retry budget is exhausted.

Evidence

  • Repro chain: boon-technologies-inc.slack.com/archives/C0B8WQ4B91N/p1788193028181899 → live webapp thread app.getboon.ai/agent/thread/1361 (real exec trace showing an unfinished-steps stall) → root cause partly filed as ENG-19208; this PR addresses ENG-18893 (Gemstone Industrial, "23 of 25 tools succeeded" / "one step didn't finish" reported on every live call).
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo — clean.
  • node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.incomplete-turn.test.ts — 114/114 passed (includes 3 new tests for shouldRetryUnfinishedSteps), both pre- and post-rebase onto latest origin/boon.

Linear: https://linear.app/getboon/issue/ENG-18893/gemstone-industrial-proposal-generation-generic-one-step-didnt-finish


Summary by cubic

Fixes Boon Agent turns that end with a recoverable tool-call failure by silently retrying them internally instead of stopping with the “N steps didn’t finish” note and manual Retry button (ENG-18893).

  • Reuses /retry's proven nudge text, bounded to 2 attempts to match booneval's own cap.
  • Applies to all channels (Slack, Teams, webapp) since the fix lives in the shared core run loop.
  • When retries are exhausted, the existing user-visible note and Retry button still fire unchanged.
  • Skips retrying aborted, externally aborted, timed-out, or side-effecting attempts (messaging/cron/session_spawn already landed) so a mutation can't be replayed.
  • Clears stale retry-nudge text between retry branches, with full-loop tests covering silent retry, budget exhaustion, and the side-effect guard.

Written for commit 21557e6. Summary will update on new commits.

Review in cubic

@claude

claude Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@gandalfboon gandalfboon 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.

Approved.

  • ENG-18893 acceptance criteria all met: real-reply turns with a non-terminal exec-class tool failure now silently retry (bounded to 2, matches booneval's own nudge.max: 2); aborted / external-abort / timed-out attempts are correctly excluded; when the budget is exhausted, today's "N steps didn't finish" note + Retry button still fire unchanged as the fallback.
  • Decision helper shouldRetryUnfinishedSteps is properly extracted to run/incomplete-turn.ts alongside its siblings, per that directory's guidance to keep run.ts thin.
  • Integration point in run.ts sits cleanly after the compaction-continuation guard and before the reasoning-only-exhausted branch; payloadsWithToolMedia, aborted, externalAbort, timedOut are all in scope; per-turn counter is loop-local so it resets on each new user turn; instruction is nulled after success and joined into the next attempt's prompt additions alongside the other three retry nudges.
  • Reuses the existing RETRY_NUDGE_TEXT from commands-retry.ts and the existing isReplyPayloadNonTerminalToolErrorWarning classifier from reply-payload.ts — no duplicated logic, no new secrets, no migrations, no API contract changes.
  • Tests: 3 new focused unit tests (bound, no-warning short-circuit, aborted/external/timed-out short-circuit) + full suite passes locally on rebase (114/114 in run.incomplete-turn.test.ts). tsgo -p tsconfig.core.json clean.

Ship it.

…em to the user (ENG-18893)

A turn that ends with a real reply but a recoverable exec-class tool failure
(payloads.ts's isNonTerminalWarning) today surfaces "N steps didn't finish"
plus a manual Retry button and stops — the user has to click it or type
/retry themselves. Reuses /retry's own proven nudge text to silently retry
the same turn internally, bounded to 2 attempts (matching booneval's own
nudge cap), before ever falling through to the user-visible note.
…try (ENG-18893)

Exercises runEmbeddedAgent end-to-end via the existing overflow-compaction
harness: confirms a turn tagged nonTerminalToolErrorWarning silently retries
with RETRY_NUDGE_TEXT and, once the 2-attempt budget is exhausted, falls
through unchanged. Doubles as the local reproduction recipe for this fix —
run via: node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.incomplete-turn.test.ts
… (ENG-18893)

Code review caught two real gaps in the new silent retry:

1. shouldRetryUnfinishedSteps never checked hadPotentialSideEffects, unlike
   every sibling retry-safety check in this file and the adjacent
   compaction-continuation gate. A turn that already sent a message, added a
   cron job, or spawned a session before a later exec-class call failed
   non-terminally would still get auto-retried with 'redo it' — risking the
   model replaying an already-successful mutation with no human in the loop
   to catch the duplicate the way a manual Retry click would.

2. reasoningOnlyRetryInstruction/emptyResponseRetryInstruction were never
   reset when a different retry branch fired, unlike
   compactionContinuationRetryInstruction (and the new
   unfinishedStepsRetryInstruction) which already reset themselves. A stale
   instruction from an earlier iteration could get concatenated into a later
   attempt's prompt alongside an unrelated retry's nudge text. Fixed by
   resetting all four together at the point where none of the earlier
   branches fired this iteration.

Both closed with new unit + full-loop coverage.
@convyusboy
convyusboy force-pushed the ridho/eng-18893-gemstone-industrial-proposal-generation-generic-one-step branch from 85089be to 21557e6 Compare September 3, 2026 11:07

@gandalfboon gandalfboon 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.

Re-approved on 21557e6.

Second pass targets the two safety gaps I missed first time — both real.

  • hadPotentialSideEffects gate: shouldRetryUnfinishedSteps now short-circuits when the same-turn attempt already committed a mutation, in lockstep with sibling shouldRetryMissingAssistantTurn (run.ts:3876) and shouldRetrySilentErrorAssistantTurn (run.ts:3892). Reads accumulatedReplayState.hadPotentialSideEffects after observeReplayMetadata folds the just-completed attempt in (2402), so the flag is fresh for this iteration. Prevents the redo it nudge from replaying a Slack send / cron.add / sessions_spawn that already succeeded before a later exec failure.
  • Reset-all-four-together: reasoningOnlyRetryInstruction + emptyResponseRetryInstruction are now nulled at run.ts:3909-3912 alongside compactionContinuationRetryInstruction and the new unfinishedStepsRetryInstruction, at the point where none of the earlier retry branches continued. Removes the stale-instruction concat path where a no-longer-applicable nudge could ride into a later iteration's prompt additions (buildRunLoopIterationPrompt joins the four).

Tests:

  • never retries unfinished steps once the attempt had potential side effects — direct helper test.
  • never auto-retries unfinished steps after a messaging-tool send already landed — full-loop test with didSendViaMessagingTool: true fixture, asserts exactly 1 attempt and no unfinished steps detected warn.
  • Existing bound / no-warning / aborted-externalAbort-timedOut / silent-retry-then-succeed / budget-exhausted cases all preserved.

Mechanics:

  • No new logic, no new secrets, no API contract changes.
  • MAX_UNFINISHED_STEPS_RETRY_ATTEMPTS = 2 still matches booneval nudge.max: 2.
  • Reset block only clears when both reasoning-only + empty-response branches skipped their continue this iteration, so live instructions aren't clobbered.

CI status: check-lint in progress, build-artifacts / check-test-types / check-shrinkwrap / check-dependencies / Security-High CodeQL all green; remaining shards queued. check-additional-extension-package-boundary running. No red.

Ship it.

@convyusboy

Copy link
Copy Markdown
Collaborator Author

Superseded by #188 — this PR got stuck in a GitHub-side desync after a force-push (head.sha wouldn't advance, and reopen was rejected with "state cannot be changed... branch was force-pushed or recreated"). No code was lost; all commits from this branch carried over to #188.

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