Skip to content

refactor(agents): make multi-agent ownership explicit (H2-1 core) - #114388

Merged
steipete merged 72 commits into
mainfrom
claude/no-stored-default
Aug 12, 2026
Merged

steipete merged 72 commits into
mainfrom
claude/no-stored-default

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Related: #112678
Related: #113637

What Problem This Solves

Resolves a problem where multi-agent installations persisted an ambient default: true marker and then inferred that agent across sessions, channels, automation, and authorization paths. After roster changes or restart, that implicit default could select the wrong agent, lose a legacy owner, or allow colliding bare session keys such as global to be attributed to the requester instead of their durable owner.

Why This Change Was Made

The final design removes the stored default marker and uses sole-agent-or-explicit selection. A write-once agents.ownership: "explicit" stamp records intentional roster ownership, while a load-time WeakMap sidecar retains the legacy owner only as migration evidence and compatibility input.

Before retiring the marker, compatibility ownership is materialized into the surfaces that need durable identity: channel bindings, heartbeat, system-agent and Talk settings, auth inheritance, and the configured fixed session store. Fixed-store rows follow the persisted owner contract (configured, retired, or none); configured ownership is authoritative, retired ownership fails closed, and authorization surfaces reject conflicting explicit agents.

The same ownership ladder now covers Gateway, CLI/TUI, session aliases and IDs, task runtimes, active runs, broadcasts, transcript lookup, and migration/recovery paths. Plugin discovery uses the config-wide manifest registry. Gateway protocol additions (ownership and selectionRequired) remain additive, and Doctor owns the shipped config/data migrations.

User Impact

Single-agent installations continue to select their sole agent without extra configuration. Multi-agent installations now receive an actionable explicit-selection response instead of silently adopting a default or another agent's session/task state. Existing installations retain and durably materialize their legacy owner during migration, including bare fixed-store sessions, while conflicting and ownerless authorization requests fail closed.

Operators also get Doctor repairs for marker retirement, fixed-store ownership, heartbeat cadence, and startup-owned cron rows. Remote clients can consume the additive ownership metadata without breaking older protocol consumers.

Evidence

  • Exact current head 376669573fa853faff8352d8777a0ece94d65493: full pull-request CI green in run 31647212132, including production tsgo, check:test-types, lint, security/CodeQL, Plugin SDK API baseline, UI/E2E, iOS, and changed test shards.
  • Full changed-surface gate: node scripts/check-changed.mjs green on Testbox run 31335091251.
  • Full type/build lane: pnpm tsgo:all && pnpm check:test-types && pnpm build green on Testbox run 31336280194.
  • Touched tests, unfiltered: 952 tests passed across 11 Vitest shards on Testbox run 31336453657. The final task-owner repair additionally passed both unfiltered colocated suites: 10 tests across src/tasks/task-owner-access.test.ts and src/plugins/runtime/runtime-tasks.test.ts.
  • Linux-generated Plugin SDK contract reconciliation: Testbox tbx_01kzvyf8dx3dmxcac08v85pvwk, run 31643290834, generated the final infra-runtime contract hash; the exact-head Linux baseline gate then passed.
  • External ownership gate reviewed head 61e8f70f246fecbf29628574b0a78fb3eb4047bc clean. Subsequent changes were a conflict-free source replay onto current main plus generated Plugin SDK baseline reconciliation only.

ClawSweeper rank-up moves and maintainer dispositions:

  • Applied: trusted agentId is threaded from tool context and explicit task-session bindings; agent-scoped keys retain their encoded owner, and agentless bare bindings fail closed. A paired-agent global regression covers get, list, resolve, and cancel.
  • Resolved: the two previously unlocated CodeQL concerns were not reproduced; exact-head CodeQL and security checks have no blocking finding.
  • Resolved: exact-head availability and proof gaps are superseded by the external gate clearance and exact-head green CI above.
  • Skipped with maintainer acceptance: a live Doctor upgrade/restart artifact was not published. Deterministic Doctor, cron handoff, session ownership, channel routing, explicit-selection, and migration suites provide the substitute proof; no private runtime artifact or sensitive endpoint was created.
  • Not repeated: sibling Codex CLI inspection was part of an already-gated older span, and the post-clearance delta changes no Codex behavior—only mechanical replay and generated contracts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: voice-call Channel integration: voice-call app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling channel: feishu Channel integration: feishu extensions: anthropic extensions: qa-lab extensions: codex size: XL maintainer Maintainer-authored PR labels Jul 27, 2026
