Skip to content

feat(cli): run agent exec against the ambient config, composed in memory - #116038

Merged
steipete merged 4 commits into
mainfrom
steipete/agent-exec-in-memory-config
Jul 29, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/agent-exec-in-memory-config

Conversation

@steipete

@steipete steipete commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw agent exec ignored the operator's config entirely. A one-shot turn could not reach configured providers, credentials, or agentRuntime harness selection, so codeModeEngaged came back false on a machine where code mode was enabled, and a configured Codex/Pi harness silently did not apply. Exec is the folder-scoped coding entrypoint; behaving unlike codex or claude, which always read their configuration, made it surprising.

It also wrote its config to a temporary file and repointed OPENCLAW_CONFIG_PATH at it.

Why This Change Was Made

Config is now layered in three parts and composed in memory:

  1. Exec defaults apply only where your config leaves a setting unset (skip bootstrap, sandbox off, coding tool profile, fs restricted to --cwd, full exec policy for a headless turn).
  2. Your config wins over those defaults, so a configured sandbox, shell env, or tool profile is never downgraded.
  3. The invocation wins last: the run is scoped to --cwd, never bootstraps, and explicit flags outrank the resolved config.

The temp file is gone. clearConfigCache is a no-op shim whose comment states "runtime snapshot is the only in-process cache now", so setRuntimeConfigSnapshot is the actual config mechanism — the file was a disk round trip to reach an in-memory setter. Harmless when it held five hardcoded defaults; once it held a real config it wrote ${ENV}-substituted provider keys to a same-UID file the run's own exec tool could read, defeating env-var indirection. Nothing in the exec path spawns a subprocess that reads OPENCLAW_CONFIG_PATH, and no agent or tool path calls writeConfigFile, so the file justified nothing.

Config fields that outrank invocation-owned facts are stripped from the run config rather than overlaid, because a deep merge cannot remove a key:

  • agents.entries.*.agentDir beats the state dir for session and transcript storage, so an ephemeral run would write state into the operator's persistent agent directory where deleting the temp state dir cannot reach it.
  • agents.entries.*.runtime.acp.cwd beats --cwd, so a native harness could edit the wrong repository. (agents.bindings[].acp.cwd needs no equivalent: exec runs no channel, so no binding matches.)

Stored-credential lookup deliberately reads the pre-strip base via resolveDefaultAgentDir(baseConfig). Run state must be ephemeral, but credential ownership must still follow the operator's configured agent directory, or a run authenticates against the wrong profile store.

--auth-env-only now reads no config at all, and pairing it with --config is rejected rather than silently ignored. Sanitizing was whack-a-mole: apiKey, then secret headers, then request.auth, then an inline env block, then login-shell import. A config is a credential store by design, so the only closed way to promise environment-only credentials is not to read one.

Both process globals the command touches — the runtime config snapshot and config-applied env vars — are captured before resolution and restored during cleanup, so a programmatic caller gets its own state back.

User Impact

openclaw agent exec now behaves like the other folder-scoped coding CLIs: configured providers, credentials, and harness selection apply, and codeModeEngaged reports truthfully.

Two behavior changes worth calling out:

  • A config that exists but cannot be parsed now fails the run instead of silently degrading to exec defaults, which would have dropped a configured sandbox.
  • --config is read through the normal loader, so JSON5 syntax and $include resolve relative to it.

Escape hatches are unchanged in spirit: --isolated ignores the ambient config, --config <path> pins an exact file, and --auth-env-only restricts credentials to the process environment.

Known limitation, documented in docs/cli/agent.md: the state directory is also where installed plugins live, so the default ephemeral one cannot discover plugins installed with openclaw plugins install. If your config selects a provider or harness from a non-bundled plugin, use --state-dir ~/.openclaw. Splitting those two meanings of OPENCLAW_STATE_DIR is a separate change.

Evidence

  • node scripts/run-vitest.mjs src/commands/agent-exec.test.ts — 47 passed.
  • node scripts/run-vitest.mjs src/config — 2933 passed across 212 files.
  • node scripts/run-tsgo.mjs -p tsconfig.json --noEmit — clean.
  • autoreview (codex gpt-5.6-sol, xhigh): clean, no accepted/actionable findings.

