Skip to content

fix(cron): keep valid command env vars when a sibling value is non-string (#105433) - #106100

Merged
steipete merged 2 commits into
openclaw:mainfrom
MoerAI:fix/cron-env-preserve-valid
Jul 16, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
MoerAI:fix/cron-env-preserve-valid

Conversation

@MoerAI

@MoerAI MoerAI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #105433

What Problem This Solves

A command cron job whose env map contained a single non-string value silently lost its entire environment. For example, env: { DEBUG: true, PATH: "/bin" } sent to cron.add/cron.update was normalized down to no env at all — the valid PATH string was discarded alongside the invalid DEBUG boolean, before the Gateway ever validated the request. Operators got no error and no indication that their configured environment had vanished.

Why This Change Was Made

Root cause: normalizeTrimmedStringRecord in src/cron/normalize.ts returned undefined as soon as any entry was non-string, and the env branch treats undefined as "delete the whole field". So one bad value discarded every valid sibling.

The sibling helper in the same file, normalizeTrimmedStringArray, already handles this correctly: it filters invalid entries and only collapses to undefined when nothing valid remains. This change makes the record helper match that behavior — skip invalid entries, and only normalize the map away entirely when no valid entries survive.

Owner boundary: the fix stays inside the record normalizer that owns this semantic, mirroring the array normalizer right next to it. No caller, schema, or Gateway-validation change.

Non-goals: it does not change how an all-invalid or absent env is handled (still dropped/absent), and does not alter the Gateway request schema.

User Impact

Valid cron command environment variables now survive when a sibling value is malformed, instead of the whole env map silently disappearing. Fully-valid env maps are unchanged (byte-for-byte).

Evidence

Real behavior on current head d80bbd782a01, exercised through the actual normalizeCronJobCreate path with a command payload env: { DEBUG: true, PATH: "/bin" }:

Before fix:

payload.env = null
PATH preserved?  false

After fix:

payload.env = {"PATH":"/bin"}
PATH preserved?  true
  • vitest run src/cron/normalize.test.ts (cron config) — 62 passed, including 2 new #105433 regression tests (keeps valid sibling; drops the block only when no valid entries remain).
  • Negative control: with the source fix stashed but the tests present, the "keeps valid env" test fails (expected undefined to deeply equal { PATH: '/bin' }) — proving the test actually guards this bug.
  • run-tsgo -p tsconfig.core.json and -p test/tsconfig/tsconfig.core.test.json — no errors.
  • oxfmt --check on both touched files — clean.

AI-assisted (Claude Code); I have reviewed and understand every line.

@MoerAI

MoerAI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

CI note: the single red check (checks-node-compact-small-3 → test/scripts/plugin-sdk-surface-report.test.ts, "keeps default public surface budgets pinned to current source counts") is a pre-existing public-surface-budget baseline drift on main, not introduced by this change.

  • This PR's diff is export-neutral: it only edits the body of the non-exported normalizeTrimmedStringRecord and adds two tests — zero exports/callables added or removed (git show HEAD -- src/cron/normalize.ts has no changed export lines).
  • The budget test compares the committed default budget against the computed source graph and expects exports: 10641, callableExports: 5357, but the current source graph produces 10640 / 5356 — one fewer of each. A removal drift like that cannot come from a body-only change.
  • Reproduced locally on this branch (rebased onto main): identical AssertionError: expected { exports: 10640 } to deeply equal { exports: 10641 }.

I've deliberately left the plugin-sdk surface-budget baseline untouched — silencing that check by editing the baseline is maintainer-owned and out of scope for this fix.

The cron env fix itself is fully green: vitest run src/cron/normalize.test.ts → 62 passed (incl. the 2 new #105433 regression tests), plus the real before/after behavior proof in the PR description.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 13, 2026
@clawsweeper

clawsweeper Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 13, 2026, 3:16 AM ET / 07:16 UTC.

Summary
Changes the cron string-record normalizer to filter malformed entries while retaining valid siblings, with regression tests for mixed-validity and all-invalid command environment maps.

PR surface: Source +8, Tests +34. Total +42 across 2 files.

Reproducibility: yes. The existing record helper's early undefined result explains the full-field deletion, while the PR supplies direct before/after output and a negative-control regression test through normalizeCronJobCreate.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #105433
Summary: This PR is the direct candidate fix for the canonical cron environment-loss issue.

Members:

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

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The branch is behind current main, so exact-head refresh and review should confirm no intervening cron normalization change affects this invariant; stale base drift alone does not indicate a merge regression.

Maintainer options:

  1. Decide the mitigation before merge
    Land the owner-local filtering fix after exact-head refresh and merge gating, preserving valid command environment strings while continuing to remove an entirely invalid map without changing the Gateway schema.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is needed; refresh the behind branch if necessary, apply ordinary exact-head merge gates, and keep the linked issue open until this or an equivalent fix merges.

Security
Cleared: The internal normalizer and test-only diff adds no dependency, workflow, secret, permission, artifact-download, or supply-chain surface.

Review details

Best possible solution:

Land the owner-local filtering fix after exact-head refresh and merge gating, preserving valid command environment strings while continuing to remove an entirely invalid map without changing the Gateway schema.

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

Yes. The existing record helper's early undefined result explains the full-field deletion, while the PR supplies direct before/after output and a negative-control regression test through normalizeCronJobCreate.

Is this the best way to solve the issue?

Yes. Filtering inside the owning record normalizer matches the adjacent string-array behavior and avoids adding special cases to cron callers or changing the Gateway contract.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This fixes a bounded cron data-preservation bug with a focused implementation and limited blast radius.
  • 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. Sufficient (live_output): The PR provides direct before-and-after output through the changed runtime path plus a negative control demonstrating that the regression test fails without the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides direct before-and-after output through the changed runtime path plus a negative control demonstrating that the regression test fails without the fix.
Evidence reviewed

PR surface:

Source +8, Tests +34. Total +42 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 34 0 +34
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 43 1 +42

What I checked:

  • Owner-local implementation: The patch changes the record normalizer so malformed entries are skipped and a non-empty source record collapses only when no valid entries survive, preserving the existing empty-record result. (src/cron/normalize.ts:58, d80bbd782a01)
  • Public-path regression coverage: The added tests exercise normalizeCronJobCreate, confirm a valid PATH survives a malformed sibling, confirm an entirely invalid map is removed, and validate both normalized requests through validateCronAddParams. (src/cron/normalize.test.ts:465, d80bbd782a01)
  • Real behavior proof: The PR body records before-and-after output through the actual create normalizer, and its negative control reports that the mixed-validity test fails when the implementation change is removed. (src/cron/normalize.test.ts:465, d80bbd782a01)
  • Canonical issue relationship: The open linked issue reports the identical loss of the full cron environment record when one value is non-string, and this PR uses closing syntax for that issue. (src/cron/normalize.ts:58, d80bbd782a01)
  • Feature-history provenance: Earlier cron management work in commit 77c3b14 touched cron operation and Gateway validation boundaries, providing useful routing history for review of this normalization invariant. (src/cron/service/ops.ts, 77c3b142a966)
  • Release state: The latest release, v2026.6.11, predates this pull request; this candidate fix is not established as shipped and the linked issue should remain open until a fix merges. (src/cron/normalize.ts:58, e085fa1a3ffd)

Likely related people:

  • Takhoffman: Introduced substantial adjacent cron management and validation work in commit 77c3b14, making them a plausible reviewer for cron normalization behavior. (role: historical cron feature contributor; confidence: medium; commits: 77c3b142a966; files: src/cron/service/ops.ts, src/gateway/protocol/schema/cron.ts, src/gateway/server-methods/cron.ts)
  • steipete: Merged the historical cron management change associated with commit 77c3b14 and is therefore a useful secondary routing candidate for this owner boundary. (role: merger of adjacent cron work; confidence: medium; commits: 77c3b142a966; files: src/cron/service/ops.ts, src/gateway/protocol/schema/cron.ts, src/gateway/server-methods/cron.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-13T07:01:02.046Z sha d80bbd782a018a556abd39293505d80fd7c43991 :: needs maintainer review before merge. :: none

@MoerAI
MoerAI force-pushed the fix/cron-env-preserve-valid branch from d80bbd7 to 9c3ccc5 Compare July 15, 2026 07:30
…ring (openclaw#105433)

normalizeTrimmedStringRecord returned undefined whenever any env value was non-string, so payload normalization deleted the entire env map before gateway schema validation, silently dropping valid siblings (e.g. env {DEBUG:true, PATH:'/bin'} lost PATH). It now filters invalid entries and only normalizes the map away when no valid entries remain, matching the sibling normalizeTrimmedStringArray behavior in the same file.
@MoerAI
MoerAI force-pushed the fix/cron-env-preserve-valid branch from 9c3ccc5 to 0882fa5 Compare July 15, 2026 07:51
@MoerAI

MoerAI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

ClawSweeper proof for current head 0882fa577d87c63698b6116de157c7af1013d7f5:

Rebased onto latest main. This clears the stale plugin-sdk-surface-report failure that came from the old base (unrelated to the cron change). During the rebase, main had grown src/cron/normalize.test.ts to just under the 1000-line test-file max-lines cap, so appending the two #105433 regression tests pushed it over. Rather than grow that file, I moved the two regression tests into a new colocated file src/cron/normalize.command-env.test.ts and left normalize.test.ts at main's size. The source fix in src/cron/normalize.ts is unchanged.

Verification on the rebased head:

  • node scripts/run-vitest.mjs src/cron/normalize.command-env.test.ts — 2 tests passed
  • oxfmt --check — clean on both files
  • CI on 0882fa5 — converging green (no failures).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 15, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS and removed size: S labels Jul 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a6493c400d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cron/normalize.ts
Comment on lines +64 to +65
if (!key || typeof rawValue !== "string") {
throw new Error("command env must be an object with non-blank keys and string values");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve valid env entries in mixed maps

When a command payload has env: { PATH: "/bin", DEBUG: true }, this branch throws and the gateway catches it as INVALID_REQUEST, so the job is not created or updated and the valid PATH entry still never survives. The normalizer already canonicalizes inputs before CronPayloadSchema validation; for this mixed-env case, filter out malformed entries and keep the string-valued siblings instead of failing the whole request.

Useful? React with 👍 / 👎.

Comment thread src/cron/normalize.ts
Comment on lines 284 to +285
if ("env" in next) {
const env = normalizeTrimmedStringRecord(next.env);
if (env !== undefined) {
next.env = env;
} else {
delete next.env;
}
next.env = normalizeCommandEnv(next.env);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate env only for command payloads

This runs before the kind-specific pruning later in coercePayload, so an otherwise valid agentTurn or systemEvent add/update that carries a stray non-object/non-string env now fails during normalization even though those branches delete env for non-command payloads. Guard this normalization on next.kind === "command" or move it into the command branch so irrelevant fields continue to be pruned.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 2947598 into openclaw:main Jul 16, 2026
125 of 134 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor

Final behavior note: the maintainer rewrite changed the fix shape before landing. A present malformed command env map is rejected with INVALID_REQUEST; invalid entries are not partially filtered. Valid string maps and absent env fields keep their prior behavior. The focused Gateway validation suite passed 116/116 at the prepared head.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 17, 2026
…ring (openclaw#105433) (openclaw#106100)

* fix(cron): keep valid command env vars when a sibling value is non-string (openclaw#105433)

normalizeTrimmedStringRecord returned undefined whenever any env value was non-string, so payload normalization deleted the entire env map before gateway schema validation, silently dropping valid siblings (e.g. env {DEBUG:true, PATH:'/bin'} lost PATH). It now filters invalid entries and only normalizes the map away when no valid entries remain, matching the sibling normalizeTrimmedStringArray behavior in the same file.

* fix(cron): reject malformed command env maps

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

---------

Co-authored-by: Peter Steinberger <[email protected]>
@MoerAI
MoerAI deleted the fix/cron-env-preserve-valid branch July 20, 2026 01:23
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…ring (openclaw#105433) (openclaw#106100)

* fix(cron): keep valid command env vars when a sibling value is non-string (openclaw#105433)

normalizeTrimmedStringRecord returned undefined whenever any env value was non-string, so payload normalization deleted the entire env map before gateway schema validation, silently dropping valid siblings (e.g. env {DEBUG:true, PATH:'/bin'} lost PATH). It now filters invalid entries and only normalizes the map away when no valid entries remain, matching the sibling normalizeTrimmedStringArray behavior in the same file.

* fix(cron): reject malformed command env maps

Co-authored-by: MoerAI <[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

gateway Gateway runtime 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: 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] Silent deletion of entire env block on non-string value in cron payload normalization

2 participants