Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
cfca4ff
Add atomic paired owner appends for snapshot recovery
vanedaltro Nov 6, 2026
0d21b0b
Retain owned non-Git restore workers through acknowledgement
vanedaltro Nov 6, 2026
52147d8
Record native ownership before snapshot file and parent effects
vanedaltro Nov 6, 2026
d90b519
Add snapshot recovery review and journaled filesystem resolution
vanedaltro Nov 6, 2026
93b4b61
Preserve durable native acknowledgements during late scope disposal
vanedaltro Nov 6, 2026
fd732d8
Track snapshot uncertainty by exact native activity owner
vanedaltro Nov 6, 2026
f306392
Add owned non-Git recovery admission and paired settlement
vanedaltro Nov 6, 2026
354e5ca
Reconcile committed recovery journal acknowledgements
vanedaltro Nov 7, 2026
36c6b1a
Reconcile ordinary restore acknowledgements from paired receipts
vanedaltro Nov 7, 2026
fd68e5c
Bind snapshot reservations to retained native lifetime locks
vanedaltro Nov 7, 2026
8262c0f
Resolve exited snapshot preparations before origin publication
vanedaltro Nov 7, 2026
4bdb3f6
Cancel exited snapshot preparations before source admission
vanedaltro Nov 7, 2026
3388dc9
Give snapshot workers independent checkout claims
vanedaltro Nov 7, 2026
7e47017
Verify retained snapshot checkout proof at consuming commits
vanedaltro Nov 7, 2026
6f65d35
Publish initialized checkout claims with exact lifetime context
vanedaltro Nov 7, 2026
d877526
Persist complete checkout resources before snapshot source admission
vanedaltro Nov 7, 2026
e81192e
Bind preparation receipts to retained checkout resources
vanedaltro Nov 7, 2026
1564463
Acknowledge exact pre-effect snapshot checkout claims after durable s…
vanedaltro Nov 7, 2026
4378f4e
Verify exact Git snapshot paths and blob object identities
vanedaltro Nov 7, 2026
7edb0ca
Verify scoped Git tree catalogs before restore planning
vanedaltro Nov 7, 2026
d37c0ce
Import verified Git file images through native recovery journals
vanedaltro Nov 7, 2026
0cb9eeb
Journal symbolic-link images without following their targets
vanedaltro Nov 7, 2026
878bd56
Validate native Git namespace and rule inputs before journaling
vanedaltro Nov 7, 2026
e6fc670
Bind Git checkpoint policy inputs to capture-time fingerprints
vanedaltro Nov 7, 2026
48d8736
Retain exact working-tree images in Git checkpoint graphs
vanedaltro Nov 7, 2026
0dde140
Share native Git planning with managed preview and raw path selection
vanedaltro Nov 7, 2026
99aa6f8
Reserve exact native snapshot lifetimes for Git Locations
vanedaltro Nov 7, 2026
592b6a1
Bind ordinary restore receipts to exact native checkout resources
vanedaltro Nov 7, 2026
08bc1d9
Acknowledge exact restore checkout claims after durable consuming com…
vanedaltro Nov 7, 2026
9484b9c
Journal owned no-op restores and bind distinct native namespaces corr…
vanedaltro Nov 7, 2026
b0cc526
Retain original native recovery resources through resolution work
vanedaltro Nov 7, 2026
0a7cfad
Bind and reconcile both recovery checkout owners
vanedaltro Nov 7, 2026
4d80131
Preserve Git object formats and retained copy history
vanedaltro Nov 7, 2026
f2e8d7f
Bind native Git policy to configuration origins
vanedaltro Nov 7, 2026
5be7ab9
Retain typed copy image provenance in Git recovery journals
vanedaltro Nov 7, 2026
4f0bfe8
Bind generated Git excludes to source policy
vanedaltro Nov 7, 2026
bacade3
Add typed snapshot recovery CLI commands
vanedaltro Nov 7, 2026
0dfb499
Add terminal snapshot recovery and request discovery
vanedaltro Nov 7, 2026
d8a7242
Add typed preparation recovery CLI commands
vanedaltro Nov 7, 2026
55d746e
Add terminal preparation recovery and receipt discovery
vanedaltro Nov 7, 2026
86d505a
Test preparation recovery across terminal process death
vanedaltro Nov 7, 2026
793aa08
Reclaim acknowledged file-copy restore payloads
vanedaltro Nov 7, 2026
f085c5e
Reclaim acknowledged recovery pair payloads
vanedaltro Nov 7, 2026
3e187e2
Reclaim cancelled prepared snapshot payloads
vanedaltro Nov 7, 2026
ee6ad80
Bind native Git handoffs to user index observations
vanedaltro Nov 7, 2026
b27f7e8
Revalidate generated Git size exclusions before native effects
vanedaltro Nov 7, 2026
e5ba38d
Bind Git size classification to observed user inputs
vanedaltro Nov 7, 2026
b2f35a2
Exercise owned Git restores through runtime workers
vanedaltro Nov 7, 2026
a6f80a0
Restore registered managed checkout sources with owned workers
vanedaltro Nov 7, 2026
2fcd745
Merge remote-tracking branch 'origin/main' into feat/managed-recovery…
vanedaltro Nov 9, 2026
b75315e
Keep snapshot warnings nonfatal in JSONL exec
vanedaltro Nov 9, 2026
3d3471f
Reclaim managed Git payloads with retained checkout proofs
vanedaltro Nov 9, 2026
351fd1e
Reclaim acknowledged symbolic-link journal payloads
vanedaltro Nov 9, 2026
9ac06c4
Publish JSONL last messages through exclusive temporary files
vanedaltro Nov 9, 2026
634a7ac
Retire completed JSONL payloads into bounded accounting
vanedaltro Nov 9, 2026
c971ac7
Settle open structured results before terminal drain exit
vanedaltro Nov 9, 2026
03b4526
Reconcile durable structured results before resuming inference
vanedaltro Nov 9, 2026
1be0364
Preserve structured result ownership across steering
vanedaltro Nov 10, 2026
75d8459
Reclaim cancelled prepared Git snapshot payloads
vanedaltro Nov 10, 2026
e2b3ba1
Honor fallback snapshot retention during collection
vanedaltro Nov 10, 2026
2ec1b1c
Bind prepared intent updates to preallocated native slots
vanedaltro Nov 10, 2026
124c11b
Retain collection policy provenance across interrupted pruning
vanedaltro Nov 10, 2026
50e0037
Allow complete native recovery verification on Intel runners
vanedaltro Nov 10, 2026
5be366b
Record metadata retirement phases at the Store writer
vanedaltro Nov 10, 2026
053dbfa
Retire acknowledged snapshot metadata through exact native plans
vanedaltro Nov 10, 2026
b4f1804
Write repeated raw Git blobs once per capture
vanedaltro Nov 10, 2026
b42f5fc
Verify metadata retirement across cancellation and paired recovery
vanedaltro Nov 10, 2026
991b151
Retire consumed checkout claims through durable native metadata plans
vanedaltro Nov 10, 2026
1f5b704
Verify managed metadata retirement after real process death
vanedaltro Nov 10, 2026
d702c85
Retire ordinary restore metadata without displaced bytes
vanedaltro Nov 10, 2026
af0d10e
Retire empty preparation and recovery journals
vanedaltro Nov 10, 2026
2fb4183
Verify reclamation across unavailable Location routes
vanedaltro Nov 10, 2026
70e9495
Bind direct JSONL requests to recorded input ownership
vanedaltro Nov 10, 2026
6bd2f57
Keep managed cut fixtures within native socket path limits
vanedaltro Nov 10, 2026
9d0f6dc
Apply trusted configuration limits to instruction loading
vanedaltro Nov 10, 2026
1922fda
Bound complete instruction rendering and exact reminder delivery
vanedaltro Nov 10, 2026
c9e0c37
Load reviewed path rules with fenced definition identity
vanedaltro Nov 10, 2026
fa2c9df
Fence nested reminders to the active context epoch
vanedaltro Nov 10, 2026
25e7e89
Bind read reminders to the captured native location
vanedaltro Nov 10, 2026
83af7dc
Bind scoped rule delivery to observed file reads
vanedaltro Nov 10, 2026
856f522
Record native receipts for scoped edit rules
vanedaltro Nov 10, 2026
aeb12a6
Deliver scoped rules for completed patch effects
vanedaltro Nov 10, 2026
a4d28df
Carry scoped rule receipts through intercepted shell patches
vanedaltro Nov 10, 2026
eb1f298
Add authenticated stored context inspection and TUI panel
vanedaltro Nov 11, 2026
cf016df
Persist context source provenance and observation status
vanedaltro Nov 11, 2026
64052cb
Record context estimates from assembled provider requests
vanedaltro Nov 11, 2026
2a628f1
Gate native retirement helpers with their platform consumers
vanedaltro Nov 11, 2026
90234d3
Gate Unix Git corruption fixture helpers on Unix
vanedaltro Nov 11, 2026
17d076f
Record dispatched input provenance on background Jobs
vanedaltro Nov 11, 2026
794202a
Retain snapshot ownership through worker disposal
vanedaltro Nov 11, 2026
a7ff349
Synchronize context surfaces and recovery CI coverage
vanedaltro Nov 11, 2026
e8b4a25
Retain snapshot ownership during partial construction
vanedaltro Nov 11, 2026
d831d40
Add bounded input-owned Job state lookup
vanedaltro Nov 11, 2026
44b9ea8
Preserve input ownership through Job handbacks
vanedaltro Nov 11, 2026
71fc43d
Retain JSONL inputs through owned background settlement
vanedaltro Nov 11, 2026
34033f9
Retain input-scoped interruption controls and receipts
vanedaltro Nov 11, 2026
b6f72d0
Wire JSONL interruption to retained input controls
vanedaltro Nov 11, 2026
20e0aae
Bind JSONL request presence to admitted input clients
vanedaltro Nov 11, 2026
e56f2eb
Merge remote-tracking branch 'origin/main' into feat/managed-recovery…
leonardoaraujosantos Nov 12, 2026
a194afd
Iterate snapshot fixture changes with enumerate
leonardoaraujosantos Nov 12, 2026
78a2527
Report instruction files changed on disk in context inspection
leonardoaraujosantos Nov 12, 2026
2a80f65
Test scoped rule redelivery after compaction starts a new Epoch
leonardoaraujosantos Nov 12, 2026
3fc8c0f
Estimate the next request in context inspection
leonardoaraujosantos Nov 12, 2026
f7f2ce5
Release the lifecycle guard last in acknowledgement and preparation w…
leonardoaraujosantos Nov 13, 2026
0c66b2f
Retry a busy last-message destination on Windows; bound the long reco…
leonardoaraujosantos Nov 13, 2026
6fb0f9e
Test JSONL input capacity, oversized lines and a stalled stdout reader
leonardoaraujosantos Nov 13, 2026
781b04a
Test a lost JSONL admission acknowledgement against a real server
leonardoaraujosantos Nov 13, 2026
3b6e3ef
Count lost acknowledgements without a deprecated atomic method
leonardoaraujosantos Nov 13, 2026
f3c2add
Confirm a doubly lost JSONL admission from the Session inbox
leonardoaraujosantos Nov 13, 2026
b3578ef
Let the JSONL test server choose its own port and keep stderr
leonardoaraujosantos Nov 13, 2026
e2a5b07
Accept server passwords that start with a hyphen; test a server crash…
leonardoaraujosantos Nov 13, 2026
cbbda39
Fence scoped-rule delivery to the current approval generation at sett…
leonardoaraujosantos Nov 14, 2026
988c734
List delivered rules with their current approval in context inspection
leonardoaraujosantos Nov 14, 2026
443e73d
Test scoped-rule delivery across server restart
leonardoaraujosantos Nov 14, 2026
0c97e19
Report withheld rule definitions in context inspection
leonardoaraujosantos Nov 14, 2026
3dbb8a1
Report scoped and withheld rule definitions in doctor
leonardoaraujosantos Nov 14, 2026
ce92865
Test rule leakage, precedence and estimate consistency
leonardoaraujosantos Nov 14, 2026
8a87fbb
Test stale, wrong-kind and cross-driver JSONL replies
leonardoaraujosantos Nov 14, 2026
e60946b
Redact secrets in JSONL error, result and end lines
leonardoaraujosantos Nov 14, 2026
6dda753
Add exec --include-hook-events from durable hook receipts
leonardoaraujosantos Nov 14, 2026
00327e0
Stamp descendant requests with their root input cohort
leonardoaraujosantos Nov 14, 2026
db0a816
Lend a descendant only the root cohort of its running subagent Job
leonardoaraujosantos Nov 14, 2026
917761b
Let the JSONL driver own descendant and hook-originated asks
leonardoaraujosantos Nov 14, 2026
7f7e46d
Stop an owned subagent subtree on scoped input interruption
leonardoaraujosantos Nov 14, 2026
0152433
Reconcile instruction-rule and JSONL docs with delivered behaviour
leonardoaraujosantos Nov 14, 2026
c0d4461
Revert exec --include-hook-events here in favour of add-exec-hook-events
leonardoaraujosantos Nov 14, 2026
d24eb6a
Test non-Git renames, unsupported entries and mid-restore editor writes
leonardoaraujosantos Nov 14, 2026
f8c4d7e
Test cap visibility and staged/branch retention through App and TUI
leonardoaraujosantos Nov 14, 2026
14cb011
Kill ordinary file-copy restores at writer commit and payload reclaim
leonardoaraujosantos Nov 14, 2026
abcfb0f
Kill managed paired and prepared metadata retirement mid-unlink
leonardoaraujosantos Nov 14, 2026
0a759e0
Prove partial checkout construction stays fenced and list it in recovery
leonardoaraujosantos Nov 14, 2026
54e13a9
Keep preparation listing available when the construction inventory fails
leonardoaraujosantos Nov 14, 2026
0a71bba
Narrow removed-Location and metadata-retirement evidence notes
leonardoaraujosantos Nov 14, 2026
7a80f98
Elide revoked or changed delivered rules on replay
leonardoaraujosantos Nov 15, 2026
e441996
End a JSONL driver with a structured server_lost error and resume hint
leonardoaraujosantos Nov 15, 2026
405d3f9
List recovery journals of a removed Location as orphaned and read-only
leonardoaraujosantos Nov 15, 2026
ec6b299
Keep default managed Git source admission off and pin it with a test
leonardoaraujosantos Nov 15, 2026
51c0c56
Refuse a file-copy restore when an unsupported entry replaced a chang…
leonardoaraujosantos Nov 15, 2026
ba659e3
Specify an owner-only discard for construction evidence (awaiting rev…
leonardoaraujosantos Nov 15, 2026
a897afb
Record owner answers for construction-evidence discard
leonardoaraujosantos Nov 16, 2026
3ecbf9b
Compare doctor rule paths separator-neutrally and give Intel snapshot…
leonardoaraujosantos Nov 16, 2026
866fae7
Merge origin/main into feat/managed-recovery-owner
leonardoaraujosantos Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ binary_id(cyber-account)
| binary_id(cyber-snapshot)
| binary_id(cyber-snapshot::file_copy_platform)
| binary_id(cyber-snapshot::snapshots)
| binary_id(cyber-store) & (test(writer::tests::) | test(migrate::tests::messaging_) | test(migrate::tests::usage_origin_))
| binary_id(cyber-store) & (test(writer::tests::) | test(store::paired_tests::) | test(migrate::tests::snapshot_worker_) | test(migrate::tests::messaging_) | test(migrate::tests::usage_origin_))
| binary_id(cyber-store::store)
| binary_id(cyber-tools) & (test(tools::bash::shell_tests) | test(plugin_host::) | test(browser::) | test(dev_server::) | test(permissions::engine::tests::message_send) | test(permissions::engine::tests::remote_attach) | test(remote_skills) | test(lsp::) | test(mcp::stdio::tests) | test(mcp::roots::tests) | test(mcp::elicitation::tests) | test(mcp::sampling::tests) | test(tools::process::tests) | test(tools::tool_search::tests) | test(mcp::pool::tests) | test(mcp::launch::tests) | test(mcp::http::tests) | test(mcp::oauth) | test(hook_commands::launch::tests) | test(sandboxing::tests) | test(permissions::filesystem) | test(tools::background::tests) | test(tools::monitor::) | test(tools::deliver::tests) | test(tools::powershell::tests) | test(permissions::dry_run) | test(sandboxing::tests::refusal_lines) | test(permissions::engine::tests::sandbox_boundary_needs_an_explicit_user_allow) | test(permissions::engine::tests::workflow_run) | test(permissions::taint::) | test(untrusted::))
| binary_id(cyber-tools::agent_context)
Expand Down Expand Up @@ -249,3 +249,9 @@ test-group = "windows-native"
[[profile.ci-windows.overrides]]
filter = "binary_id(cyber-tools::isolated_subagents)"
test-group = "isolated-subagents"

# The reviewed-recovery end-to-end test kills and restarts the owner several times; on
# main it already took 8–9.5 of its 10 minutes on the Windows runner.
[[profile.ci-windows.overrides]]
filter = "binary_id(cyber-cli::branches_cli) & test(reviewed_recovery_code_stages_survive_kill_restage_and_clear_without_adopting_owner_files)"
slow-timeout = { period = "60s", terminate-after = 20 }
1 change: 1 addition & 0 deletions .github/workflows/binary-editor-proof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
paths:
- crates/cyber-core/src/binary/**
- crates/cyber-core/src/worktrees/**
- crates/cyber-core/Cargo.toml
- Cargo.lock
- .github/workflows/binary-editor-proof.yml
Expand Down
262 changes: 257 additions & 5 deletions .github/workflows/non-git-snapshot-proof.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All notable changes to Cyber Code are recorded here. The format follows [Keep a
### Added

- Computer use reports a platform-neutral capability report (schema version 2): a derived mode (`unsupported`, `capture_only`, `input_enabled`), stable reason codes, authority kind, honored selectors and the support evidence level, alongside the existing macOS fields. Receipts add platform, grant, target and frame references, a reason, cleanup state and timestamps; HTTP errors add a `reason` code. `cyber computer allow <session> --preview <id> --yes` confirms a printed review by its identifier.
- `cyber exec --format stream-json --include-hook-events` adds a `hook_event` line for each hook that ran for the run's Session (hook ID, event, scope, outcome, decision, duration, and the tool call it guarded), before the line of what it gated. Hook input, output, reasons and environment are never included. The instance event stream carries the underlying `session.hook.receipt` summaries when asked with `include=hook_receipts`.
- `cyber exec --format stream-json --include-hook-events` adds a `hook_event` line for each hook that ran for the run's Session (hook ID, event, scope, outcome, decision, duration, and the tool call it guarded), before the line of what it gated. Hook input, output, reasons and environment are never included. The instance event stream carries the underlying `session.hook.receipt` summaries when asked with `include=hook_receipts`, and so does a Session's event stream (`/sessions/{id}/events`) for that Session's own receipts, which `--input-format stream-json` runs follow.

### Changed

Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/cyber-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mdns-sd = { version = "0.21", default-features = false }
url = "2"

[dev-dependencies]
blake3 = "1"
aws-lc-rs = "1"
jsonwebtoken = { version = "=10.3.0", default-features = false, features = ["aws_lc_rs"] }
cyber-client = { path = "../cyber-client" }
Expand All @@ -62,3 +63,6 @@ windows-sys = { version = "0.61.2", features = ["Win32_Foundation", "Win32_Syste

[lints]
workspace = true

[features]
native-git-acceptance = ["cyber-snapshot/native-git-acceptance"]
75 changes: 75 additions & 0 deletions crates/cyber-app/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ impl ToolHost for AppHost {
self.builtin.claude_compat(directory)
}

fn instruction_limits(
&self,
directory: &str,
) -> Result<cyber_core::config::InstructionLimits, String> {
self.builtin.instruction_limits(directory)
}

fn language(&self, directory: &str) -> Option<cyber_core::locale::Locale> {
self.builtin.language(directory)
}
Expand All @@ -99,6 +106,21 @@ impl ToolHost for AppHost {
self.builtin.instruction_read_gate(directory)
}

fn instruction_rule_gate(
&self,
directory: &str,
) -> Option<cyber_server::runtime::instructions::RuleGate> {
self.builtin.instruction_rule_gate(directory)
}

fn rule_approval(
&self,
root: &std::path::Path,
generation: &str,
) -> cyber_server::runtime::RuleApproval {
self.builtin.rule_approval(root, generation)
}

fn finalize_skill_output(
&self,
directory: &str,
Expand Down Expand Up @@ -274,6 +296,43 @@ impl ToolHost for AppHost {
self.builtin.claim_binary_location(info, document, cancel)
}

fn claim_snapshot_location<'a>(
&'a self,
info: &'a cyber_server::runtime::SessionInfo,
activity: &'a str,
cancel: CancellationToken,
) -> BoxFuture<'a, Result<cyber_server::runtime::LocationLease, String>> {
self.builtin.claim_snapshot_location(info, activity, cancel)
}

fn claim_snapshot_location_bound<'a>(
&'a self,
info: &'a cyber_server::runtime::SessionInfo,
activity: &'a str,
lifetime: Option<&'a cyber_server::runtime::SnapshotLifetimeBinding>,
cancel: CancellationToken,
) -> BoxFuture<'a, Result<cyber_server::runtime::LocationLease, String>> {
self.builtin
.claim_snapshot_location_bound(info, activity, lifetime, cancel)
}

fn snapshot_checkout_constructions(
&self,
info: &cyber_server::runtime::SessionInfo,
) -> Result<Vec<cyber_core::worktrees::SnapshotConstruction>, String> {
self.builtin.snapshot_checkout_constructions(info)
}

fn reacquire_snapshot_location(
&self,
info: &cyber_server::runtime::SessionInfo,
lifetime: &cyber_server::runtime::SnapshotLifetimeBinding,
bindings: &[cyber_core::worktrees::CheckoutBinding],
) -> Result<Box<dyn cyber_server::runtime::SnapshotLocationGuard>, String> {
self.builtin
.reacquire_snapshot_location(info, lifetime, bindings)
}

fn prepare_child_continuation<'a>(
&'a self,
parent: &'a cyber_server::runtime::SessionInfo,
Expand Down Expand Up @@ -321,6 +380,22 @@ impl ToolHost for AppHost {
self.builtin.execute(call, cancel)
}

fn execute_observed(
&self,
call: Invocation,
cancel: CancellationToken,
) -> BoxFuture<'_, cyber_server::runtime::ObservedExecution> {
if self.remote.has(&call.name) {
return Box::pin(async move {
cyber_server::runtime::ObservedExecution {
outcome: self.execute(call, cancel).await,
files: None,
}
});
}
self.builtin.execute_observed(call, cancel)
}

fn lifecycle_hooks(
&self,
event: cyber_server::runtime::LifecycleHook,
Expand Down
16 changes: 6 additions & 10 deletions crates/cyber-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod registration;
pub mod retention;
mod server;
mod services;
pub mod snapshot_reclamation;
pub mod update_check;

use std::path::PathBuf;
Expand Down Expand Up @@ -325,17 +326,11 @@ impl App {
let loader = Arc::clone(&config);
let snapshot_store = store.clone();
let references: Arc<cyber_snapshot::ReferencesFn> = Arc::new(move || {
let rows = snapshot_store.read(|db| {
let mut query = db.prepare("SELECT DISTINCT j.value FROM event e,json_tree(e.data) j WHERE j.type='text' AND j.value LIKE 'copy:%' LIMIT 100001")?;
let rows = query.query_map([], |row|row.get::<_,String>(0))?.collect::<Result<Vec<_>,_>>()?;
Ok(rows)
}).map_err(|error|error.to_string())?;
if rows.len() > 100000 {
return Err("Snapshot reference limit exceeded; pruning refused".into());
}
Ok(rows.into_iter().collect())
snapshot_store
.read(cyber_server::runtime::snapshot_reclamation::references)
.map_err(|error| error.to_string())
});
let snaps = cyber_snapshot::GitSnapshots::with_policy(
let snaps = cyber_snapshot::GitSnapshots::with_reclamation(
opts.paths.data.clone(),
Arc::new(move |p| loader(p).map(|(v, _)| v).unwrap_or(Value::Null)),
vec![
Expand All @@ -345,6 +340,7 @@ impl App {
opts.paths.tmp.clone(),
],
Some(references),
Some(snapshot_reclamation::policy(store.clone())),
);
snaps.spawn_gc();
snaps
Expand Down
141 changes: 141 additions & 0 deletions crates/cyber-app/src/snapshot_reclamation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! Compose native cleanup with the same serialized writer that owns references.
mod metadata;
use cyber_server::runtime::{
SnapshotOrigin,
snapshot_reclamation::{self as records, Completion, Plan, Record},
};
use cyber_snapshot::reclamation::{Collect, Delete, Policy, Settlement};
use cyber_store::{Expected, NewEvent, Store, StoreError};
use std::sync::Arc;

pub(crate) struct Reclamation(pub Arc<Store>);
/// Bind native maintenance to this owned Store. Embedders must use the same
/// Store as their runtime; this grants no HTTP or source-file capability.
pub fn policy(store: Arc<Store>) -> Arc<dyn Policy> {
Arc::new(Reclamation(store))
}
fn invalid(error: impl std::fmt::Display) -> StoreError {
StoreError::InvalidAppend(error.to_string())
}

impl Policy for Reclamation {
fn receipt(&self, origin: &SnapshotOrigin) -> Result<Option<Settlement>, String> {
let origin = origin.clone();
self.0
.read(move |db| {
let tx = db.unchecked_transaction()?;
let Some(receipt) = records::settlement_receipt(&tx, &origin)? else {
return Ok(None);
};
let settled_at_ms = tx.query_row(
"SELECT time FROM event WHERE aggregate_id=?1 ORDER BY seq DESC LIMIT 1",
[&origin.activity_id],
|row| row.get(0),
)?;
tx.commit()?;
Ok(Some(Settlement {
receipt,
settled_at_ms,
}))
})
.map_err(|error| error.to_string())
}
fn record(&self, receipt: &records::Receipt) -> Result<Option<Record>, String> {
let receipt = receipt.clone();
self.0
.read(move |db| {
let tx = db.unchecked_transaction()?;
let record = records::lookup(&tx, &receipt)?;
tx.commit()?;
Ok(record)
})
.map_err(|error| error.to_string())
}
fn reclaim(&self, plan: Plan, delete: Delete) -> Result<u64, String> {
plan.validate().map_err(|error| error.to_string())?;
let id = Plan::id(&plan.receipt).map_err(|error| error.to_string())?;
let existing = self.record(&plan.receipt)?;
if let Some(existing) = existing {
if existing.plan != plan {
return Err("Reclamation plan differs from retained request".into());
}
if existing.completed {
return Ok(0);
}
} else {
let prepare = plan.clone();
self.0
.append_checked(&id, Expected::Seq(-1), move |db| {
prepare.authorize(db)?;
let event = NewEvent::new(
records::PLANNED,
serde_json::to_value(&prepare).map_err(invalid)?,
);
Ok((vec![event], ()))
})
.map_err(|error| error.to_string())?;
}
let consume = plan.clone();
let removed = self
.0
.transaction(move |db| {
let record = records::lookup(db, &consume.receipt)?
.ok_or_else(|| invalid("Missing committed reclamation plan"))?;
if record.completed || record.plan != consume {
return Err(invalid("Reclamation request changed before deletion"));
}
consume.authorize(db)?;
// No network, child processes, callbacks into Store or source-file
// work. Native locks/pins remain owned by this bounded closure.
delete().map_err(invalid)
})
.map_err(|error| error.to_string())?;
let completion = Completion {
plan_id: id.clone(),
removed_bytes: removed,
};
self.0
.append_checked(&id, Expected::Seq(0), move |db| {
plan.authorize(db)?;
if completion.removed_bytes != plan.total_bytes()? {
return Err(invalid("Reclamation byte accounting changed"));
}
Ok((
vec![NewEvent::new(
records::COMPLETED,
serde_json::to_value(completion).map_err(invalid)?,
)],
(),
))
})
.map_err(|error| error.to_string())?;
Ok(removed)
}
fn retire(
&self,
payload: Plan,
plan: records::metadata::Plan,
delete: Delete,
) -> Result<u64, String> {
metadata::retire(self, payload, plan, delete)
}
fn collect(&self, collect: Collect) -> Result<(), String> {
self.0
.transaction(move |db| collect(&records::references(db)?).map_err(invalid))
.map_err(|error| error.to_string())
}
fn retirement_batch(
&self,
directory: Option<&str>,
after: Option<&str>,
) -> Result<cyber_snapshot::reclamation::RetirementBatch, String> {
metadata::batch(self, directory, after)
}
fn refused(&self, directory: &str, error: &str) {
cyber_core::log::warn(
"snapshot",
"Snapshot reclamation refused; retained evidence is protected",
serde_json::json!({"directory":directory,"reason":error}),
);
}
}
Loading
Loading