Skip to content

refactor(agents): split exec tool pipeline - #113807

Merged
steipete merged 2 commits into
mainfrom
codex/j2-bashexec
Jul 25, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/j2-bashexec

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

src/agents/bash-tools.exec.ts mixed script parsing, safe file preflight, request preparation, policy resolution, host dispatch, and process lifecycle in one 2,166-line module. That kept a high-consequence command-execution surface on the max-lines suppression baseline and made focused review unnecessarily difficult.

Why This Change Was Made

This behavior-neutral refactor leaves the original path as the public facade, separates script-target parsing from ambiguity analysis, isolates safe script reads and shell-bleed validation, moves workdir/environment request preparation behind one helper, and keeps exec policy, approval, host dispatch, and lifecycle ordering together. Static and dynamic import behavior is preserved, including the lazy fs-safe boundary.

Three pre-existing defects were found during the audit: an unbounded output-update backlog under consumer lag, a pre-spawn session-record leak, and permissive negative timeout handling. They were deliberately not fixed here so this split remains reviewable, and they are tracked separately in dedicated fix work.

Beyond the split

None. No behavior, policy, timeout, cleanup, approval, environment-filtering, allowlist, or execution-order change is included.

User Impact

No user-visible behavior change. Maintainers get smaller, cohesive modules for reviewing and evolving the exec surface, and src/agents/bash-tools.exec.ts leaves the max-lines baseline.

Evidence

  • Real Linux runtime proof on Blacksmith Testbox run 30173668655, using the actual createExecTool pipeline with no mocks:
    • permitted request: allowed={"status":"completed","exitCode":0,"output":"proof-ok"}
    • protected preflight: protected={"blocked":true,"message":"exec preflight: detected likely shell variable injection ($DM_JSON) in node script: bad.js:1."}
    • the temporary proof driver and temporary workdir were deleted after the run
  • Focused Vitest: 5 exec-focused files, 134 passed and 4 skipped.
  • Blacksmith Testbox tbx_01kyd93s65qdznxpydsvs3yd9v: pnpm tsgo:core and pnpm build passed; build emitted no [INEFFECTIVE_DYNAMIC_IMPORT] warning.
  • Blacksmith Testbox tbx_01kyd9dj1nss6qv981gc5zh757: rebased-head pnpm check:changed passed, including max-lines ratchet, formatting, core/core-test types, core lint, runtime import cycles, and boundary guards.
  • Autoreview: clean, no accepted/actionable findings; overall correctness 0.98.
  • git diff --check: clean.

AI-assisted: yes. I reviewed the complete execution path and understand the resulting module boundaries.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 25, 2026
@steipete steipete self-assigned this Jul 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 25, 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 repository_dispatch).
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: 🦪 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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 25, 2026, 4:02 PM ET / 20:02 UTC.

ClawSweeper review

What this changes

The PR moves OpenClaw’s agent shell-execution pipeline out of one large module into focused modules for script analysis, safe preflight, request preparation, and policy/host/process execution, while preserving the existing public facade.

Merge readiness

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

Keep this active refactor open for normal owner review. The branch is current, labeled maintainer, and its reported CI coverage is strong; however, the supplied evidence contains tests, builds, and checks rather than directly inspectable after-refactor execution proof for this security-sensitive command path.

Priority: P2
Reviewed head: 57a281d049a9531825ee76b37eb7586290c71529

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has strong stated automated validation and a coherent module split, but real execution proof is still a merge gate for this command-execution refactor.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR reports tests, builds, and CI checks, but the supplied body has no directly inspectable after-fix execution transcript or redacted runtime log; add real-run evidence and redact private paths, endpoints, IPs, tokens, and other sensitive data before posting it. 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 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR reports tests, builds, and CI checks, but the supplied body has no directly inspectable after-fix execution transcript or redacted runtime log; add real-run evidence and redact private paths, endpoints, IPs, tokens, and other sensitive data before posting it. 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 Current implementation boundary: Current main keeps the complete exec request pipeline in bash-tools.exec.ts; the PR extracts the same parsing, preflight, request-preparation, and runtime responsibilities into four modules while retaining the facade.
Public-surface preservation intent: The PR removes src/agents/bash-tools.exec.ts from the max-lines suppression baseline and reduces it to a facade, while adding dedicated modules for request preparation, execution, script target parsing, ambiguity handling, and preflight.
Validation reported by the PR: The PR body reports successful focused exec tests, TypeScript core checks, build, changed-file checks, lint/type/boundary guards, and security checks; this is useful supplemental validation but is not a directly inspectable real execution transcript.
Findings None None.
Security None None.

How this fits together

The agent exec tool receives a shell request from an agent, derives workdir and environment facts, applies command policy and approval rules, then launches on an allowed host and reports process output and lifecycle state. This refactor separates those internal stages while keeping the original exec entry point for callers.

flowchart LR
  A[Agent tool request] --> B[Exec public facade]
  B --> C[Script target and ambiguity analysis]
  C --> D[Safe preflight]
  D --> E[Workdir and environment preparation]
  E --> F[Policy approval and host dispatch]
  F --> G[Process output and lifecycle result]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR reports tests, builds, and CI checks, but the supplied body has no directly inspectable after-fix execution transcript or redacted runtime log; add real-run evidence and redact private paths, endpoints, IPs, tokens, and other sensitive data before posting it. 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) - The extracted modules still sit on the shell-command trust boundary: an ordering or data-flow drift between parsing, preflight, approval, environment preparation, and host dispatch could change enforcement without being visible in compile or build checks.
  • Resolve merge risk (P1) - The PR body reports validation but does not include directly inspectable after-refactor command-execution evidence; a redacted runtime transcript should demonstrate both an allowed representative command and a retained rejection/preflight path before merge.
Agent review details

Security

None.

PR surface

Source +68, Other -1. Total +67 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 6 2224 2156 +68
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 7 2224 2157 +67

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Add representative runtime proof (recommended)
    Provide redacted terminal output or runtime logs showing one permitted exec path and one rejected or preflighted script path on the refactored head before merging.
  2. Accept the evidence gap deliberately
    A responsible owner may merge based on the existing test and CI evidence if they explicitly accept that no direct runtime transcript was retained for this behavior-neutral split.

Technical review

Best possible solution:

Retain the existing facade and land the split only after redacted real-run evidence demonstrates that representative allowed execution and a protected rejection/preflight case preserve their prior outcomes and ordering.

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

Not applicable: this PR is a behavior-neutral refactor rather than a report of failing existing behavior. The review question is equivalence of the command-execution path, not reproduction of a user bug.

Is this the best way to solve the issue?

Yes, conditionally: keeping the public facade while splitting cohesive internal stages is a maintainable direction, provided the extracted security and lifecycle boundaries are proven equivalent with focused runtime evidence.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is an internal refactor with no stated user-visible behavior change, but it affects the agent command-execution path and warrants normal careful review.
  • add merge-risk: 🚨 security-boundary: The diff reorganizes parsing, script preflight, environment preparation, approval, and host dispatch that collectively enforce execution safety.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports tests, builds, and CI checks, but the supplied body has no directly inspectable after-fix execution transcript or redacted runtime log; add real-run evidence and redact private paths, endpoints, IPs, tokens, and other sensitive data before posting it. 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.

Label justifications:

  • P2: This is an internal refactor with no stated user-visible behavior change, but it affects the agent command-execution path and warrants normal careful review.
  • merge-risk: 🚨 security-boundary: The diff reorganizes parsing, script preflight, environment preparation, approval, and host dispatch that collectively enforce execution safety.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports tests, builds, and CI checks, but the supplied body has no directly inspectable after-fix execution transcript or redacted runtime log; add real-run evidence and redact private paths, endpoints, IPs, tokens, and other sensitive data before posting it. 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:

  • Current implementation boundary: Current main keeps the complete exec request pipeline in bash-tools.exec.ts; the PR extracts the same parsing, preflight, request-preparation, and runtime responsibilities into four modules while retaining the facade. (src/agents/bash-tools.exec.ts:1, 57a281d049a9)
  • Public-surface preservation intent: The PR removes src/agents/bash-tools.exec.ts from the max-lines suppression baseline and reduces it to a facade, while adding dedicated modules for request preparation, execution, script target parsing, ambiguity handling, and preflight. (config/max-lines-baseline.txt:380, 57a281d049a9)
  • Validation reported by the PR: The PR body reports successful focused exec tests, TypeScript core checks, build, changed-file checks, lint/type/boundary guards, and security checks; this is useful supplemental validation but is not a directly inspectable real execution transcript. (src/agents/bash-tools.exec-run.ts:1, 57a281d049a9)
  • Protected maintainer handling: The supplied GitHub context labels this active same-day PR maintainer and shows it assigned to its author, so conservative cleanup must not auto-close it.

Likely related people:

  • steipete: Authored both commits in this active refactor and is assigned to the PR; the available review context does not provide a stronger independent feature-history owner. (role: current exec-path contributor; confidence: medium; commits: 8cb05c65155d, 57a281d049a9; files: src/agents/bash-tools.exec.ts, src/agents/bash-tools.exec-run.ts, src/agents/bash-tools.exec-request-preparation.ts)

Rank-up moves

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

  • Add redacted terminal or runtime-log proof for a permitted exec request and a retained reject/preflight scenario.
  • After updating the PR body with evidence, let the automatic review refresh or ask a maintainer to comment @clawsweeper re-review if it does not.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@steipete
steipete merged commit 73bead1 into main Jul 25, 2026
156 of 161 checks passed
@steipete
steipete deleted the codex/j2-bashexec branch July 25, 2026 20:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 26, 2026
* refactor(agents): split exec tool pipeline

* chore(agents): keep exec prep type private
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL 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