Huginn/crates/huginn-mind/src/refusal.rs

251 lines
12 KiB
Rust
Raw Normal View History

Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
//! Typed refusals of the organ. A refusal is data with a field an agent can
//! act on, never a transport error: the outcome carries it, the wire (Cut 10)
//! serialises it, the tools (Cut 13) show it.
use cultnet_rs::SelectionRefusal;
use eureka_pipeline::{PipelineKind, PipelineRef, PipelineRefusal, Short};
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
/// Every way a mind refuses. `Document` wraps the leaf's four (bounds,
/// formats, key identity, foreign type); the rest are the organ's: store
/// identity, epoch, ownership, batch shape, references, and every cross-field
/// and cross-document rule of admission.
Take the sequenced keys and make in force mean what it says The pin moves to Epiphany `d5a36c2a`, where a resolution's key ends in its per-subject sequence and a stewardship's in its per-(instance, repo) one. Two fields arrive with it, so `stewardship` and `resolution` in the fixtures set `sequence: 1` and `stewardship_n`/`resolution_n` say otherwise when a test needs a second record. Every literal key that gained `.n1` moved with it, `id_of` included. The rules the sequence was for: - `in_force` is recursive. A document is in force when no resolution that is itself in force names it, so a withdrawn resolution stops closing its subject. The old one-level version counted a withdrawal as if it still stood, which is half of why a reopened subject could not be resolved again. - The other half was A10. `refuse_collisions` no longer has a `Resolution` arm: a resolution key is not one-per-subject any more, so a collision on it means what it means for every other kind, and whether a subject is closed is A8's question. - A8 asks it, for both sequenced kinds, in the same two steps. The sequence is the writer's and must be the previous plus one over image and batch, counting every record of that scope but this document -- `ResolutionOutOfSequence`, `StewardshipOutOfSequence`. Then no record of that scope may still be in force -- `AlreadyResolved`, `AlreadyStewarded`. With both, at most one stewardship of a repo stands on a mind, which is what `stewardship_of` has been assuming. - Q19 A is enforced rather than described: a resolution whose subject is a resolution of a resolution is `IncompatibleResolution`. A withdrawal cannot be withdrawn; a closure is reinstated by resolving the subject again. - `derive` sets a sequence on each write it makes, from the same image the rule reads. Two existing tests move with the rules. `subject_resolves_at_most_once` is now `a_subject_with_a_resolution_in_force_refuses_another` and separates the two refusals. The hand-off test's last case used to be an A4 collision between a batch's own stewardship and the derived one; the derived write now takes the sequence after the batch's, so there is nothing left to collide and the batch is refused as out of sequence instead. 31 tests, 0 warnings; `cargo check --workspace` clean. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:28:17 +02:00
///
/// The two sequenced kinds refuse in the same pair of shapes: an
/// `OutOfSequence` when the writer's `sequence` is not the previous plus one,
/// and `AlreadyResolved`/`AlreadyStewarded` when a record of that scope is
/// still in force.
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub enum MindRefusal {
Document(PipelineRefusal),
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
ForeignInstance { declared: String, mind: String },
MissingIdentity,
ForeignEpoch { found: String, expected: String },
ForeignStore { r#type: String },
MindAlreadyOwned { path: String },
BatchSize { actual: u32 },
IdentityCollision { kind: PipelineKind, id: String },
MissingReference { kind: PipelineKind, id: String },
/// `closed_by` is the resolution in force: to correct the closure, withdraw it (a resolution of `closed_by`), then resolve `subject` again at the next sequence.
AlreadyResolved { subject: String, closed_by: String },
Take the sequenced keys and make in force mean what it says The pin moves to Epiphany `d5a36c2a`, where a resolution's key ends in its per-subject sequence and a stewardship's in its per-(instance, repo) one. Two fields arrive with it, so `stewardship` and `resolution` in the fixtures set `sequence: 1` and `stewardship_n`/`resolution_n` say otherwise when a test needs a second record. Every literal key that gained `.n1` moved with it, `id_of` included. The rules the sequence was for: - `in_force` is recursive. A document is in force when no resolution that is itself in force names it, so a withdrawn resolution stops closing its subject. The old one-level version counted a withdrawal as if it still stood, which is half of why a reopened subject could not be resolved again. - The other half was A10. `refuse_collisions` no longer has a `Resolution` arm: a resolution key is not one-per-subject any more, so a collision on it means what it means for every other kind, and whether a subject is closed is A8's question. - A8 asks it, for both sequenced kinds, in the same two steps. The sequence is the writer's and must be the previous plus one over image and batch, counting every record of that scope but this document -- `ResolutionOutOfSequence`, `StewardshipOutOfSequence`. Then no record of that scope may still be in force -- `AlreadyResolved`, `AlreadyStewarded`. With both, at most one stewardship of a repo stands on a mind, which is what `stewardship_of` has been assuming. - Q19 A is enforced rather than described: a resolution whose subject is a resolution of a resolution is `IncompatibleResolution`. A withdrawal cannot be withdrawn; a closure is reinstated by resolving the subject again. - `derive` sets a sequence on each write it makes, from the same image the rule reads. Two existing tests move with the rules. `subject_resolves_at_most_once` is now `a_subject_with_a_resolution_in_force_refuses_another` and separates the two refusals. The hand-off test's last case used to be an A4 collision between a batch's own stewardship and the derived one; the derived write now takes the sequence after the batch's, so there is nothing left to collide and the batch is refused as out of sequence instead. 31 tests, 0 warnings; `cargo check --workspace` clean. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:28:17 +02:00
ResolutionOutOfSequence { subject: String, expected: u32, actual: u32 },
AlreadyStewarded { repo: String },
StewardshipOutOfSequence { repo: String, expected: u32, actual: u32 },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
IncompatibleResolution { subject_kind: PipelineKind, outcome: String },
Re-derive what the batch derived, and stop re-raising an earlier record Two rules Soul's follow-up pass falsified, both in admission. A batch that derives a write could not be replayed. `derive` set every derived sequence to `latest + 1` over an image that already held the first admission's derived record, so the second admission produced a different document, A8 refused it -- `AlreadyResolved` on the source side, and `AlreadyStewarded` on the receiving one -- and A9 never saw the digest it would have recognised. `derive` now reproduces the record it already made when image or batch holds one, found by what the derivation writes into it: a resolution `Answered` by this ruling, a withdrawal whose reason is this hand-off's key, an assignment whose note is. The same document comes back byte for byte, A9 answers with the first receipt, and only a batch that never landed takes `latest + 1`. A withdrawal could re-raise an earlier record over a later one, which is the rationale Q19 A's cap rests on and the cap alone does not carry. Withdrawing a resolution puts its subject back in force, so a repo handed away and handed back could have the hand-off's withdrawal withdrawn and stand under two assignments at once; a supersession withdrawn while the revision that superseded it stood left two revisions in force, which is what the finding rule reads for its invariant vocabulary. `WouldReinstateOverLater` refuses that: the record the withdrawal would reinstate, against anything in force and later in the scope that record is sequenced in -- `(instance, repo)` for a stewardship, the subject for a resolution, the campaign for a target and the cut for a cut spec. Four tests, one per fix and kind: the ruling's resolution and both sides of a hand-off replayed to `AlreadyAdmitted` with the first receipt and no second receipt in the store; the retaken repo and the superseded revision refused, with the later record still the only one in force. Four more tests for rules the code already held and the suite could not tell from weaker ones: a sequence gap refuses on both sequenced kinds rather than only a taken sequence; the latest sequence counts the batch as well as the image; the Q19 cap reads a chain landing in one batch; and the hand-off's second withdrawal of one assignment takes the next sequence, not `1`. 41 tests, 0 warnings. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 20:21:04 +02:00
WouldReinstateOverLater { subject: String, later: String },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
CitesResolvedDocument { kind: PipelineKind, id: String },
EmptySupersession,
UnknownSupersessor { id: String },
/// A consolidation and the supersession of the memory it consumes come together: `memory` consolidates `consumed`, or is named as superseding it, without the other half in the batch.
UnpairedConsolidation { memory: String, consumed: String },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
RevisionWithoutSupersession { kind: PipelineKind, revision: u32 },
DuplicateLabel { field: String, label: String },
InvalidOptions { question: String },
InvalidChoice { ruling: String, choice: String },
QuoteWithoutOperator { ruling: String },
/// A `desk_answer` reached a door other than the desk's (an admit, an import or a derivation): `id` is its key.
DeskAnswerOutsideDesk { id: String },
/// A desk request the Mind cannot read as an answer: `field` names the part (the fork, `answered_at`, an answer carrying neither choice nor note, a malformed answer id).
DeskRequestInvalid { field: String },
/// The desk's `request_id_conflict` (CultLib PR #72): this `(answerer, request_id)` already bound another body. Nothing is stored.
DeskRequestIdConflict { request_id: String },
/// `campaign` names the refused document: a campaign, or a target revision that empties its predecessor's repos.
Close the epoch record, the minted leaf refusal and the nested resolution Soul's Cut 8 pass found three rules the code only half held and one document that promised more than the crate does. The opener's step 3 said "exactly one epoch record at the current epoch" and checked neither the count nor the key: a record keyed anything at all was read as the epoch record, and a second one was never looked at, so a current record beside a foreign one passed or refused on nothing but the order the store returned them in. Step 3 now counts before it reads, refuses a record under any key but the epoch, and names the defect in `found`: the stored epoch, the offending key, or the count. The campaign row minted `PipelineRefusal::FieldBound` for an empty `repos`. The organ does not get to invent the leaf's refusals; an empty `repos` is admission's own rule and is now `MindRefusal::EmptyRepos`. The matrix admitted `Withdrawn` on a resolution, which made a subject resolvable twice over: withdraw the resolution and the subject is open again. A subject resolves at most once, and a resolution is not itself a subject, so `resolution` joins `campaign`, `cut_report`, `verdict`, `instance` and `hand_off` as not resolvable. The key grammar still spells a resolution of a resolution; admission refuses it here. Self's default ruling on Q17, standing until the operator rules. `README.md` and `AGENTS.md` claimed CultNet publication and a Qdrant connection in the present tense and called the store `.cc`. The daemon is a stub, nothing connects to Qdrant, and the live crate writes `mind.redb`. They say so now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:53:08 +02:00
EmptyRepos { campaign: String },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
RepoNotInCampaign { repo: String },
UnknownDependency { cut: String },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
CutReportWithoutSpec { report: String },
SpecMismatch { field: String },
RangeOutsideCommits { head: String },
FalsifiedClaimWithoutConfirmedFinding { claim: String },
UnprovenClaimWithConfirmedFinding { claim: String },
PromiseWithoutVerdict { promise: String },
UnknownMutationLabel { label: String },
FindingWithoutRange,
FindingWithoutEvidence,
UnknownInvariant { label: String },
NotStewarded { repo: String },
/// `campaign` moved to mind `to`: nothing is written under its root here any more, whoever asks.
CampaignMoved { campaign: String, to: String },
/// A campaign moves to another mind, never to the one that gives it up.
MoveToSelf,
/// A Moved resolution is final; withdrawing it would leave two minds keeping the campaign.
MoveIsFinal,
/// An import names this mind as its source.
ImportFromSelf,
/// An import carries a document of `root`, which is no campaign this mind holds or the batch carries, or under which this mind holds a native write that is not a follow-up or idea admitted after the import began, or which cites or resolves one of its own native documents.
ImportOutsideCampaign { root: String },
/// A move names `root`, this mind's own instance: an instance's records are not a campaign's to freeze.
MoveOfInstanceRoot { root: String },
/// An import lists `id` as external, but this mind (or the batch) holds it.
ExternalPresent { id: String },
/// The persona document fails the published schema: `path` is the
/// document location (a key the schema does not declare is `*`) and
/// `message` the schema keyword that failed. Never the offending value.
PersonaInvalid { path: String, message: String },
/// The document's `personaId` is not this mind's instance, which is
/// `instance`.
PersonaForeign { instance: String },
/// The put's `expected_updated_at` is not the stored document's
/// `updatedAt`, which is `stored` (none when no persona is stored).
PersonaStale { stored: Option<String> },
/// The document's `provenance.authority` is not `canonical`: a projection
/// or an import is not the mind's persona.
PersonaNotCanonical,
/// A run claims work another run in force already holds: `item` is the
/// claimed document's id and `run` the id of the run that holds it.
AlreadyClaimed { item: String, run: RunId },
/// A run of hers opens, or is reinstated, while another in-force run of
/// hers of the same instance and turn is live: `run` is the holder's id
/// (ruling one-live-self-run).
AlreadyLive { run: RunId },
/// The one refusal a mind never raises: the answer exceeds the largest
/// body the organ will deliver by any plane, one send or a deferred body.
/// It lives here because a refusal rides the response schema and there is
/// one of those, so a client reads it the way it reads every other refusal
/// rather than parsing a second vocabulary. `bytes` is the encoded answer
/// (the payload, not its envelope) and `limit` is the largest body the
/// daemon defers, both so a caller can narrow its own request; nothing is
/// truncated or paginated on its behalf. The daemon owns it and its
/// deferral bound decides it; no rule of the mind is involved.
Refuse an answer that will not fit, by name A reply larger than one send could carry was handed to the hub anyway. The hub refused it, the loop printed the error and served past, and the client waited for an answer nothing would ever send. A real-sized read was lost in silence, which is the one thing this surface promises not to do: a refusal is typed, and that has to hold at every size. `within_window` now encodes the reply and measures it against the window this module configures, before a send it can already see will fail. Over the limit, the answer becomes `MindRefusal::ResponseTooLarge { bytes, limit }` on the response schema, reaching the client exactly as every other refusal does, with the encoded size and the limit so a caller can narrow its own request. Nothing is truncated, paginated or retried. The arithmetic, measured rather than estimated. One `PipelineCutSpec` with every list at the leaf's bound -- 256 file changes, 64 deletes, keeps, adds, builds, tests, negative checks and operator checks, a full authority map and structural delta -- is about 980,000 bytes of field content. As a `View` response, base64 in the operation envelope and MessagePack around that, it encodes to 1,315,551 bytes. The window is `MAX_PENDING_RELIABLE_PACKETS` (1024) times `MAX_FRAGMENT_BYTES` (1200), so 1,228,800. A single document at the leaf's own bounds therefore does not fit, by 86,751 bytes. The window's values are unchanged by ruling: what a list read should return is an open question, and raising the window would bake multi-megabyte answers in as ordinary traffic before that question is answered. The module documentation states 1,228,800 as the current bound rather than as a design target. The test admits two cut specs into a real mind: one at 256 file changes and one narrowed to 180, whose view encodes to 1,189,495 bytes. Over one loopback session the query, the wide view and the open items are each refused by name, and the narrow view is then delivered whole. Both halves are load-bearing: the delivered answer sits 39,305 bytes under the limit, so `D22` and `D22L`, which shrink the configured window, break it. `D20` removes the gate, `D20L` measures against a larger number than the hub carries, `D20L2` and `D20L3` collapse the two fields the refusal reports, `D21` sends it as a failure envelope instead, and `D22`, `D22L` and `D22L2` shrink each half of the window the gate trusts. All eight die. The whole suite, 51 entries and M0, is green. Two reads pipelined on one session are still not both answered, and the module documentation says so: the window is per session and counts what is unacknowledged, so a second large reply sent before the first is acknowledged fails to send even though each passes the gate alone. The gate measures one answer against the window, not against what the session still has room for. That is not fixed here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 00:08:10 +02:00
ResponseTooLarge { bytes: u64, limit: u64 },
/// A selection the substrate or the organ's value door refused: `field`
/// is the selection field the client sent, `value` the offending part.
SelectionInvalid { field: String, value: Option<String>, message: String },
/// A cursor that does not decode, does not belong to this selection or
/// was not minted by this process, or names a snapshot this mind has not
/// reached.
CursorInvalid { message: String },
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
Unavailable { detail: String },
}
impl std::fmt::Display for MindRefusal {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "mind refusal: {self:?}")
}
}
impl std::error::Error for MindRefusal {}
impl From<PipelineRefusal> for MindRefusal {
fn from(refusal: PipelineRefusal) -> Self {
Self::Document(refusal)
}
}
/// The one total mapping from the substrate's refusals, with no wildcard arm.
/// `CursorStale` is unreachable: the organ answers at the cursor's own `asOf`,
/// so a stale refusal is an organ defect and says so. `ReferenceOutsideTarget`
/// is integrity: A7 admits only referents of the declared kind, so a stored
/// edge outside its target means the store is not what admission wrote.
impl From<SelectionRefusal> for MindRefusal {
fn from(refusal: SelectionRefusal) -> Self {
match refusal {
SelectionRefusal::Invalid(invalid) => {
Self::SelectionInvalid { field: invalid.field, value: invalid.value, message: invalid.message }
}
SelectionRefusal::CursorInvalid { message } => Self::CursorInvalid { message },
SelectionRefusal::CursorStale { as_of, current } => Self::Unavailable {
detail: format!("cursor_stale: the organ answers at the cursor's asOf ({as_of}), yet was asked at {current}"),
},
reference @ SelectionRefusal::ReferenceOutsideTarget { .. } => {
Self::Unavailable { detail: format!("stored reference outside its declared target: {reference}") }
}
}
}
}
/// The id of a run: a full pipeline id of kind Run. A refusal that names a
/// holder carries one, so a reader gets a run's id from the wire only if it
/// parses as one; a peer cannot fill it with any other string. The only ways
/// in are `TryFrom<String>`, which every deserialized value passes, and the
/// admission rules, which name a run the mind holds. The error is a fixed
/// message: it never echoes the offered value.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(try_from = "String", into = "String")]
pub struct RunId(String);
impl RunId {
/// The id as text.
pub fn as_str(&self) -> &str {
&self.0
}
/// The reference to the run this id names.
pub fn to_ref(&self) -> PipelineRef {
PipelineRef { kind: PipelineKind::Run, id: Short(self.0.clone()) }
}
/// The key of a run the mind holds, which admission already held to the
/// grammar when it admitted the run.
pub(crate) fn held(key: &str) -> Self {
Self(key.into())
}
}
impl TryFrom<String> for RunId {
type Error = &'static str;
fn try_from(id: String) -> Result<Self, Self::Error> {
let candidate = PipelineRef { kind: PipelineKind::Run, id: Short(id) };
candidate.validate_ref().map_err(|_| "not a run id")?;
Ok(Self(candidate.id.0))
}
}
impl From<RunId> for String {
fn from(id: RunId) -> Self {
id.0
}
}
#[cfg(test)]
mod tests {
use super::*;
use cultnet_rs::SelectionInvalid;
/// The mapping is the organ's word on each substrate refusal: a bad
/// selection and a bad cursor cross as themselves, and the two the organ
/// is built never to raise cross as integrity faults, not as anything a
/// client could act on.
#[test]
fn each_substrate_refusal_maps_to_one_organ_refusal() {
let invalid = SelectionInvalid { field: "keys".into(), value: Some("x".into()), message: "no".into() };
assert_eq!(
MindRefusal::from(SelectionRefusal::Invalid(invalid)),
MindRefusal::SelectionInvalid { field: "keys".into(), value: Some("x".into()), message: "no".into() }
);
assert_eq!(
MindRefusal::from(SelectionRefusal::CursorInvalid { message: "bad".into() }),
MindRefusal::CursorInvalid { message: "bad".into() }
);
assert!(matches!(
MindRefusal::from(SelectionRefusal::CursorStale { as_of: 3, current: 4 }),
MindRefusal::Unavailable { detail } if detail.contains("cursor_stale")
));
let outside = SelectionRefusal::ReferenceOutsideTarget {
from_schema_id: "a".into(),
from_key: "k".into(),
role: "answers".into(),
to_schema_id: "b".into(),
to_key: "j".into(),
};
assert!(matches!(MindRefusal::from(outside), MindRefusal::Unavailable { .. }));
}
/// A run id from the wire is a run's id or nothing: other kinds' ids and
/// arbitrary strings are refused, and the refusal never repeats the text.
#[test]
fn a_run_id_is_a_run_key_and_never_any_other_string() {
let held = "eureka:run:mind-1";
let id: RunId = serde_json::from_str(&format!("\"{held}\"")).unwrap();
assert_eq!((id.as_str(), serde_json::to_string(&id).unwrap()), (held, format!("\"{held}\"")));
assert_eq!(id.to_ref(), PipelineRef { kind: PipelineKind::Run, id: Short(held.into()) });
for bad in ["not even a key", "eureka:cut_spec:cut-x.r1", "eureka:run:", "eureka:run:a:b", ""] {
let error = serde_json::from_str::<RunId>(&format!("\"{bad}\"")).unwrap_err().to_string();
assert!(error.contains("not a run id") && (bad.is_empty() || !error.contains(bad)), "{error}");
}
let wire = serde_json::from_str::<MindRefusal>(r#"{"AlreadyLive":{"run":"not even a key"}}"#);
assert!(wire.is_err());
}
}