Mutation-checked rather than assumed — each of these fails its test when the production line is broken and passes when restored:

  • setRuntimeConfigSnapshot(runConfig) → clearRuntimeConfigSnapshot()
  • the cleanup step that undoes config-applied env vars
  • restoring the caller's prior snapshot instead of clearing it
  • capturing the prior snapshot before ambient resolution (an ambient load pins one of its own)
  • resolveDefaultAgentDir(baseConfig) → resolveDefaultAgentDir({})

Two review findings were rejected with evidence rather than patched, and both are pinned by tests or comments: createConfigIO(...).loadConfig() cannot be shadowed by a published runtime snapshot (that is the factory loader, which reads the file directly; only the module-level loader pins), and a failed config load leaks no env vars (applyConfigEnvVars runs last inside the try, and the loader restores from its own catch).

Guard allowlist

src/commands/agent-exec.ts is added to PROCESS_BOUNDARY_DIRECT_CONFIG_LOAD_FILES in scripts/lib/config-boundary-guard.mjs, alongside the two existing CLI entries. The guard's own message sanctions getRuntimeConfig() "at an explicit process boundary", and that is exactly what the ambient path uses. --config <path> cannot: getRuntimeConfig() reads the ambient location and resolves from an already published runtime snapshot, so it cannot express a pinned run. The file-scoped loader is the point of the flag, and the accompanying test asserts a pinned config is not shadowed by a snapshot.

steipete added 2 commits July 29, 2026 11:45
Exec previously ignored the operator's config entirely, so a one-shot turn
could not reach configured providers, credentials, or agentRuntime harness
selection. It now layers config the way other folder-scoped coding CLIs do.

The composed config is published as this process's runtime snapshot rather
than serialized to a temp file and re-read through OPENCLAW_CONFIG_PATH. The
snapshot is the only in-process config cache, so the file only ever fed it --
while writing env-substituted provider keys to disk where the run's own exec
tool could read them.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: L maintainer Maintainer-authored PR labels Jul 29, 2026
@steipete
steipete marked this pull request as ready for review July 29, 2026 18:50
@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 29, 2026
@clawsweeper

clawsweeper Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 29, 2026, 3:21 PM ET / 19:21 UTC.

ClawSweeper review

What this changes

The branch makes openclaw agent exec compose ambient or pinned configuration in memory, adds --config and --isolated, and documents the resulting credential, provider, and harness behavior.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 6 items remain

Keep this PR open. The in-memory configuration composition is a plausible fix, but it changes the established credential-source default from environment-only to config, stored-profile, and external-CLI discovery without maintainer-confirmed upgrade direction or real after-fix behavior proof.

Priority: P1
Reviewed head: 096432e6a36b22af0a777c273254f1c4049e5d0f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The PR has substantial targeted coverage and a credible secret-at-rest improvement, but a P1 compatibility decision and real behavior proof remain unresolved.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Focused tests and type checking are reported, but the PR needs a redacted after-fix terminal or live-runtime artifact showing ambient provider/harness selection and --auth-env-only isolation; redact keys, IPs, and non-public endpoints. 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) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Focused tests and type checking are reported, but the PR needs a redacted after-fix terminal or live-runtime artifact showing ambient provider/harness selection and --auth-env-only isolation; redact keys, IPs, and non-public endpoints. 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 4 items Credential default changes: The branch changes --auth-env-only from a default-on restriction to default-off, so existing invocations without flags can begin reading configured, stored, and external CLI credentials.
PR describes the changed trust boundary: The PR body confirms that normal execution now reads the operator configuration while --auth-env-only becomes an opt-in mode that reads no configuration.
Prior review blocker remains applicable: The latest completed ClawSweeper review identified preserving the environment-only credential default as a P1 concern; the current head explicitly retains the opposite default rather than resolving the compatibility decision.
Findings 1 actionable finding [P1] Preserve the environment-only credential default
Security Needs attention Default expands credential sources: Changing the default to disable authEnvOnly allows no-flag executions to consult configured, stored, and external credentials where they previously used only process environment variables.

How this fits together

openclaw agent exec is the one-shot CLI path that turns a prompt and working directory into an embedded agent run. It resolves configuration and credentials before selecting a provider or coding harness, then passes the composed runtime state into the agent execution loop.

flowchart LR
  A[CLI flags and prompt] --> B[Agent exec command]
  C[Ambient or pinned config] --> D[In-memory config composition]
  B --> D
  D --> E[Credential and provider resolution]
  E --> F[Agent runtime and harness selection]
  F --> G[One-shot agent result]
Loading

Decision needed

