Skip to content

fix(sessions): spread env for exact-entries worker reads - #158789

Closed
FkyBird1982 wants to merge 1 commit into
openclaw:mainfrom
FkyBird1982:fix/cron-agentturn-dataclone-error
Closed

FkyBird1982 wants to merge 1 commit into
openclaw:mainfrom
FkyBird1982:fix/cron-agentturn-dataclone-error

Conversation

@FkyBird1982

@FkyBird1982 FkyBird1982 commented Sep 26, 2026 •

Copy link
Copy Markdown

Fixes #157986 (also reported as #158788)

Problem

On Windows, cron isolated agent turns fail at setup with DataCloneError: #<Object> could not be cloned. | unavailable (2026.9.6, see the issue for the full postmortem). cloneEnvWithPlatformSemantics returns a proxy-wrapped env on Windows; the proxy reaches the exact-entries worker input and cannot cross the structured-clone boundary at worker.postMessage.

Solution

Spread env when preparing the session-exact-entries worker input in session-transcript-worker-readers.ts, matching the existing readRowFacts behavior two readers above. This is the one boundary every readExactEntries caller crosses, so the fix covers all callers regardless of which one passes a platform-semantics env.

Impact

Windows-only defect; other platforms already submit a plain object, and the spread is a no-op for them. No behavior change beyond making the input cloneable.

Evidence

  • Production postmortem in Cron agent turns fail at setup with DataCloneError on Windows (2026.9.6) #158788: all 9 isolated-agent cron jobs failed at setup (43–922 ms) on Windows; the failing task input was identified via field-level clone probing on the worker pool boundary, and readExactEntries' input shape (kind, env, sessionKeys, lifecycleSessionKey, projection, includeMembers, includeAuthorization, continuation, database) matched the session-exact-entries request exactly.
  • With an equivalent boundary fix deployed, the same jobs completed normally again (e.g. a previously failing job ran 52.9 s end-to-end with model usage; a second one on a different provider chain ran 93.8 s and delivered).
  • New regression test session-transcript-worker-readers.test.ts submits through a stubbed runRequest with a proxied env and asserts the prepared input survives structuredClone.

After-fix run trace (production, redacted)

Before the boundary fix, the same job failed at setup in 43 ms:

{
  "jobId": "b3b0aeb6-52c3-4574-8999-5f240551e9de",
  "action": "finished",
  "status": "error",
  "completionStatus": "failed",
  "error": "DataCloneError: #<Object> could not be cloned. | unavailable",
  "durationMs": 43,
  "runAtIso": "2026-09-26T16:57:18.617+08:00",
  "jobName": "<redacted: local OneNote sync job>"
}

After deploying an equivalent boundary fix (the deployed hot patch retries the same worker.postMessage input as a JSON round-trip at the pool boundary; this PR instead spreads env before submission — both act on the same env object at the same structured-clone boundary), the same job succeeded on manual trigger and then again on its natural schedule:

{
  "jobId": "b3b0aeb6-52c3-4574-8999-5f240551e9de",
  "action": "finished",
  "status": "ok",
  "completionStatus": "succeeded",
  "durationMs": 25206,
  "runAtIso": "2026-09-26T17:57:18.687+08:00",
  "provider": "zai",
  "model": "glm-5.3-flash",
  "usage": { "input_tokens": 10374, "output_tokens": 180, "total_tokens": 26170, "cache_read_tokens": 15616 },
  "jobName": "<redacted: local OneNote sync job>",
  "summary": "<redacted>"
}

A second agentTurn job on the same instance (daily web briefing, different schedule) also completed after the fix:

{
  "jobId": "0a648e82-4f2c-47ad-8a47-adc12e232b0e",
  "status": "ok",
  "completionStatus": "succeeded",
  "durationMs": 93799,
  "runAtIso": "2026-09-26T17:17:12.567+08:00",
  "provider": "zai",
  "model": "glm-5.3-flash",
  "usage": { "input_tokens": 31711, "output_tokens": 2193 },
  "jobName": "<redacted: daily web intel briefing job>",
  "summary": "<redacted: multi-section briefing generated and delivered>"
}

Job names, summaries, and delivery targets are redacted (local business content); all status, timing, usage, and error fields are verbatim from openclaw cron runs <jobId> on the affected Windows instance.

Test cost

