Skip to content

feat(agents): tell a channel why a turn stopped and when a completion attempt is its last - #251

Merged
insomnius merged 3 commits into
boonfrom
ariefrahman/eng-20495-turn-budget-continue
Sep 29, 2026
Merged

insomnius merged 3 commits into
boonfrom
ariefrahman/eng-20495-turn-budget-continue

Conversation

@insomnius

@insomnius insomnius commented Sep 28, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Resolves a problem where a Boon Agent chat user is left with no explanation when a turn stops early. Two cases:

  • Sub-agent result turn. When a sub-agent finished, the parent's result turn could run past the chat turn budget. openclaw retried it up to three times, then gave up or parked it. The channel plugin couldn't tell which attempt was the last, so every attempt stayed silent and the user saw nothing.
  • All models failed. When every model candidate failed, the user got the generic "Something went wrong and automatic retries didn't recover" as a normal reply. A plugin couldn't tell a transient provider outage from billing or context overflow without matching that text.

Why This Change Was Made

Both are additive facts the channel needs, so openclaw now passes them along instead of discarding them:

  • SubagentCompletionRequest.finalAttempt?: boolean
    • True when the completion owner won't be called again for this completion.
    • Computed from the same cleanup decision the lifecycle applies after a failure (resolveCleanupDecision).
  • Failure code on the reply payload. The all-models-failed payload now carries the GatewayFailureCode the runner already resolved, including the will_auto_retry → agent_failed_transient_after_retries downgrade.
    • Plugins read it with getReplyPayloadGatewayFailure(payload) → { code, retryAffordance } from openclaw/plugin-sdk/reply-payload, beside getReplyPayloadToolFailureDigest.

Non-goals:

  • No wire, text or retry-policy change.
  • llm.complete behavior is unchanged. A version that threw on provider errors was dropped, because the bundled clickclack plugin doesn't catch it.

User Impact

None on its own. Owners that ignore the new fields behave exactly as before. It unblocks anychat-boon-web posting a visible "Paused" row with progress on the final sub-agent result attempt, and a model_unavailable row instead of generic text.

  • Companion PRs: getboon/anychat-boon-web#149, getboon/boon#15217
  • Ticket: ENG-20495

Evidence

  • Focused tests:
    • node scripts/run-vitest.mjs src/agents/subagent-announce.test.ts src/agents/subagent-registry-lifecycle.test.ts src/agents/subagent-registry-cleanup.test.ts src/agents/subagent-completion-owner.test.ts → 65 passed.
    • agent-runner-execution / gateway-failure-code / wired-hooks-reply-payload-sending / reply-utils → 324 passed.
    • Red first: finalAttempt: expected undefined to deeply equal true and TypeError: getReplyPayloadGatewayFailure is not a function.
  • Static checks:
    • node scripts/run-tsgo.mjs -p tsconfig.core.json and -p test/tsconfig/tsconfig.core.test.json → exit 0.
    • oxlint and oxfmt clean on the touched files; check-import-cycles → 0 cycles.
    • Plugin SDK API baseline regenerated (pnpm plugin-sdk:api:gen). It adds getReplyPayloadGatewayFailure, GatewayFailureCode and RetryAffordance.
  • Live (local stack, gateway built from this branch, 45s chat turn budget):
    • A sub-agent result turn over budget was silent on attempts 1–2.
    • On attempt 3 it posted a paused row with "Done so far / Still to do". Gateway log: Subagent announce give up (owner_terminal) ... retries=3 deliveryError="turn_budget_exceeded".

https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG


Summary by cubic

Adds two additive signals so channels can explain early turn stops instead of leaving the user with silence or a generic error.

  • SubagentCompletionRequest.finalAttempt tells a completion owner when retries have been exhausted, so it can post a visible halt on the final sub-agent result attempt rather than staying quiet.
  • Final all-models-failed replies now attach the resolved GatewayFailureCode (with RetryAffordance) to the payload, reachable via getReplyPayloadGatewayFailure() from openclaw/plugin-sdk/reply-payload. Channels can now tell billing/context overflow from transient provider outages without matching text.

Owners that ignore the new fields behave exactly as before. Unblocks anychat-boon-web showing a "Paused" row on the last sub-agent attempt and a model_unavailable row instead of generic failure text. Addresses ENG-20495.

Written for commit 3a729dd. Summary will update on new commits.

Review in cubic

A channel plugin that owns a sub-agent completion gets a retryable failure
retried up to the announce retry limit, then the completion is given up or
suspended. The owner never knew which attempt was the last, so a plugin that
hit a turn budget on the final attempt stayed silent and the user saw
nothing.

SubagentCompletionRequest gains an optional `finalAttempt`, computed from the
same cleanup decision the lifecycle applies after a failure, so a plugin can
post a visible halt on the attempt that will not be retried. Additive: owners
that ignore it behave as before.

