Skip to content

fix(cron): preserve whitespace in command cwd CLI options - #172869

Merged
roboclaw-bot merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/cron-cwd-trim-201
Oct 21, 2026
Merged

roboclaw-bot merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/cron-cwd-trim-201

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw automations add --command-cwd "/repo/job " (or --on-exit-cwd/--stream-cwd) silently rewrites the working directory to /repo/job before the cron command runs, so the command executes in the wrong directory while reporting success. On Unix /repo/job is a legal, distinct directory. This switches all cwd CLI options and downstream normalization/identity/lookup sites from trimming readers (normalizeOptionalString/.trim()) to whitespace-preserving readNonBlankString, matching command.

Why This Change Was Made

The repair spans every cwd trim site end-to-end:

  • CLI boundary: schedule-options.ts (onExitCwd/streamCwd), register.cron-add.ts (commandCwd), and the edit path register.cron-edit.ts (edit still parsed cwd with a trimming reader while add already preserved it).
  • Gateway normalization: normalize.ts (coerceSchedule cwdRaw), normalize-payload.ts (payload.cwd).
  • Schedule identity (schedule-identity.ts:71,87): on-exit/stream identity used normalizeOptionalString(schedule.cwd), so a cwd edit /repo/job → /repo/job looked unchanged → scheduleChanged=false → a running on-exit payload with deleteAfterRun=true could delete the job. Now uses readNonBlankString.
  • Windows executable lookup: executable-path.ts:34 and windows-command.ts:74 resolved against options.cwd.trim(). Both now use raw cwd, matching the spawned child cwd.

readNonBlankString is the same primitive each function already uses for command, removing within-function inconsistency. Blank cwd still returns undefined (rejected), unchanged.

User Impact

Pass a cron cwd with leading/trailing whitespace and the command runs in exactly that directory. Cwd-whitespace-only edits are detected as real changes (preventing accidental job deletion). Windows relative-executable selection agrees with the spawned cwd. Blank cwd still rejected; other paths unaffected.

Evidence

Before/after — stored cwd at each layer for input "/repo/job ":

Layer Before After
CLI add + edit "/repo/job" (trimmed) "/repo/job " (preserved)
Gateway normalize "/repo/job" (trimmed) "/repo/job " (preserved)
Schedule identity trimmed → edits look identical preserved → edits detected
Windows lookup trimmed cwd raw cwd

Gateway + schedule-identity + executable-path regressions (pre-fix RED / post-fix GREEN): coerceSchedule/normalizeCronPayload store "/repo/job " verbatim; blank rejected; identity detects cwd edits (RED); executable-path resolves job/tool (RED). vitest: 40 passed.

Windows production fn proof (pre-fix vs post-fix):

$ tsx windows-selection-production-fn.mts
FIXED   resolveExecutablePathCandidate('bin/tool.exe',{cwd:".../job "}) -> .../job /bin/tool.exe
PRE-FIX resolveExecutablePathCandidate('bin/tool.exe',{cwd:".../job"})  -> .../job/bin/tool.exe
PATH case: relative entry `bin` resolved vs raw cwd -> .../job /bin/tool  (PASS)

Full shipped CLI → Gateway → SQLite → spawn (local dev Gateway, Unix, head bffc5d6):

$ openclaw cron add proof-job --command "sh ./marker.sh" --command-cwd "/tmp/oc-proof-work/job " --every 1h
{ "payload": { ..., "cwd": "/tmp/oc-proof-work/job " } }
$ openclaw cron run <id> --wait   # status ok, exitCode 0
$ ls "/tmp/oc-proof-work/job "/ran-in-*   # only trailing-space dir has marker

Native Windows proof (GitHub Actions windows-latest, shipped openclaw.mjs → dev Gateway → SQLite → spawn, head bffc5d6):

=== CASE 1: Relative executable (bin\tool.cmd), trailing-space cwd ===
Stored cwd: C:\oc-winproof\job  (length 19 — trailing space preserved)
Summary: selected_executable=C:\oc-winproof\job\bin\tool.cmd  child_cwd=C:\oc-winproof\job
Diagnostics: command ok: "bin\\tool.cmd"  ExitCode: 0

=== CASE 2: Bare executable (tool) via PATH=bin, trailing-space cwd ===
Stored cwd: C:\oc-winproof\job  (length 19 — trailing space preserved)
Summary: selected_executable=C:\oc-winproof\job\bin\tool.cmd  child_cwd=C:\oc-winproof\job
Diagnostics: command ok: "tool"  ExitCode: 0