Question Recommendation
Should openclaw agent exec preserve environment-only credentials by default, or intentionally make ambient config and stored credentials the default source for existing invocations? Preserve the existing default: Keep environment-only credentials as the default and make ambient-config credential use an explicit opt-in path.

Why: This is a user-visible credential and provider-routing contract change; tests can verify either implementation but cannot choose the upgrade policy.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Focused tests and type checking are reported, but the PR needs a redacted after-fix terminal or live-runtime artifact showing ambient provider/harness selection and --auth-env-only isolation; redact keys, IPs, and non-public endpoints. 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.
  • Preserve the environment-only credential default (P1) - This changes an existing no-flag invocation from environment-only credentials to reading config, stored profiles, and external CLI credentials. That silently changes provider and credential selection for scripts; retain the default or add an explicit ambient-config opt-in after maintainer direction.
  • Resolve security concern: Default expands credential sources - Changing the default to disable authEnvOnly allows no-flag executions to consult configured, stored, and external credentials where they previously used only process environment variables.
  • Resolve merge risk (P1) - Existing scripts that relied on the documented default credential boundary can silently begin consulting configuration, stored profiles, or external CLI credentials after upgrade.
  • Resolve merge risk (P1) - The PR has no after-fix real-runtime artifact showing both intended ambient provider/harness selection and the environment-only isolation boundary.

Findings

  • [P1] Preserve the environment-only credential default — src/cli/program/register.agent-turn.ts:147
  • [medium] Default expands credential sources — src/cli/program/register.agent-turn.ts:147
Agent review details

Security

Needs attention: The patch removes a temporary on-disk config exposure, but its new default broadens credential discovery for existing unattended CLI calls and needs explicit approval.

PR surface

Source +172, Tests +361, Docs +8, Other +5. Total +546 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 212 40 +172
Tests 2 378 17 +361
Docs 1 13 5 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 0 +5
Total 7 608 62 +546

Review metrics

Metric Value Why it matters
Credential and config surface 2 CLI flags added; 1 credential default changed The new run-selection flags are additive, but changing the credential default affects existing unattended invocations and provider routing.

Stored data model

Persistent data-model change detected: serialized state: src/commands/agent-exec.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Restore an opt-in credential transition (recommended)
    Retain environment-only credentials for unchanged invocations and expose ambient configuration as an explicit mode, with focused regression coverage.
  2. Accept the credential-source change
    A maintainer may intentionally adopt stored and configured credentials as the default after documenting the upgrade impact and reviewing real runtime evidence.

Technical review

Best possible solution:

Keep environment-only credential sourcing as the compatibility default and add an explicit, documented opt-in for ambient configuration, unless a maintainer deliberately accepts the credential-source default change with clear upgrade guidance and real behavior proof.

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

Yes, from source: invoking openclaw agent exec without credential flags follows the changed default and can now reach configuration and stored credential discovery. The PR's test suite covers the option parsing, but no real runtime artifact demonstrates the full provider/harness path.

Is this the best way to solve the issue?

No. The in-memory composition avoids the temporary secret-bearing config file, but silently reversing the credential-source default is not the narrowest compatibility-safe solution without a maintainer product decision.

Full review comments:

  • [P1] Preserve the environment-only credential default — src/cli/program/register.agent-turn.ts:147
    This changes an existing no-flag invocation from environment-only credentials to reading config, stored profiles, and external CLI credentials. That silently changes provider and credential selection for scripts; retain the default or add an explicit ambient-config opt-in after maintainer direction.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.86

AGENTS.md: unclear because the file could not be read completely.

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

Labels

Label justifications:

  • P1: The PR can alter credential and provider selection for existing agent exec users without an invocation-level opt-in.
  • merge-risk: 🚨 compatibility: Changing --auth-env-only from default-on to default-off changes the behavior of existing scripts that omit the flag.
  • merge-risk: 🚨 auth-provider: The new default expands provider credential discovery from process environment variables to configured and stored sources.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Focused tests and type checking are reported, but the PR needs a redacted after-fix terminal or live-runtime artifact showing ambient provider/harness selection and --auth-env-only isolation; redact keys, IPs, and non-public endpoints. 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

Security concerns:

  • [medium] Default expands credential sources — src/cli/program/register.agent-turn.ts:147
    Changing the default to disable authEnvOnly allows no-flag executions to consult configured, stored, and external credentials where they previously used only process environment variables.
    Confidence: 0.9

What I checked:

  • Credential default changes: The branch changes --auth-env-only from a default-on restriction to default-off, so existing invocations without flags can begin reading configured, stored, and external CLI credentials. (src/cli/program/register.agent-turn.ts:147, 096432e6a36b)
  • PR describes the changed trust boundary: The PR body confirms that normal execution now reads the operator configuration while --auth-env-only becomes an opt-in mode that reads no configuration. (src/commands/agent-exec.ts:276, 096432e6a36b)
  • Prior review blocker remains applicable: The latest completed ClawSweeper review identified preserving the environment-only credential default as a P1 concern; the current head explicitly retains the opposite default rather than resolving the compatibility decision. (src/cli/program/register.agent-turn.ts:147, 096432e6a36b)
  • Existing validation is supplemental: The PR reports focused Vitest coverage, config tests, and type checking, but no redacted terminal or live-runtime artifact demonstrates the changed ambient-config and credential-boundary behavior after the fix. (src/commands/agent-exec.test.ts:304, 096432e6a36b)

Likely related people:

  • steipete: Authored the four commits that introduce the in-memory configuration path, credential-owner handling, boundary-guard exception, and CLI-default change; broader merged-history ownership could not be established from the available review evidence. (role: current implementation author; confidence: medium; commits: 109f07637741, edea730f12ae, 236a6bd15e01; files: src/commands/agent-exec.ts, src/cli/program/register.agent-turn.ts, src/commands/agent-exec.test.ts)

Rank-up moves

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

  • Resolve the credential-default direction with a compatibility-safe implementation or explicit maintainer approval.
  • Add a redacted terminal or live-runtime transcript proving configured execution and --auth-env-only isolation; updating the PR body should trigger re-review automatically, or a maintainer can comment @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 (2 earlier review cycles)
  • reviewed 2026-07-29T18:56:06.620Z sha edea730 :: needs real behavior proof before merge. :: [P1] Preserve the environment-only credential default
  • reviewed 2026-07-29T19:07:41.041Z sha 236a6bd :: needs real behavior proof before merge. :: [P1] Preserve environment-only credentials by default

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Jul 29, 2026
@steipete
steipete merged commit d6f9aff into main Jul 29, 2026
121 of 123 checks passed
@steipete
steipete deleted the steipete/agent-exec-in-memory-config branch July 29, 2026 19:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 29, 2026
* origin/main: (39 commits)
  feat(apple): media renditions, Now Playing, video upload (#116051)
  feat(android): media renditions, MediaSession, video upload (#116037)
  feat(cli): run agent exec against the ambient config, composed in memory (#116038)
  fix #95351: [Feature]: Generic JSONL line-parsing hook for CliBackendPlugin (native tool-card support beyond claude-stream-json) (#95386)
  feat(plugins): allow per-turn tool narrowing in prompt hooks (#114151)
  docs(hooks): mark pairing hook observation-only (#116055)
  docs(control-ui): document composer capability menu (#115858)
  fix(build): bound declaration memory use (#116021)
  fix: Slack replies recover after gateway startup replay (#115991)
  fix(azure-speech): keep valid voices from malformed catalogs (#115067)
  fix(agents): prevent model runtime startup timeout (#116039)
  fix(ui): explain unavailable MCP tool catalogs (#115994)
  fix(skills): run experience review outside released request roots (#116040)
  docs(security): add safe Gmail reader setup (#116041)
  chore: refresh browser gateway runtime (#116043)
  test: isolate gateway sequence lifecycle coverage
  docs: note gateway reconnect sequence fix
  test: cover gateway sequence reset on restart
  test: cover gateway sequence reset on reconnect
  fix: reset gateway event sequence on reconnect
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
…ory (openclaw#116038)

* feat(cli): run agent exec against the ambient config, composed in memory

Exec previously ignored the operator's config entirely, so a one-shot turn
could not reach configured providers, credentials, or agentRuntime harness
selection. It now layers config the way other folder-scoped coding CLIs do.

The composed config is published as this process's runtime snapshot rather
than serialized to a temp file and re-read through OPENCLAW_CONFIG_PATH. The
snapshot is the only in-process config cache, so the file only ever fed it --
while writing env-substituted provider keys to disk where the run's own exec
tool could read them.

* fix(cli): resolve exec stored credentials from the configured agent dir

* chore(scripts): allow agent exec the file-scoped config loader at its process boundary

* test(cli): cover the exec credential default and pinned-config flags
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 maintainer Maintainer-authored PR 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts 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.

1 participant