Skip to content

Managed recovery: real process-death cuts and recovery scenarios for M2-M8 - #140

Merged
leonardoaraujosantos merged 24 commits into
mainfrom
feat/managed-recovery-resolution
Nov 18, 2026
Merged

leonardoaraujosantos merged 24 commits into
mainfrom
feat/managed-recovery-resolution

Conversation

@leonardoaraujosantos

@leonardoaraujosantos leonardoaraujosantos commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Advances #93.

Includes #138: this branch contains every commit of feat/construction-evidence-discard (#138), including the upgrade_cli archive-limit fix, and now targets main directly; #123 is already merged.

What this does

Works through managed-recovery tasks M2–M8 in openspec/changes/complete-daily-coding-surfaces/tasks.md. Each task was checked against its wording, and this PR fills the gaps that can be closed on one machine. No recovery protocol or product behaviour changes. The only production edits are debug-only process-cut points (cyber_core::process_cut::pause), which release builds compile out.

New process-cut points

  • cyber-snapshot copy/restore.rs:
    • copy-restore-origin-published
    • copy-restore-intent-published
    • copy-restore-progress-recorded (after each progress record; also fires inside keep/rollback)
    • copy-restore-filesystem-completed
  • cyber-server runtime/snapshot_work.rs:
    • recovery-pair-writer-commit
    • recovery-journal-acknowledged
    • ordinary-restore-journal-acknowledged

Tests (crates/cyber-cli/tests/support/restore_cuts.rs, part of branches_cli)

Each test runs the real CLI and service and SIGKILLs the service at a cut point. Every case also checks that the transcript does not move and that no inference starts.

Task Case
M2 Kill after origin with no intent.json, and after the intent with no staged image. The exited preparation is cancelled through sessions recovery-preparation.
M2 Unit test binary_document_activity_never_grants_snapshot_recovery_authority.
M3 The private journals directory is replaced between review and confirm, first by an equal-content copy, then by a symlink alias. Both are refused before any source effect.
M4 keep/rollback after a kill right after a progress record.
M4 A staged code undo beside an inactive branch is killed mid-restore. Recovery neither stages nor commits it, and the branch stays exportable.
M4 A keep/rollback itself killed mid-exchange. Its journal is kept as separate evidence and the request is never redispatched (resolved_by_another_request after the child is resolved).
M5 Real kill after the paired recovery writer commit. Before this, the cut was simulated by a metadata reset.
M6/M8 Kill after filesystem completion with displaced images, and after the ordinary and paired journal acknowledgements but before the reply.
M7 TUI code_unavailable_preview_enters_journal_recovery_with_c: from a code preview refused by a retained restore, C opens journal recovery.

Docs and specs

  • docs/rewind.md: how to resolve an interrupted keep/rollback.
  • implementation.md: the M8 cut matrix is updated, and the increment is recorded.
  • tasks.md: a note under each task.

Second round

  • Payload cleanup (M6/M8). Keep, rollback and cancelled-preparation cleanup is killed mid-deletion (restore_cuts::cleanup). A fresh owner completes the frozen plan exactly once. A new debug point, copy-restore-images-prepared, makes the fully prepared state deterministic.

  • Git equivalents (M3/M4/M8). restore_cuts::managed::git_* (requires native-git-acceptance) runs these cases in a managed Git worktree:

    • progress cuts with keep and rollback
    • staged undo beside an inactive branch
    • filesystem completion
    • paired cut after the database write
    • interrupted resolution
    • namespace swap
    • damaged intent.json

    damaged_retained_intent_refuses_recovery_without_effects covers both backends.

  • Routes and SDK (M7).

    • recovery_routes_refuse_stale_and_foreign_requests_without_effects calls every recovery route on a real service.
    • sdk/typescript/test/recovery.e2e.test.ts kills a real service mid-restore, then resolves the journal through the SDK. It also checks that stale requests get 409, foreign requests get 409/404, and nothing triggers inference or moves the transcript.
  • Review (M8). Findings are in implementation.md under "M8 substantive code and security review". Two defects were fixed, each with a regression test that failed before the fix:

    • Keep cleanup could unlink an owner file left in a private slot. Fixed in copy/reclamation/paired.rs, test kept_recovery_cleanup_never_unlinks_an_unowned_slot_inode.
    • A repeated acknowledgement rewrote already-acknowledged intents, which breaks a planned metadata retirement. Fixed in copy/resolution.rs, test repeated_acknowledgement_never_rewrites_acknowledged_intents.
    • One hardening fix: a resolution is admitted only when the existence check returns NotFound.
  • CI. non-git-snapshot-proof.yml now runs restore_cuts:: and ordinary_cuts:: on ubuntu-24.04, ubuntu-24.04-arm, macos-15 and macos-15-intel.

  • Merged the updated base branch (20734f45).

