DeepSeek-Reasonix icon indicating copy to clipboard operation
DeepSeek-Reasonix copied to clipboard

Fix CLI recovery session proliferation and resume clarity / 修复 CLI 恢复会话膨胀与识别

Open SivanCola opened this issue 4 months ago • 0 comments

Summary

  • group conflict-recovery copies with their source session across CLI resume surfaces
  • label recovery copies with a short parent session ID and prefer the newest visible leaf
  • automatically move only covered, untouched, idle, unleased recovery copies to the recoverable session trash
  • make interrupted cleanup durable without exposing older Reasonix versions to an unsafe pre-trash marker

Problem

CLI conflict-recovery branches can accumulate after save conflicts. The resume picker previously flattened them into ordinary sessions, so users could not tell which entry was the original conversation and --continue could select an arbitrary ancestor or copy.

Root cause

The CLI ignored the recovery lineage already exposed by agent.ListSessions and never invoked the conservative recovery-branch cleanup used by Desktop. The shared cleanup path also needed an ordering contract that remained safe when an older runtime reconciled a marker written by a newer CLI.

Fix

Resume ordering now keeps each recovery family together, preserves whole families at the picker cap, and puts the newest visible leaf first. Recovery entries carry a localized badge containing the short parent ID.

CLI startup and resume flows run conservative recovery hygiene. A branch is eligible only when:

  • its metadata identifies it as a recovery branch
  • its transcript still matches the original recovery digest
  • its parent contains all branch content
  • it has been idle for at least 24 hours
  • no runtime holds its session lease

Before moving anything, cleanup acquires the parent removal guard, then the branch removal guard, and revalidates both idle time and parent coverage. The Desktop-compatible trash metadata and transcript are published before the cleanup marker, so even an older runtime can only remove redundant sidecars after the conversation is already recoverable.

No setting or manual cleanup step is added.

Concurrency and data safety

  • Verified safe: parent and branch save/lease locks stay held across final coverage validation and trash publication.
  • Verified safe: active CLI/Desktop sessions are skipped through the shared lease registry and cross-process lease probe.
  • Verified safe: a continued, diverged, corrupt, missing-parent, or fresh recovery branch is preserved.
  • Verified safe: interrupted new-version cleanup resumes through the typed recovery-trash marker.
  • Verified safe across versions: older runtimes see the transcript in the existing Desktop trash layout before they can observe the new cleanup operation.

Compatibility audit

Surface Old-data / old-runtime behavior Conclusion
Session JSONL and branch metadata No schema fields or identifiers change; sessions without recovery metadata keep their existing ordering and behavior. Backward compatible
Desktop trash layout Uses the existing .trash/<item>/<session>.jsonl and .trash-meta.json contract. Existing Desktop restore remains compatible
Cleanup-pending operation New runtimes recognize recovery-trash:<item>; older runtimes may use their ordinary cleanup callback only after the transcript is already recoverable. Cross-version safe
CLI translations Adds one catalogue string in English, Simplified Chinese, and Traditional Chinese; no persisted data changes. Backward compatible

Verification

  • go test ./...
  • go vet ./...
  • focused go test -race for recovery GC, parent/branch guards, interrupted trash reconciliation, and CLI resume ordering
  • ./scripts/cache-guard.sh
  • focused Desktop session/recovery cleanup tests
  • explicit regression coverage for publishing the recoverable transcript before the cleanup marker

Related: #7215

SivanCola avatar Aug 03 '26 15:08 SivanCola