@steipete steipete self-assigned this Jul 27, 2026
@steipete
steipete force-pushed the claude/no-stored-default branch from 9e39e7c to 1d64c4a Compare July 27, 2026 06:58
@steipete
steipete marked this pull request as ready for review July 27, 2026 06:58
@steipete
steipete requested a review from a team as a code owner July 27, 2026 06:58
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 12, 2026, 6:09 PM ET / 22:09 UTC.

ClawSweeper review

What this changes

Replaces implicit multi-agent default selection with explicit ownership, migration, and agent-scoped routing across config, sessions, Gateway, task runtime, UI, and plugin discovery.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: this is maintainer-owned, protected ownership work, and current main still selects an omitted agent through the persisted default marker. The local checkout cannot load the exact PR head, so no exact-head merge verdict is safe.

Priority: P1
Reviewed head: 93fe3c28c2e018f1724c4ed22fda29cefaff6929
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has substantial stated validation, but current-head and dependency inspection are unavailable in this environment.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: This maintainer-authored PR supplies CI and suite evidence; the external-contributor proof gate does not apply, but exact-head evidence remains unavailable to this reviewer.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR supplies CI and suite evidence; the external-contributor proof gate does not apply, but exact-head evidence remains unavailable to this reviewer.
Evidence reviewed 5 items Current-main default selection remains: When callers omit an agent ID, the resolver chooses the entry marked default or the first agent; this is the ambient-selection behavior the PR proposes to replace.
Current-main migration preserves default markers: The roster migration materializes main with default:true and repairs absent or duplicate markers by selecting an effective default, so current main does not already implement the PR's central change.
Prior ownership groundwork: Merged commits establish the preceding roster-injection and per-surface ownership work referenced by this PR.
Findings None None.
Security Needs attention Inspect exact-head authorization changes: The supplied PR changes ownership and authorization paths, but the current head is unavailable in this checkout, preventing a conclusive security-boundary review.

How this fits together

Agent selection begins with configuration and legacy roster migration, then feeds Gateway/session/task routing and user interfaces. The change makes ownership explicit before those consumers read or mutate agent-scoped state.

flowchart LR
  A[Config and legacy roster] --> B[Ownership resolution]
  B --> C[Doctor migration]
  B --> D[Gateway and session routing]
  B --> E[Task runtime]
  D --> F[UI and channel requests]
  E --> G[Agent-scoped task results]
Loading

Decision needed

Question Recommendation
Should this protected maintainer PR remain paused until an exact-head review can inspect the branch and its Codex CLI integration, rather than relying on earlier-head evidence in the body? Pause for exact-head evidence: Wait for accessible exact-head source, current checks, and Codex contract inspection before deciding merge readiness.

Why: The PR changes compatibility-sensitive ownership and invokes Codex-related behavior, but this reviewer cannot load the current head or sibling Codex source.

Before merge

  • Resolve security concern: Inspect exact-head authorization changes - The supplied PR changes ownership and authorization paths, but the current head is unavailable in this checkout, preventing a conclusive security-boundary review.
  • Resolve merge risk (P1) - The PR removes a persisted selection behavior and changes session/task ownership, so upgrade behavior needs exact-head source and migration proof before merge.
  • Resolve merge risk (P1) - The exact PR head and Codex dependency source could not be inspected because the checkout lacks the objects and GitHub DNS was unavailable.

Findings

  • [low] Inspect exact-head authorization changes
Agent review details

Security

Needs attention: No concrete vulnerability was established, but the exact-head security-sensitive ownership and Codex CLI changes could not be inspected.

Review metrics

Metric Value Why it matters
Production versus test LOC Not computed: exact PR head object unavailable locally The requested production/test classification cannot be derived safely from the supplied partial file list.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-schema.sql, serialized state: src/sessions/session-lifecycle-events.ts, serialized state: src/state/openclaw-state-db.generated.d.ts, serialized state: test/non-isolated-runner.test.ts, serialized state: ui/src/lib/session-viewer-presence.test.ts, serialized state: ui/src/lib/session-viewer-presence.ts, and 7 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Verify upgrade ownership (recommended)
    Obtain exact-head proof that released multi-agent configurations migrate durable owners and that ambiguous requests return actionable selection errors.
  2. Pause the branch
    Keep the maintainer-owned PR open until the unavailable head and dependency evidence can be reviewed.

Technical review

Best possible solution:

Review the exact current head after its objects and the relevant Codex source are available; retain a single explicit ownership resolver with Doctor-owned migration for released configurations.

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

No high-confidence runtime reproduction was run. Current main source does show that omitted agent selection resolves through the default marker or first roster entry.