Status

All local items requested for M2–M8 are done. Tasks are ticked only where everything except platform evidence is done. Platform results come only from this PR's CI runs; see the conversation. Open owner questions are listed in implementation.md.

Verification (local macOS arm64 only)

  • Full branches_cli (40 tests) under nextest ci with --test-threads 4.
    • terminal_preparation_recovery_survives_client_kill_with_a_committed_reply_withheld failed its first try under load, then passed on retry.
    • Run alone, it passed three times in a row (about 72 s each).
    • I did not reproduce the failure on the base branch.
    • It does not touch the new cut points: they do nothing unless CYBER_TEST_PROCESS_CUT is set.
  • cyber-tui view::rewind tests.
  • cyber-server snapshot_recovery unit tests.
  • cargo fmt --check.
  • cargo clippy --all-targets -D warnings.
  • openspec validate --all --strict, spec_lint (0 errors) and spec_inventory --check.
  • No CLI or API change, so docs/cli.md, OpenAPI and the SDK are unchanged.

Observe a stage through a no-follow, non-blocking handle (regular single-link
file, 1 MiB bound, SHA-256), move it with a no-replace rename into a private
discarded/<key>/ slot of its namespace and unlink it there only while its
identity still matches. Checkout claim and acknowledgement stages are fenced by
their constructor lock and published records; file-copy cancellation-record
stages are bound to their exact origin, the namespace lock and the owner's
lifetime lock, and quarantined bytes keep counting toward the snapshot cap.
Review is read-only and fingerprints the stage and Session revision; confirm
re-fences the Session and owner activity, records a durable
session.snapshot.construction_discarded.1 intent, quarantines and unlinks the
stage and completes the receipt. A repeated request ID resumes the frozen plan,
lookup never acts and maintenance retries pending unlinks hourly. Review and
confirm refuse bearer, peer, browser and MCP callers with 403.
cyber sessions recovery-discard lists, reviews and confirms one stage;
recovery-discard-request looks a receipt up. sessions recovery, the TUI
recovery panels and cyber doctor show construction evidence and discard
pending requests with the exact command; the TUI has no discard action.
A SIGKILLed claim stage refuses discard while its preparation is unresolved and
for a stale review, then is discarded and worktree removal is admitted. A cut
table kills the service after the intent, after the quarantine move and after
the unlink; each request resumes, maintenance finishes a moved stage and doctor
reports it as pending meanwhile.
A binary-document activity can neither publish a snapshot origin nor pass
snapshot recovery review, before or after launch, and the refused review
appends nothing. The production guards already existed; this covers the M2
obligation that snapshot workers never reuse binary-document authority.
…ft open

Add debug-only process-cut points after origin publication, after intent
publication, after each progress record, after filesystem completion, after
the paired recovery writer commit and after the ordinary and paired journal
acknowledgements. Release builds compile them out.

restore_cuts.rs drives the real CLI/service through each point and checks
the durable state, keep/rollback or preparation cancellation, lookup-only
retries and no transcript movement or inference. It also covers a staged
undo beside an inactive branch, an interrupted keep/rollback retained as
independent evidence, and replacement or aliasing of the private journal
namespace between review and confirmation.
…idence

docs/rewind.md explains how an interrupted resolution journal is resolved
before the original. implementation.md updates the M8 cut matrix and records
the increment; tasks.md notes per managed-recovery task (local macOS arm64
only, platform acceptance still open).
…recovery

A code preview refused because a retained restore needs owned recovery shows
the recovery hint, and C sends a recovery listing request instead of another
preview.
…tion

A separate maintenance process runs production reclamation and is SIGKILLed
once any planned payload is unlinked; a fresh owner completes the identical
frozen plan once, keeps intents and the cancellation record, and lookups
return the same receipts. A debug-only point after image preparation gives a
deterministic fully prepared cancellation.
…ade fixture

The two path helpers are only used by the Unix implementation and broke the
Windows -D warnings build. The doctor JSON test now expects the new
construction discards check. The upgrade test archive is compressed at the
fastest level, since a stored debug binary on Linux CI now exceeds the
upgrader's 512 MiB download cap.
The restore_cuts fixture can now be a tracked managed Git worktree, and the
progress, completion, paired writer-commit, interrupted-resolution, staged
undo with inactive branch, namespace swap and damaged-intent cases run there
under native-git-acceptance. A corrupt or missing retained intent refuses
listing, review and a reviewed confirmation without source effects on both
backends. The native snapshot proof workflow runs restore_cuts and
ordinary_cuts on the Linux and macOS matrix.
Every recovery route is called on the real service after a real partial
restore: stale, foreign-Session, changed-content and unknown requests are
refused without effects, and lookup, repeated confirmation and
acknowledgement return the same receipt. A new SDK end-to-end test kills a
real service mid-restore and resolves the journal through the SDK.
Paired cleanup deleted whatever inode the keep outcome had observed in the
original journal slot. An owner write racing an exchange can leave the
owner's file there; it is reviewed as foreign and keep is allowed, so after
retention the owner's latest bytes were unlinked. The slot inode must now be
the recorded original source or prepared target, as ordinary and resolution
cleanup already required.
Every repeated explicit acknowledgement rewrote both intents and swapped
their slot inodes, which breaks identities pinned by a planned metadata
retirement and makes a resumed retirement refuse. Published metadata is now
left untouched. A resolution is also admitted only when its journal is
definitely absent, not on any metadata error.
@leonardoaraujosantos
leonardoaraujosantos marked this pull request as ready for review November 16, 2026 22:25
@leonardoaraujosantos

Copy link
Copy Markdown
Contributor Author

CI on 4044d5ca:

  • Snapshot native proof (run 43969386260) passed on ubuntu-24.04, ubuntu-24.04-arm, macos-15 and macos-15-intel. This run includes the new "Restore and recovery process-death cuts" step (restore_cuts::, ordinary_cuts::).
  • CI (run 43969386108): every job passed except Rust (ubuntu-latest).
    • The one failure is cyber-cli::upgrade_cli script_upgrade_replaces_the_binary_after_verification, which failed on both tries.
    • The base branch at 20734f45 fails the same test in run 43953405907.
    • This PR does not touch upgrade_cli.

On Linux CI the debug binary with line tables is larger than the upgrader's
per-member archive limit, so compression alone did not keep the fixture
valid. A stripped copy still runs, which the test needs to check that the
next start removes cyber.old.
…-resolution

# Conflicts:
#	openspec/changes/complete-daily-coding-surfaces/implementation.md
@leonardoaraujosantos
leonardoaraujosantos changed the base branch from feat/construction-evidence-discard to main November 18, 2026 01:54
@leonardoaraujosantos
leonardoaraujosantos merged commit 386a49c into main Nov 18, 2026
58 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant