Repository navigation
Add passive session recovery checkpoints - #72209
likewen-tech wants to merge 2 commits into
Conversation
Greptile SummaryThis PR introduces passive session recovery checkpoints that write task context to a local JSONL ledger and JSON recovery bundle after Two P2 concerns:
Confidence Score: 4/5Safe 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 AIThis 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, |
There was a problem hiding this 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.
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.| } | ||
|
|
||
| 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; |
There was a problem hiding this 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.
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.|
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 detailsBest 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.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
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
|
CI note: this PR is scoped to passive session recovery checkpoints under 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:
Result: 4 test files passed / 40 tests passed. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
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
update_plan,sessions_yield, andsessions_spawn.Safety notes
Verification
pnpm check:changed✅pnpm test:changed✅ — 384 files / 4013 tests passed / 4 skippedsrc/agents/system-prompt.test.ts✅ — 62 tests passedNotes
A local sparse-checkout issue initially excluded
ui/, causingcheck:changedcore-test typecheck to fail on missing UI imports. Addinguiback to sparse-checkout resolved it; the finalpnpm check:changedrun passed.