Is this the best way to solve the issue?

Unclear: explicit ownership is consistent with the preceding merged groundwork, but the exact implementation cannot be compared with current main while the PR head is unavailable.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: This changes agent/session selection across active multi-agent Gateway and task workflows.
  • merge-risk: 🚨 compatibility: Existing persisted default-agent configuration is being retired and migrated.
  • merge-risk: 🚨 session-state: The intended behavior changes attribution of bare session keys and task ownership.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR supplies CI and suite evidence; the external-contributor proof gate does not apply, but exact-head evidence remains unavailable to this reviewer.

Evidence

Security concerns:

  • [low] Inspect exact-head authorization changes
    The supplied PR changes ownership and authorization paths, but the current head is unavailable in this checkout, preventing a conclusive security-boundary review.
    Confidence: 0.94

What I checked:

  • Current-main default selection remains: When callers omit an agent ID, the resolver chooses the entry marked default or the first agent; this is the ambient-selection behavior the PR proposes to replace. (src/agents/agent-scope-config.ts:144, 5bcbbcf6fdd9)
  • Current-main migration preserves default markers: The roster migration materializes main with default:true and repairs absent or duplicate markers by selecting an effective default, so current main does not already implement the PR's central change. (src/config/legacy.roster.ts:63, 5bcbbcf6fdd9)
  • Prior ownership groundwork: Merged commits establish the preceding roster-injection and per-surface ownership work referenced by this PR. (src/agents/agent-scope-config.ts:144, 82d1a03f2559)
  • Exact-head inspection blocked: The local repository is a promisor checkout without the PR head object; resolving it attempted a fetch, but GitHub DNS was unavailable. The exact diff, LOC split, and current-head source cannot be independently inspected here.
  • Codex dependency gate blocked: The supplied diff adds TUI coverage for resolving and invoking the Codex CLI, an affirmative dependency signal, but sibling ../codex is absent and cannot be cloned while GitHub DNS is unavailable. (src/tui/tui.local-auth.test.ts:1)

Likely related people:

  • steipete: Peter Steinberger authored the two merged preparatory ownership commits and this PR's supplied commit history. (role: introduced related ownership groundwork; confidence: high; commits: 82d1a03f2559, 4bfb26415aed; files: src/agents/agent-scope-config.ts, src/config/legacy.roster.ts)
  • Vincent Koc: Current-main blame assigns the default-resolution and roster-migration lines to the recent current-tree commit. (role: recent current-main contributor; confidence: medium; commits: d82edfc4d225; files: src/agents/agent-scope-config.ts, src/config/legacy.roster.ts, src/gateway/server-methods/agent-id-shared.ts)

Rank-up moves

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

  • Make the exact PR head available to review and complete the remaining exact-head checks.
  • Provide access to the relevant Codex source or a maintained contract reference for the CLI invocation path.

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 (102 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-12T17:00:52.033Z sha 4d53650 :: found issues before merge. :: [P1] Reject bare-key task access without an agent
  • reviewed 2026-08-12T17:09:23.861Z sha d024485b59ebf48b95c2c062ba3da6652f204b82 :: needs changes before merge. :: [P1] Reject bare-key task access without an agent
  • reviewed 2026-08-12T18:00:27.208Z sha 3a20d65 :: found issues before merge. :: [P1] Reject bare-key task access without an agent
  • reviewed 2026-08-12T19:17:08.006Z sha 772dc97f3d2b3fc35d434533c282d86760ec5740 :: found issues before merge. :: [P1] Reject task access when caller agent is missing
  • reviewed 2026-08-12T20:14:39.479Z sha 8ee396e :: found issues before merge. :: [P1] Reject bare-key task access without an agent | [P1] Scope managed task flows by agent
  • reviewed 2026-08-12T20:30:15.330Z sha 8972aa0 :: found issues before merge. :: [P1] Reject agentless bare-key task access
  • reviewed 2026-08-12T21:07:56.339Z sha 61e8f70f246fecbf29628574b0a78fb3eb4047bc :: found issues before merge. :: [P1] Propagate agent identity into bound task runtimes
  • reviewed 2026-08-12T21:33:51.500Z sha 8bfe9d6 :: found issues before merge. :: [P1] Propagate agent identity into bound task runtimes

@steipete
steipete force-pushed the claude/no-stored-default branch 2 times, most recently from 1f039ea to b840ee9 Compare July 27, 2026 13:05
@openclaw-barnacle openclaw-barnacle Bot added the channel: telegram Channel integration: telegram label Jul 27, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: discord Channel integration: discord cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants