Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion control/crates/layerfs-control/tests/kernel_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn actual_daemon_install_hello_bind_status_no_constructor_and_session_end() {
// The real binary's Commit of an unchanged Workspace: the same root, no
// new Commit record.
assert!(
matches!(control.call(Request::Commit(layerfs_bridge::control::CommitControl { token: bound.token, force: false, message: None, })).unwrap(), Reply::Committed(layerfs_history::CommitOutcome::UpToDate { head: None, root }) if root == bound.binding.effective_root)
matches!(control.call(Request::Commit(layerfs_bridge::control::CommitControl { token: bound.token, force: false, message: None, expected: None })).unwrap(), Reply::Committed(layerfs_history::CommitOutcome::UpToDate { head: None, root }) if root == bound.binding.effective_root)
);
let after = layerfs_sandbox::internal::workspace(&mut control)
.status(bound.token)
Expand Down
112 changes: 102 additions & 10 deletions control/crates/layerfs-control/tests/mount_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn original_lost_control_reply_is_not_replayed_or_settled_by_an_observer() {
token,
force: false,
message: None,
expected: None,
})
);
let OperationCause::Exchange(original) = &failure.cause else {
Expand Down Expand Up @@ -222,6 +223,7 @@ fn another_control_channel_observes_running_commit_and_refuses_unmount_before_ef
token,
force: false,
message: None,
expected: None,
}))
});
entered.recv_timeout(Duration::from_secs(3)).unwrap();
Expand Down Expand Up @@ -257,8 +259,12 @@ fn another_control_channel_observes_running_commit_and_refuses_unmount_before_ef
f.cleanup();
}

/// An original local uncertainty (the overlay's outcome unknown) keeps the
/// capture: the Workspace is `Uncertain` and refuses another Commit and a
/// normal unmount. Before the Publish phase only local uncertainty does
/// this; a Store unknown there folds back (next test).
#[test]
fn an_original_unknown_blocks_another_commit_and_normal_unmount() {
fn an_original_local_unknown_blocks_another_commit_and_normal_unmount() {
let f = fixture::Fixture::new("control-unknown");
let branch = f.host.project.branch.branch.id;
let service = f.service.clone();
Expand All @@ -270,12 +276,13 @@ fn an_original_unknown_blocks_another_commit_and_normal_unmount() {
);
let original = service
.serve_one(connection, |_, _, _| {
Err(layerfs_daemon::store::CommitError::Storage(
layerfs_storage::StorageError::UnknownOutcome {
original: Box::new(layerfs_storage::StorageError::Integrity(
"original producer uncertainty",
)),
},
Err(layerfs_daemon::store::CommitError::Workspace(
layerfs_workspace::WorkspaceError::Overlay(
layerfs_overlay::OverlayError::Uncertain {
cause: Box::new(layerfs_overlay::OverlayError::Quarantined),
completion: None,
},
),
))
})
.unwrap();
Expand All @@ -294,29 +301,108 @@ fn an_original_unknown_blocks_another_commit_and_normal_unmount() {
let (token, binding) = mount(&mut client, identity(89), branch);
fixture::write(&f.service, token, b'U');
assert!(
matches!(client.call(Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, })).unwrap(),Reply::Refused(value) if value.code==ControlCode::Unknown)
matches!(client.call(Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, expected: None })).unwrap(),Reply::Refused(value) if value.code==ControlCode::Unknown)
);
let observed = status(&mut client, token);
assert_eq!(observed.activity, Activity::Uncertain);
assert_eq!(observed.binding, binding);
assert!(observed.published.is_none());
assert!(observed.local.unwrap().captured.is_some());
assert!(
matches!(f.service.execute_control(&Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, })),
matches!(f.service.execute_control(&Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, expected: None })),
Err(layerfs_daemon::control::Failure::Custody(value)) if value.code == ControlCode::Unknown && value.published.is_none())
);
assert!(
matches!(client.call(Request::Unmount(layerfs_bridge::control::UnmountControl { token, discard: true })).unwrap(),Reply::Refused(value) if value.code==ControlCode::Unknown)
);
assert!(
matches!(client.call(Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, })).unwrap(),Reply::Refused(value) if value.code==ControlCode::Unknown)
matches!(client.call(Request::Commit(layerfs_bridge::control::CommitControl { token, force: false, message: None, expected: None })).unwrap(),Reply::Refused(value) if value.code==ControlCode::Unknown)
);
let retained = worker.join();
assert!(retained.outcome.is_err());
println!("CONTROL_UNKNOWN producer_original_retained=true normal_unmount=Unknown another_commit=Unknown no_reentry=true");
drop(retained);
f.cleanup();
}

