Skip to content

feat(refine): reversible /refine undo (snapshot-before-write rollback) - #90284

Closed
HermesZum wants to merge 1 commit into
NousResearch:mainfrom
HermesZum:feat/prime-agent-refine-rollback-v2
Closed

feat(refine): reversible /refine undo (snapshot-before-write rollback)#90284
HermesZum wants to merge 1 commit into
NousResearch:mainfrom
HermesZum:feat/prime-agent-refine-rollback-v2

Conversation

@HermesZum

@HermesZum HermesZum commented Aug 19, 2026

Copy link
Copy Markdown

Summary

Adds a snapshot-before-write + atomic-restore safety net to the existing /refine so a review run that writes memory/skills can be undone with /refine undo. Ports prime-agent's "reversible self-improvement" feature by extending the existing /refine primitive — no architecture fork, no prompt-cache or message-role invariant break (F1 touches only memory/skill files).

Closes #90283.

Changes

  • agent/refine_rollback.py (new, stdlib-only, fully unit-tested): snapshot/restore/list/index. Includes a data-loss guard — restore refuses to wipe a live dir when its snapshot storage is missing files the manifest promised (capture/store corruption), reporting the skipped target instead of emptying the user's memory.
  • hermes_cli/cli_commands_mixin.py: /refine snapshots memory + skills synchronously before the background fork writes (best-effort; never blocks the review). New /refine undo restores the latest session snapshot; surfaces a precise message for the corruption-guard skip case.
  • run_agent._spawn_background_review + agent/background_review (spawn_background_review_thread / _run_review_in_thread): thread snapshot_id passthrough + undo: /refine undo hint in the completion summary.
  • skills/continual-harness/ (skill-primary, R8): SKILL.md + standalone inspector script (list/restore/delete/latest). Core changes are a thin shim — no special-casing in core write paths (CONTRIBUTING: don't special-case in core).

Design notes

  • Off by default: snapshot is opt-in per /refine call; automatic post-turn reviews are unchanged.
  • Snapshot resolves the live profile skills dir via _skills_dir() (multi-profile safe) rather than the static import-time SKILLS_DIR.
  • Storage: HERMES_HOME/review_snapshots/<id>/ with a per-session index. v1 covers files only (memory .md + skills); the SQLite cognitive store is excluded.
  • Atomic per-directory restore (build-into-temp, swap) so a crash mid-restore cannot corrupt the live tree.

Relationship to existing work (Step-0 duplicate search, see #90283)

Test plan

  • New hermetic suite tests/hermes_cli/test_refine_rollback.py: 8 tests (snapshot copy, index, restore, missing, list filter, delete, corruption guard, empty-target undo).
  • Regression: test_background_review.py (10), review/isolation suites (24), test_goals.py (36) — green, no regressions in touched modules.
  • py_compile clean on all touched modules.

Invariants preserved

  • No conversation/system-prompt mutation (F1 touches only memory/skill files) → prompt-cache + message-role invariants hold.
  • Best-effort snapshot: a snapshot failure never blocks a /refine.

Notes / asks

  • This is F1 only, split out from a larger prime-agent port (F2 token-budget, F3 peer-steer tracked separately) to keep the surface small for review.
  • Open question for maintainers (in feat: reversible /refine undo (snapshot-before-write rollback) #90283): CLI /refine undo thin shim vs. pure skill+config flag; snapshot storage path; v1 file-only scope.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/skills Skills system (list, view, manage) tool/memory Memory tool and memory providers needs-decision Awaiting maintainer decision before any implementation labels Aug 19, 2026
@HermesZum

Copy link
Copy Markdown
Author

Status update (2026-08-20): rebased onto current upstream/main, MERGEABLE

This branch was rebased onto the current upstream/main (which had advanced since the branch was opened and merged its own run_budget_seconds wall-clock feature). The rebase was clean — GitHub now reports this PR as MERGEABLE with no conflicts.

Validation note for reviewers: this sandbox does not have the project's uv/pytest venv, so the full tests/ regression suite has not been executed here. Verification done locally: py_compile clean on all touched modules + hermetic stub smoke tests of the new logic. The real regression gate is GitHub CI on this PR — please check the CI run before merging.

No behavior change from the prior revision; only the base moved forward.

… F1 v2)

Add a snapshot-before-write + atomic-restore safety net so a user-triggered
/refine can be undone with '/refine undo'.

v2 correction over the dropped first attempt:
- Skill-primary surface (R8): harness logic + docs live in
  skills/continual-harness/ (SKILL.md + standalone inspector script); the
  CLI is a thin shim. No special-casing in core write paths.
- Data-loss guard: restore refuses to wipe a live dir when its snapshot
  storage is missing files the manifest promised (capture/store corruption),
  instead reporting the skipped target. A genuinely-empty snapshot target
  still restores to empty (legitimate undo).
- Snapshot resolves the live profile skills dir via _skills_dir() (multi-
  profile aware) rather than the static import-time SKILLS_DIR.

Implementation:
- agent/refine_rollback.py: stdlib-only snapshot/restore/list/index with the
  corruption guard (fully unit-tested, 8 hermetic tests).
- hermes_cli/cli_commands_mixin.py: /refine snapshots memory+skills before the
  background fork; new /refine undo restores the latest session snapshot.
- run_agent._spawn_background_review + agent/background_review
  (spawn_background_review_thread/_run_review_in_thread): thread snapshot_id
  passthrough + 'undo: /refine undo' hint in the completion summary.
- skills/continual-harness/{SKILL.md,scripts/refine_rollback_cli.py}: user
  docs + standalone inspector (list/restore/delete/latest).

Off by default: snapshot is opt-in per /refine call; automatic post-turn
reviews unchanged. No conversation/system-prompt mutation (F1 touches only
memory/skill files), so prompt-cache and message-role invariants hold.

Validation: 8 hermetic F1 tests pass; background_review + refine + goals
suites green (24 + 36) with no regressions; py_compile clean.
@HermesZum
HermesZum force-pushed the feat/prime-agent-refine-rollback-v2 branch from 9f64cf1 to 371b969 Compare August 20, 2026 20:50
@HermesZum

Copy link
Copy Markdown
Author

Closing: features moved to a private plugin (HermesZum/prime-agent-features). This PR is withdrawn.

@HermesZum HermesZum closed this Aug 20, 2026
@HermesZum
HermesZum deleted the feat/prime-agent-refine-rollback-v2 branch August 20, 2026 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers tool/skills Skills system (list, view, manage) type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: reversible /refine undo (snapshot-before-write rollback)

2 participants