Skip to content

openclaw: harden state JSON persistence and prewarm caching/error handling - #444

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/openclaw-state-prewarm-hardening
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/openclaw-state-prewarm-hardening

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 4, 2026

Copy link
Copy Markdown

Summary

Hardens OpenClaw plugin state persistence (packages/openclaw/src/state.js) and prompt warm-up (packages/openclaw/src/prewarm.js):

  • state.js:
    • Reject JSON arrays and non-plain objects in readJson(), loadRoomState(), saveRoomState(), joinState(), and saveJoinState() (previously typeof [] === "object" let a corrupt array join field silently drop room keys on JSON.stringify).
    • Guard joinState() / saveJoinState() with Object.hasOwn so prototype keys (e.g., toString) cannot leak functions, handle null/corrupt sibling entries safely during eviction sorting, and ignore non-object fields.
    • Use a per-write unique temp filename in writeJson() and unlink the temp file in catch so failed writes do not collide or leave .tmp files behind.
  • prewarm.js:
    • Include prewarmFile() in remember()'s dedup key and only update last after writeJson() succeeds, so transient write failures do not suppress future saves and switching state dirs still persists prewarm.json.
    • Validate params as a plain object and tools as an array in fixedPart() / replayBody() (preventing strings/arrays from spreading into indexed keys), and require a string system in replayBody().
    • Treat ai-gendone carrying err in prewarm() as a skipped warm-up (return null) instead of logging success, and guard promise settlement to fire once.

Verification

  • node --check on packages/openclaw/src/state.js, packages/openclaw/src/prewarm.js, packages/openclaw/test/state_prewarm_test.mjs: clean.
  • node --test packages/openclaw/test/state_prewarm_test.mjs: 4/4 passed (confirmed 4/4 RED before fix).
  • npm run test:packages: 217 passed, 6 skipped, 0 failed.
  • npm run test:runtime: 6/6 runtime checks passed.

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 4, 2026 20:43
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant