Repository navigation
fix(cron): preserve whitespace in command cwd CLI options - #172869
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis 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 ".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherAutomation 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12, Tests +68. Total +80 across 12 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (15 earlier review cycles; latest 8 shown)
Reviewed October 20, 2026, 8:14 PM ET / October 21, 2026, 00:14 UTC (Revision 16). |
5856edc to
42d6869
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
42d6869 to
937b402
Compare
|
🦞👀 Re-review progress:
|
937b402 to
d2ff325
Compare
|
🦞👀 Re-review progress:
|
d2ff325 to
c4716cd
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
c4716cd to
a01e285
Compare
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
|
🦞👀 Re-review progress:
|
bffc5d6 to
903dc76
Compare
|
🦞👀 Re-review progress:
|
903dc76 to
e8311c4
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
--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)
e8311c4 to
4e12020
Compare
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]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…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]>
What Problem This Solves
openclaw automations add --command-cwd "/repo/job "(or--on-exit-cwd/--stream-cwd) silently rewrites the working directory to/repo/jobbefore the cron command runs, so the command executes in the wrong directory while reporting success. On Unix/repo/jobis a legal, distinct directory. This switches all cwd CLI options and downstream normalization/identity/lookup sites from trimming readers (normalizeOptionalString/.trim()) to whitespace-preservingreadNonBlankString, matchingcommand.Why This Change Was Made
The repair spans every cwd trim site end-to-end:
schedule-options.ts(onExitCwd/streamCwd),register.cron-add.ts(commandCwd), and the edit pathregister.cron-edit.ts(edit still parsed cwd with a trimming reader while add already preserved it).normalize.ts(coerceSchedulecwdRaw),normalize-payload.ts(payload.cwd).schedule-identity.ts:71,87): on-exit/stream identity usednormalizeOptionalString(schedule.cwd), so a cwd edit/repo/job→/repo/joblooked unchanged →scheduleChanged=false→ a running on-exit payload withdeleteAfterRun=truecould delete the job. Now usesreadNonBlankString.executable-path.ts:34andwindows-command.ts:74resolved againstoptions.cwd.trim(). Both now use raw cwd, matching the spawned child cwd.readNonBlankStringis the same primitive each function already uses forcommand, removing within-function inconsistency. Blank cwd still returnsundefined(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 ":"/repo/job"(trimmed)"/repo/job "(preserved)"/repo/job"(trimmed)"/repo/job "(preserved)Gateway + schedule-identity + executable-path regressions (pre-fix RED / post-fix GREEN):
coerceSchedule/normalizeCronPayloadstore"/repo/job "verbatim; blank rejected; identity detects cwd edits (RED); executable-path resolvesjob/tool(RED).vitest: 40 passed.Windows production fn proof (pre-fix vs post-fix):
Full shipped CLI → Gateway → SQLite → spawn (local dev Gateway, Unix, head
bffc5d6):Native Windows proof (GitHub Actions
windows-latest, shippedopenclaw.mjs→ dev Gateway → SQLite → spawn, headbffc5d6):Case 1 tests
resolveExecutablePathCandidate(relative executable with separator); Case 2 testsresolveWindowsCommandFromCwdOrPath(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_cwdreflect WindowsCreateProcessWtrailing-space trim onlpCurrentDirectory(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):/tmp/oc-dm-work/job(trimmed)bffc5d6/tmp/oc-dm-work/job(preserved)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.tsstays as on main, andsrc/process/windows-command.tsuses the same rule, with blank-cwd regression tests for both.