Skip to content

Add passive session recovery checkpoints - #72209

Closed
likewen-tech wants to merge 2 commits into
openclaw:mainfrom
likewen-tech:fix/session-recovery-continuity-2026-04-26
Closed

likewen-tech wants to merge 2 commits into
openclaw:mainfrom
likewen-tech:fix/session-recovery-continuity-2026-04-26

Conversation

@likewen-tech

Copy link
Copy Markdown
Contributor

Summary

Adds passive session recovery checkpoints so automatically recreated sessions can recover task context without pretending to remember, inheriting old approvals, or auto-executing recovered steps.

What changed

  • Add session recovery prompt discipline that separates confirmed, uncertain, missing, blocked, and expired-approval context.
  • Add local Task Ledger / Recovery Bundle storage under the OpenClaw state directory.
  • Add passive checkpoint writes for update_plan, sessions_yield, and sessions_spawn.
  • Keep recovery informational only: no auto-resume, no auto-execute, no approval/auth/permission inheritance.

Safety notes

  • Recovered context is data, not instruction.
  • Prior approvals are explicitly marked expired / not inherited.
  • Writes are best-effort and do not change primary tool behavior.
  • Failed/forbidden spawns do not record successful handoff checkpoints.

Verification

  • pnpm check:changed ✅
  • pnpm test:changed ✅ — 384 files / 4013 tests passed / 4 skipped
  • Core typecheck ✅
  • Targeted recovery agents tests ✅ — 33 tests passed
  • src/agents/system-prompt.test.ts ✅ — 62 tests passed

Notes

A local sparse-checkout issue initially excluded ui/, causing check:changed core-test typecheck to fail on missing UI imports. Adding ui back to sparse-checkout resolved it; the final pnpm check:changed run passed.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL labels Apr 26, 2026
@greptile-apps

greptile-apps Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces passive session recovery checkpoints that write task context to a local JSONL ledger and JSON recovery bundle after update_plan, sessions_yield, and sessions_spawn calls, and surfaces that context in the agent system prompt under a "Session Recovery Discipline" section. The safety framing is careful — recovered context is informational only, no approvals are inherited, and all checkpoint writes are wrapped in try/catch so failures never affect primary tool behavior.

Two P2 concerns:

  • The third SECRET_PATTERNS entry matches bare keywords (token, secret, authorization) followed by : or =, which is broad enough to silently redact legitimate natural-language summaries written by agents (e.g. \"Update secret management step\" → \"Update [REDACTED] step\"), corrupting the recovery context it is meant to preserve.
  • appendTaskLedgerEvent uses synchronous fs.mkdirSync + fs.appendFileSync, blocking the Node.js event loop on every plan update, yield, and spawn.

Confidence Score: 4/5

Safe to merge with awareness of the two P2 concerns; no critical correctness or security defects found.

All issues found are P2: one is a design-level redaction pattern that can corrupt its own output under certain natural-language inputs, and one is a sync I/O concern on a best-effort code path. No P0/P1 defects identified — the core recovery discipline logic, prompt injection guards, approval non-inheritance invariants, and test coverage all look sound.

src/agents/session-recovery-state.ts — SECRET_PATTERNS[2] breadth and synchronous I/O.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/session-recovery-state.ts
Line: 115

Comment:
**`token` keyword in `SECRET_PATTERNS[2]` will silently corrupt legitimate recovery context**

The third pattern matches `\btoken\s*[:=]\s*[^\s,;]+`, which fires on natural-language summaries that contain "token" followed by `:` or `=`. For example, an `update_plan` explanation like `"Update secret management step"` will match `secret management` and write `"Update [REDACTED] step"` to the ledger — silently dropping context the agent wrote. Similarly, a yield message of `"authorization: waiting for security review"` would be stored as `"authorization: [REDACTED]"`.

The high-confidence pattern keywords (`api_key`, `Bearer`, `github_pat` prefixes) are specific enough to be safe; `token`, `secret`, `authorization`, `password` as naked dictionary words are too broad for free-text summaries.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/agents/session-recovery-state.ts
Line: 200-207

Comment:
**Synchronous I/O blocks the event loop on every checkpoint write**

`appendTaskLedgerEvent` calls `fs.mkdirSync` + `fs.appendFileSync` synchronously. These are invoked on every `update_plan`, `sessions_yield`, and `sessions_spawn` execution, blocking the Node.js event loop for the duration of each disk write. On slow filesystems or under load this degrades the responsiveness of the primary tool path. Since checkpoints are explicitly described as best-effort and fire-and-forget, consider offloading via `setImmediate` + async `fs.promises.mkdir`/`fs.promises.appendFile`, or at minimum making the function `async` so callers can await it without blocking.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Add passive session recovery checkpoints" | Re-trigger Greptile

const SECRET_PATTERNS = [
/\b(?:sk|pk|rk|ghp|gho|ghu|github_pat)_[A-Za-z0-9_=-]{12,}\b/g,
/\b[A-Za-z0-9._%+-]+:[A-Za-z0-9._%+-]{12,}@/g,
/\b(?:api[_-]?key|token|secret|password|passwd|authorization)\s*[:=]\s*[^\s,;]+/gi,

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 token keyword in SECRET_PATTERNS[2] will silently corrupt legitimate recovery context

The third pattern matches \btoken\s*[:=]\s*[^\s,;]+, which fires on natural-language summaries that contain "token" followed by : or =. For example, an update_plan explanation like "Update secret management step" will match secret management and write "Update [REDACTED] step" to the ledger — silently dropping context the agent wrote. Similarly, a yield message of "authorization: waiting for security review" would be stored as "authorization: [REDACTED]".

The high-confidence pattern keywords (api_key, Bearer, github_pat prefixes) are specific enough to be safe; token, secret, authorization, password as naked dictionary words are too broad for free-text summaries.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/session-recovery-state.ts
Line: 115

Comment:
**`token` keyword in `SECRET_PATTERNS[2]` will silently corrupt legitimate recovery context**

The third pattern matches `\btoken\s*[:=]\s*[^\s,;]+`, which fires on natural-language summaries that contain "token" followed by `:` or `=`. For example, an `update_plan` explanation like `"Update secret management step"` will match `secret management` and write `"Update [REDACTED] step"` to the ledger — silently dropping context the agent wrote. Similarly, a yield message of `"authorization: waiting for security review"` would be stored as `"authorization: [REDACTED]"`.

The high-confidence pattern keywords (`api_key`, `Bearer`, `github_pat` prefixes) are specific enough to be safe; `token`, `secret`, `authorization`, `password` as naked dictionary words are too broad for free-text summaries.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +200 to +207
}

export function appendTaskLedgerEvent(input: TaskLedgerEventInput): TaskLedgerEvent {
const event = normalizeTaskLedgerEvent(input);
const ledgerPath = resolveTaskLedgerPath();
fs.mkdirSync(path.dirname(ledgerPath), { recursive: true, mode: 0o700 });
fs.appendFileSync(ledgerPath, `${JSON.stringify(event)}\n`, { encoding: "utf8", mode: 0o600 });
return event;

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 Synchronous I/O blocks the event loop on every checkpoint write

appendTaskLedgerEvent calls fs.mkdirSync + fs.appendFileSync synchronously. These are invoked on every update_plan, sessions_yield, and sessions_spawn execution, blocking the Node.js event loop for the duration of each disk write. On slow filesystems or under load this degrades the responsiveness of the primary tool path. Since checkpoints are explicitly described as best-effort and fire-and-forget, consider offloading via setImmediate + async fs.promises.mkdir/fs.promises.appendFile, or at minimum making the function async so callers can await it without blocking.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/session-recovery-state.ts
Line: 200-207

Comment:
**Synchronous I/O blocks the event loop on every checkpoint write**

`appendTaskLedgerEvent` calls `fs.mkdirSync` + `fs.appendFileSync` synchronously. These are invoked on every `update_plan`, `sessions_yield`, and `sessions_spawn` execution, blocking the Node.js event loop for the duration of each disk write. On slow filesystems or under load this degrades the responsiveness of the primary tool path. Since checkpoints are explicitly described as best-effort and fire-and-forget, consider offloading via `setImmediate` + async `fs.promises.mkdir`/`fs.promises.appendFile`, or at minimum making the function `async` so callers can await it without blocking.

How can I resolve this? If you propose a fix, please make it concise.

@clawsweeper

clawsweeper Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Keep open for maintainer review: the feature is useful but the current branch is not merge-ready because it adds parallel JSON/JSONL session-state sidecars, lacks a runtime path that loads recovered bundles into recreated sessions, and has no real behavior proof.

Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review.

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

Not applicable as a bug reproduction; this is a feature PR. For the proposed behavior, there is not yet high-confidence real setup proof that a recreated session loads and safely uses the recovered bundle.

Is this the best way to solve the issue?

No. The idea is useful, but this implementation is not the best path until storage ownership, runtime loading, non-blocking writes, and sensitive-state handling are fixed or explicitly accepted by maintainers.

Security review:

Security review needs attention: The diff introduces sensitive persistent session-recovery metadata outside the canonical state model and needs storage/redaction boundary work before merge.

  • [medium] Recovery sidecars can persist sensitive session metadata — src/agents/session-recovery-state.ts:108
    The new JSONL and JSON bundle files can store task summaries, workspace ids, session ids, child session keys, agent ids, and handoff status outside the canonical SQLite/session-state access controls and migration path.
    Confidence: 0.88
  • [medium] Spawn checkpoints save child session identifiers — src/agents/tools/sessions-spawn-tool.ts:141
    Successful spawn handoffs include childSessionKey, runId, and agent ids in confirmed recovery items; those identifiers are local session-routing metadata and should be treated as sensitive state with an explicit retention and access boundary.
    Confidence: 0.82
  • [low] Redaction is broad but not a complete sensitive-state boundary — src/agents/session-recovery-state.ts:115
    The regex-based text redaction can both miss structured sensitive metadata and corrupt legitimate recovery text, so it should not be the main security control for persisted recovery bundles.
    Confidence: 0.76

AGENTS.md: found and applied where relevant.

What I checked:

  • stale F-rated PR: PR was opened 2026-04-26T14:20:37Z, is older than 60 days, and the latest review rated it F.
  • proof blocker: real behavior proof is missing and proof tier is F, so this branch is not merge-ready without contributor follow-up.
  • no human follow-up: live comments and timeline hydrated by apply contain no non-automation activity after the ClawSweeper review.

Likely related people:

  • scoootscooob: Authored the merged compaction checkpoint feature, which is the closest current checkpoint primitive and constrains future recovery/checkpoint semantics. (role: introduced adjacent behavior; confidence: high; commits: f4fcaa09a358; files: src/gateway/session-compaction-checkpoints.ts, src/gateway/server-methods/sessions.ts, packages/gateway-protocol/src/schema/sessions.ts)
  • jalehman: Opened the session/transcript SQLite storage flip PR referenced by the active storage tracker, which is directly relevant to whether new recovery state may live outside SQLite. (role: adjacent storage owner; confidence: medium; commits: b55986c0342f; files: src/config/sessions/**, src/state/**, src/agents/**)
  • ly-wang19: Recently changed checkpoint lookup behavior in session accessor code, making them relevant for current checkpoint metadata routing. (role: recent area contributor; confidence: medium; commits: aca905cce50a; files: src/config/sessions/session-accessor.ts)
  • Dallin Romney: Current main blame on the touched agent tool and prompt wrapper files points to a recent broad refresh commit, so this is a routing signal for current file ownership rather than original feature authorship. (role: recent area contributor; confidence: low; commits: f749de4f0a6a; files: src/agents/tools/update-plan-tool.ts, src/agents/tools/sessions-yield-tool.ts, src/agents/tools/sessions-spawn-tool.ts)

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

# Conflicts:
#	src/agents/tools/sessions-spawn-tool.test.ts
#	src/agents/tools/sessions-spawn-tool.ts
#	src/agents/tools/sessions-yield-tool.ts
#	src/agents/tools/update-plan-tool.ts
@likewen-tech

Copy link
Copy Markdown
Contributor Author

CI note: this PR is scoped to passive session recovery checkpoints under src/agents.

Current failing jobs appear to be outside this PR's changed paths (redaction/provider/full-suite shard failures). This PR does not touch the extension/provider paths implicated by the failing logs. I am not disabling or bypassing checks; any failure shown to touch session recovery remains blocking.

Local verification for the session recovery scope:

  • src/agents/session-recovery-state.test.ts
  • src/agents/tools/sessions-spawn-tool.test.ts
  • src/agents/tools/sessions-yield-tool.test.ts
  • src/agents/tools/update-plan-tool.test.ts

Result: 4 test files passed / 40 tests passed.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 20, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 20, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels May 20, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 14, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 17, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant