Skip to content

fix(agents): stop utility fallbacks when the caller cancels its own attempt - #207262

Merged
obviyus merged 4 commits into
mainfrom
core/utility-self-cancel
Nov 28, 2026
Merged

obviyus merged 4 commits into
mainfrom
core/utility-self-cancel

Conversation

@obviyus

@obviyus obviyus commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A utility task that cancels its own work makes the fallback chain run the next utility model.

  • The Activity recap, titles and transcript summaries pass a currency guard (assertCurrent) to runUtilityCompletion. The guard throws when the task's own work goes stale: the recap's session changed or a newer recap took over ("Activity recap lifecycle or utility model changed"), the title owner retired, or a newer transcript capture owner took the lane.
  • When it throws, the caller's abort signal is still live. The fallback runner's only cancel fact is that signal (resolveChainStopReason, model-fallback-attempt.ts), so it counts the throw as a model failure and starts the next utility model.
  • Real-user log signature (a production team Gateway, 4.35 h): 72 model_fallback_decision candidate_failed on the utility primary with the recap's self-cancel error; 19 of them went on to a configured utility fallback that the runtime does not offer, each failing with model_not_found and a "Activity recap deferred" line.

Change

runUtilityCompletion (the one owner every utility user goes through) wraps the caller's assertCurrent on the fallback path. When it throws, a local controller is aborted with that same error and the error is rethrown. The chain receives AbortSignal.any([caller, local]), so the existing caller-cancel stop applies. No error-name or message match, no new error class, no runner change.

  • A real model failure with a current caller still falls back (test).
  • The no-fallback path is unchanged: with one candidate there is no next model to stop.

User impact

  • Recaps, titles, transcript notes and composer predictions that go stale stop at once instead of trying the next utility model, and a stale recap no longer produces a fallback model_not_found error or a retry delay. The chain logs one model fallback chain stopped reason=caller_signal_aborted line instead.
  • Not changed: progress narration and the session observer already cancel through their abort signal.

Evidence

Test Main This PR
utility-completion.runtime.test.ts: guard throws the recap's AbortError, caller signal live 3 model calls 1
conversation-label-generator.test.ts: title owner retires during the utility attempt gpt-mini, utility-backup gpt-mini
summary-model.test.ts: a newer capture owner takes the summary lane during the attempt (real lane-generation guard) utility-test-model, utility-backup utility-test-model
Guard present, model fails with a timeout falls back falls back
  • Each red was run with main's utility-completion.ts against the new tests; all green with the change. The three touched test files pass in full (19, 21 and 18 tests).
  • tsgo:core, core test typecheck and oxlint on the touched files are clean.
  • Adversarial review: land. Its one gap is taken: composer prediction's custom runner called the raw caller guard (composer-prediction-completion.ts), so its throw bypassed the wrapper; it now calls the candidate's guard. The review also confirmed that the wrapper sees only the caller's guard: the operator-model check, the timeout and the closed check inside isolated completion still fall back as before.
  • Local review on head e0b861ed: patch is correct, 0 findings, security cleared.
  • Live proof gap (named): the self-cancel is a timing race (the session changes or a newer task takes over during the model call), so an isolated Gateway run cannot trigger it on demand. The tests drive the real guards (recap error shape, the title owner's guard, the transcript lane generation) through the real fallback runner. Production confirmation is the post-deploy log count: the recap self-cancel fallback decisions should go from 72 per 4.35 h to 0.

…ttempt

A utility task's currency guard (Activity recap, titles, transcript summaries) throws when its own work
goes stale, while the caller's abort signal stays live. The fallback runner only treats an aborted
signal as a cancel, so it counted the throw as a model failure and ran the next utility model.
runUtilityCompletion now aborts a linked signal with the guard's error, so the chain stops on the
existing caller-cancel fact.
…llback chain

Its custom runner called the raw caller guard, so the throw bypassed runUtilityCompletion's cancel signal.
@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. labels Nov 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

The PR stops utility model fallbacks when the caller's existing stale-task guard throws.

Example: A title request uses openai/gpt-mini with openai/utility-backup configured, and its owner retires during completion.

  • Before: The utility chain attempts utility-backup after the stale-task error.
  • After: The chain stops after gpt-mini and preserves the cancellation error.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct, but required after-fix production-path evidence is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Superseded utility work unnecessarily starts backup models and can produce misleading failure messages and retry delays.
Reason: This maintainer-authored repair restores existing cancellation intent with a focused shared-owner change.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a concrete cancellation defect in the shared utility fallback path, and source review found no introduced correctness bugs.

Reviewed head: 5bcb1ab32fdd211f0be583d8708c5ba6f9e3534f

Before merge

None.

Findings

None.

Agent review details

How this fits together

Utility callers supply model settings, cancellation signals, and lifecycle guards; the shared completion adapter runs candidates through the model fallback owner and returns a result or terminal error.

flowchart TD
  A[Utility task owner] --> B[Utility completion adapter]
  B --> C[Model fallback runner]
  C --> D[Isolated completion]
  D --> E[Caller lifecycle guard]
  E --> F[Local cancellation signal]
  F --> C
Loading

Technical review

Best possible solution:

Keep cancellation translation in the existing utility adapter and have custom runners consume its candidate guard.

Do we have a high-confidence way to reproduce the issue?

Main's guard-error and signal paths establish the defect, supported by the author's reported regression failures; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch fixes the cancellation classification at its shared owner without changing model-error classification or adding another retry mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d8c456001c10.

Provenance checked

  • Utility fallback adapter and composer candidate guard keeps the original intent (6861671: Independent utility fallback chains reuse the existing fallback runner while isolated completion retains runtime and credential ownership; composer checks its restrictions for each candidate.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6861671 adds src/agents/utility-completion.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6861671cda97; files: src/agents/utility-completion.ts)
  • Ayaan Zaidi: Raw commit 85abd8b adds src/gateway/composer-prediction-completion.ts:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 85abd8bbd0bd; files: src/gateway/composer-prediction-completion.ts)
  • Vincent Koc: Raw commit c8e786c adds src/gateway/composer-prediction-completion.ts:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: c8e786ca8aee; files: src/gateway/composer-prediction-completion.ts)

