Repository navigation
fix(agents): honor the configured system agent for ambient owner resolution - #126504
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 9:32 PM ET / August 20, 2026, 01:32 UTC. ClawSweeper reviewWhat this changesThe PR makes unscoped agent-owned operations consistently prefer an explicit request, then Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessThis PR is still necessary: current main resolves a retained legacy owner before the configured system agent, contrary to the documented unscoped-owner contract. The patch centralizes the intended precedence, has no discrete correctness finding, and should remain open for maintainer review and exact-head CI. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherAgent-scope configuration selects the agent whose model, credentials, workspace, and catalog serve unscoped operations such as Doctor and model status. Callers supply an optional owner; the resolver selects one agent before downstream model/auth and plugin work. flowchart LR
A[Unscoped command or service] --> B[Optional requested agent]
B --> C[Ambient owner resolution]
C --> D[Configured system agent]
C --> E[Legacy owner or sole agent]
D --> F[Model auth workspace state]
E --> F
F --> G[Doctor gateway and CLI output]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -91, Tests +51, Docs 0. Total -40 across 48 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical ambient-owner resolver with documented precedence and preserve explicit-agent selection only on surfaces that intentionally require it. Do we have a high-confidence way to reproduce the issue? Yes. Current main visibly selects the legacy compatibility owner first, while the documented system-agent contract and focused multi-agent regression cases establish the conflicting-roster path. Is this the best way to solve the issue? Yes. Centralizing precedence in the ambient resolver is the narrowest maintainable repair and removes caller-specific policy copies rather than adding fallbacks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bfc6bd3da5e4. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Addressing the two before-merge items ahead of landing. Resolve merge risk (P1) — done. Exact-head CI is green at Complete next step (P2) — done. Landing as maintainer with exact head green. On the flagged stored-data-model change: verified as a false positive. Both flagged files are pure call-site migrations with no schema, serialization-format, or migration-logic change. The one semantically meaningful line is
Only the last case changes, and it changes from a dead end to a working resolution, so no existing persisted session can be re-pointed and no migration is required. |
|
Merged via squash.
|
What Problem This Solves
Resolves a problem where operators running more than one agent could not get OpenClaw to honor
agents.defaults.systemAgent.agentId, the setting documented as the owner for unscoped operatorreads. Two separate things went wrong on multi-agent rosters:
--agentcould fail outright. With
agents.ownership: "explicit"and two agents,openclaw doctorreporteddoctor:hooks-model run failed: Multiple agents are configured, but this operation has no explicit ownereven whensystemAgent.agentIdwas set, because the ambient owner never consulted it.src/agents/context.tsresolved their own owner and swallowed the resulting throw, so every modelquietly fell back to configured-only context limits with no error anywhere.
Underneath both: there were two competing definitions of "who owns ambient work", and they disagreed.
Why This Change Was Made
agent-scope-config.tscarried four overlapping helpers — a system-agent pair that triedsystemAgent.agentIdfirst, and an ambient pair that tried the legacydefault=truemarker first.The same decision was additionally open-coded in
state-migrations.doctor.ts, spelled out as atwo-clause condition in
validation-core.ts, and duplicated at three consumers.The two families genuinely disagree on a roster zod accepts (exactly one legacy marker, so
ownership: "explicit"is not required, plus asystemAgent.agentIdnaming a different entry):legacy-first resolves
alphawhile system-agent-first resolvesbeta. Legacy-first is the wrongprecedence —
agents.defaults.systemAgent.agentIdis documented as the owner for unscoped readswith "explicit request agentId always wins", so a stripped legacy marker must not outrank config the
operator explicitly wrote.
This collapses all of it into one canonical pair with precedence
requested -> systemAgent.agentId -> legacy compatibility -> sole agent, deletes the twosystem-agent functions outright rather than aliasing them, migrates every caller, and removes the
duplicated policy at consumers. Ambiguous rosters still fail closed, now naming the config knob.
Non-goals:
resolveDefaultAgentIdand its remaining callers are untouched, and onboarding,session-ownership, and auth-inheritance compatibility boundaries are deliberately preserved because
they own different shipped contracts and should not inherit ambient system-agent precedence.
User Impact
Operators running multi-agent rosters can now set
agents.defaults.systemAgent.agentIdonce andhave unscoped reads actually use it. Model context limits are correct on those rosters instead of
silently degrading to configured-only values. When ownership really is ambiguous the error now names
the setting to fix rather than emitting generic selection guidance.
Behavior change worth calling out for review: on a roster carrying both a legacy
default=truemarker and a different configured
systemAgent.agentId, the ambient owner is now the configuredsystem agent rather than the legacy marker. The previous ordering is not in any release tag.
Production LOC is net -91.
Evidence
Regression tests fail on pre-change code for the right reason, verified by reverting only the
production file and re-running:
Expected: "beta" / Received: "alpha"for a configured system agentversus a raw legacy marker, the same for a retained migrated marker,
Expected: "gamma" / Received: "alpha"for an explicit requested owner, plus the fail-closedcontext assertion and default-agent-directory resolution.
context.lookup.test.tsincludingNumber of calls: 0.Validation:
skills, flows, auto-reply, cron, and talk: 52 files, 1,532 tests passing across 12 shards.
node scripts/check-changed.mjsclean, including all three Knip unused-export scans and0 runtime import cycles.
pnpm buildclean.Live proof, isolated
OPENCLAW_STATE_DIRper case,hooks.gmail.modelconfigured,node dist/index.js doctor --non-interactive:alpha.default: trueplussystemAgent.agentId: betaresolvesagentDirunderagents/beta/agent(the behavior change, proved end to end), doctor exit 0.ownership: "explicit"two-agent roster plussystemAgent.agentId: betaresolves underagents/beta/agent, nodoctor:hooks-modelfailure, doctor exit 0.