Case 1 tests resolveExecutablePathCandidate (relative executable with separator); Case 2 tests resolveWindowsCommandFromCwdOrPath (bare executable via relative PATH). Stored cwd preserves trailing space (length 19) through CLI, Gateway, SQLite, and executable resolution. Both commands executed (exitCode 0). selected_executable/child_cwd reflect Windows CreateProcessW trailing-space trim on lpCurrentDirectory (OS-level, outside this PR's scope). Unix full-chain (above) shows end-to-end execution in trailing-space dir.

Real upgrade proof (stable v2026.10.4 → candidate, same SQLite, head bffc5d6):

# stable v2026.10.4 creates job with trailing-space cwd → stored TRIMMED (bug)
# kill stable, launch candidate on same state → existing job loads/runs (status ok)
# candidate creates new job → stored cwd preserved (fixed), marker in trailing-space dir
Created by Stored cwd Runs in
stable v2026.10.4 /tmp/oc-dm-work/job (trimmed) plain dir
candidate bffc5d6 /tmp/oc-dm-work/job (preserved) trailing-space dir

Existing settings/jobs load and work after upgrade; no schema/migration change. Edge cases: empty/undefined cwd → process.cwd(); all-blank → undefined.

Full cwd-relevant shard: 7 files, 164 tests passed.

Maintainer fixup

Maintainer fixup (cfdf580): the shared executable/Windows lookups now keep #172814's blank-cwd fallback. A non-blank cwd is used verbatim (whitespace preserved); a whitespace-only cwd still falls back to process.cwd(). src/infra/executable-path.ts stays as on main, and src/process/windows-command.ts uses the same rule, with blank-cwd regression tests for both.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@SunnyShu0925
SunnyShu0925 marked this pull request as ready for review October 15, 2026 06:59
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves meaningful whitespace in cron working directories through CLI parsing, normalization, schedule identity, and Windows command lookup.

Example: Create a command automation with --command-cwd "/repo/job ".

  • Before: The directory becomes "/repo/job", potentially running the command in a different directory.
  • After: The stored directory remains "/repo/job ", and Unix execution uses that directory.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, useful repair with shipped-entry-point evidence, existing-state compatibility proof, and no actionable findings; CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied terminal output exercises the shipped CLI through Gateway normalization, SQLite, and spawn on Unix, plus native Windows relative and PATH executable lookup; the final fixup retains nonblank behavior and restores the established blank-cwd fallback.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A scheduled command can report success after running in a different directory because significant path whitespace was removed.
Reason: Exact directory selection is an execution correctness contract, and the repair uses existing owners without adding options or changing the intended blank-input policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a concrete wrong-directory execution bug that remains on current main; no actionable patch defect was found.

Priority: P2
Reviewed head: cfdf580d5c48507facd8211c4841bf309ca7b898

Before merge

None.

Findings

None.

Agent review details

How this fits together

Automation CLI options enter Gateway cron normalization and SQLite storage; schedule identity controls watcher replacement and run settlement, while process runners consume the stored working directory.

flowchart TD
  A[Automation CLI] --> B[Gateway normalization]
  B --> C[SQLite jobs]
  C --> D[Schedule identity]
  C --> E[Command and watcher runners]
  D --> E
  E --> F[Executable lookup and spawn]
Loading

Technical review

Best possible solution:

Preserve nonblank cwd strings verbatim in the existing owners while retaining blank-input rejection, stream clearing, and shared lookup fallbacks.

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

Current-main CLI and normalization readers visibly trim valid directory bytes; supplied Unix CLI execution output demonstrates the resulting directory mismatch without requiring a new reproduction run.

Is this the best way to solve the issue?

The patch repairs the producers and identity comparisons with existing string readers, preserves established blank semantics, and introduces no unnecessary production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 13c25be3c713.

Provenance checked

  • Command cwd CLI parsing changes intended behavior with a stated reason (b8adc11: Command jobs introduced CLI-first shell execution with optional cwd; later blank-input validation deliberately rejected empty creation paths.)
  • Schedule cwd normalization and identity changes intended behavior with a stated reason (feat(cron): stream schedule sources with durable source identity #112387: Stream sources use schedule identity to retire replaced work; later coercion consolidation retained trimming, while the command-whitespace repair established byte preservation for execution inputs.)
  • Payload field normalization changes intended behavior with a stated reason (729e65e: The consolidation shared payload normalization without an intended behavior change; separating cwd preserves execution bytes while leaving model and thinking normalization intact.)
  • Windows executable lookup changes intended behavior with a stated reason (4f287dd: The Execa migration retained OpenClaw-owned Windows executable selection and shell protections; this repair aligns relative PATH lookup with the supplied cwd and retains the blank fallback.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 98742bc adds src/cron/schedule-identity.ts:76 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 98742bc2c7f2; files: src/cron/schedule-identity.ts)
  • Linze Shi: Raw commit 9d33bbc adds src/cron/schedule-identity.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 9d33bbca28b3; files: src/cron/schedule-identity.ts)

PR surface

Source +12, Tests +68. Total +80 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 23 11 +12
Tests 5 70 2 +68
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 93 13 +80

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Whitespace-bearing directory names can silently select a different working directory, but the affected CLI workflow has limited scope.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-15T13:16:28.143Z sha a01e285 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-15T14:10:20.093Z sha a01e285 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-15T14:21:58.803Z sha a01e285 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T13:02:13.516Z sha bffc5d6deb3f7c46e36a34c009ed9580760254cb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T13:09:17.462Z sha bffc5d6deb3f7c46e36a34c009ed9580760254cb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T15:52:51.577Z sha bffc5d6deb3f7c46e36a34c009ed9580760254cb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-16T16:27:53.150Z sha bffc5d6deb3f7c46e36a34c009ed9580760254cb :: needs maintainer review before merge. :: none
  • reviewed 2026-10-20T04:51:26.562Z sha e8311c4e73d76c4ec366907caa0078fb22bec964 :: needs maintainer review before merge. :: none

Reviewed October 20, 2026, 8:14 PM ET / October 21, 2026, 00:14 UTC (Revision 16).

@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from 5856edc to 42d6869 Compare October 15, 2026 08:43
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from 42d6869 to 937b402 Compare October 15, 2026 09:34
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from d2ff325 to c4716cd Compare October 15, 2026 10:40
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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 Oct 15, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from c4716cd to a01e285 Compare October 15, 2026 13:09
@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

SunnyShu0925 added a commit to SunnyShu0925/openclaw that referenced this pull request Oct 16, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from bffc5d6 to 903dc76 Compare October 20, 2026 04:32
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 20, 2026
@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from 903dc76 to e8311c4 Compare October 20, 2026 04:42
@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Oct 20, 2026
--on-exit-cwd, --stream-cwd, and --command-cwd were normalized with
normalizeOptionalString, which trims leading/trailing whitespace. A path
like "/repo/job " (a legal Unix directory) was silently rewritten to
"/repo/job" before reaching the spawned cron command, so the command ran
in the wrong directory while reporting success.

Use readNonBlankString instead, matching the existing onExitCommand
handling in the same function. Blank values are still rejected (returns
undefined), so the blank-gate behavior is unchanged.

Ref: BUG-201-cron-command-cwd-trim-swallows-path (local finding)
@SunnyShu0925
SunnyShu0925 force-pushed the fix/cron-cwd-trim-201 branch from e8311c4 to 4e12020 Compare October 20, 2026 13:08
Keep openclaw#172814's executable-path rule (non-blank cwd preserved verbatim,
whitespace-only cwd falls back to process.cwd()) and apply the same rule
to Windows bare-command PATH lookup, so lookup and spawn agree on
untrimmed cwd without treating a blank cwd as a literal directory.

