import: an imported record never cites or resolves the receiver's own native document
Soul F1: the window left open by `inert_in_window` let a later imported record withdraw or cite the receiver's native follow-up. Admission now refuses an imported document that cites or resolves a native document of its own root (another root's native documents are cited as ever). Stale docs and the import help name the amended rule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
241a4d5584
commit
9958555d71
5 changed files with 39 additions and 4 deletions
|
|
@ -62,7 +62,7 @@ The file is a JSON array of 1 to 64 documents, each {\"kind\": <kind>, \"value\"
|
|||
Every key the schema does not know is refused (exit 2) with its path; nothing is sent. \
|
||||
After Committed or AlreadyAdmitted the batch is read back and compared with what was sent: `read back <n> equal`, or exit 5 with the ids and field paths that differ. A batch whose rulings or questions have in-force neighbours is held once: exit 6, the neighbours printed with a token, nothing sent. Run the same command with --seen <token> to admit it; a batch or --agent that changed needs a new token (a wrong one is exit 2).";
|
||||
|
||||
const IMPORT_HELP: &str = "Reads the giver's mind (it sends Query alone) and admits its receipts for the campaign into this one, one batch per source receipt, in order, each naming the giver's receipt in imported_from. It refuses unless the campaign is moved to this mind (exit 1), and when this mind already holds records under the campaign that it did not import from the giver (exit 1). A rerun after any stop resumes at the first batch this mind does not hold; it prints `imported <campaign> from <instance>: ... verified` only after comparing every document it holds with the giver's (exit 5 if one differs). Until it prints imported, this mind writes nothing else under the campaign; a write that collides stops the import with the refusal (exit 1). Exit 3 Unavailable (rerun), 4 the history cannot be replayed whole (a receipt over 64 documents, too many external referents, a receipt held in part). Only a Self run can run it: a Persona's traffic to a peer's huginn port is fenced.";
|
||||
const IMPORT_HELP: &str = "Reads the giver's mind (it sends Query alone) and admits its receipts for the campaign into this one, one batch per source receipt, in order, each naming the giver's receipt in imported_from. It refuses unless the campaign is moved to this mind (exit 1), and when this mind already holds records under the campaign that it did not import from the giver, except follow-ups and ideas it admitted after the import began, which stay in place and are named (exit 1). A rerun after any stop resumes at the first batch this mind does not hold; it prints `imported <campaign> from <instance>: ... verified` only after comparing every document it holds with the giver's (exit 5 if one differs). Until it prints imported, this mind writes nothing else under the campaign; a write that collides stops the import with the refusal (exit 1). Exit 3 Unavailable (rerun), 4 the history cannot be replayed whole (a receipt over 64 documents, too many external referents, a receipt held in part). Only a Self run can run it: a Persona's traffic to a peer's huginn port is fenced.";
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "huginn", about = "Huginn's mind: whoami, view, query, recipes, persona, admit, import, recall, schema", arg_required_else_help = true)]
|
||||
|
|
|
|||
|
|
@ -511,7 +511,8 @@ fn derive(docs: &Docs<'_>, mind: &Slug) -> Vec<PipelineDocument> {
|
|||
}
|
||||
|
||||
/// An import replays a campaign's history: every document is rooted at a campaign this mind holds
|
||||
/// or the batch carries, and the mind holds no native write under that root, so the source's own
|
||||
/// or the batch carries, and the mind holds no native write under that root but a follow-up or idea
|
||||
/// admitted after the import began (`inert_in_window`) that no imported document cites or resolves, so the source's own
|
||||
/// derivations stand alone and no native rule is bypassed for a record the mind could have written.
|
||||
/// Instance-rooted records (hand-offs, stewardships, runs, memories, thoughts) are never history
|
||||
/// to replay.
|
||||
|
|
@ -522,6 +523,11 @@ fn refuse_unscoped_import(docs: &Docs<'_>) -> Result<(), MindRefusal> {
|
|||
if docs.find(PipelineKind::Campaign, &campaign).is_none() || docs.root_holds_native_write(root) {
|
||||
return Err(MindRefusal::ImportOutsideCampaign { root: root.into() });
|
||||
}
|
||||
// The receiver's native follow-ups and ideas stand beside a replay; the replay never reaches them.
|
||||
// Another root's native documents may be cited, as ever; only this root's are the receiver's own.
|
||||
if citations(&staged.document).iter().any(|(_, referent)| root_and_local(&referent.id.0).0 == root && docs.is_native(referent.kind, &referent.id.0)) {
|
||||
return Err(MindRefusal::ImportOutsideCampaign { root: root.into() });
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ impl<'i> Docs<'i> {
|
|||
self.batch.iter().find(|staged| staged.kind == kind && staged.key == id).map(|staged| &staged.document)
|
||||
}
|
||||
|
||||
/// Whether the mind holds this document as its own write rather than an import.
|
||||
pub(crate) fn is_native(&self, kind: PipelineKind, id: &str) -> bool {
|
||||
self.image.id_of(kind, id).filter(|row| self.visible(*row)).is_some_and(|row| self.image.row(row).view.admission.provenance.imported_from.is_none())
|
||||
}
|
||||
|
||||
pub(crate) fn in_image(&self, kind: PipelineKind, id: &str) -> Option<&PipelineDocument> {
|
||||
self.image.id_of(kind, id).filter(|row| self.visible(*row)).map(|row| &self.image.row(row).view.document)
|
||||
}
|
||||
|
|
@ -68,7 +73,7 @@ impl<'i> Docs<'i> {
|
|||
self.in_batch(kind, id).or_else(|| self.in_image(kind, id))
|
||||
}
|
||||
|
||||
/// Whether this mind holds a native write under `root` (the batch is not asked).
|
||||
/// Whether this mind holds a native write under `root` that an import must not meet (the batch is not asked).
|
||||
pub(crate) fn root_holds_native_write(&self, root: &str) -> bool {
|
||||
self.image.root_holds_native_write(root)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -613,6 +613,30 @@ fn an_import_resumes_past_a_follow_up_or_idea_the_receiver_wrote_after_it_began(
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_import_never_cites_or_resolves_a_follow_up_the_receiver_wrote() {
|
||||
let q1 = id("question", "Q1");
|
||||
let mut recv = receiver();
|
||||
committed(import_from_kiko(&mut recv, vec![campaign(&[REPO]), question("Q1", &["A", "B"], "A")]));
|
||||
let native = follow_up("FU-N", r(K::Question, &q1));
|
||||
let native_ref = r(K::FollowUp, &pipeline_key(&native).unwrap());
|
||||
committed(admit(&mut recv, vec![native]));
|
||||
let before = head(&recv);
|
||||
// An imported record that withdraws the receiver's own follow-up mixes a replay into her work.
|
||||
assert_eq!(
|
||||
refusal(import_from_kiko(&mut recv, vec![resolution(native_ref.clone(), ResolutionOutcome::Withdrawn { reason: "x".into() })])),
|
||||
MindRefusal::ImportOutsideCampaign { root: CAMPAIGN.into() }
|
||||
);
|
||||
// Nor may one cite it.
|
||||
assert_eq!(
|
||||
refusal(import_from_kiko(&mut recv, vec![follow_up("FU-I", native_ref.clone())])),
|
||||
MindRefusal::ImportOutsideCampaign { root: CAMPAIGN.into() }
|
||||
);
|
||||
assert_eq!(head(&recv), before);
|
||||
// Her follow-up still closes natively.
|
||||
committed(admit(&mut recv, vec![resolution(native_ref, ResolutionOutcome::Withdrawn { reason: "x".into() })]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_replay_under_another_source_is_no_replay() {
|
||||
let mut recv = receiver();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ pub enum MindRefusal {
|
|||
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 which this mind holds a native write under.
|
||||
/// 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 },
|
||||
|
|
|
|||
Loading…
Reference in a new issue