Skip to content

fix(agents): prevent fallback after stale lifecycle abort - #117168

Merged
vincentkoc merged 1 commit into
mainfrom
audit/issue-116418-lifecycle-20260801
Aug 1, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
audit/issue-116418-lifecycle-20260801

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Closes #116418

What Problem This Solves

Fixes an issue where users selecting an Ollama or other primary model could be silently routed to a configured fallback when the primary attempt was aborted because it belonged to a stale Gateway lifecycle.

Why This Change Was Made

Stale lifecycle ownership is a local coordination failure, not a provider failure. This change gives that abort a stable internal identity and stops model fallback before another provider is invoked, including when a generic timeout-shaped AbortError wraps the lifecycle error. Explicit provider failure metadata remains authoritative.

User Impact

Gateway lifecycle failures now surface on the requested run instead of silently invoking a cloud fallback. This preserves the user's provider choice and avoids unexpected remote usage or charges.

Thanks @Myer66 for the corrected lifecycle trace and reproducible routing evidence.

Evidence

  • node scripts/run-vitest.mjs src/agents/failover-error.test.ts — 106 passed
  • node scripts/run-vitest.mjs src/agents/model-fallback.test.ts — 138 passed
  • Live isolated Ollama route reached provider=ollama, api=ollama, endpoint=local, model llama3.2:3b; the small model later made an unrelated invalid sessions_yield call.
  • Formatting, targeted oxlint, import-cycle, env-var budget, conflict-marker, max-lines, and git diff --check checks passed.
  • Two Codex autoreview passes reported no accepted/actionable findings.
  • Full changed-check delegation was unavailable because the configured Blacksmith/Crabbox backend was not ready. Local tsgo also encounters the unchanged packages/terminal-core/src/ansi.ts TS2554 baseline failure; the linked sparse install cannot resolve @openclaw/session-url-contract/parse. Exact-head CI remains the authoritative broad gate.

AI-assisted implementation; the maintainer reviewed the code path, tests, and live proof.

@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 1, 2026 02:24
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the audit/issue-116418-lifecycle-20260801 branch from 95cb32b to 44509d7 Compare August 1, 2026 02:28
@vincentkoc
vincentkoc force-pushed the audit/issue-116418-lifecycle-20260801 branch from 44509d7 to a056ebc Compare August 1, 2026 02:30
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 31, 2026, 11:14 PM ET / August 1, 2026, 03:14 UTC.

ClawSweeper review

What this changes

The branch marks stale Gateway lifecycle aborts with a stable internal code so model fallback stops instead of silently trying another configured provider.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding. Current main still turns a stale Gateway lifecycle into an unstructured AbortError, while the fallback runner only stops for recognized coordination failures; this branch gives that producer-owned abort a closed code and recognizes nested instances without overriding an explicitly identified provider failure. The PR remains necessary and should stay open for maintainer review because it intentionally changes fallback routing for an auth/provider-sensitive path.

Priority: P1
Reviewed head: a056ebca84057b0cde3c1678cf631226b592bc40

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-aligned repair with regression coverage and green exact-head checks; its remaining consideration is the intentional provider-routing semantic change.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the provided body also records a redacted live isolated Ollama-route observation plus exact-head proof checks.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the provided body also records a redacted live isolated Ollama-route observation plus exact-head proof checks.
Evidence reviewed 7 items Current stale-lifecycle producer: Current main throws a generic AbortError for a stale lifecycle generation, without a machine-readable identity that the fallback classifier can recognize.
Fallback decision boundary: The fallback runner rethrows recognized coordination errors before recording a failed candidate or proceeding to another model, so classification is the correct owner boundary for this defect.
Patch applies the canonical fix: The PR changes the lifecycle producer to emit a stable stale-lifecycle error and updates the shared classifier to detect it through wrappers while retaining direct provider-failure precedence.
Findings None None.
Security None None.

How this fits together

Agent runs capture a Gateway lifecycle generation before executing a selected model. If the Gateway rotates, the lifecycle guard aborts stale work; the model-fallback runner classifies that error to decide whether to retry a fallback provider or surface the original failure.

flowchart LR
  A[Requested model run] --> B[Gateway lifecycle guard]
  B --> C{Generation current?}
  C -->|No| D[Stale lifecycle abort]
  D --> E[Failover error classification]
  E --> F{Local coordination or provider failure?}
  F -->|Local coordination| G[Surface requested-run failure]
  F -->|Provider failure| H[Try configured fallback]
Loading