Co-authored-by: jalehman <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 21, 2026
@roboclaw-bot
roboclaw-bot enabled auto-merge (squash) October 21, 2026 00:19
@roboclaw-bot
roboclaw-bot merged commit 8ef2b80 into openclaw:main Oct 21, 2026
140 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
…72869)

* fix(cron): preserve whitespace in command cwd CLI options

--on-exit-cwd, --stream-cwd, and --command-cwd were normalized with
normalizeOptionalString, which trims leading/trailing whitespace. A path
like "/repo/job " (a legal Unix directory) was silently rewritten to
"/repo/job" before reaching the spawned cron command, so the command ran
in the wrong directory while reporting success.

Use readNonBlankString instead, matching the existing onExitCommand
handling in the same function. Blank values are still rejected (returns
undefined), so the blank-gate behavior is unchanged.

Ref: BUG-201-cron-command-cwd-trim-swallows-path (local finding)

* fix(cron): keep blank-cwd fallback in shared executable resolution

Keep openclaw#172814's executable-path rule (non-blank cwd preserved verbatim,
whitespace-only cwd falls back to process.cwd()) and apply the same rule
to Windows bare-command PATH lookup, so lookup and spawn agree on
untrimmed cwd without treating a blank cwd as a literal directory.

Co-authored-by: jalehman <[email protected]>

---------

Co-authored-by: jalehman <[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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

2 participants