Skip to content

fix: existing automations fail after account-binding upgrades - #172792

Merged
roboclaw-bot merged 9 commits into
mainfrom
openclaw/investigate-cron-model-migration-172590
Oct 15, 2026
Merged

roboclaw-bot merged 9 commits into
mainfrom
openclaw/investigate-cron-model-migration-172590

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #172590

What Problem This Solves

Fixes: existing automations fail after upgrading to required inference-account binding, even when their model was already explicitly selected.

User Impact

Repairing Doctor can adopt an explicitly selected or sole eligible shared stored account without pinning inherited models or changing fallback lists. Repairs are backed up and idempotent; existing bindings, authored fields, runtime state and valid approval authority are preserved.

Migration is best effort: malformed jobs and recoverable inspection/backup/commit failures produce actionable warnings, not upgrade failure. Ambiguous, unavailable, personal-account, direct-key and native-owned cases are not silently assigned another account. Startup diagnostics do not disable jobs or capture credentials. Managed updates and the standard container entrypoint reach repairing Doctor; manual source upgrades still require openclaw doctor --fix before Gateway startup.

Best effort does not mean bypassing account authority or admitting unsafe database state.

Why This Change Was Made

The reporter evidence matches missing durable account adoption, not a model-pin requirement. Last-used telemetry may reflect fallback and does not establish account authority.

The existing Doctor owner now inspects canonical SQLite partitions, including stores without legacy quarantine files. Canonical current model/session/config selection and auth planning select an explicit or unambiguous shared account. Exclusive maintenance, credential-preserving CAS, verified backup and live authority checks guard persistence. Binding-only changes preserve uniquely attributable valid scheduled-approval revisions without minting or reviving permissions.

Evidence

  • 55 migration/auth/startup tests, 99 credential-writer/database-worker guard tests, 4 heartbeat boundary tests, and 14 probe/survivor tests passed (172 distinct cases, including the previously counted 5 survivor cases). Real Doctor proof covers canonical-only SQLite, inactive partitions, inherited/default/session/fallback preservation, existing bindings, backup/idempotence, grant consumption and subsequent revocation refusal.
  • Negative controls reproduced missing adoption, malformed-row batch abandonment and the absent startup barrier. Fixes preserve bad rows while migrating unrelated jobs. Injected backup I/O failure gives a warning and no cron writes. Exact writer-edge/maintenance-branch registrations retain sibling/unguarded/nested-callback rejection; the real T1 ratchet stays 223 → 223. Scoped lint/format/syntax, line-cap, diff and Docker boundary guards passed. Independent reviews are clean through P2 after required fixes.
  • Migration 5-case cold run: 98.65s; guard99: 3.83s; heartbeat4: 46.18s; final probe/survivor14: 2.44s (wrapper4.73s). New startup tests virtualize retry time. No provider calls or production jobs were used.
  • Current-head CI completed: 62 successful jobs, 2 failed, 25 skipped. Node tests, production/test types, guards and security-fast passed. The sole root failure is two inherited typescript(no-generated-empty-object-type) diagnostics in chat-composer-types.ts and chat-pane-session-controls.ts; the CI gate is downstream. Actual tested merge 241b6252 has baseline 469837ed and head c707a81c. The entire UI tree, dependency lockfile, lint configuration and runtime wrappers are identical to that baseline. This is source-qualified attribution, not a separately executed baseline lint run; CI remains failed and native inherited-failure admission must still satisfy live security/review/authority checks.
  • The final published 9.7 upgrade survivor passed package integrity/install, the published updater and candidate Doctor, canonical SQLite preservation with zero quarantine, two content-verified repair backups, idempotence, installed cron execution under both historical and explicit owners, and transcript continuity. The corrected fixture waits for documented /startupz completion before all-agent probes; production readiness, admission, assertions and timeouts are unchanged.
  • Inspected run payload binds reviewed harness c707a81c to immutable product package 8cbf3c69, artifact 11951618954 from producer 38687795948 attempt 1. Only four harness/test files differ; product implementation is unchanged. Package SHA-256: b0e4f30b4938b47d31ec4781ed651a244335bb7ef9bf9a243e48565e64e777c9. Runtime receipts both returned ok; session continuity was preserved. This proof uses manual restart and synthetic system events, not automatic supervisor restart or a live inference-provider request.