Before merge

  • Resolve merge risk (P2) - Merging intentionally changes a stale lifecycle abort from fallback-eligible to terminal: a real provider failure that is wrapped with a stale lifecycle error must still retain its explicit provider identity and continue through configured fallback. The branch's direct-identity guard and focused tests address that boundary, but it is an auth/provider routing behavior that merits owner review.
  • Complete next step (P2) - No mechanical repair remains from this review; the protected maintainer-owned PR needs agent-runtime review of its intentional fallback-routing change before merge.
Agent review details

Security

None.

PR surface

Source +46, Tests +52. Total +98 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 49 3 +46
Tests 2 52 0 +52
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 101 3 +98

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Land with the guarded terminal classification (recommended)
    Accept the intentional routing change after reviewing that explicit direct provider metadata remains fallback-eligible while stale lifecycle ownership loss surfaces on the requested run.

Technical review

Best possible solution:

Land the producer-owned error identity and shared fallback classification after an agent-runtime owner confirms the intended stale-lifecycle-versus-provider-failure precedence on the current head; the linked report can then close through the merged PR.

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

Yes. Current main throws the stale lifecycle as an ordinary AbortError at src/infra/agent-events.ts:197, and the fallback runner only terminates on classified coordination errors at src/agents/model-fallback-runner.ts:505; the PR's focused wrapper test models that exact decision boundary.

Is this the best way to solve the issue?

Yes. Giving the lifecycle owner a closed error identity and recognizing it in the shared fallback classifier is narrower and more maintainable than adding provider-specific exceptions or message matching; the direct-provider-identity guard preserves the competing provider-failure contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a0fe02a6dcf3.

Labels

Label justifications:

  • P1: A stale lifecycle can silently route a user-selected local model to a configured cloud fallback, changing provider choice and potential usage immediately.
  • merge-risk: 🚨 auth-provider: The branch changes when configured fallback providers may be invoked, so an incorrect classification could surface an error instead of using the user's fallback route.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the provided body also records a redacted live isolated Ollama-route observation plus exact-head proof checks.

Evidence

What I checked:

  • Current stale-lifecycle producer: Current main throws a generic AbortError for a stale lifecycle generation, without a machine-readable identity that the fallback classifier can recognize. (src/infra/agent-events.ts:197, 02457657f012)
  • Fallback decision boundary: The fallback runner rethrows recognized coordination errors before recording a failed candidate or proceeding to another model, so classification is the correct owner boundary for this defect. (src/agents/model-fallback-runner.ts:505, 02457657f012)
  • Patch applies the canonical fix: The PR changes the lifecycle producer to emit a stable stale-lifecycle error and updates the shared classifier to detect it through wrappers while retaining direct provider-failure precedence. (src/agents/failover-error.ts:501, a056ebca8405)
  • Regression coverage: The branch adds focused coverage for direct and wrapped stale lifecycle errors, including an Ollama-primary fallback chain that must make exactly one run attempt. (src/agents/model-fallback.test.ts:1931, a056ebca8405)
  • Current-path provenance: Blame attributes the current resolver and lifecycle guard lines to the recent lifecycle/refactor history, with the linked base commit 7fba71eb7aeb73f6a3b146389e251625efb4fd07 immediately preceding this PR's base. (src/agents/failover-error.ts:895, 9ec20c4a1d6b)
  • Current-main comparison: The PR head is not an ancestor of the current main checkout; current main lacks src/infra/agent-lifecycle-error.ts and still has the generic lifecycle abort, so the reported behavior is not already implemented. (src/infra/agent-events.ts:197, 02457657f012)

Likely related people:

  • Peter Steinberger: Current blame attributes the resolver and stale-lifecycle guard lines to his recent lifecycle/refactor history, including the mainline base immediately before this PR. (role: recent area contributor; confidence: medium; commits: 9ec20c4a1d6b, 7fba71eb7aeb; files: src/agents/failover-error.ts, src/infra/agent-events.ts)
  • vincentkoc: The PR author also appears in recent lifecycle-focused history and authored the candidate repair that spans the lifecycle producer and shared fallback classifier. (role: recent lifecycle contributor; confidence: medium; commits: a056ebca8405, d8f229f2e6; files: src/infra/agent-events.ts, src/agents/failover-error.ts, src/agents/model-fallback.test.ts)

Rank-up moves

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

  • Obtain agent-runtime owner review of the stale-lifecycle versus explicit-provider-failure precedence before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-01T02:36:03.723Z sha a056ebc :: needs maintainer review before merge. :: none

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer disposition for the remaining optional ClawSweeper rank-up move: landing is explicitly approved in this maintenance run. The reviewed boundary is the direct-provider-identity guard: explicit provider metadata remains fallback-eligible, while a stale lifecycle error without that direct identity is terminal coordination. This is covered by the direct/wrapped classifier tests, the Ollama-primary single-attempt fallback test, exact-head CI, and two clean autoreview passes. No broader routing change is included.

