fix: add defensive safeguards and documentation for session persistence (#27)

- Add defensive verification in deactivateWorker to catch any accidental
  session clearing bugs
- Enhance documentation in activateWorker, deactivateWorker, and
  updateWorker to clearly explain session preservation behavior
- Add comprehensive example flow in activateWorker docs showing session
  reuse across multiple tasks and tiers
- Add test suite for session persistence (projects.test.ts) to prevent
  regression
- Add npm test script to run test suite

This ensures sessions persist per tier after task completion, enabling
session reuse across multiple tasks of the same tier for massive token
savings (~50K per reuse) and context preservation.

Fixes: Bug where sessions could theoretically be accidentally cleared
during worker state updates, though current code was already correct.
This adds defense-in-depth to make the invariant bulletproof.
This commit is contained in:
Lauren ten Hoor
2026-02-10 10:52:12 +08:00
parent 38ad3fe27f
commit d1a02d988d
3 changed files with 254 additions and 3 deletions

View File

@@ -28,7 +28,8 @@
},
"scripts": {
"check": "tsc --noEmit",
"watch": "tsc --noEmit --watch"
"watch": "tsc --noEmit --watch",
"test": "node --test lib/**/*.test.ts"
},
"peerDependencies": {
"openclaw": ">=2026.0.0"