Skip to content

fix(cli): let nested agent exec --timeout override the parent flag - #125256

Merged
steipete merged 3 commits into
openclaw:mainfrom
zyw02:auto/prospect-agent-exec-timeout-inherit
Aug 23, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
zyw02:auto/prospect-agent-exec-timeout-inherit

Conversation

@zyw02

@zyw02 zyw02 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Closes #125255

Before merge (ClawSweeper)

  • Add real behavior proof — exact-head pnpm openclaw agent exec on an isolated HOME/state dir, not a mocked executor.
  • Resolve merge risk (P1) — after-fix evidence is a real CLI run; the mocked parser matrix stays in Focused regression tests.
  • Resolve merge risk (P1) — inherit comment is two lines stating the option-source invariant.
  • Complete next step (P2) — contributor-provided real CLI proof on this PR.

What Problem This Solves

Fixes an issue where operators who run openclaw agent --timeout <parent> exec --timeout <leaf> … would still execute the nested headless turn under the parent deadline. The production CLI enables positional options, so those two flags are distinct values: the parent agent --timeout is a Gateway/agent-turn override, and exec --timeout is the isolated embedded-run deadline. When both are written on the same argv (copied parent flags plus an explicit longer exec budget, or a script that tightens only the nested command), the leaf flag was parsed and then discarded.

The user-visible symptom is a silently wrong timeout, not a parse error. agent exec --timeout 120 alone works. agent --timeout 30 exec … correctly inherits 30 seconds onto exec because the leaf option defaults to "600". Combining them, which looks like an override, used 30 seconds. That is the worst class of CLI bug for this surface: the command starts, the operator believes they raised the deadline, and the run dies at the parent budget.

This is bounded to option merge for openclaw agent exec. It does not change Gateway RPC timeouts, cron jobs, or exec-tool child process killing.

Why This Change Was Made

The exec action merged timeout with parentOpts?.timeout ?? opts.timeout. That parent-first ?? exists because the leaf --timeout has a Commander default of "600", so opts.timeout ?? parent would never inherit a parent-only flag. The workaround over-corrected: once the parent is set, it always wins, including when the leaf source is "cli".

The repo already has the owner for this contract: inheritOptionFromParent in src/cli/command-options.ts. It returns an ancestor value only when the child source is missing or "default". Gateway run options use the same pattern for defaulted children (inherited ?? resolved[key] for wsLog). This patch applies that helper to exec --timeout and keeps leaf-first ?? for model / thinking / messageFile, which have no leaf default.

Non-goals: changing the 600s default, changing parent agent --timeout units, rewriting other nested flags, or touching agentExecCommand timeout parsing. Invalid --timeout strings still fail in normalizeTimeoutSeconds after merge.

User Impact

openclaw agent exec now treats --timeout the same way operators already expect from nested Commander flags and from sibling --model / --thinking:

  • Explicit exec --timeout is the deadline for that run.
  • If exec --timeout is omitted, a parent agent --timeout still inherits (scripts can keep putting the flag before exec).
  • If neither is set, exec still uses "600".

Operators who already pass only one of the two flags see no behavior change. Operators who pass both get the leaf value they wrote next to exec, so long isolated turns can actually use the longer budget.

Review feedback addressed

ClawSweeper reviewed 5818be1a00126c1310213153bdb37f2dab711ea2 and blocked on real CLI proof (mocked parser/executor handoff only), plus keeping the inherit comment as the smallest option-source statement.

This revision (445387f8c168326ce2690da8b330623a680851c0) shortens that comment to two lines and attaches an isolated pnpm openclaw transcript below. No other nested flags were rewritten.

Evidence

Real-behavior proof

Exact-head real CLI proof (production pnpm openclaw -> scripts/run-node.mjs)
reviewed_head=445387f8c168326ce2690da8b330623a680851c0
previous_reviewed_head=5818be1a00126c1310213153bdb37f2dab711ea2
base_sha=8cae198210de93c1158131a1aee9d925e1ed7e22