@vincentkoc
vincentkoc merged commit 5d97721 into main Aug 1, 2026
128 of 133 checks passed
@vincentkoc
vincentkoc deleted the audit/issue-116418-lifecycle-20260801 branch August 1, 2026 03:17
vincentkoc added a commit to chenyangjun-xy/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  test(google): cover live transcript overflow
  fix(google): bound live transcript accumulation
wingwkyuen pushed a commit to tcgoidc/openclaw that referenced this pull request Aug 1, 2026
* commit '6938f7dddb63bad59862c014c427d63f0a41a6f4': (368 commits)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
  refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157)
  fix(ui): retire stale Gateway event-log observers (openclaw#117169)
  fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141)
  refactor(ui): unify filtered session list ownership (openclaw#117158)
  refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149)
  fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957)
  refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150)
  refactor(reply): unify turn lifecycle state ownership (openclaw#117145)
  fix(ui): preserve emoji agent avatar initials (openclaw#104912)
  refactor(auto-reply): unify command and directive ownership (openclaw#117143)
  refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146)
  ...
sunlit-deng pushed a commit to sunlit-deng/openclaw that referenced this pull request Aug 1, 2026
* commit '441d6ab254df14fb6939a8a261f474904ff9c500': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* commit '55215cd9edd2b585cbaee5481d5352aabf7e4399': (368 commits)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  fix(ui): keep canvas lease renewals lifecycle-owned and timer-safe (openclaw#117173)
  fix(teams): restore the official square product icon (openclaw#117170)
  refactor(ui): replace duplicated locale bundles with canonical translation memory (openclaw#117157)
  fix(ui): retire stale Gateway event-log observers (openclaw#117169)
  fix(agents): keep subagent status consistent after restart and large fan-outs (openclaw#117141)
  refactor(ui): unify filtered session list ownership (openclaw#117158)
  refactor(agents): consolidate context budgets and compaction recovery (openclaw#117149)
  fix(net-policy): redact sig and x-* auth params in URLs and bodies (openclaw#116957)
  refactor(agents): remove duplicate generated-media delivery fallbacks (openclaw#117150)
  refactor(reply): unify turn lifecycle state ownership (openclaw#117145)
  fix(ui): preserve emoji agent avatar initials (openclaw#104912)
  refactor(auto-reply): unify command and directive ownership (openclaw#117143)
  refactor(plugins): consolidate descriptor and startup ownership (openclaw#117146)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* origin/main:
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (openclaw#114949)
  fix(gateway): yield before post-ready background work (openclaw#117083)
  test(google): cover live transcript overflow
  fix(google): bound live transcript accumulation
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* commit 'ae4e662145b6aa162777cdb1c011b3f04ddd230d': (388 commits)
  fix(qqbot): ignore blank app id fallbacks (openclaw#109460)
  fix(feishu): consume implicit reply targets across media delivery (openclaw#117196)
  fix(exec): preserve approved command output when sessions resume (openclaw#117177)
  fix(qa): use public subagent fanout evidence (openclaw#116832)
  fix(googlechat): cancel unread auth response bodies before release (openclaw#115873)
  fix(queue): prevent cron saturation from starving hook dispatch (openclaw#116666)
  fix(gateway): sessions.steer retry no longer interrupts an active run when replaying a cached idempotency key (openclaw#116969)
  fix(irc): config validation rejects documented channels.irc.configWrites key (openclaw#112392)
  fix(mistral): keep terminal error branch lint-clean
  fix(onboard): stop a full reset from resetting the default workspace when the config is unreadable (openclaw#114110)
  refactor(i18n): remove unused Apple contradiction report (openclaw#117182)
  fix(google): stop scraping Gemini CLI OAuth credentials (openclaw#117167)
  perf: count large histories before Gateway prewarm (openclaw#117118)
  fix(signal): restore provider-safe original attachment filenames (openclaw#115107)
  refactor(channels): unify setup ownership across bundled channels (openclaw#117188)
  fix: allow gateway service commands for named profiles (openclaw#116314)
  fix(plugins): invalidate bundled artifact locations after metadata refresh (openclaw#117041)
  fix(ollama): honor model requests and pull completion contracts (openclaw#117171)
  fix(agents): prevent fallback after stale lifecycle abort (openclaw#117168)
  fix(telegram): confirm polling before long poll (openclaw#116970)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

[Bug] Ollama provider never selected as primary in 2026.7.1: routing always falls back to the next model

1 participant