/// Finding #4: an unknown Store outcome during construction, before the
/// Publish phase, cannot have published. The capture folds back, the reply
/// is `Failed`, the Workspace stays `Idle`, the change is kept, and a later
/// Commit and a normal unmount are admitted.
#[test]
fn a_store_unknown_before_publication_folds_back_and_admits_a_commit() {
let f = fixture::Fixture::new("control-unknown-folds");
let branch = f.host.project.branch.branch.id;
let service = f.service.clone();
let policy = f.installed.opened.store.policy().construction();
let (channel, worker) = support::pair(move |connection| {
drop(
service
.serve_one(connection, |_, _, _| unreachable!())
.unwrap(),
);
let original = service
.serve_one(connection, |_, _, _| {
Err(layerfs_daemon::store::CommitError::Storage(
layerfs_storage::StorageError::UnknownOutcome {
original: Box::new(layerfs_storage::StorageError::Integrity(
"original producer uncertainty",
)),
},
))
})
.unwrap();
drop(
service
.serve_one(connection, |_, _, _| unreachable!())
.unwrap(),
);
drop(
service
.serve_one(connection, |save, _, snapshot| {
fixture::construct(save, snapshot, b'U', policy)
})
.unwrap(),
);
drop(
service
.serve_one(connection, |_, _, _| unreachable!())
.unwrap(),
);
original
});
let mut client = Control::new(channel);
let (token, binding) = mount(&mut client, identity(90), branch);
fixture::write(&f.service, token, b'U');
let reply = client
.call(Request::Commit(layerfs_bridge::control::CommitControl {
token,
force: false,
message: None,
expected: None,
}))
.unwrap();
assert!(
matches!(&reply, Reply::Refused(value) if value.code == ControlCode::Failed),
"{reply:?}"
);
let observed = status(&mut client, token);
assert_eq!(observed.activity, Activity::Idle);
assert_eq!(observed.binding, binding);
assert!(observed.published.is_none());
let record = committed(&mut client, token);
assert_eq!(record.parent, binding.branch.head_commit);
close(&mut client, token);
let original = worker.join();
let failed = match &original.outcome {
Err(layerfs_daemon::control::Failure::Commit(failed)) => failed,
other => panic!("{:?}", other.as_ref().err()),
};
assert!(failed.locally_settled && !failed.uncertain());
println!("CONTROL_UNKNOWN_FOLDS producer_unknown_before_publish=Failed capture=folded_back later_commit=Committed normal_unmount=allowed");
drop(original);
f.cleanup();
}
#[test]
fn status_retains_known_publication_when_the_engine_is_unavailable() {
let f = fixture::Fixture::new("control-local-failure");
Expand Down Expand Up @@ -364,6 +450,7 @@ fn status_retains_known_publication_when_the_engine_is_unavailable() {
token,
force: false,
message: None,
expected: None,
}));
(client, reply)
});
Expand Down Expand Up @@ -433,6 +520,7 @@ fn product_control_commit_captures_the_frontier_releases_its_owners_and_is_then_
},
force: false,
message: None,
expected: None,
})),
Err(layerfs_daemon::control::Failure::Rejected(
ControlCode::Invalid,
Expand All @@ -448,6 +536,7 @@ fn product_control_commit_captures_the_frontier_releases_its_owners_and_is_then_
token,
force: false,
message: None,
expected: None,
}))
.unwrap();
let record = match &done.reply {
Expand Down Expand Up @@ -483,6 +572,7 @@ fn product_control_commit_captures_the_frontier_releases_its_owners_and_is_then_
token,
force: false,
message: None,
expected: None,
}))
.unwrap();
assert!(
Expand Down Expand Up @@ -648,6 +738,7 @@ fn a_definite_commit_failure_whose_capture_is_not_resolved_answers_unknown() {
token,
force: false,
message: None,
expected: None,
}));
(client, reply)
});
Expand Down Expand Up @@ -750,6 +841,7 @@ fn an_unresolved_moved_head_failure_is_answered_and_not_dropped() {
token,
force: false,
message: None,
expected: None,
}));
(client, reply)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl WorkspaceApi<'_> {
token,
force: false,
message: None,
expected: None,
});
match self.exchange(request.clone())? {
Reply::Committed(outcome) => Ok(outcome),
Expand Down
54 changes: 50 additions & 4 deletions control/crates/layerfs-sandbox/src/workspace/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,35 @@ pub fn listed_head(listed: &SdkValue, id: BranchId) -> Option<String> {
/// resolver, a full id or a prefix of 8 or more of its characters.
pub type Resolve<'a> = dyn FnMut(&str) -> Outcome + 'a;

/// The daemon's `HeadMoved` for a Commit sent with `--expected`: the head
/// moved after the check above, and the publication refused it with nothing
/// committed. Answered as the check answers a head that is not the expected
/// one: `Conflict`, naming the head as `commit`.
fn moved_from_expected(
expected: Option<layerfs_history::NodeId>,
failure: &crate::OperationFailure,
) -> Option<SdkRefusal> {
let OperationCause::Remote(refused) = &failure.cause else {
return None;
};
let moved = match (expected, refused.code, &refused.moved) {
(Some(_), layerfs_bridge::control::ControlCode::HeadMoved, Some(moved)) => moved,
_ => return None,
};
let head = layerfs_bridge::sdk_values::node_text(moved.actual_head.map_or(
layerfs_history::NodeId::Layer(moved.actual_base),
layerfs_history::NodeId::Commit,
));
let refusal = layerfs_home::outcome::refused(
"Conflict",
format!(
"the Branch's head moved to {head} after --expected was checked; nothing was committed"
),
);
let refusal = with_next(refusal, "commit", SdkValue::text(head));
Some(with_next(refusal, "conflicts", SdkValue::List(Vec::new())))
}

/// The full id of the Commit `--expected` names, resolved in the Store: a
/// prefix more than one Commit starts with is refused `InvalidInput` with
/// `matches` beside it; one no Commit has, `NoSuchCommit`.
Expand All @@ -350,9 +379,10 @@ fn expected_id(text: &str, resolve: &mut Resolve<'_>) -> Result<String, SdkRefus
/// made over: a head that is not it refuses the Commit `Conflict`, naming
/// the head as `commit`, before anything is captured. The head is the one
/// `branch get` answers, so a Branch with no Commit of its own is at the
/// Commit it was forked at (RC-A F2). The check is one read before the
/// Commit is sent; a head that moves after it is merged as any Commit
/// merges.
/// Commit it was forked at (RC-A F2). The expected head also travels with
/// the Commit: the daemon merges only with it, and the publication checks it
/// again inside its own transaction, so a head that moves after this read is
/// refused `HeadMoved` with nothing published, forced or not.
pub fn commit_with(
host: &Host,
path: Option<&str>,
Expand Down Expand Up @@ -396,13 +426,29 @@ pub fn commit_with(
return Err(with_next(refusal, "conflicts", SdkValue::List(Vec::new())));
}
}
let expected = expected
.map(|text| {
layerfs_bridge::sdk_values::unhex(text)
.and_then(|bytes| layerfs_history::NodeId::from_slice(&bytes).ok())
.ok_or_else(|| {
layerfs_home::outcome::refused(
"Failed",
"the Store named no Commit id for --expected; nothing was committed",
)
})
})
.transpose()?;
let reply = workspace(&mut control)
.commit_with(CommitControl {
token,
force,
message: host.message.text().map(str::to_owned),
expected,
})
.map_err(values::failure)?;
.map_err(|failure| match moved_from_expected(expected, &failure) {
Some(refusal) => refusal,
None => values::failure(failure),
})?;
let value = values::commit(&reply)?;
// the Layer the Branch was forked at, from the mount this process
// holds (no read): an unchanged fresh fork's head (call surface 2.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn an_unreadable_commit_answer_leaves_its_outcome_unknown() {
token: token(),
force: false,
message: None,
expected: None,
});
let refused = refusal(&unreadable(commit)).unwrap();
assert_eq!(refused.code, "Unknown");
Expand Down
5 changes: 5 additions & 0 deletions core/crates/layerfs-history/src/contract/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ pub struct CommitRequest {
pub meta: CommitMeta,
/// Overwrite a head that moved instead of refusing.
pub force: bool,
/// The node the Branch must answer as its head (its head Commit, else
/// its base Layer) when the transaction publishes, whatever `force`
/// says; another head is refused `HeadMoved`. `None` checks only
/// `expected_head` and `force`.
pub required_head: Option<NodeId>,
}

/// One side of a Branch merge.
Expand Down
9 changes: 6 additions & 3 deletions docs/architecture/api/sdk/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,18 @@ long form adds `outcome`, `branch`, `parent` (the Commit before it, or for a
Branch's first Commit the publication it was forked at; null when
unchanged), `root`, `message`, `created_at` and `merged_from`. `--expected
C` refuses `Conflict` unless the Branch's head is `C`, an id or a prefix of
8 or more characters resolved as `commit get` resolves it; the check is one
read before the Commit.
8 or more characters resolved as `commit get` resolves it. It is checked
before the Commit and again inside the publication's own transaction: a head
that moves after the first check is refused the same way, with nothing
committed, and is never merged with. `--force --expected C` replaces only
`C`.

| Refusal | When |
| --- | --- |
| `Conflict` | a path conflicts, or the head is not `--expected`; nothing is committed. It carries `commit` (the head), `conflicts` (the first 20 paths) and `conflicts_count` |
| `InvalidInput` | an `--expected` prefix several Commits start with (`matches`) |
| `Busy` | another control operation runs on the Workspace ([`control/registry.rs`](../../../../engine/crates/layerfs-daemon/src/control/registry.rs)) |
| `Unknown` | an earlier Commit's install was uncertain or failed (`detail.phase: "admission"`): the daemon keeps that custody and refuses new Commits; or the reply was lost |
| `Unknown` | an earlier Commit's outcome was unknown or its install failed, and the one resolution this Commit ran first did not settle it (`detail.phase: "admission"`, the reason in `detail`): the daemon keeps that custody and refuses new Commits; or the reply was lost |

After an uncertain Commit read `commit list` (a new head?) and
`workspace status`. A lost reply does not remove a published Commit.
Expand Down
5 changes: 4 additions & 1 deletion docs/architecture/core/compare-and-merge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ A conflict is decided, not left open: text files get marker blocks, binary or
type conflicts keep one side, and each path is listed with a `ConflictKind`.
`branch.merge` refuses a conflicted result; merge-on-commit installs it as the
Workspace's base and refuses the next Commit while a listed file still holds a
complete marker block ([Merge](merge.md)).
complete marker block ([Merge](merge.md)). The Workspace's view changes where
the merge changed it; a merge whose changes rows written after the capture
cover is not installed at all, clean or conflicted (`LiveConflict`,
[Commit](../../engine/commit/README.md#what-it-does)).

### Tree comparison

Expand Down
4 changes: 3 additions & 1 deletion docs/architecture/core/history/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ or any process, memory, socket or stdout/stderr state.
| --- | --- |
| Stack profile or scope differs | `Integrity("Commit context")` |
| Base moved, or head moved without `force` | `HeadMoved(MovedState)` with expected and actual head and base |
| Head moved, `force`, base unchanged | new Commit keeps `expected_head` as parent; `displaced` names the old head |
| `required_head` set and the Branch answers another head (its head Commit, else its base Layer), forced or not | `HeadMoved(MovedState)` |
| Head moved, `force`, base unchanged | new Commit keeps `expected_head` as parent; `displaced` names the head the transaction read. Commits between `expected_head` and it stay on its first-parent chain, so `displaced` and parent links reach them all (and keep them, for collection) |
| Branch advance matches no row | `HeadMoved`: the advance replaces only the head this transaction read (`commit_advance_branch` has a `head_commit_id` predicate), so a writer that moved the Branch meanwhile (a PostgreSQL lane connection lost inside the lane) publishes nothing over it |
| `candidate_root` equals the effective root | `UpToDate { head, root }` |
| Otherwise | `Committed { record, displaced: None }` |

Expand Down
Loading