PR surface

Source +20, Tests +86. Total +106 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 22 2 +20
Tests 3 87 1 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 109 3 +106

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Supply the cancellation and ordinary-failure production-path evidence described above.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 28, 2026, 12:38 AM ET / 05:38 UTC.

@obviyus
obviyus merged commit e2fa67a into main Nov 28, 2026
128 checks passed
@obviyus
obviyus deleted the core/utility-self-cancel branch November 28, 2026 05:41
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…ttempt (openclaw#207262)

## Problem

A utility task that cancels its own work makes the fallback chain run the next utility model.

- The Activity recap, titles and transcript summaries pass a currency guard (`assertCurrent`) to `runUtilityCompletion`. The guard throws when the task's own work goes stale: the recap's session changed or a newer recap took over ("Activity recap lifecycle or utility model changed"), the title owner retired, or a newer transcript capture owner took the lane.
- When it throws, the caller's abort signal is still live. The fallback runner's only cancel fact is that signal (`resolveChainStopReason`, `model-fallback-attempt.ts`), so it counts the throw as a model failure and starts the next utility model.
- Real-user log signature (a production team Gateway, 4.35 h): 72 `model_fallback_decision candidate_failed` on the utility primary with the recap's self-cancel error; 19 of them went on to a configured utility fallback that the runtime does not offer, each failing with `model_not_found` and a "Activity recap deferred" line.

## Change

`runUtilityCompletion` (the one owner every utility user goes through) wraps the caller's `assertCurrent` on the fallback path. When it throws, a local controller is aborted with that same error and the error is rethrown. The chain receives `AbortSignal.any([caller, local])`, so the existing caller-cancel stop applies. No error-name or message match, no new error class, no runner change.

- A real model failure with a current caller still falls back (test).
- The no-fallback path is unchanged: with one candidate there is no next model to stop.

## User impact

- Recaps, titles, transcript notes and composer predictions that go stale stop at once instead of trying the next utility model, and a stale recap no longer produces a fallback `model_not_found` error or a retry delay. The chain logs one `model fallback chain stopped reason=caller_signal_aborted` line instead.
- Not changed: progress narration and the session observer already cancel through their abort signal.

## Evidence

| Test | Main | This PR |
|---|---|---|
| `utility-completion.runtime.test.ts`: guard throws the recap's `AbortError`, caller signal live | 3 model calls | 1 |
| `conversation-label-generator.test.ts`: title owner retires during the utility attempt | `gpt-mini`, `utility-backup` | `gpt-mini` |
| `summary-model.test.ts`: a newer capture owner takes the summary lane during the attempt (real lane-generation guard) | `utility-test-model`, `utility-backup` | `utility-test-model` |
| Guard present, model fails with a timeout | falls back | falls back |

- Each red was run with main's `utility-completion.ts` against the new tests; all green with the change. The three touched test files pass in full (19, 21 and 18 tests).
- `tsgo:core`, core test typecheck and oxlint on the touched files are clean.
- Adversarial review: land. Its one gap is taken: composer prediction's custom runner called the raw caller guard (`composer-prediction-completion.ts`), so its throw bypassed the wrapper; it now calls the candidate's guard. The review also confirmed that the wrapper sees only the caller's guard: the operator-model check, the timeout and the closed check inside isolated completion still fall back as before.
- Local review on head `5bcb1ab3` (after merging main for openclaw#207259): patch is correct, 0 findings, security cleared.
- Live proof gap (named): the self-cancel is a timing race (the session changes or a newer task takes over during the model call), so an isolated Gateway run cannot trigger it on demand. The tests drive the real guards (recap error shape, the title owner's guard, the transcript lane generation) through the real fallback runner. Production confirmation is the post-deploy log count: the recap self-cancel fallback decisions should go from 72 per 4.35 h to 0.

Co-authored-by: Ayaan Zaidi <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
…ttempt (#207262)

## Problem

A utility task that cancels its own work makes the fallback chain run the next utility model.

- The Activity recap, titles and transcript summaries pass a currency guard (`assertCurrent`) to `runUtilityCompletion`. The guard throws when the task's own work goes stale: the recap's session changed or a newer recap took over ("Activity recap lifecycle or utility model changed"), the title owner retired, or a newer transcript capture owner took the lane.
- When it throws, the caller's abort signal is still live. The fallback runner's only cancel fact is that signal (`resolveChainStopReason`, `model-fallback-attempt.ts`), so it counts the throw as a model failure and starts the next utility model.
- Real-user log signature (a production team Gateway, 4.35 h): 72 `model_fallback_decision candidate_failed` on the utility primary with the recap's self-cancel error; 19 of them went on to a configured utility fallback that the runtime does not offer, each failing with `model_not_found` and a "Activity recap deferred" line.

## Change

`runUtilityCompletion` (the one owner every utility user goes through) wraps the caller's `assertCurrent` on the fallback path. When it throws, a local controller is aborted with that same error and the error is rethrown. The chain receives `AbortSignal.any([caller, local])`, so the existing caller-cancel stop applies. No error-name or message match, no new error class, no runner change.

- A real model failure with a current caller still falls back (test).
- The no-fallback path is unchanged: with one candidate there is no next model to stop.

## User impact

- Recaps, titles, transcript notes and composer predictions that go stale stop at once instead of trying the next utility model, and a stale recap no longer produces a fallback `model_not_found` error or a retry delay. The chain logs one `model fallback chain stopped reason=caller_signal_aborted` line instead.
- Not changed: progress narration and the session observer already cancel through their abort signal.

## Evidence

| Test | Main | This PR |
|---|---|---|
| `utility-completion.runtime.test.ts`: guard throws the recap's `AbortError`, caller signal live | 3 model calls | 1 |
| `conversation-label-generator.test.ts`: title owner retires during the utility attempt | `gpt-mini`, `utility-backup` | `gpt-mini` |
| `summary-model.test.ts`: a newer capture owner takes the summary lane during the attempt (real lane-generation guard) | `utility-test-model`, `utility-backup` | `utility-test-model` |
| Guard present, model fails with a timeout | falls back | falls back |

- Each red was run with main's `utility-completion.ts` against the new tests; all green with the change. The three touched test files pass in full (19, 21 and 18 tests).
- `tsgo:core`, core test typecheck and oxlint on the touched files are clean.
- Adversarial review: land. Its one gap is taken: composer prediction's custom runner called the raw caller guard (`composer-prediction-completion.ts`), so its throw bypassed the wrapper; it now calls the candidate's guard. The review also confirmed that the wrapper sees only the caller's guard: the operator-model check, the timeout and the closed check inside isolated completion still fall back as before.
- Local review on head `5bcb1ab3` (after merging main for #207259): patch is correct, 0 findings, security cleared.
- Live proof gap (named): the self-cancel is a timing race (the session changes or a newer task takes over during the model call), so an isolated Gateway run cannot trigger it on demand. The tests drive the real guards (recap error shape, the title owner's guard, the transcript lane generation) through the real fallback runner. Production confirmation is the post-deploy log count: the recap self-cancel fallback decisions should go from 72 per 4.35 h to 0.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit e2fa67a)

Release adaptation: Combine the release transcript summary helpers with the upstream cancel-through-persistence regression imports.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Release adaptation: Keep current recap lease and profile checks, return deliberate role refusals without retry, and snapshot only the admitted model restriction for each observer run. Adapt role regression fixtures to the stable admission API.

Companion audit: #206962 already committed as the ordered companion. #207774 plugin generation handling is already in stable. #207262 cancellation, #205607 title fallback, and #208460 provider routing are separate existing behaviors; #207247 is follow-up documentation.

(cherry picked from commit 6d8d1f5)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…ttempt (#207262)

A utility task that cancels its own work makes the fallback chain run the next utility model.

- The Activity recap, titles and transcript summaries pass a currency guard (`assertCurrent`) to `runUtilityCompletion`. The guard throws when the task's own work goes stale: the recap's session changed or a newer recap took over ("Activity recap lifecycle or utility model changed"), the title owner retired, or a newer transcript capture owner took the lane.
- When it throws, the caller's abort signal is still live. The fallback runner's only cancel fact is that signal (`resolveChainStopReason`, `model-fallback-attempt.ts`), so it counts the throw as a model failure and starts the next utility model.
- Real-user log signature (a production team Gateway, 4.35 h): 72 `model_fallback_decision candidate_failed` on the utility primary with the recap's self-cancel error; 19 of them went on to a configured utility fallback that the runtime does not offer, each failing with `model_not_found` and a "Activity recap deferred" line.

`runUtilityCompletion` (the one owner every utility user goes through) wraps the caller's `assertCurrent` on the fallback path. When it throws, a local controller is aborted with that same error and the error is rethrown. The chain receives `AbortSignal.any([caller, local])`, so the existing caller-cancel stop applies. No error-name or message match, no new error class, no runner change.

- A real model failure with a current caller still falls back (test).
- The no-fallback path is unchanged: with one candidate there is no next model to stop.

- Recaps, titles, transcript notes and composer predictions that go stale stop at once instead of trying the next utility model, and a stale recap no longer produces a fallback `model_not_found` error or a retry delay. The chain logs one `model fallback chain stopped reason=caller_signal_aborted` line instead.
- Not changed: progress narration and the session observer already cancel through their abort signal.

| Test | Main | This PR |
|---|---|---|
| `utility-completion.runtime.test.ts`: guard throws the recap's `AbortError`, caller signal live | 3 model calls | 1 |
| `conversation-label-generator.test.ts`: title owner retires during the utility attempt | `gpt-mini`, `utility-backup` | `gpt-mini` |
| `summary-model.test.ts`: a newer capture owner takes the summary lane during the attempt (real lane-generation guard) | `utility-test-model`, `utility-backup` | `utility-test-model` |
| Guard present, model fails with a timeout | falls back | falls back |

- Each red was run with main's `utility-completion.ts` against the new tests; all green with the change. The three touched test files pass in full (19, 21 and 18 tests).
- `tsgo:core`, core test typecheck and oxlint on the touched files are clean.
- Adversarial review: land. Its one gap is taken: composer prediction's custom runner called the raw caller guard (`composer-prediction-completion.ts`), so its throw bypassed the wrapper; it now calls the candidate's guard. The review also confirmed that the wrapper sees only the caller's guard: the operator-model check, the timeout and the closed check inside isolated completion still fall back as before.
- Local review on head `5bcb1ab3` (after merging main for #207259): patch is correct, 0 findings, security cleared.
- Live proof gap (named): the self-cancel is a timing race (the session changes or a newer task takes over during the model call), so an isolated Gateway run cannot trigger it on demand. The tests drive the real guards (recap error shape, the title owner's guard, the transcript lane generation) through the real fallback runner. Production confirmation is the post-deploy log count: the recap self-cancel fallback decisions should go from 72 per 4.35 h to 0.

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit e2fa67a)

Release adaptation: exercise the same capture owner supersession with the stable utterance snapshot shape and public provider types. Later PR-number mentions are unrelated; no required follow-up.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
* refactor: prepare transcript speaker attribution once per snapshot

* test: assert prepared transcript turns across the SQLite worker

(cherry picked from commit 3990574)

Release adaptation: retain stable provider and protocol types while sharing the existing persisted speaker roster across capped summary and Markdown presentation. No persisted schema changes.

Release adaptation: integration conflict with 8e715d1 (#207262) resolved by preserving the capture-owner cancellation test and providing prepared snapshot turns for its store fixture.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant