Skip to content

feat(cli): let agent exec select a configured agent - #125141

Closed
yu-xin-c wants to merge 4 commits into
openclaw:mainfrom
yu-xin-c:codex/124768-agent-exec-agent
Closed

yu-xin-c wants to merge 4 commits into
openclaw:mainfrom
yu-xin-c:codex/124768-agent-exec-agent

Conversation

@yu-xin-c

@yu-xin-c yu-xin-c commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #124768

What Problem This Solves

openclaw agent exec could not target an agent in an explicit multi-agent fleet. The parent agent command accepted --agent, but the nested exec command neither declared the option nor inherited it. Without a generic owner, the run failed before it could reach that agent's configured workspace, runtime, or stored OAuth profiles.

Why This Change Was Made

This adds --agent <id> to the nested command and uses the existing roster normalization and validation path. An explicit selection now wins over legacy and system-owner compatibility defaults, scopes stored auth to the selected agent directory, and uses that agent's configured workspace unless --cwd explicitly overrides it. Temporary session and database state remain isolated exactly as before.

Current main already includes #124697, which aligned the implicit exec owner with agents.defaults.systemAgent. This PR builds on that owner seam and adds the missing explicit selection contract for fleets that intentionally have no generic default.

I also checked Codex's source contract directly: CODEX_HOME owns the Codex config directory, and its credential file is $CODEX_HOME/auth.json. Selecting the OpenClaw agent before entering the harness/auth boundary is therefore required for deterministic credential ownership.

User Impact

Operators can now run either form:

openclaw agent exec --agent ops "Run the focused tests"
openclaw agent --agent ops exec "Run the focused tests"

The selected agent contributes its runtime, stored credentials, and default workspace. Existing invocations without --agent retain their current process-working-directory and owner-resolution behavior, and --cwd remains the final workspace override.

Evidence

  • Regression reproduced before the implementation: the parent-position --agent ops parsed successfully but was absent from the options passed to agentExecCommand.

  • node scripts/run-vitest.mjs src/cli/program/register.agent.test.ts src/commands/agent-exec.test.ts src/commands/agent-exec.agent-owner.test.ts src/agents/agent-scope-config.test.ts (95 tests passed).

  • pnpm docs:check-mdx (774 files passed).

  • Focused oxfmt --check and oxlint passed for all touched files.

  • pnpm check completed every preflight guard, all 94 package-lock validations, and core/UI/extensions/scripts/test typechecks. The unrelated full-repository core lint shard was manually stopped after 180 seconds with no diagnostics; focused lint passed.

  • Source-built openclaw agent exec --help displays the new option and example.

  • Commit 4c94f7bbf5 adds a real child-process E2E with an installed proof harness, two explicit agents, no system owner, --agent beta, and an explicit --cwd override. The focused E2E passed and captured this redacted child stdout:

    {
      "ok": true,
      "status": "ok",
      "final": "SELECTED_AGENT_OK agent=beta workspace=<tmp>/workspaces/override",
      "model": "proof-model",
      "provider": "exec-proof",
      "sessionId": "exec-proof-session"
    }
  • A live source CLI smoke with an explicit two-agent config and no system owner selected beta, passed owner/auth admission without the reported 401, and entered the native Codex app-server path. The app-server did not return a final response within the 120-second smoke window, so this is recorded as boundary evidence rather than a successful model E2E.

@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: M labels Aug 17, 2026
@yu-xin-c
yu-xin-c force-pushed the codex/124768-agent-exec-agent branch from bacbded to 4f87510 Compare August 17, 2026 07:21
@yu-xin-c
yu-xin-c marked this pull request as ready for review August 17, 2026 07:22
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 3, 2026, 3:07 AM ET / 07:07 UTC.

ClawSweeper review

What this changes

Adds --agent &lt;id> to openclaw agent exec, selecting that configured agent’s runtime, credentials, and default workspace while keeping one-shot run state isolated.

Merge readiness

⛔ Blocked before merge - 4 items remain

This PR remains necessary: current main still lacks an agent exec selector for an explicit multi-agent fleet. The branch is conflict-marked against substantial current-main auth/state work, and its real-process harness proof does not yet show a completed configured-Codex OAuth run.

Priority: P2
Reviewed head: c89d77683fe2846cdd315b76162ff8a36bd0d75d

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has focused source and process-level harness coverage, but its current-main conflict and missing successful native OAuth completion prevent merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The changed production owner is selected-agent agent exec; the supplied real child-process run proves CLI-to-harness routing, workspace precedence, and isolated state, but it uses a custom harness. The provided native Codex smoke has no successful after-fix response, so configured stored-OAuth completion remains uncovered; add redacted terminal or live output after the rebase. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The changed production owner is selected-agent agent exec; the supplied real child-process run proves CLI-to-harness routing, workspace precedence, and isolated state, but it uses a custom harness. The provided native Codex smoke has no successful after-fix response, so configured stored-OAuth completion remains uncovered; add redacted terminal or live output after the rebase. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Introduced CLI contract: The PR declares --agent &lt;id> on the nested exec command and inherits the parent-position value, covering both supported option positions.
Selected-owner boundary: The branch validates the requested ID against the configured roster, resolves its workspace before publishing isolated runtime config, and scopes auth to that resolved agent directory.
Current-main gap: Current main's AgentExecCliOptions has no agent field, and its command continues to resolve agent exec with no requested owner; the central user problem is therefore not already implemented.
Findings None None.
Security None None.

How this fits together

openclaw agent exec runs one embedded, headless agent turn from the CLI. It resolves configuration and agent ownership, prepares isolated state and credentials, then hands the selected runtime and workspace to the embedded agent runner.

flowchart LR
  A[CLI invocation] --> B[Parse agent and workspace options]
  B --> C[Resolve configured agent]
  C --> D[Prepare isolated run configuration]
  D --> E[Scope selected agent credentials]
  E --> F[Run embedded agent]
  F --> G[CLI result and cleanup]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The changed production owner is selected-agent agent exec; the supplied real child-process run proves CLI-to-harness routing, workspace precedence, and isolated state, but it uses a custom harness. The provided native Codex smoke has no successful after-fix response, so configured stored-OAuth completion remains uncovered; add redacted terminal or live output after the rebase. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - GitHub reports the branch as unmergeable; rebasing must preserve current main’s stored-auth state source and temporary-state isolation rather than restoring the older two-argument auth scope.
  • Resolve merge risk (P1) - The supplied process proof completes only against a custom harness. The native configured-Codex OAuth smoke entered the app-server path but did not produce an after-fix completion, so the reported OAuth outcome remains unproven.
  • Complete next step (P2) - Rebase onto current main and attach redacted successful configured-Codex OAuth output for agent exec --agent before merge.
Agent review details

Security

None.

PR surface

Source +43, Tests +313, Docs +2, Other 0. Total +358 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 94 51 +43
Tests 4 334 21 +313
Docs 1 3 1 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 9 432 74 +358

Review metrics

Metric Value Why it matters
Production versus test delta production +94/-51 (net +43); tests +334/-21 (net +313); docs +3/-1 The production growth implements a new leaf-level CLI selection path and isolated-owner handling; the rebase should absorb it into current main’s newer split command architecture.
Public CLI selection option 1 leaf option added --agent &lt;id> changes how existing multi-agent installations select runtime, credentials, and workspace.

Merge-risk options

Maintainer options:

  1. Rebase and prove the configured OAuth path (recommended)
    Rebase onto current main, retain its current auth/state-scope behavior, and post redacted after-fix terminal output from a successful configured-Codex OAuth selected-agent run.
  2. Pause the branch
    Keep this PR unmerged if the selected-agent contract cannot be reconciled with current main and demonstrated against the configured native runtime.

Technical review

Best possible solution:

Rebase the explicit-selection wiring onto current main’s split agent-exec architecture, preserve its auth/state ownership behavior, and attach redacted terminal output from a successful configured-Codex OAuth agent exec --agent completion.

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

Yes, by source inspection: current main neither parses a nested agent exec --agent option nor passes a requested owner to its agent-owner resolver. The reviewed branch adds both paths, but this review did not execute the untrusted contributor branch.

Is this the best way to solve the issue?

Yes in principle: it reuses the existing configured-agent resolver and validates both parent and leaf option positions. It must first be rebased so the same solution preserves current-main auth and temporary-state semantics.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded multi-agent CLI workflow that currently cannot explicitly target a configured agent.
  • merge-risk: 🚨 compatibility: The new CLI option changes configured-agent and workspace selection and must be reconciled with newer current-main command behavior.
  • merge-risk: 🚨 auth-provider: The selected agent determines which stored provider credentials are presented to the embedded runtime.
  • merge-risk: 🚨 session-state: The change deliberately separates selected-agent credentials from temporary run state, a boundary that requires preservation during rebase.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The changed production owner is selected-agent agent exec; the supplied real child-process run proves CLI-to-harness routing, workspace precedence, and isolated state, but it uses a custom harness. The provided native Codex smoke has no successful after-fix response, so configured stored-OAuth completion remains uncovered; add redacted terminal or live output after the rebase. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Introduced CLI contract: The PR declares --agent &lt;id> on the nested exec command and inherits the parent-position value, covering both supported option positions. (src/cli/program/register.agent-turn.ts:136, c89d77683fe2)
  • Selected-owner boundary: The branch validates the requested ID against the configured roster, resolves its workspace before publishing isolated runtime config, and scopes auth to that resolved agent directory. (src/commands/agent-exec.ts:610, c89d77683fe2)
  • Current-main gap: Current main's AgentExecCliOptions has no agent field, and its command continues to resolve agent exec with no requested owner; the central user problem is therefore not already implemented. (src/commands/agent-exec-input.ts:11, b55b7256cc0d)
  • Rebase-sensitive current-main evolution: Since the branch head, main split the command input surface and changed the auth-scope invocation to retain the stored auth state source; GitHub reports this PR as dirty, so the final merged behavior has not been established. (src/commands/agent-exec.ts:388, b55b7256cc0d)
  • Harness proof coverage: The added child-process test exercises CLI parsing, isolated runtime configuration, plugin discovery, selected-agent routing, explicit cwd precedence, and temporary agent-directory isolation, but its provider is a purpose-built local proof harness rather than a configured Codex OAuth completion. (src/commands/agent-exec-plugin.e2e.test.ts:203, c89d77683fe2)
  • Codex credential-location contract: Direct inspection confirms Codex resolves CODEX_HOME as its configuration directory and defines its credential structure at $CODEX_HOME/auth.json; this makes the selected-agent auth-directory boundary relevant to the PR’s native-Codex claim. (codex-rs/utils/home-dir/src/lib.rs:5, be6e8eac029b)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Leon-SK668: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Rebase onto current main and preserve the current auth-state ownership inputs.
  • Attach redacted terminal output of a successful configured-Codex OAuth agent exec --agent run; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-20T12:42:41.101Z sha 84d1f3d :: needs changes before merge. :: [P1] Preserve isolation for list-form agent rosters
  • reviewed 2026-08-20T13:46:39.547Z sha f3e93cd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-20T13:57:13.923Z sha c89d776 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-20T14:38:47.750Z sha c89d776 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T22:41:19.042Z sha c89d776 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-29T23:52:56.757Z sha c89d776 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-30T00:00:25.051Z sha c89d776 :: needs real behavior proof before merge. :: none
  • reviewed September 3, 2026, 3:07 AM ET / 07:07 UTC sha unknown :: needs real behavior proof before merge. :: none

@yu-xin-c
yu-xin-c force-pushed the codex/124768-agent-exec-agent branch from 4f87510 to 4c94f7b Compare August 17, 2026 08:16
@yu-xin-c

Copy link
Copy Markdown
Contributor Author

Added completed selected-agent behavior proof in 4c94f7bbf5.

The new E2E starts a real child CLI process with an installed proof harness, two explicit agents, no system owner, --agent beta, and an explicit --cwd override. The focused test passes and captured this redacted child stdout:

{
  "ok": true,
  "status": "ok",
  "final": "SELECTED_AGENT_OK agent=beta workspace=<tmp>/workspaces/override",
  "model": "proof-model",
  "provider": "exec-proof",
  "sessionId": "exec-proof-session"
}

The harness emits its actual params.agentId and params.workspaceDir, so the result proves both selected-agent routing and explicit cwd precedence across CLI parsing, config loading, plugin discovery, runtime preparation, harness execution, and result projection.

Direct Codex source verification was performed against openai/codex@23094236acac6fdc22f67a408ea8ccb8fac8e6e1:

Validation after the update: selected-agent E2E passed, 95 focused unit/integration tests passed, core typecheck passed, and focused format/lint passed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 17, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed 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. labels Aug 17, 2026
@yu-xin-c
yu-xin-c force-pushed the codex/124768-agent-exec-agent branch from 4c94f7b to 84d1f3d Compare August 20, 2026 12:35
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Aug 20, 2026
@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 20, 2026
@yu-xin-c

Copy link
Copy Markdown
Contributor Author

Addressed the list-roster isolation finding in f3e93cd527 and the assertion-safety CI ratchet in c89d77683f.

  • Both agents.entries and agents.list now drop inherited agentDir / ACP cwd and pin the run workspace.
  • The real child-process proof now uses a list-only runtime snapshot with a configured persistent agent directory and verifies the actual run uses <openclaw-agent-exec-*>/agents/beta/agent instead.
  • Validation: 130 focused tests, core + commands test typechecks, format/lint, max-lines and assertion-safety ratchets, and the rebuilt selected-agent E2E all pass.
  • Final-head GitHub checks: 141 passed, 39 skipped, 0 failed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 3, 2026
@yu-xin-c

Copy link
Copy Markdown
Contributor Author

Closing this aging proposal as part of contribution backlog cleanup. Current-main agent exec integration and successful native configured-agent authentication proof remain outstanding. I am withdrawing the stale implementation rather than continuing to keep the conflicted branch open. This closure does not claim the requested capability is already available.

@yu-xin-c yu-xin-c closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agent exec cannot select an agent or reuse Codex OAuth in a multi-agent config

1 participant