Isolated operator surface:
HOME=<ephemeral>
OPENCLAW_STATE_DIR=<ephemeral>
--isolated --json --cwd <ephemeral workspace>
No operator ~/.openclaw and no provider keys were used.

Parser/runtime:
src/cli/program/build-program.ts enablePositionalOptions()
src/cli/program/register.agent-turn.ts exec action merge
src/commands/agent-exec.ts normalizeTimeoutSeconds

1) Both flags explicit; parent valid, leaf sentinel
$ pnpm openclaw agent --timeout 30 exec "proof-timeout-merge" --timeout nope --json --isolated --cwd <ws>
{
  "ok": false,
  "status": "error",
  "model": null,
  "provider": null,
  "error": {
    "message": "--timeout must be a non-negative integer in seconds.",
    "kind": "exception"
  }
}
--timeout must be a non-negative integer in seconds.
exit=1

2) Both flags explicit; parent sentinel, leaf valid
$ pnpm openclaw agent --timeout nope exec "proof-timeout-merge" --timeout 120 --json --isolated --cwd <ws>
{
  "ok": false,
  "status": "error",
  "model": null,
  "provider": null,
  "error": {
    "message": "Agent harness runtime \"codex\" is unavailable because its plugin registration is missing from this prepared run. Enable or reinstall the plugin that provides this runtime, restart the Gateway, then retry.",
    "kind": "exception"
  }
}
exit=1

3) Parent-only inherit, invalid
$ pnpm openclaw agent --timeout nope exec "proof-timeout-merge" --json --isolated --cwd <ws>
--timeout must be a non-negative integer in seconds.
exit=1

4) Parent-only inherit, valid
$ pnpm openclaw agent --timeout 30 exec "proof-timeout-merge" --json --isolated --cwd <ws>
error: Agent harness runtime "codex" is unavailable ...
exit=1

Interpretation on exact head 445387f8c168326ce2690da8b330623a680851c0:

  • Case 1 proves the nested leaf governs merge: parent 30 is a legal integer. Parent-first ?? would have accepted it and continued. The run instead rejected nope in normalizeTimeoutSeconds before a model turn.
  • Case 2 is the inverse: parent nope would have failed timeout validation if inherited. The leaf 120 passed merge; the later harness error is a prepared-run plugin gap in this isolated checkout, not timeout parsing.
  • Cases 3 and 4 keep parent-only inherit: defaulted exec --timeout still takes a parent CLI value.
  • This is a real configured CLI entry (pnpm openclaw), fail-before-provider for the deadline string. It does not wall-clock a live model cancellation.

Evidence scope: production CLI parse + exec timeout normalize. No gateway persistence. Isolated session UUIDs omitted.

Focused regression tests

node scripts/run-vitest.mjs src/cli/program/register.agent.test.ts
→ 26 passed
Reviewed head: 445387f8c168326ce2690da8b330623a680851c0

Matrix in "resolves nested exec --timeout from the explicit leaf, then the parent, then the default":
1. leaf-only --timeout 120
2. parent-only --timeout 30 (inherit)
3. both explicit → leaf 120 wins
Default 600 remains covered by "runs the nested headless exec command with repeatable fallbacks".

The new test failed on pre-fix code for the intended reason (timeout: "30" vs "120") and passes after the owner-boundary repair.

Local CI gates (exact tip)

GATE tip=445387f8c168326ce2690da8b330623a680851c0 mode=lean
- claw: real CLI timeout-merge transcript; inherit comment reduced to two lines
- vitest: src/cli/program/register.agent.test.ts → pass (26)
- transcript: yes (pnpm openclaw, isolated HOME/state, --isolated)
- extra: oxlint tsconfig.core.json on register.agent-turn.ts + register.agent.test.ts → pass
- full-types/lanes: skipped (claw follow-up; surface=src/cli/program/register.agent-turn.ts)
→ PUSH allowed: yes

Production LOC vs original base: inherit helper import + two-line invariant comment + source-aware merge (net smaller than the first tip's four-line comment). No new config, env, or protocol surface.

Permalinks:

Remaining Risk

  • Other nested flags on agent exec (--json OR-merge, model/thinking leaf-first) were left as-is because they do not have a leaf default that forces a parent-first ??. If a future leaf option gains a default, it should use inheritOptionFromParent, not copy this old timeout merge.
  • This does not change how agentExecCommand parses invalid timeout strings; those still throw --timeout must be a non-negative integer in seconds after merge.
  • Live wall-clock cancellation of a running model was not exercised; the bug is which string is forwarded as the deadline.
  • Current-head GitHub check-lint-core-5 failed on unrelated src/config/sessions/types.ts max-lines (701). That file is not in this diff; upstream main already shortened it. Not repaired here.

AI-assisted development

An AI coding assistant drafted the patch, regression test, real-CLI proof, and this description. A human operator is expected to review the inherit behavior against Commander positional options before merge.

@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 cli CLI command changes size: XS labels Aug 17, 2026
@clawsweeper clawsweeper Bot added 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 maintainer review before merge. Reviewed August 17, 2026, 6:35 PM ET / 22:35 UTC.

ClawSweeper review

What this changes

The PR makes an explicit nested agent exec --timeout override a parent agent --timeout while retaining parent-only inheritance and the 600-second exec default.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: this is a focused, source-supported fix for a current-main nested CLI precedence bug. The contributor addressed the prior proof request with an exact-head real CLI transcript; no blocking correctness finding remains, pending exact-head CI completion.

Priority: P2
Reviewed head: 445387f8c168326ce2690da8b330623a680851c0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A clean bounded fix with a real CLI transcript and focused regression coverage; exact-head CI is the remaining normal merge gate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The exact-head isolated production CLI transcript demonstrates the changed timeout-selection behavior before the unavailable agent runtime boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head isolated production CLI transcript demonstrates the changed timeout-selection behavior before the unavailable agent runtime boundary.
Evidence reviewed 8 items Current-main defect: The current-main ancestor keeps the parent-first merge at line 190; a no-diff comparison confirms this file remains unchanged through current main.
Patch owner boundary: The PR replaces that merge with the canonical source-aware helper immediately before calling the embedded execution command.
Callee behavior: The embedded command validates the merged timeout before constructing the agent run request and forwards that value as the run timeout.
Findings None None.
Security None None.

Live Proof

Live proof recording

Recorded live on the PR head (445387f8c168), 0.867s, terminal surface.

How this fits together

The agent CLI parses parent and nested command options, merges them into an isolated embedded-agent request, and passes the selected deadline to execution. This change determines which operator-provided timeout reaches that run.

flowchart LR
  A[Operator command] --> B[CLI parser]
  B --> C[Parent and nested timeout values]
  C --> D[Source-aware inheritance]
  D --> E[Embedded agent execution]
  E --> F[Timeout validation and run]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still in progress; merge only after required checks complete successfully.
  • Resolve merge risk (P1) - Production code is net +3 lines for an existing-helper import and a two-line invariant comment; no smaller net-neutral expression preserves the default-aware precedence contract clearly.
  • Resolve merge risk (P1) - Commander source/types could not be inspected locally because the dependency package and network access are unavailable; the contributor’s production CLI transcript mitigates this reviewer-side limitation.
  • Complete next step (P2) - No repair lane is needed; maintainers should wait for exact-head CI before the normal merge decision.
Agent review details

Security

None.

PR surface

Source +3, Tests +29. Total +32 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 29 0 +29
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 33 1 +32

Review metrics

Metric Value Why it matters
Production vs test delta production +4/-1, tests +29/-0 The production growth is limited to adopting an existing helper and documenting its option-source invariant; the test addition covers the three affected precedence cases.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #125255
Summary: This PR is the linked candidate repair for the reported nested CLI timeout-precedence bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge after exact-head CI passes, keeping timeout precedence in the existing source-aware helper and its production-parser regression matrix.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge after exact-head CI passes, keeping timeout precedence in the existing source-aware helper and its production-parser regression matrix.

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

Yes, from source: positional parsing, the current-main merge, and the execution handoff establish the failing both-explicit case; the contributor also supplied an exact-head real CLI transcript.

Is this the best way to solve the issue?

Yes: this repairs the producer-side option merge with the repository’s shared default-aware inheritance helper rather than adding a downstream timeout workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded nested CLI timeout-precedence defect without changing Gateway-wide timeout policy.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The exact-head isolated production CLI transcript demonstrates the changed timeout-selection behavior before the unavailable agent runtime boundary.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head isolated production CLI transcript demonstrates the changed timeout-selection behavior before the unavailable agent runtime boundary.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Commit d90dcc2 introduced the current-main registration file containing the original timeout merge, which remains unchanged on current main. (role: current implementation introducer; confidence: high; commits: d90dcc2111ba; files: src/cli/program/register.agent-turn.ts)

Rank-up moves

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

  • Wait for required exact-head CI to finish successfully.

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.

@zyw02

zyw02 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the Before-merge items on head 445387f8c168326ce2690da8b330623a680851c0:

  • Isolated real pnpm openclaw agent exec timeout-merge transcript is in the PR Evidence section (leaf sentinel vs valid parent, and the inverse).
  • Inherit comment reduced to the two-line option-source invariant.
  • Focused tests: node scripts/run-vitest.mjs src/cli/program/register.agent.test.ts → 26 passed.

@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.

Re-review progress:

@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
Preserve the contributor's source-aware timeout inheritance while resolving the
current main registration-test conflict. Exercise every precedence case through
the existing production-equivalent positional Commander harness and retain the
current guided-agent creation and failed-agent exit behavior.

Co-authored-by: zyw02 <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification on refreshed signed contributor head 4bf5d0693bbf0b059e54e1e50673857ae161e771:

  • Root cause: agent exec declares its own --timeout default of 600, but its option producer previously selected the parent timeout first. Commander records whether each value came from default or cli, so an explicitly supplied nested timeout was incorrectly overwritten by an explicitly supplied parent timeout.
  • Canonical repair: use the existing source-aware inheritOptionFromParent helper at the registration owner. Explicit nested --timeout 120 wins over parent --timeout 30; parent-only 30 still propagates, and the established exec default remains 600. No Gateway-wide timeout, public option, configuration, or runtime behavior is expanded.
  • Current-main refresh: resolved the genuine historical test conflict while preserving the contributor commit as the merge's first parent and keeping @zyw02 credited. The modern guided-agent creation assertion and fix(cli): exit non-zero when an agent turn fails #125557's nonzero agent failure exit propagation remain intact. The existing shared CLI test helper now enables Commander positional options exactly like the real production program; the redundant nested test-only parser helper was removed.
  • Direct Commander dependency proof: installed lib/command.js sets option defaults with source default, explicit flags with source cli, and stops parent option parsing at subcommands when positional parsing is enabled; getOptionValueSource exposes that exact distinction.
  • Actual focused owner proof: node scripts/run-vitest.mjs src/cli/program/register.agent.test.ts src/cli/command-options.test.ts passed 44 tests across two shards: 26 real registration/positional-parser cases and 18 shared inheritance cases.
  • Fresh isolated structured reviews both passed: precommit full 3,400-byte patch and final exact-head full 3,514-byte patch; TruffleHog clean, no actionable findings.
  • Fresh exact-head CI 32664838266 must complete green before landing; Workflow Sanity 32664838317 is already green.
  • Production delta: +4/-1 (net +3) for the existing shared-helper import and required two-line source-precedence invariant; tests +24/-1, removing duplicate setup while covering leaf-only, parent-only, and both-explicit precedence.

Fixes #125255. Thanks @zyw02 for the original owner-boundary repair and production-parser regression.

@steipete
steipete merged commit d0db8a9 into openclaw:main Aug 23, 2026
183 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 24, 2026
…penclaw#125256)

* fix(cli): let nested agent exec --timeout override the parent flag

* fix(cli): keep nested exec --timeout inherit comment to the option-source invariant

---------

Co-authored-by: zyw02 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: agent --timeout wins over nested exec --timeout when both are set

2 participants