Reported and proposed by @obviyus; builds on the account-continuity work by @fuller-stack-dev.

Worked on by

Work sessions


View the OpenClaw team session

roboclaw-bot and others added 2 commits October 15, 2026 03:42
Adopt an explicit or unambiguous currently eligible stored account through repairing Doctor without rewriting model inheritance or fallbacks. Preserve still-valid scheduled approval references and warn before unmigrated jobs dispatch.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 524a6ccf-82be-40a8-bc9c-1e40e845e494
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: XL labels Oct 15, 2026
roboclaw-bot and others added 2 commits October 15, 2026 04:12
Keep malformed legacy session targets inside the per-job warning boundary so unrelated accounts still migrate. Prove inactive malformed rows stay unchanged, later jobs migrate, and backup I/O failure remains warning-only without cron writes.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 6a402b94-4fcc-4d45-a88c-776ccea31e14
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review October 15, 2026 04:19
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: c707a81c29e4c6c95e967727b5c0c4d054496fdc
  • Maintainer: @roboclaw-bot
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/authorization-enrollment-runtime.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

roboclaw-bot and others added 3 commits October 15, 2026 05:16
Audit and register the exact credential-preserving enrollment caller and its synchronous exclusive-maintenance branch. Keep unguarded, sibling and nested-callback writes under the existing guards; regenerate the inventory from its owner.

Move the unchanged cron heartbeat override sanitizer into the existing heartbeat configuration owner so the new startup diagnostic does not grow the oversized Gateway assembly.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Stop creating a retired raw JSON source after the published baseline Doctor. Preserve the ten canonical owner and delivery specimens and require no quarantine, unchanged updater/Doctor entry state, both content-verified repair backups, idempotence and installed Gateway continuity.

The old cell correctly refused unsupported state before reaching Doctor; retirement admission is unchanged.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 05083e4f-966d-4e07-a05a-23acd2f3573b
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 15, 2026
roboclaw-bot and others added 2 commits October 15, 2026 06:43
Use the produced startup probe state before optional-agent history reads in
the canonical cron survivor, without retries around runtime assertions or
changes to production readiness, database admission, or probe timeouts.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 3012a4f6-fbc4-4908-bc21-ac8373ef64d4
@roboclaw-bot
roboclaw-bot merged commit d277de7 into main Oct 15, 2026
183 of 186 checks passed
@roboclaw-bot
roboclaw-bot deleted the openclaw/investigate-cron-model-migration-172590 branch October 15, 2026 14:47
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