The new test is a single pure unit test with an injected request runner (no worker, no database, no timers). Measured locally on Windows (pnpm test src/config/sessions/session-transcript-worker-readers.test.ts --maxWorkers=1):

  • Cold run (first transform of the shard): 41.8 s shard wall / 38.98 s vitest duration, transform dominates (95%).
  • Warm rerun: 19.07 s shard wall / 16.20 s vitest duration; the test itself executes in under 1 s (worker 7%, the rest is local transform overhead that CI's warm vitest caches avoid).
  • CI seconds: not yet available — this PR is from a first-time fork, so repo workflows are currently skipped pending maintainer approval.

- Windows platform-semantics env proxies from cloneEnvWithPlatformSemantics cannot cross the worker structured-clone boundary, so cron isolated agent turns failed at setup with DataCloneError before the model ran
- spread env when preparing the exact-entries input, matching the existing readRowFacts behavior, and add a regression test
@clawsweeper

clawsweeper Bot commented Sep 26, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR copies the environment into a plain object before submitting exact session-entry reads to a worker.

Example: An isolated agentTurn automation runs on Windows with OpenClaw 2026.9.6.

  • Before: Setup fails with DataCloneError before the model runs because input.env is a Proxy.
  • After: The worker receives a cloneable environment snapshot and the automation can proceed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair has credible production evidence and no discrete introduced finding, but its user value is already supplied by a merged replacement.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Redacted cron receipts from the affected Windows installation show recovery after equivalent environment normalization at the real worker boundary, supported by independent Windows deployment reports; these exercise the transformation rather than the exact source checkout.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: No · Fix scope: Complete
User problem: Windows isolated automations fail during session setup before generating a reply.
Reason: The original repair has clear user value, but merging this branch now adds no distinct capability beyond the landed replacement.

Merge readiness

⛔ Blocked before merge - 2 items remain

The repair is superseded by a merged fix, but the same author's paired issue remains open; the keep-open guard requires maintainer judgment before retiring this PR.

Priority: P3
Reviewed head: 6ddfdd612fb0f383e4e252660fe612d645fb77c5
Owner decision: Required. See Decision needed.

Decision needed

  • Question: May this superseded PR be retired separately while its same-author report remains open?
  • Recommendation: Approve separate retirement: Close the redundant PR in favor of the merged replacement while preserving the paired report's release-verification discussion.
  • Why: Source and release evidence settle the exact-entry repair, but the paired report remains unresolved and no recorded maintainer decision authorizes separate disposition.

Before merge

  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Product: not worth merging - The original repair has clear user value, but merging this branch now adds no distinct capability beyond the landed replacement.

Findings

None.

Agent review details

How this fits together

Cron setup and session admission request session entries through the history worker, which reads SQLite and returns entries and lifecycle facts.

flowchart LR
A[Automation or session admission] --> B[Exact entry reader]
B --> C[Environment snapshot]
C --> D[Worker transport]
D --> E[SQLite session read]
E --> F[Entries and lifecycle facts]
Loading

Technical review

Best possible solution:

Retain the landed storage-fact capture and coordinate retirement of this redundant PR with its paired report.

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

The supplied Windows production traces establish the historical Proxy-transfer failure; current main captures a plain storage environment, and no current-main execution was performed.

Is this the best way to solve the issue?

The original snapshot addresses the demonstrated clone failure, but the landed replacement is more complete because it also handles store discovery and restores Windows environment semantics inside the worker.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exact-entry worker request preparation keeps the original intent (dbd3bf7: The hydration refactor moved saved transcript work off thread while retaining session, storage, and manager ownership checks.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +4, Tests +34. Total +38 across 2 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 9 5 +4
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 5 +38

Root-cause cluster

Relationship: superseded
Canonical: #160075
Summary: The merged replacement owns the exact-entry environment-transfer repair and the related nested discovery transport.

Members:

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

Labels

Label changes:

  • add P3: The remaining work is coordinated backlog cleanup because the targeted transport repair already exists in main and published release source.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove P1: Current review triage priority is P3, so this older priority label is no longer current.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status no longer selects a status label.

Label justifications:

  • P3: The remaining work is coordinated backlog cleanup because the targeted transport repair already exists in main and published release source.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed September 26, 2026, 5:49 AM ET / 09:49 UTC sha unknown :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-26T10:49:53.442Z sha 6ddfdd6 :: needs changes before merge. :: none
  • reviewed 2026-09-26T12:01:51.536Z sha 6ddfdd6 :: needs changes before merge. :: none

Reviewed October 10, 2026, 10:43 AM ET / 14:43 UTC (Revision 4).

@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 Sep 26, 2026
@veritasaiflows-cell

Copy link
Copy Markdown

Independent Windows reproduction and fix verification for this PR (tracks #157067).

Environment: OpenClaw 2026.9.6 (eb377ac), npm install, Node v26.7.0, Windows 11 x64.

Impact observed: since upgrading to 2026.9.6, every isolated agentTurn cron job fails in cron-setup with DataCloneError: #<Object> could not be cloned. | unavailable. In our case that was Memory Dreaming Promotion, a release-watch job, and a nightly gate. Command, script, and systemEvent jobs are unaffected. Text-mode openclaw status fails the same way (WorkerTaskPoolCore.start, worker-task-pool-*.mjs:609).

Offending field: I wrapped Worker.prototype.postMessage with a preload hook and walked the failing message. The top-level input keys are kind, env, sessionKeys, lifecycleSessionKey, projection, includeMembers, includeAuthorization, continuation, database. The only non-cloneable value is input.env, and it has no bad children. That is the win32 Proxy returned by cloneEnvWithPlatformSemantics.

Fix verification: a second preload spreads input.env ({ ...env }) only when it fails structuredClone, which is the same transformation as this PR:

run exit result
openclaw status (stock 2026.9.6) 1 DataCloneError: #<Object> could not be cloned.
same, with the env spread 0 full status renders; exactly 1 env object spread

Minimal proof of the mechanism:

structuredClone(new Proxy({ A: "1" }, {}));            // DataCloneError
structuredClone({ ...new Proxy({ A: "1" }, {}) });     // { A: "1" }

One note for review: on current main, session-entry-read-runtime.ts passes env: database.env into owner.readExactEntries(...). database.env can be the platform-semantics Proxy, so spreading inside readExactEntries, as this PR does, covers that caller. The other runtime entry points built from cloneEnvWithPlatformSemantics (lines ~62, ~309, ~586) may deserve the same treatment wherever their env reaches a worker.

@ralf003

ralf003 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Independent production verification of this exact fix shape, from a separate Windows deployment (tracks #157067 / #157986).

Environment: OpenClaw 2026.9.6 (eb377ac), npm install, Node v24.16.0, Windows 11 x64, gateway as a scheduled task.

Impact observed: since the 2026.9.6 upgrade, every isolated agentTurn cron job on this host failed in cron-setup with DataCloneError: #<Object> could not be cloned. | unavailable — 6 production jobs, including */15 and */30-minute high-frequency jobs, plus 2 more that auto-disabled after repeated failures. Command/script jobs on the same gateway were unaffected.

Root cause confirmed: identical to the thread — cloneEnvWithPlatformSemantics returns a case-insensitive env Proxy on Windows; readExactEntries forwards input.env un-cloned into the session-exact-entries worker request; worker.postMessage rejects the Proxy. Field-level clone probing of the failing message showed input.env is the only non-cloneable field.

Fix verification (equivalent boundary, one layer downstream): instead of patching the reader, we applied the same env snapshot as a local hot patch at the transport boundary ({ ...input, env: { ...input.env } } before postMessage in WorkerTaskPoolCore.start). Result: all 6 jobs re-enabled and returned to ok/succeeded; verified via manual triggers and scheduled runs; zero DataCloneError in the gateway log since the patch. Since the two fixes act on the same env object at the same structured-clone boundary, this independently validates the transformation this PR applies at the exact-entries reader.

One note for maintainers: spreading at the transport layer also covers any other worker path that could carry a platform-semantics env; spreading inside readExactEntries (as this PR does) is the more surgical variant. If session-entry-read-runtime.ts (or other cloneEnvWithPlatformSemantics entry points) can reach a worker without passing through readExactEntries, the same one-line snapshot may be warranted there for consistency — worth a quick check before merge.

+1 for this PR from a production deployment.

@desksk

desksk commented Oct 1, 2026

Copy link
Copy Markdown

Cross-link from a Windows field report (OpenClaw 2026.9.7, Node 24.18.0): the same uncloneable env also breaks the rpc/http request builder, which this PR's reader-side change does not cover.

Evidence: instrumenting the generic pool's postMessage (payload walk only when it throws) named the offending value as input.request.env, top-level keys input, taskId, interactive, nativeSections, sampleMemory — i.e. an rpc/http request; captureHistoryRequest() skips env capture for kind === "rpc" | "http". On that host every inbound channel dispatch failed with WorkerTaskError: DataCloneError, not just isolated cron setup.

A local workaround that restored all ten agents: a plain string snapshot of payload.input.request.env immediately before the pool posts. It would be good if the merge also covered that builder (or wherever the request env is produced), otherwise this failure mode survives on Windows hosts that only exercise the rpc/http path. Details in #157067.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Oct 10, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @FkyBird1982 for the diagnosis, production evidence, and focused fix. This exact-entry repair is already covered by #160075, merged as a181c3f1d908, so I’m closing this PR as superseded.

Verified on current main 88177be90aa8: readExactEntries captures the environment before submission, the capture owner returns plain storage facts, and the worker restores Windows case-insensitive lookup semantics. Existing regression coverage includes structured-clone submission and real-worker admission/cron discovery with a Windows environment Proxy; I inspected that coverage without running it on this host.

The proposed boundary fix and regression are already represented on main. #158788 remains open for its release-verification discussion; the separately reported rpc/http path is outside this PR’s repair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automations: every agentTurn job fails with DataCloneError, while command/script payloads work

5 participants