ENG-20495

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG
When every model candidate fails, the runner already classifies the failure
into a GatewayFailureCode, then keeps only the copy text. A channel plugin
saw `isError: true` and could not tell a transient provider outage
(retrying helps) from billing or context overflow (it does not) without
matching the text.

Attach the resolved code, including the will_auto_retry downgrade, to the
final failure payload's metadata and expose it through the plugin SDK as
`getReplyPayloadGatewayFailure(payload) -> { code, retryAffordance }`,
beside getReplyPayloadToolFailureDigest. Additive: no wire or text change.

ENG-20495

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG
@insomnius
insomnius requested a review from a team September 28, 2026 17:10
…yFailure

The new reply-payload getter adds one public callable export and three
public exports (the getter plus the GatewayFailureCode and RetryAffordance
types).

ENG-20495

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG
@augusteo

Copy link
Copy Markdown

@gandalf Please review and, if satisfied, approve #251 on exact current head 3a729dd3574a11f47643895a02da6d3cd8588885.

Summary: Additive OpenClaw SDK/runtime support for final sub-agent completion attempts and gateway failure reply code/retry affordance.

Please review this exact head and provide a human APPROVED review if satisfied; check final-attempt completion behavior and gateway failure payload compatibility. This is a request only, not an approval; all required checks and Gandalf's exact-head approval are required before merge.

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

Verified at head 3a729dd:

  • Strictly additive SDK surface: SubagentCompletionRequest.finalAttempt, ReplyPayloadMetadata.gatewayFailureCode, getReplyPayloadGatewayFailure + the two exported types; budgets bumped (+3 exports/+1 fn) and the baseline sha regenerated. Nothing removed or narrowed.
  • finalAttempt uses ONE retry policy (resolveCleanupDecision) for both the pre-call flag and the post-failure decision, so the two can't drift; the pre-call prediction race (late expiry / new pending descendants) is documented on the field. Tests pin attemptCount 2 -> final, 0 -> not, and the keep/ok final attempt suspends instead of failing.
  • resolveTerminalGatewayFailureCode downgrades will_auto_retry codes once, and the same code drives both the copy and the payload metadata, so a channel never sees a code/copy mismatch. setReplyPayloadMetadata merges (...previous), so the isError marking survives.
  • Plugin-side consumption (anychat-boon-web#149) feature-detects the getter, so merge order is genuinely free.
  • All check lanes green.

No findings.

@insomnius

Copy link
Copy Markdown
Author

Local-stack test screenshot

This used a gateway built from this branch, with chatTurnBudgetSeconds: 45. A sub-agent result turn over budget was silent on attempts 1–2. On attempt 3 (finalAttempt: true, then Subagent announce give up (owner_terminal) ... retries=3), anychat-boon-web posted a paused row with progress. Full set: https://gist.github.com/insomnius/7cd798b2a26f97cf1dadbfd04d41d04d

@insomnius
insomnius merged commit 9332056 into boon Sep 29, 2026
145 checks passed
@insomnius
insomnius deleted the ariefrahman/eng-20495-turn-budget-continue branch September 29, 2026 08:25
insomnius added a commit that referenced this pull request Sep 29, 2026
…+ fast-uri 3.1.7) (#252)

* chore(release): bump version 2026.6.11-boon.47 -> 2026.6.11-boon.48

Root version, 135 plugin manifests synced via scripts/sync-plugin-versions.ts (pnpm plugins:sync), root + 68 extension npm-shrinkwrap.json version fields and openclaw peerDependency ranges bumped, CHANGELOG section for boon.48.

Shipping: #251 (SubagentCompletionRequest.finalAttempt tells a completion owner its attempt will not be retried; getReplyPayloadGatewayFailure on the plugin SDK exposes the terminal GatewayFailureCode + retry affordance of an all-models-failed reply; plugin SDK surface budget raised for the new getter and types).

Base = 2026.6.11-boon.47. Gateway plus @openclaw/slack, @openclaw/msteams and @openclaw/diagnostics-prometheus bumped in lockstep; no separately published plugin source changed in this train, so a gateway roll delivers all of it.

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG

* fix(deps): bump the fast-uri override 3.1.6 -> 3.1.7 for GHSA-qw65-cvwx-89v3 / GHSA-58mr-gqgx-xq4g

Two HIGH advisories published after boon.47 cover fast-uri 3.1.6
(authority injection via an unvalidated port in serialize; host confusion
via an unclosed bracket in the URI authority). Move the workspace override
to the patched 3.1.7 and refresh the lockfile plus the three shrinkwraps
that resolve it (root, acpx, lobster). pnpm-audit-prod now reports no
high advisories.

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG

* docs(changelog): note the fast-uri security bump in boon.48

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG

* docs(changelog): describe the fast-uri fix without advisory IDs

Address review: public release notes carry no GHSA identifiers or internal
audit/lockfile detail. Keep a concise user-facing security note.

Claude-Session: https://claude.ai/code/session_01FSeHegCidN6qEU1sTf2KzG
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.

2 participants