obviyus added a commit that referenced this pull request Oct 15, 2026
…lback (#173411)

Related: #172590, #172792

## What Problem This Solves

Since #172590, an automation created before account binding has no recorded inference account. When its model route authenticates with an environment or provider-config key (`models.providers.<id>.apiKey`, a documented setup), two things go wrong after an update:

1. **Every run is refused** with "Automation has no recorded inference account". #172792's Doctor migration deliberately does not adopt these jobs ("environment/provider-config credential, not a durable stored account"), so the refusal stays until someone hand-edits each job.
2. **The refusal falls through the model fallback chain.** The refusal is a plain `Error`, so `runWithModelFallback` tries the next candidate. A job whose fallback is credentialless or uses a native CLI login then runs on that model and reports `ok`. On a real install, two hourly OpenAI jobs began running on an Anthropic fallback right after the update. This is the account switch #172590 exists to prevent, now across providers, and with no visible error.

## Why This Change Was Made

Rule: a key the operator configured in env or provider config is the only credential such a legacy job could have used, so the job keeps running on it. A stored account, or any other ambient credential (AWS SDK, runtime), still needs explicit adoption. Every account refusal ends the run and never tries a fallback model.

- `isConfiguredKeyAuthSource` in `provider-model-auth-source-plan.ts` names the admitted direct sources: synthetic (credentialless), `environment` and `provider-config`. The cron gate in `auth-plan.ts` and the Doctor migration share it.
- `auth-plan.ts`: for an unbound cron job, the gate refuses stored profiles and other direct sources (`aws-sdk`, `runtime`, `none`), as before. Configured keys pass.
- The account refusal in the embedded runner, CLI preparation and the cron CLI path is recorded with `recordModelFallbackStop`, the existing owner of terminal errors in the fallback chain, so `runWithModelFallback` rethrows it.
- Doctor (`inference-binding-migration.ts`) skips configured-key routes instead of warning, because no stored account exists to record. Other direct sources still warn.
- Docs: `cron-jobs/payloads.md` and `cron-jobs/troubleshooting.md` describe the rule and the no-fallback refusal.

Unchanged: bound jobs, creation of new jobs (still requires a stored account), personal and native accounts, the startup diagnostic, and the binding format. No schema or stored-row change.

## User Impact

Automations created before account binding that use an env or provider-config key keep running on the same key and billing after the update, with no Doctor warning. A job that does need adoption now fails visibly with the adoption instructions instead of silently running on another model or provider.

## Evidence

- **Regressions through the real embedded runner** (`isolated-agent.auth-continuity.integration.test.ts`; real auth planning, cron and fallback runner, only provider HTTP stubbed):
  - "keeps running on its provider-config key": fails on `main` (all models refused or failed) and passes here with one request carrying `Bearer synthetic-config-key`.
  - "stops on an unadopted stored account instead of falling back": fails on `main` (status `ok`, because the loopback fallback ran) and passes here (status `error`, no provider request).
- **Auth boundary contract** (`inference-binding-executor.test.ts`):
  - cron now matches event for a provider-config key;
  - refusal is kept for a stored account and for an explicit `aws-sdk` route (the source is `{ kind: "direct", evidence: "aws-sdk" }`);
  - credentialless, native and synthetic-marker routes still pass.
- **Doctor** (`inference-binding-migration.accounts.test.ts`): no warning for the direct-key job. The other refusal cases are unchanged.
- **Focused suites pass:** Doctor migration (both files), auth-profile propagation, inference-binding executor, CLI routing authority, auth-controller binding, auth continuity integration.
- **Published-driver × candidate upgrade, live** (real Gateway, CLI, cron, auth and HTTP paths; local SSE mock provider; synthetic keys; `models.providers.openai.apiKey` as an env SecretRef; fallback `local/mock-b` on a credentialless loopback route):
  - **`v2026.10.3`:** `cron add` an isolated job, then `cron run`. Status `ok`, one request to the OpenAI mock with `Bearer synthetic-config-key`. The job row has no `inferenceBinding`.
  - **`main` base (`51ba56f`) on a copy of that state:** `doctor --fix` warns "inference account was not migrated: The current route uses an environment/provider-config credential…". `cron run` reports `ok`, but the only provider request went to `/local/v1/responses`, and run history shows the fallback model. This is the silent fallback.
  - **Candidate (`689032d`) on another copy:** `doctor --fix` gives no migration warning. `cron run` returns `ok` with one request to the OpenAI mock (`Bearer synthetic-config-key`) and none to `local`. Run history shows `openai`.
  - **Refusal on the candidate:** after an `openai` api-key profile is added and becomes eligible for the route (config key removed, profile selected), `cron run` fails with "Automation has no recorded inference account…", and neither provider receives a request. While an explicit provider SecretRef is configured, adding a profile does not change the route: the job keeps the configured key (`prepare-auth.ts` lets an authored provider SecretRef take priority over automatic profile selection).
  - The heads after the live run (`a2f83dc`, `04fbdc7`) change only the source predicate and its type: `aws-sdk` and `runtime` sources are refused again, as on `main`. The configured-key and refusal paths above are the same code.
- **Existing data:** no stored shape changes. In the upgrade run, a job created by `v2026.10.3` loads and runs on this candidate. Bound jobs keep their binding, as the existing continuity test shows.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 15, 2026
…of failing every run (#173509)

Related: #172590, #172792, #173411

## What Problem This Solves

After an update, an automation created before account binding keeps failing on every run when Doctor cannot choose an account for it:

- **Several eligible stored accounts** (for example an API key and a subscription login for one provider): Doctor only warns "More than one inference account is eligible", and every run then fails with "Automation has no recorded inference account" until someone edits the job by hand.
- **Creating a new job** whose route uses a key in env or provider config is refused ("requires a stored inference account"), although since #173411 an old job on the same key keeps running.

## Why This Change Was Made

Rule: a job with no recorded account gets the account its next unbound run would use. That is an explicit selection, or else the first account from the runtime's normal planner, the same account every unbound run used before #172590. Refuse only when no account fits, or when that account is another person's personal login. Keys in env or provider config, and credentialless routes, have no stored account to record: they keep the job unbound, for creation as well as for runs.

- **Doctor (`inference-binding-migration.ts`):**
  - computes the current route with the same `prepareAgentRuntimeAuth` call as a run, including the provider preferred-profile hook (`resolveProviderAuthProfileId`), which it did not pass before;
  - when several accounts are eligible, records the planner's first account instead of refusing;
  - names the other eligible accounts and the `automations edit … --model …@<profileId>` command in its change log;
  - leaves explicit selections, missing accounts, personal-account refusal, backup and commit unchanged.
- **Creation (`captureCronInferenceBinding`)** uses the run's predicate (`isConfiguredKeyAuthSource`): a configured-key route creates an unbound job instead of failing. Other direct sources are still refused.
- **Docs:** `cron-jobs/payloads.md` and `cron-jobs/troubleshooting.md`.

Not changed: AWS SDK and runtime credentials (they still need adoption; a separate follow-up can admit declared AWS SDK routes), bound jobs and their protection against later default or order changes, personal-account rules, native/CLI runtime ownership, the binding format and the stored data. A manual source upgrade still needs `openclaw doctor --fix`, as the docs already say. Managed updates and the container entrypoint run it. There is no new runtime write path: recording an account from a run would need the credential authority capture that Doctor's offline maintenance scope provides, and every supported update path already reaches Doctor.

## User Impact

After an update, an old automation with several eligible accounts keeps running on the same account it used before, and Doctor reports which account it recorded and how to change it. New automations can use a key in env or provider config, like old ones.

## Evidence

- **Doctor regression** (`inference-binding-migration.accounts.test.ts`): the `ambiguous` job (two eligible OpenAI accounts, one in cooldown) now records `openai:a`, the planner's first account, with "Also eligible: openai:b". On `main` the same test fails with "More than one inference account is eligible". A job whose session holds an earlier automatic fallback to another provider records the default provider's account, not the fallback's.
- **Creation** (`cron.inference-binding.test.ts`): `cron.add` on an env key and on a provider-config key creates an unbound job. On `main` both are refused.
- **Personal accounts** (new Doctor test): with a personal account first in `auth.order`, the unattended planner never selects it, so Doctor records the shared account a run would use and never the personal one. The existing Gateway test "requires the personal owner for explicit creation and account adoption" covers explicit adoption.
- **Focused suites pass:** Doctor migration (both files), Gateway cron binding, inference-binding executor, auth-profile propagation.
- **Fleet census** (read-only Doctor previews on four real installs): see the comment on #172590.
- **Live differential** (real Gateway and CLI; a mock OpenAI provider that logs each request's `Authorization` header; two stored OpenAI profiles added through the CLI, `openai:alpha` then `openai:beta`, with `auth.order.openai = [beta, alpha]`; synthetic keys; a credentialless `local` fallback):

  | Step | Build | Result | Provider request |
  |---|---|---|---|
  | 1 | `v2026.10.3` | `cron run` → `ok`; the job row has no `inferenceBinding` | `Bearer sk-synthetic-beta-…` |
  | 2 | `main` (`19752be`) | Doctor: "More than one inference account is eligible: openai:beta, openai:alpha". `cron run` → `error` "Automation has no recorded inference account…" | none, not even the fallback |
  | 3 | this head | Doctor: "retain openai:beta for openai/gpt-6-mock … Also eligible: openai:alpha"; row `inferenceBinding.profileId = "openai:beta"`. `cron run` → `ok` | `Bearer sk-synthetic-beta-…`, the same as step 1 |
  | 4 | this head | `auth.order` reversed to [alpha, beta], Gateway restarted, `cron run` → `ok` | `Bearer sk-synthetic-beta-…`: the binding holds |
  | 5 | this head vs `main` | fresh state with only `models.providers.openai.apiKey`: `cron add` succeeds with no binding and the run uses that key. `main` refuses `cron add` with "requires a stored inference account" | `Bearer sk-synthetic-config-…` |

  The account recorded in step 3 is not the alphabetical or first-added profile. It is the one the stable build actually sent.
- **Live boundary cases** on the candidate, from the differential state (Doctor recorded `openai:beta`):
  - the `openai:beta` key is replaced through `models auth paste-api-key`: `cron run` → `error` "Automation inference account was replaced. Explicitly select an authorized account again."; 0 provider requests, no fallback;
  - `openai:beta` is removed through `models auth logout`: `cron run` → `error`; 0 provider requests; `openai:alpha` is not used and no fallback runs. The error text is "MCP authorization was disconnected or replaced" (`MCP_AUTHORIZATION_RETIRED`), a misleading message from the existing authorization owner, not from this PR (follow-up).
  - A live personal-account case is not possible from a synthetic CLI: `users.authConnect` needs a signed-in person. Instead, `isolated-agent.auth-continuity.integration.test.ts` > "records the shared account a run plans, never a personal one listed first" connects a real personal account (`ensureProfileForEmail` + `connectUserModelAccountAsync`), puts it first in `auth.order` next to a shared API key, runs the real Doctor migration and then the real embedded cron runner with only provider HTTP stubbed. Doctor records the shared account. The run returns `ok`, and the only provider request carries the shared key (`Bearer synthetic-platform-key`): the personal key is never sent, and no fallback runs.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#172792)

* fix(cron): migrate unbound accounts during upgrades

Adopt an explicit or unambiguous currently eligible stored account through repairing Doctor without rewriting model inheritance or fallbacks. Preserve still-valid scheduled approval references and warn before unmigrated jobs dispatch.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>

* fix: existing automations fail after account-binding upgrades

Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 524a6ccf-82be-40a8-bc9c-1e40e845e494

* fix(cron): isolate legacy migration failures per job

Keep malformed legacy session targets inside the per-job warning boundary so unrelated accounts still migrate. Prove inactive malformed rows stay unchanged, later jobs migrate, and backup I/O failure remains warning-only without cron writes.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>

* fix: existing automations fail after account-binding upgrades

Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 6a402b94-4fcc-4d45-a88c-776ccea31e14

* fix(cron): register guarded Doctor enrollment ownership

Audit and register the exact credential-preserving enrollment caller and its synchronous exclusive-maintenance branch. Keep unguarded, sibling and nested-callback writes under the existing guards; regenerate the inventory from its owner.

Move the unchanged cron heartbeat override sanitizer into the existing heartbeat configuration owner so the new startup diagnostic does not grow the oversized Gateway assembly.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>

* test(cron): use canonical SQLite upgrade survivor state

Stop creating a retired raw JSON source after the published baseline Doctor. Preserve the ten canonical owner and delivery specimens and require no quarantine, unchanged updater/Doctor entry state, both content-verified repair backups, idempotence and installed Gateway continuity.

The old cell correctly refused unsupported state before reaching Doctor; retirement admission is unchanged.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>

* fix: existing automations fail after account-binding upgrades

Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 05083e4f-966d-4e07-a05a-23acd2f3573b

* test: await agent startup before cron upgrade continuity

Use the produced startup probe state before optional-agent history reads in
the canonical cron survivor, without retries around runtime assertions or
changes to production readiness, database admission, or probe timeouts.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>

* fix: existing automations fail after account-binding upgrades

Worked on by:
- @obviyus
- @fuller-stack-dev
- @Kimiyu-186
- @steipete

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
OpenClaw-Publication: 3012a4f6-fbc4-4908-bc21-ac8373ef64d4

---------

Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…lback (openclaw#173411)

Related: openclaw#172590, openclaw#172792

## What Problem This Solves

Since openclaw#172590, an automation created before account binding has no recorded inference account. When its model route authenticates with an environment or provider-config key (`models.providers.<id>.apiKey`, a documented setup), two things go wrong after an update:

1. **Every run is refused** with "Automation has no recorded inference account". openclaw#172792's Doctor migration deliberately does not adopt these jobs ("environment/provider-config credential, not a durable stored account"), so the refusal stays until someone hand-edits each job.
2. **The refusal falls through the model fallback chain.** The refusal is a plain `Error`, so `runWithModelFallback` tries the next candidate. A job whose fallback is credentialless or uses a native CLI login then runs on that model and reports `ok`. On a real install, two hourly OpenAI jobs began running on an Anthropic fallback right after the update. This is the account switch openclaw#172590 exists to prevent, now across providers, and with no visible error.

## Why This Change Was Made

Rule: a key the operator configured in env or provider config is the only credential such a legacy job could have used, so the job keeps running on it. A stored account, or any other ambient credential (AWS SDK, runtime), still needs explicit adoption. Every account refusal ends the run and never tries a fallback model.

- `isConfiguredKeyAuthSource` in `provider-model-auth-source-plan.ts` names the admitted direct sources: synthetic (credentialless), `environment` and `provider-config`. The cron gate in `auth-plan.ts` and the Doctor migration share it.
- `auth-plan.ts`: for an unbound cron job, the gate refuses stored profiles and other direct sources (`aws-sdk`, `runtime`, `none`), as before. Configured keys pass.
- The account refusal in the embedded runner, CLI preparation and the cron CLI path is recorded with `recordModelFallbackStop`, the existing owner of terminal errors in the fallback chain, so `runWithModelFallback` rethrows it.
- Doctor (`inference-binding-migration.ts`) skips configured-key routes instead of warning, because no stored account exists to record. Other direct sources still warn.
- Docs: `cron-jobs/payloads.md` and `cron-jobs/troubleshooting.md` describe the rule and the no-fallback refusal.

Unchanged: bound jobs, creation of new jobs (still requires a stored account), personal and native accounts, the startup diagnostic, and the binding format. No schema or stored-row change.

## User Impact

Automations created before account binding that use an env or provider-config key keep running on the same key and billing after the update, with no Doctor warning. A job that does need adoption now fails visibly with the adoption instructions instead of silently running on another model or provider.

## Evidence

- **Regressions through the real embedded runner** (`isolated-agent.auth-continuity.integration.test.ts`; real auth planning, cron and fallback runner, only provider HTTP stubbed):
  - "keeps running on its provider-config key": fails on `main` (all models refused or failed) and passes here with one request carrying `Bearer synthetic-config-key`.
  - "stops on an unadopted stored account instead of falling back": fails on `main` (status `ok`, because the loopback fallback ran) and passes here (status `error`, no provider request).
- **Auth boundary contract** (`inference-binding-executor.test.ts`):
  - cron now matches event for a provider-config key;
  - refusal is kept for a stored account and for an explicit `aws-sdk` route (the source is `{ kind: "direct", evidence: "aws-sdk" }`);
  - credentialless, native and synthetic-marker routes still pass.
- **Doctor** (`inference-binding-migration.accounts.test.ts`): no warning for the direct-key job. The other refusal cases are unchanged.
- **Focused suites pass:** Doctor migration (both files), auth-profile propagation, inference-binding executor, CLI routing authority, auth-controller binding, auth continuity integration.
- **Published-driver × candidate upgrade, live** (real Gateway, CLI, cron, auth and HTTP paths; local SSE mock provider; synthetic keys; `models.providers.openai.apiKey` as an env SecretRef; fallback `local/mock-b` on a credentialless loopback route):
  - **`v2026.10.3`:** `cron add` an isolated job, then `cron run`. Status `ok`, one request to the OpenAI mock with `Bearer synthetic-config-key`. The job row has no `inferenceBinding`.
  - **`main` base (`a8d5d3a`) on a copy of that state:** `doctor --fix` warns "inference account was not migrated: The current route uses an environment/provider-config credential…". `cron run` reports `ok`, but the only provider request went to `/local/v1/responses`, and run history shows the fallback model. This is the silent fallback.
  - **Candidate (`689032d`) on another copy:** `doctor --fix` gives no migration warning. `cron run` returns `ok` with one request to the OpenAI mock (`Bearer synthetic-config-key`) and none to `local`. Run history shows `openai`.
  - **Refusal on the candidate:** after an `openai` api-key profile is added and becomes eligible for the route (config key removed, profile selected), `cron run` fails with "Automation has no recorded inference account…", and neither provider receives a request. While an explicit provider SecretRef is configured, adding a profile does not change the route: the job keeps the configured key (`prepare-auth.ts` lets an authored provider SecretRef take priority over automatic profile selection).
  - The heads after the live run (`a2f83dc`, `04fbdc7`) change only the source predicate and its type: `aws-sdk` and `runtime` sources are refused again, as on `main`. The configured-key and refusal paths above are the same code.
- **Existing data:** no stored shape changes. In the upgrade run, a job created by `v2026.10.3` loads and runs on this candidate. Bound jobs keep their binding, as the existing continuity test shows.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…of failing every run (openclaw#173509)

Related: openclaw#172590, openclaw#172792, openclaw#173411

## What Problem This Solves

After an update, an automation created before account binding keeps failing on every run when Doctor cannot choose an account for it:

- **Several eligible stored accounts** (for example an API key and a subscription login for one provider): Doctor only warns "More than one inference account is eligible", and every run then fails with "Automation has no recorded inference account" until someone edits the job by hand.
- **Creating a new job** whose route uses a key in env or provider config is refused ("requires a stored inference account"), although since openclaw#173411 an old job on the same key keeps running.

## Why This Change Was Made

Rule: a job with no recorded account gets the account its next unbound run would use. That is an explicit selection, or else the first account from the runtime's normal planner, the same account every unbound run used before openclaw#172590. Refuse only when no account fits, or when that account is another person's personal login. Keys in env or provider config, and credentialless routes, have no stored account to record: they keep the job unbound, for creation as well as for runs.

- **Doctor (`inference-binding-migration.ts`):**
  - computes the current route with the same `prepareAgentRuntimeAuth` call as a run, including the provider preferred-profile hook (`resolveProviderAuthProfileId`), which it did not pass before;
  - when several accounts are eligible, records the planner's first account instead of refusing;
  - names the other eligible accounts and the `automations edit … --model …@<profileId>` command in its change log;
  - leaves explicit selections, missing accounts, personal-account refusal, backup and commit unchanged.
- **Creation (`captureCronInferenceBinding`)** uses the run's predicate (`isConfiguredKeyAuthSource`): a configured-key route creates an unbound job instead of failing. Other direct sources are still refused.
- **Docs:** `cron-jobs/payloads.md` and `cron-jobs/troubleshooting.md`.

Not changed: AWS SDK and runtime credentials (they still need adoption; a separate follow-up can admit declared AWS SDK routes), bound jobs and their protection against later default or order changes, personal-account rules, native/CLI runtime ownership, the binding format and the stored data. A manual source upgrade still needs `openclaw doctor --fix`, as the docs already say. Managed updates and the container entrypoint run it. There is no new runtime write path: recording an account from a run would need the credential authority capture that Doctor's offline maintenance scope provides, and every supported update path already reaches Doctor.

## User Impact

After an update, an old automation with several eligible accounts keeps running on the same account it used before, and Doctor reports which account it recorded and how to change it. New automations can use a key in env or provider config, like old ones.

## Evidence

- **Doctor regression** (`inference-binding-migration.accounts.test.ts`): the `ambiguous` job (two eligible OpenAI accounts, one in cooldown) now records `openai:a`, the planner's first account, with "Also eligible: openai:b". On `main` the same test fails with "More than one inference account is eligible". A job whose session holds an earlier automatic fallback to another provider records the default provider's account, not the fallback's.
- **Creation** (`cron.inference-binding.test.ts`): `cron.add` on an env key and on a provider-config key creates an unbound job. On `main` both are refused.
- **Personal accounts** (new Doctor test): with a personal account first in `auth.order`, the unattended planner never selects it, so Doctor records the shared account a run would use and never the personal one. The existing Gateway test "requires the personal owner for explicit creation and account adoption" covers explicit adoption.
- **Focused suites pass:** Doctor migration (both files), Gateway cron binding, inference-binding executor, auth-profile propagation.
- **Fleet census** (read-only Doctor previews on four real installs): see the comment on openclaw#172590.
- **Live differential** (real Gateway and CLI; a mock OpenAI provider that logs each request's `Authorization` header; two stored OpenAI profiles added through the CLI, `openai:alpha` then `openai:beta`, with `auth.order.openai = [beta, alpha]`; synthetic keys; a credentialless `local` fallback):

  | Step | Build | Result | Provider request |
  |---|---|---|---|
  | 1 | `v2026.10.3` | `cron run` → `ok`; the job row has no `inferenceBinding` | `Bearer sk-synthetic-beta-…` |
  | 2 | `main` (`c41a47d`) | Doctor: "More than one inference account is eligible: openai:beta, openai:alpha". `cron run` → `error` "Automation has no recorded inference account…" | none, not even the fallback |
  | 3 | this head | Doctor: "retain openai:beta for openai/gpt-6-mock … Also eligible: openai:alpha"; row `inferenceBinding.profileId = "openai:beta"`. `cron run` → `ok` | `Bearer sk-synthetic-beta-…`, the same as step 1 |
  | 4 | this head | `auth.order` reversed to [alpha, beta], Gateway restarted, `cron run` → `ok` | `Bearer sk-synthetic-beta-…`: the binding holds |
  | 5 | this head vs `main` | fresh state with only `models.providers.openai.apiKey`: `cron add` succeeds with no binding and the run uses that key. `main` refuses `cron add` with "requires a stored inference account" | `Bearer sk-synthetic-config-…` |

  The account recorded in step 3 is not the alphabetical or first-added profile. It is the one the stable build actually sent.
- **Live boundary cases** on the candidate, from the differential state (Doctor recorded `openai:beta`):
  - the `openai:beta` key is replaced through `models auth paste-api-key`: `cron run` → `error` "Automation inference account was replaced. Explicitly select an authorized account again."; 0 provider requests, no fallback;
  - `openai:beta` is removed through `models auth logout`: `cron run` → `error`; 0 provider requests; `openai:alpha` is not used and no fallback runs. The error text is "MCP authorization was disconnected or replaced" (`MCP_AUTHORIZATION_RETIRED`), a misleading message from the existing authorization owner, not from this PR (follow-up).
  - A live personal-account case is not possible from a synthetic CLI: `users.authConnect` needs a signed-in person. Instead, `isolated-agent.auth-continuity.integration.test.ts` > "records the shared account a run plans, never a personal one listed first" connects a real personal account (`ensureProfileForEmail` + `connectUserModelAccountAsync`), puts it first in `auth.order` next to a shared API key, runs the real Doctor migration and then the real embedded cron runner with only provider HTTP stubbed. Doctor records the shared account. The run returns `ok`, and the only provider request carries the shared key (`Bearer synthetic-platform-key`): the personal key is never sent, and no fallback runs.

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

Copy link
Copy Markdown

Additional release data point: in an isolated upgrade reproduction from 2026.10.6 to 2026.10.10-beta.3, a legacy isolated automation failed before inference with Automation has no recorded inference account. Explicitly select its account with a model@profile update before running it. An explicit account-selection update restored execution; the earlier release did not reproduce the failure.

beta.3's Doctor cron source lacks inference-binding-migration.ts, while main contains this repair. Its payload docs still require explicit legacy adoption. This appears consistent with a repair not yet included in that release branch. We did not test a build containing the migration, and this is not evidence that the merged repair fails. No account identifiers or job payloads are attached.

amittell added a commit to amittell/openclaw that referenced this pull request Oct 31, 2026
…lback (openclaw#173411)

Fork carry of upstream 26da73b onto v2026.10.10-beta.4. The 2026.10.10
release branch took openclaw#172590's account gate but not this fix. After the beta.4
deploy, both bots refused every legacy agentTurn automation with "Automation has
no recorded inference account", because their routes use a provider-config key:
models.providers.gpufarm.apiKey, held as a file SecretRef.

Carried verbatim:
- isConfiguredKeyAuthSource;
- the embedded, CLI and cron CLI account gates;
- recordModelFallbackStop on every account refusal.

Dropped: the Doctor half (inference-binding-migration.ts and its test). beta.4
does not have that module, because openclaw#172792 is not on the release branch. The
docs now describe the run rule without Doctor.

Added isolated-agent.auth-continuity.file-secretref.integration.test.ts, which
reproduces the bots' setup: a custom openai-completions provider whose apiKey is
a singleValue file SecretRef, resolved through the secrets runtime. It covers
two cases, with and without a declared auth profile that the agent store does
not hold. Both fail on beta.4 with the bots' error and pass here.

(cherry picked from commit 26da73b)
tideclaw-bot added a commit that referenced this pull request Nov 5, 2026
Adapt #172792, #173411, #173509 and #180492 to release/2026.11.2.
Retain the existing configured-key admission, worker ownership, runtime
authority and session provenance behavior. Add offline binding migration
with verified backups and approval retention, planned eligible account
selection, and exact forwarded CLI account identity with live guards.

Co-authored-by: RoboClaw <[email protected]>
Co-authored-by: obviyus <[email protected]>
Co-authored-by: fuller-stack-dev <[email protected]>
Co-authored-by: Kimiyu-186 <[email protected]>
Co-authored-by: steipete <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: Vito Cappello <[email protected]>
Co-authored-by: VACInc <[email protected]>
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 commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants