diff --git a/docs/plans/prepared-effect-input-carry.md b/docs/plans/prepared-effect-input-carry.md new file mode 100644 index 00000000000..55a41aa5f0c --- /dev/null +++ b/docs/plans/prepared-effect-input-carry.md @@ -0,0 +1,205 @@ +# Prepared effect input carried into nullary warm rows (PR two of the #10994 chain) + +ADJUDICATED AND IMPLEMENTED. The model below was sent to eager-raven-113, fierce-lark-661 and +bright-boar-435 before any code was written; all three approved both decisions (2026-09-14), each +with one condition, and every condition is discharged in the landed change: + +- the carried value's DISPOSITION is printed on the floor's phase line beside its content digest, + so a run whose carrier refused is diagnosable rather than silent (bright-boar's condition on + Decision 1); +- `std.materialization_ladder` is cited IN SOURCE, not only here: the four obligations are typed + values in `v2.workflow.floor_prepared_effect_input_ladder`, decided by the ladder's own fold and + exercised by `v2.test.floor_prepared_effect_input_ladder` (the condition both fierce-lark and + eager-raven attached to Decision 2); +- the binding's absence after the tier is cleared has its own control (eager-raven's condition b). + +Two things the evidence found that this document's first cut did not, recorded because both +changed the implementation rather than the prose: + +1. `run_in_context` calls `call_function` DIRECTLY, reaching neither the cross-claim tier nor the + prepared-input binding. A control that evaluated the producer that way asserted a value + RECOMPUTE also produces — the decoration DESIGN section 4b names. The controls now evaluate + through an ordinary call site and assert an OBSERVED SERVE from the tier's own hit observer. +2. With that fixed, the changed-carrier RED went red on the REAL implementation: the + producer-to-carry map held a CLONE of the carry, so re-binding the acquisition left the key + unchanged and the producer was served a value derived from the previous carrier. It now holds + the acquisition NODE and reads its current binding at every key derivation. + +## The gap, stated at the floor's own vocabulary + +`v2.workflow.floor_pure_producer_share` admits two fill dispositions and only two: + +- a WARM row is NULLARY and preparation-forceable — `install_pure_producer_share` evaluates it + once in a Hermetic frame over its own module scope and the fill is billed to preparation; +- a CLAIM-FORCED row has claim-shaped arguments, so it fills inside the fold on first touch and + the paying claim carries the fill. + +A producer whose value depends on one effectful read of a committed carrier fits neither. It +cannot be warmed as a nullary pure row, because `store_cross_claim_pure_memo` is keyed on +(resolved fn node, portable argument row) and an effect-dispatching nullary call contributes +NOTHING to that key — the read's content is invisible to the key, which is the ctx-blind homonym +class in its content form: two different carrier contents would share one entry. And as a +claim-forced row it re-derives per claim, which is the rostered +`shared_precondition_re_derived_once_per_claim_frame`. + +The live instance: `gunbc.roadmap_authority.roadmap_authority_projection` — one +`Filesystem.Read` of `dag/gunbc/roadmap/roadmap_acceptance_event_history.jsonl` (16 lines, +~10 KB) followed by a pure ~186 ms fold, demanded by seven required-lane claims and by #10994, +whose current blocker is an enrolment margin RED (306 ms then 279 ms against a 302 ms margin) +sitting on top of exactly this shared precondition. + +## One fact that makes the carry legitimate rather than a memo of an effect + +Hermetic mode already classifies this read as INPUT ACCESS, not a host effect: the +checkout-input carve-out in `v1_interpreter::eval_service_call` dispatches a readonly +`Filesystem.Read`/`List` WET when `hermetic_checkout_input_disposition` confirms the path under +the checkout root. The carrier is such a path. So the value is a function of the commit the run +prepared — constant for the whole prepared subject — and carrying it once is not caching an +effect, it is binding an input the run already holds fixed. Anything the disposition cannot +confirm (out-of-root, `.git`/`target`, unresolvable) is refused by that existing wall and is +therefore never carryable here either. + +## The model + +Two declarations in `v2.workflow.floor_pure_producer_share`, beside the two existing rosters. + + type PreparedEffectInput { + // The nullary declaration whose evaluation ACQUIRES the input. Resolved to a fn node at + // preparation, exactly like every rostered producer — never admitted by bare name. + acquisition: String + // Why the acquisition is a run-constant checkout input rather than host state, and the + // consumers the carry serves. Evidence fields, same discipline as RefusedShareCandidate: + // name the instrument, never transcribe its output. + ground: String + measurement: String + } + + type CarriedInputWarmRow { + producer: String // the pure fold, resolved to its fn node + parameter: String // the named parameter the carried value fills + input: String // which PreparedEffectInput.acquisition supplies it + measurement: String + } + + data floor_cross_claim_prepared_effect_inputs: List + data floor_cross_claim_carried_input_warm_rows: List + +### What preparation does + +`install_pure_producer_share` gains one phase, ordered BEFORE the existing warm loop: + +1. Resolve each `acquisition` to its fn node in a frame over the prepared subject (the existing + `floor_authority_frame`, unchanged — Hermetic). An unresolved spelling or a module outside the + subject is a stale row and STOPS THE LINE, exactly as a stale warm row does today. +2. Refuse at install any acquisition whose declaration is not nullary: a carried input with + arguments is a different concept and must not be smuggled in under this one. +3. Evaluate it ONCE, under `observe_shared_build`, so the acquisition is billed to preparation + and adjudicated by the same preparation refusal as every other shared build. +4. Reify the value totally to `PortableValue` — the SAME total walk publication already performs + — and take its content identity as the structural digest over that form (`std.content_hash` + `Fnv1a64Structural`). Printed on the `[floor-phase]` line, so the receipt says WHICH content + was carried, not merely that something was. +5. Bind (fn node → carried `Value`) for the run's prepared subject, cleared with the tier by + `clear_cross_claim_pure_memos`. + +Then, for each `CarriedInputWarmRow`, warm the producer with a ONE-ELEMENT argument row +`[(parameter, carried value)]` instead of `[]`. Everything downstream is the existing mechanism +untouched: the store keys on (producer fn node, portable argument row) and serves only after the +full portable argument row verifies structurally equal. + +### What a claim does + +- A claim's call of the ACQUISITION declaration is served the carried value instead of + re-dispatching the read. This is the only genuinely new serve path, and it is deliberately NOT + the pure memo: the pure memo refuses any call that dispatched an effect (`effect_dispatch_count` + guard), and that refusal is correct and stays. Admission here is a separate, roster-declared + binding keyed on resolved fn-node identity, installed for one prepared subject. +- A claim's call of the PRODUCER passes the same value it just received, so the portable argument + row equals the one preparation stored, and the existing cross-claim tier serves it — no new + keying, no new retention, no new lookup rule. + +### Why content identity is not a new mechanism + +The carried value IS the key material: a changed carrier content produces a different portable +argument row, `cross_claim_portable_args_match` fails, and the claim recomputes. Stale serve is +therefore unwritable rather than guarded — the §5 preference for construction over validation. +Roster identity is the resolved fn node on both halves (acquisition and producer), so the +bare-name homonym class stays closed exactly as review 57446 closed it. + +## Refusal arms (never an empty default) + +| state | disposition | +|---|---| +| acquisition module outside the prepared subject | `PreparedEffectInputModuleOutsideSubject` — line stop | +| acquisition spelling resolves to no declaration | `PreparedEffectInputUnresolved` — line stop | +| acquisition declaration is not nullary | `PreparedEffectInputNotNullary` — line stop | +| acquisition evaluation errors (read refused, hermetic refusal, parse error in the fold) | `PreparedEffectInputAcquisitionFailed` — line stop, carrying the interpreter's own located error | +| acquired value fails total reification | `PreparedEffectInputNotPortable` — line stop, with the located path/kind from the refusal itself | +| carried-input warm row naming an unknown input | `CarriedInputWarmRowInputUnknown` — line stop | +| warm evaluates but the store refuses it | the existing `PureProducerShareWarmNotStored` — line stop | + +One arm is deliberately NOT a floor refusal, and it is the one worth arguing about: when the +acquisition SUCCEEDS and returns its domain type's own refusal arm (here +`RoadmapAcceptanceEventHistoryLoadRefused`), the floor carries that value faithfully and every +claim receives the identical typed refusal it would have computed for itself. The floor does not +read domain types and must not decide that one variant of a caller's coproduct means "stop". The +alternative — the floor stopping the line on a refusal arm — would require the floor to know +`gunbc.roadmap_authority`'s vocabulary, which is the layer inversion §3 forbids. Stated here as a +deliberate divergence so it is decided rather than discovered. + +## Home in the materialization domain (§3b), and one stated divergence + +This inhabits the materialization / carried-value home: a computation identity (the resolved +declaration) joined to declared inputs (the carried value's content digest), a provider whose +scope reaches the demands' least common visible ancestor (preparation, which is the LCA of the +seven claims), a key representing every declared input the result depends on, and retention +spanning exactly the obligated lifetime (one prepared floor run). §2's ordering is respected in +the direction it demands: the demand graph is minimized FIRST — the repetition is authored +duplication whose shared-state ancestor is preparation, so the repair is the CARRY, and the +existing cross-claim tier is merely where the carried value is held. + +The divergence, stated: this does not mint a new `std.materialization_provider.ArtifactRequest` +variant. `ArtifactRequest` keys durable, cross-run artifacts by identity digest with a realization +receipt naming the provider; the carried input is an in-process value bound for the lifetime of +one prepared subject, with no store, no path, and no cross-run reuse. Minting a variant there +would put a run-scoped binding into the durable-artifact algebra. If the reviewers read that the +other way, the alternative is a real one and this is the decision to take before code. + +## Evidence + +### Executed at fixture grain, through the real `install_pure_producer_share` path + +`cargo test --release -p v1-compiler --lib pure_producer_share` — 17 passed, 0 failed. Five of +them are this change's: + +- the input is acquired ONCE and its producer warmed over it, with the producer then SERVED + (asserted from the tier's hit observer, not from the value); +- **the discriminating RED**: a changed carrier content is not served the value derived from the + old one. Discrimination receipt — with `cross_claim_key_args` returning `None` (the + empty-argument-row implementation this control targets), this test FAILS; with the real + implementation all 17 pass; +- the prepared-input binding is absent after the tier is cleared, and the producer answers for + itself again; +- a carried row naming an input nobody prepares stops the line; +- a non-nullary acquisition is refused. + +### Still owed at live grain (stated as owed, not as done) + +## Evidence plan (the live arm) + +1. **Identical verdict.** The seven required-lane claims plus #10994's forecast witness produce + the same verdicts with the rows enrolled as without. A carry that changes a verdict is a + defect, not a speedup. +2. **Present-vs-absent, per row, on one tree.** Two `workflow_dispatch` runs on a branch ref + pinned to an exact sha (the corrected instrument recorded in the roster header: a pushed side + branch triggers nothing, and a PR pair measures two different merge refs), reading + `required_floor_claim_cost.tsv` and the `[floor-shared-fill]` ledger. Admission is + serve-below-recompute at identity grain; a row that does not clear it is withdrawn into + `floor_cross_claim_refused_candidates` rather than defended by a family aggregate. +3. **No stale serve (the discriminating RED).** A control that mutates the carrier's content and + shows the previously carried value is NOT served: the portable argument row differs, the + producer recomputes, and the verdict follows the new content. Red goes green only by the key + actually carrying content identity — an entry keyed on the empty argument row passes the happy + path and fails this control. +4. **Acquisition is dispatched once.** The effect-dispatch count over a floor run is 1 for the + carrier read with the rows enrolled, N without. diff --git a/src/v1/stage0/src/cli_run/required_floor_runner.rs b/src/v1/stage0/src/cli_run/required_floor_runner.rs index 3677788aa88..8233d520544 100644 --- a/src/v1/stage0/src/cli_run/required_floor_runner.rs +++ b/src/v1/stage0/src/cli_run/required_floor_runner.rs @@ -4121,6 +4121,20 @@ pub(crate) fn install_pure_producer_share( "{FLOOR_PURE_PRODUCER_SHARE_MODULE}.floor_cross_claim_pure_producers_claim_forced" ), )?; + // The two carried-input rosters are decoded HERE, beside the other two, because their + // producers are part of the ADMITTED population: admission is one node set, and a producer + // that warms into the tier but is not admitted would store nothing while the receipt read + // green. The roster's own wall refuses a producer standing in both a plain roster and a + // carried-input row, so the union is unambiguous by construction. + let prepared_inputs = floor_decode_prepared_effect_inputs( + &roster_frame, + &format!("{FLOOR_PURE_PRODUCER_SHARE_MODULE}.floor_cross_claim_prepared_effect_inputs"), + )?; + let carried_rows = floor_decode_carried_input_warm_rows( + &roster_frame, + &format!("{FLOOR_PURE_PRODUCER_SHARE_MODULE}.floor_cross_claim_carried_input_warm_rows"), + )?; + // Admission is by RESOLVED DECLARATION IDENTITY (review 57446 F1): each qualified // roster spelling resolves to its fn node in a frame over the prepared subject, and the // interpreter admits by that node set — a bare-name homonym in a non-rostered module is @@ -4129,7 +4143,12 @@ pub(crate) fn install_pure_producer_share( let mut resolution_frames: std::collections::HashMap = std::collections::HashMap::new(); let mut admitted_nodes = Vec::new(); - for qualified in warm_rows.iter().chain(claim_forced_rows.iter()) { + let carried_producers: Vec = carried_rows.iter().map(|r| r.producer.clone()).collect(); + for qualified in warm_rows + .iter() + .chain(claim_forced_rows.iter()) + .chain(carried_producers.iter()) + { let module = match qualified.rsplit_once('.') { Some((module, _)) => module.to_string(), None => qualified.clone(), @@ -4165,6 +4184,7 @@ pub(crate) fn install_pure_producer_share( admitted_qualified: warm_rows .iter() .chain(claim_forced_rows.iter()) + .chain(carried_producers.iter()) .cloned() .collect(), refused, @@ -4189,6 +4209,160 @@ pub(crate) fn install_pure_producer_share( }, )); let mut warm_observations: Vec<(String, SharedBuildObservation)> = Vec::new(); + + // ── THE PREPARED EFFECT INPUTS, ACQUIRED ONCE AND CARRIED ──────────────────────────── + // + // Ordered BEFORE the plain warm loop because a carried-input row cannot be warmed until its + // input is bound, and every arm here stops the line: a row whose module the subject does not + // carry, a spelling that resolves to nothing, an acquisition that is not nullary, an + // acquisition that fails to evaluate, a value that is not portable. None of them has an empty + // default — an empty carry would be served to every claim as though it were the carrier's + // content, which is the fabricated-plausible-output failure with a cache in front of it. + // + // WHAT THE FLOOR DOES NOT DO IS DECIDE WHAT THE CARRIED VALUE MEANS. When the acquisition + // SUCCEEDS and returns its own coproduct's refusal arm, that refusal is carried faithfully and + // every claim receives the identical typed value it would have computed for itself — no claim + // passes where it would otherwise have failed, which is what separates propagating a refusal + // from widening one. The disposition is PRINTED (the carried variant name and content digest) + // so a run whose carrier refused is diagnosable instead of reading as a corpus problem + // (adjudicated 2026-09-14; bright-boar-435's condition on that ruling). + let mut acquisition_nodes: std::collections::HashMap< + String, + std::rc::Rc, + > = std::collections::HashMap::new(); + for input in &prepared_inputs { + let module = match input.acquisition.rsplit_once('.') { + Some((module, _)) => module.to_string(), + None => input.acquisition.clone(), + }; + if !resolution_frames.contains_key(&module) { + let frame = floor_authority_frame(prepared, &module).map_err(|why| { + format!( + "REQUIRED-FLOOR REFUSAL cause=PreparedEffectInputModuleOutsideSubject acquisition={} — the prepared input's module is not in the prepared subject; delete the stale roster row or restore it: {why}", + input.acquisition + ) + })?; + resolution_frames.insert(module.clone(), frame); + } + let frame = &resolution_frames[&module]; + let node = frame.lookup_fn_node(&input.acquisition).ok_or_else(|| { + format!( + "REQUIRED-FLOOR REFUSAL cause=PreparedEffectInputUnresolved acquisition={} — the rostered spelling names no declaration in its module's frame; fix or delete the roster row", + input.acquisition + ) + })?; + let (acquired, observation) = observe_shared_build(false, "floor-preparation", || { + v1_interpreter::acquire_prepared_effect_input(frame, &input.acquisition) + }); + let carry = acquired.map_err(|why| { + format!( + "REQUIRED-FLOOR REFUSAL cause=PreparedEffectInputAcquisitionFailed acquisition={} checkout_input={} — {why}", + input.acquisition, input.checkout_input + ) + })?; + eprintln!( + "[floor-phase] phase=prepared-effect-input-acquire state=completed acquisition={} checkout_input={} content_digest={} disposition={} cpu_ms={} wall_ms={} rss_growth_bytes={}", + input.acquisition, + input.checkout_input, + carry.digest, + carry.disposition(), + observation.cpu_ms, + observation.wall_ms, + observation.rss_growth_bytes, + ); + v1_interpreter::install_prepared_effect_input(&node, carry); + acquisition_nodes.insert(input.acquisition.clone(), node); + warm_observations.push(( + format!("PreparedEffectInputAcquire/{}", input.acquisition), + observation, + )); + } + for row in &carried_rows { + let acquisition_node = acquisition_nodes.get(&row.carried_input).ok_or_else(|| { + format!( + "REQUIRED-FLOOR REFUSAL cause=CarriedInputWarmRowInputUnknown producer={} input={} — the row declares a dependence on an input no floor_cross_claim_prepared_effect_inputs row prepares, so the value it names would never be bound", + row.producer, row.carried_input + ) + })?; + let module = match row.producer.rsplit_once('.') { + Some((module, _)) => module.to_string(), + None => row.producer.clone(), + }; + // Resolution above already framed every rostered producer's module, carried-input rows + // included (they are part of the admitted population), so the frame is present. + let frame = &resolution_frames[&module]; + let producer_node = frame.lookup_fn_node(&row.producer).ok_or_else(|| { + format!( + "REQUIRED-FLOOR REFUSAL cause=PureProducerShareProducerUnresolved producer={} — the rostered spelling names no declaration in its module's frame", + row.producer + ) + })?; + // The implicit binding is installed ONLY for the shape that needs it: a `BoundParameter` + // row's caller passes the carried value itself, so its key already represents the + // content and folding it in a second time would key one call two ways. + if row.bound_parameter.is_none() { + v1_interpreter::install_carried_input_producer(&producer_node, acquisition_node) + .map_err(|why| { + format!( + "REQUIRED-FLOOR REFUSAL cause=CarriedInputWarmRowInputUnknown \ + producer={} input={} — {why}", + row.producer, row.carried_input + ) + })?; + } + let (warm_result, warm_observation) = + observe_shared_build(false, "floor-preparation", || { + v1_interpreter::warm_cross_claim_carried_input_producer( + frame, + &row.producer, + &row.carried_input, + row.bound_parameter.as_deref(), + ) + }); + match warm_result { + Ok(outcome) => { + if !outcome.is_servable() { + let detail = match outcome.not_portable_detail() { + Some(refusal) => format!( + "{} path={} kind={}", + outcome.cause(), + if refusal.path_into_value.is_empty() { + "" + } else { + refusal.path_into_value.as_str() + }, + refusal.encountered_kind + ), + None => outcome.cause().to_string(), + }; + return Err(format!( + "REQUIRED-FLOOR REFUSAL cause=PureProducerShareWarmNotStored producer={} — the carried-input producer evaluated but its value was refused by the cross-claim store: {detail}", + row.producer + )); + } + eprintln!( + "[floor-phase] phase=prepared-effect-input-warm state=completed producer={} input={} disposition={} cpu_ms={} wall_ms={} rss_growth_bytes={}", + row.producer, + row.carried_input, + outcome.cause(), + warm_observation.cpu_ms, + warm_observation.wall_ms, + warm_observation.rss_growth_bytes, + ); + warm_observations.push(( + format!("CrossClaimCarriedInputWarm/{}", row.producer), + warm_observation, + )); + } + Err(why) => { + return Err(format!( + "REQUIRED-FLOOR REFUSAL cause=PureProducerShareWarmFailed producer={} — {why}", + row.producer + )); + } + } + } + for qualified in &warm_rows { let module = match qualified.rsplit_once('.') { Some((module, _)) => module.to_string(), @@ -4279,7 +4453,16 @@ pub(crate) fn install_pure_producer_share( warm_observation, )); } - Err(why) => { + Err(v1_interpreter::PureProducerWarmRefusal::DispatchedEffect { effects }) => { + return Err(format!( + "REQUIRED-FLOOR REFUSAL cause=PureProducerShareWarmDispatchedEffect \ + producer={qualified} effects={effects} — the warm row reached the world, \ + so the value depends on an input its empty argument row cannot represent; \ + roster the read as a prepared effect input and the fold as a carried-input \ + warm row instead" + )); + } + Err(v1_interpreter::PureProducerWarmRefusal::Failed(why)) => { return Err(format!( "REQUIRED-FLOOR REFUSAL cause=PureProducerShareWarmFailed \ producer={qualified} — {why}" @@ -4323,6 +4506,137 @@ thread_local! { /// deliberately NOT tolerated — a fourth verdict arrives with a meaning this wall does not know /// how to weigh, and treating it as "some refusal" would let the authority claim a judgement the /// executor cannot perform. +/// One row of `floor_cross_claim_prepared_effect_inputs`: an input the floor acquires ONCE at +/// preparation and carries for the prepared subject's lifetime. +#[derive(Clone)] +pub(crate) struct PreparedEffectInputRow { + acquisition: String, + checkout_input: String, +} + +/// One row of `floor_cross_claim_carried_input_warm_rows`: a producer warmed at preparation +/// whose value depends on a carried input. `ImplicitAcquisition` is the shape whose key must be +/// taught the carried content; `BoundParameter` is the shape whose caller already passes it. +#[derive(Clone)] +pub(crate) struct CarriedInputWarmRowDecoded { + producer: String, + carried_input: String, + bound_parameter: Option, +} + +fn floor_decode_prepared_effect_inputs( + hermetic: &v1_interpreter::InterpContext, + qualified_name: &str, +) -> Result, String> { + let value = v1_interpreter::run_in_context(hermetic, qualified_name, false) + .map_err(|e| format!("{qualified_name}: {e}"))?; + let items = floor_decode_list(hermetic, Some(&value)) + .map_err(|why| format!("{qualified_name} decode: {why}"))?; + let mut out = Vec::new(); + for item in items { + let v1_interpreter::Value::Record { type_name, fields } = &item else { + return Err(format!( + "{qualified_name}: expected PreparedEffectInput rows, got {}", + floor_value_shape(Some(&item)) + )); + }; + if !hermetic.sym_eq(*type_name, "PreparedEffectInput") { + return Err(format!( + "{qualified_name}: expected PreparedEffectInput, got record {}", + hermetic.resolve(*type_name) + )); + } + let field_str = |name: &str| -> Result { + match hermetic.field(fields, name) { + Some(v1_interpreter::Value::Str(s)) => Ok(s.to_string()), + other => Err(format!( + "{qualified_name}: PreparedEffectInput.{name} must be a String, got {}", + floor_value_shape(other) + )), + } + }; + out.push(PreparedEffectInputRow { + acquisition: field_str("acquisition")?, + checkout_input: field_str("checkout_input")?, + }); + } + Ok(out) +} + +fn floor_decode_carried_input_warm_rows( + hermetic: &v1_interpreter::InterpContext, + qualified_name: &str, +) -> Result, String> { + let value = v1_interpreter::run_in_context(hermetic, qualified_name, false) + .map_err(|e| format!("{qualified_name}: {e}"))?; + let items = floor_decode_list(hermetic, Some(&value)) + .map_err(|why| format!("{qualified_name} decode: {why}"))?; + let mut out = Vec::new(); + for item in items { + let v1_interpreter::Value::Record { type_name, fields } = &item else { + return Err(format!( + "{qualified_name}: expected CarriedInputWarmRow rows, got {}", + floor_value_shape(Some(&item)) + )); + }; + if !hermetic.sym_eq(*type_name, "CarriedInputWarmRow") { + return Err(format!( + "{qualified_name}: expected CarriedInputWarmRow, got record {}", + hermetic.resolve(*type_name) + )); + } + let field_str = |name: &str| -> Result { + match hermetic.field(fields, name) { + Some(v1_interpreter::Value::Str(s)) => Ok(s.to_string()), + other => Err(format!( + "{qualified_name}: CarriedInputWarmRow.{name} must be a String, got {}", + floor_value_shape(other) + )), + } + }; + // THE DEPENDENCE ARM IS READ, NOT ASSUMED. An unknown arm stops the line rather than + // defaulting to either shape: defaulting to `ImplicitAcquisition` would teach the key a + // content the producer never read, and defaulting to `BoundParameter` would key a + // nullary call on the empty row — the stale serve this row kind exists to prevent. + let bound_parameter = match hermetic.field(fields, "dependence") { + Some(v1_interpreter::Value::Variant { + variant_name, + fields: dep_fields, + .. + }) => match hermetic.resolve(*variant_name).as_str() { + "ImplicitAcquisition" => None, + "BoundParameter" => match hermetic.field(dep_fields, "parameter") { + Some(v1_interpreter::Value::Str(s)) => Some(s.to_string()), + other => { + return Err(format!( + "{qualified_name}: BoundParameter.parameter must be a String, got {}", + floor_value_shape(other) + )) + } + }, + other => { + return Err(format!( + "{qualified_name}: unknown CarriedInputDependence arm {other}" + )) + } + }, + other => { + return Err(format!( + "{qualified_name}: CarriedInputWarmRow.dependence must be a \ + CarriedInputDependence, got {}", + floor_value_shape(other) + )) + } + }; + out.push(CarriedInputWarmRowDecoded { + producer: field_str("producer")?, + carried_input: field_str("carried_input")?, + bound_parameter, + }); + } + Ok(out) +} + fn floor_decode_refused_share_candidates( hermetic: &v1_interpreter::InterpContext, qualified_name: &str, @@ -9132,6 +9446,23 @@ mod pure_producer_share_tests { measurement: String\n\ next_trigger: String\n\ }\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = []\n\ + data floor_cross_claim_carried_input_warm_rows: List = []\n\ data floor_cross_claim_refused_candidates: List = [\n\ RefusedShareCandidate {\n\ producer: \"v2.workflow.floor_pure_producer_share.tm_refused\",\n\ @@ -9174,6 +9505,80 @@ mod pure_producer_share_tests { v1_interpreter::clear_cross_claim_pure_memos(); } + /// THE RED FOR THE CONTENT-BLIND WARM: a nullary row that performs one confirmed checkout + /// read, rostered as a PLAIN warm row. Before the guard the warm path stored it under the + /// empty argument row — `Stored`, no refusal — so a changed file would have been served the + /// old value by every later claim. The read is a real hermetic checkout-input dispatch (the + /// test's cwd is inside the checkout and `Cargo.toml` is committed), not a stubbed counter, + /// so the wall is exercised on the path the floor runs. The positive control is + /// `a_carried_roster_warms_and_stores_its_nullary_rows`: a pure nullary row still stores. + #[test] + fn a_plain_warm_row_that_dispatches_an_effect_stops_the_line() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = prepared_from(&[( + "workspace/src/v2/workflow/floor_pure_producer_share.dag", + "module v2.workflow.floor_pure_producer_share\n\ + service Filesystem {\n\ + operation Read {\n\ + input { path: String }\n\ + output {\n\ + content: String from \"content\"\n\ + success: Bool from \"read_success\"\n\ + error: String from \"error\"\n\ + error_kind: String from \"error_kind\"\n\ + }\n\ + readonly\n\ + transport file { path: \"{path}\" }\n\ + }\n\ + }\n\ + fn reads_checkout() -> String {\n\ + let read = Filesystem.Read(path: \"Cargo.toml\")\n\ + read.content\n\ + }\n\ + data floor_cross_claim_pure_producers_warm: List = [\"v2.workflow.floor_pure_producer_share.reads_checkout\"]\n\ + data floor_cross_claim_pure_producers_claim_forced: List = []\n\ + type ShareRefusalVerdict =\n\ + MeasuredServeAboveRecompute\n\ + | NoMeasuredEffectOverItsConsumers\n\ + type RefusedShareCandidate {\n\ + producer: String\n\ + verdict: ShareRefusalVerdict\n\ + carrier_modules: List\n\ + measurement: String\n\ + next_trigger: String\n\ + }\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = []\n\ + data floor_cross_claim_carried_input_warm_rows: List = []\n\ + data floor_cross_claim_refused_candidates: List = []\n", + )]); + let err = install_pure_producer_share(&prepared) + .expect_err("an effectful plain warm row must refuse, never store content-blind"); + assert!( + err.contains("cause=PureProducerShareWarmDispatchedEffect") + && err.contains("producer=v2.workflow.floor_pure_producer_share.reads_checkout") + && err.contains("effects=1"), + "the refusal must name the cause, the row and the dispatch it saw: {err}" + ); + let (stores, _) = v1_interpreter::cross_claim_pure_memo_counts(); + assert_eq!(stores, 0, "nothing may be retained for the refused row"); + v1_interpreter::clear_cross_claim_pure_memos(); + } + /// THE `AlreadyPresent` PATH REPORTS THAT IT FOUND THE VALUE, NOT THAT IT BUILT IT. /// The discriminating red for review 59035: before the fix this asserted /// `BuiltByPreparation` on a warm that built nothing, so the receipt claimed preparation @@ -9199,6 +9604,23 @@ mod pure_producer_share_tests { measurement: String\n\ next_trigger: String\n\ }\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = []\n\ + data floor_cross_claim_carried_input_warm_rows: List = []\n\ data floor_cross_claim_refused_candidates: List = []\n", )]); @@ -9230,6 +9652,342 @@ mod pure_producer_share_tests { v1_interpreter::clear_cross_claim_pure_memos(); } + /// The fixture roster for the carried-input tests: one acquisition (`carrier_a`), one + /// producer that reaches it nullary (`projection`), and a SECOND acquisition returning + /// different content (`carrier_b`) which exists only so a test can bind a different carrier + /// content to the same acquisition node — the in-process stand-in for "the committed file + /// changed between two prepared runs". + fn carried_input_fixture(dependence: &str) -> PreparedRepository { + prepared_from(&[( + "workspace/src/v2/workflow/floor_pure_producer_share.dag", + &format!( + "module v2.workflow.floor_pure_producer_share\n\ + fn carrier_a() -> String {{ \"content-A\" }}\n\ + fn carrier_b() -> String {{ \"content-B\" }}\n\ + fn projection() -> String {{ concat(\"projected:\", carrier_a()) }}\n\ + fn consumer() -> String {{ projection() }}\n\ + data floor_cross_claim_pure_producers_warm: List = []\n\ + data floor_cross_claim_pure_producers_claim_forced: List = []\n\ + type CarriedInputDependence =\n\ + BoundParameter {{ parameter: String }}\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {{\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }}\n\ + type CarriedInputWarmRow {{\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }}\n\ + data floor_cross_claim_prepared_effect_inputs: List = [\n\ + PreparedEffectInput {{\n\ + acquisition: \"v2.workflow.floor_pure_producer_share.carrier_a\",\n\ + checkout_input: \"fixture/carrier.jsonl\",\n\ + ground: \"fixture\",\n\ + measurement: \"fixture\"\n\ + }}\n\ + ]\n\ + data floor_cross_claim_carried_input_warm_rows: List = [\n\ + CarriedInputWarmRow {{\n\ + producer: \"v2.workflow.floor_pure_producer_share.projection\",\n\ + carried_input: \"{dependence_input}\",\n\ + dependence: {dependence},\n\ + measurement: \"fixture\"\n\ + }}\n\ + ]\n\ + type ShareRefusalVerdict =\n\ + MeasuredServeAboveRecompute\n\ + | NoMeasuredEffectOverItsConsumers\n\ + type RefusedShareCandidate {{\n\ + producer: String\n\ + verdict: ShareRefusalVerdict\n\ + carrier_modules: List\n\ + measurement: String\n\ + next_trigger: String\n\ + }}\n\ + data floor_cross_claim_refused_candidates: List = []\n", + dependence = dependence, + dependence_input = "v2.workflow.floor_pure_producer_share.carrier_a", + ), + )]) + } + + /// Evaluate an entry and return its value beside the producer names the cross-claim tier + /// SERVED while it ran. The hit list is what separates "the right value" from "the value was + /// served": a recompute produces the same string, so a control that read only the value could + /// not tell a working share from a dead one. + fn evaluate_counting_hits( + frame: &v1_interpreter::InterpContext, + entry: &str, + ) -> (v1_interpreter::Value, Vec) { + let hits: std::rc::Rc>> = + std::rc::Rc::new(std::cell::RefCell::new(Vec::new())); + let sink = hits.clone(); + v1_interpreter::install_cross_claim_share_observer(Some( + v1_interpreter::CrossClaimShareObserver { + on_fill_begin: Box::new(|| {}), + on_fill: Box::new(|_, _, _| {}), + on_fill_abandon: Box::new(|| {}), + on_hit: Box::new(move |name| sink.borrow_mut().push(name.to_string())), + }, + )); + let value = + v1_interpreter::run_in_context(frame, entry, false).expect("the entry evaluates"); + let observed = hits.borrow().clone(); + (value, observed) + } + + /// POSITIVE CONTROL: the input is acquired ONCE at preparation, the producer is warmed over + /// it, and a later evaluation of the producer is SERVED — the shape the whole row kind + /// exists for. The acquisition's own observation is present too, because the acquire is a + /// shared preparation build and a build bounded by nothing is exactly what the observation + /// vector exists to stop. + #[test] + fn a_prepared_effect_input_is_acquired_once_and_its_producer_is_warmed_over_it() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = carried_input_fixture("ImplicitAcquisition"); + let observations = + install_pure_producer_share(&prepared).expect("the carried input installs and warms"); + let labels: Vec<&str> = observations.iter().map(|(l, _)| l.as_str()).collect(); + assert!( + labels.contains( + &"PreparedEffectInputAcquire/v2.workflow.floor_pure_producer_share.carrier_a" + ), + "the acquisition must be observed as a shared preparation build: {labels:?}" + ); + assert!( + labels.contains( + &"CrossClaimCarriedInputWarm/v2.workflow.floor_pure_producer_share.projection" + ), + "the carried-input warm must be observed: {labels:?}" + ); + let frame = floor_authority_frame(&prepared, "v2.workflow.floor_pure_producer_share") + .expect("fixture frame"); + // EVALUATE THROUGH A CALL SITE, not through `run_in_context` on the producer itself: + // `run_in_context` calls `call_function` DIRECTLY, so it reaches neither the cross-claim + // tier nor the prepared-input binding. A control that evaluated the producer that way + // would assert a value RECOMPUTE also produces — measuring nothing, in the shape DESIGN + // section 4b calls a decoration. `consumer()` is an ordinary call site, so its inner + // call goes through the same path every claim's call takes. + let (served, hits) = + evaluate_counting_hits(&frame, "v2.workflow.floor_pure_producer_share.consumer"); + match &served { + v1_interpreter::Value::Str(s) => assert_eq!(&**s, "projected:content-A"), + other => panic!("unexpected value: {other:?}"), + } + assert!( + hits.iter().any(|h| h == "projection"), + "the producer must be SERVED from the warm, not recomputed: {hits:?}" + ); + v1_interpreter::clear_cross_claim_pure_memos(); + } + + /// THE DISCRIMINATING RED: A CHANGED CARRIER CONTENT IS NOT SERVED THE OLD VALUE. + /// + /// This is the control the whole design rests on, and it is aimed at the specific wrong + /// implementation rather than at the happy path: an entry keyed on the EMPTY argument row + /// passes the positive control above and FAILS HERE, because it would serve the value + /// derived from content-A after content-B was carried. Binding a different acquired value to + /// the same acquisition node is the in-process stand-in for the committed carrier changing + /// between two prepared runs. + #[test] + fn a_changed_carrier_content_is_not_served_the_value_derived_from_the_old_one() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = carried_input_fixture("ImplicitAcquisition"); + install_pure_producer_share(&prepared).expect("the carried input installs and warms"); + let frame = floor_authority_frame(&prepared, "v2.workflow.floor_pure_producer_share") + .expect("fixture frame"); + + // Re-bind the SAME acquisition node to a different content, exactly as a second prepared + // run over a changed carrier would. + let acquisition_node = frame + .lookup_fn_node("v2.workflow.floor_pure_producer_share.carrier_a") + .expect("the acquisition resolves"); + let changed = v1_interpreter::acquire_prepared_effect_input( + &frame, + "v2.workflow.floor_pure_producer_share.carrier_b", + ) + .expect("the second carrier acquires"); + let first_digest = v1_interpreter::acquire_prepared_effect_input( + &frame, + "v2.workflow.floor_pure_producer_share.carrier_a", + ) + .expect("the first carrier acquires") + .digest; + assert_ne!( + first_digest, changed.digest, + "two different carrier contents must not share a content identity" + ); + v1_interpreter::install_prepared_effect_input(&acquisition_node, changed); + + let (served, hits) = + evaluate_counting_hits(&frame, "v2.workflow.floor_pure_producer_share.consumer"); + assert!( + !hits.iter().any(|h| h == "projection"), + "the producer must not be SERVED under a changed carrier: {hits:?}" + ); + match &served { + v1_interpreter::Value::Str(s) => assert_eq!( + &**s, "projected:content-B", + "the producer must RECOMPUTE over the changed carrier; serving \ + 'projected:content-A' is the stale serve the content key exists to make \ + unwritable" + ), + other => panic!("unexpected value: {other:?}"), + } + v1_interpreter::clear_cross_claim_pure_memos(); + } + + /// THE BINDING DIES WITH THE TIER. A carry outliving its prepared subject would serve a + /// later, differently-prepared evaluation a value acquired from ANOTHER COMMIT — a stale + /// serve the content key cannot catch, because the carried content would be exactly what is + /// wrong. After the tier is cleared the producer evaluates for itself again. + #[test] + fn the_prepared_input_binding_is_absent_after_the_tier_is_cleared() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = carried_input_fixture("ImplicitAcquisition"); + install_pure_producer_share(&prepared).expect("the carried input installs and warms"); + let frame = floor_authority_frame(&prepared, "v2.workflow.floor_pure_producer_share") + .expect("fixture frame"); + let acquisition_node = frame + .lookup_fn_node("v2.workflow.floor_pure_producer_share.carrier_a") + .expect("the acquisition resolves"); + assert!( + v1_interpreter::prepared_effect_input_is_bound(&acquisition_node), + "the binding must exist while the subject is prepared" + ); + v1_interpreter::clear_cross_claim_pure_memos(); + assert!( + !v1_interpreter::prepared_effect_input_is_bound(&acquisition_node), + "the binding must be cleared with the tier" + ); + // And the producer still answers, for itself, with nothing carried. + let (recomputed, _) = + evaluate_counting_hits(&frame, "v2.workflow.floor_pure_producer_share.consumer"); + match &recomputed { + v1_interpreter::Value::Str(s) => assert_eq!(&**s, "projected:content-A"), + other => panic!("unexpected value: {other:?}"), + } + } + + /// A carried-input row naming an input nobody prepares stops the line: the value it declares + /// a dependence on would never be bound. + #[test] + fn a_carried_row_naming_an_unprepared_input_stops_the_line() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = prepared_from(&[( + "workspace/src/v2/workflow/floor_pure_producer_share.dag", + "module v2.workflow.floor_pure_producer_share\n\ + fn carrier_a() -> String { \"content-A\" }\n\ + fn projection() -> String { concat(\"projected:\", carrier_a()) }\n\ + data floor_cross_claim_pure_producers_warm: List = []\n\ + data floor_cross_claim_pure_producers_claim_forced: List = []\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = []\n\ + data floor_cross_claim_carried_input_warm_rows: List = [\n\ + CarriedInputWarmRow {\n\ + producer: \"v2.workflow.floor_pure_producer_share.projection\",\n\ + carried_input: \"v2.workflow.floor_pure_producer_share.carrier_a\",\n\ + dependence: ImplicitAcquisition,\n\ + measurement: \"fixture\"\n\ + }\n\ + ]\n\ + type ShareRefusalVerdict =\n\ + MeasuredServeAboveRecompute\n\ + | NoMeasuredEffectOverItsConsumers\n\ + type RefusedShareCandidate {\n\ + producer: String\n\ + verdict: ShareRefusalVerdict\n\ + carrier_modules: List\n\ + measurement: String\n\ + next_trigger: String\n\ + }\n\ + data floor_cross_claim_refused_candidates: List = []\n", + )]); + let err = install_pure_producer_share(&prepared) + .expect_err("a row naming an unprepared input must stop the line"); + assert!( + err.contains("CarriedInputWarmRowInputUnknown"), + "refusal must name the cause: {err}" + ); + v1_interpreter::clear_cross_claim_pure_memos(); + } + + /// A NON-NULLARY ACQUISITION IS REFUSED, because a carried input WITH arguments is a + /// different concept: which argument row would preparation have acquired it under? + #[test] + fn a_non_nullary_acquisition_is_refused() { + v1_interpreter::clear_cross_claim_pure_memos(); + let prepared = prepared_from(&[( + "workspace/src/v2/workflow/floor_pure_producer_share.dag", + "module v2.workflow.floor_pure_producer_share\n\ + fn carrier_a(seed: String) -> String { concat(\"content-\", seed) }\n\ + fn projection() -> String { \"projected\" }\n\ + data floor_cross_claim_pure_producers_warm: List = []\n\ + data floor_cross_claim_pure_producers_claim_forced: List = []\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = [\n\ + PreparedEffectInput {\n\ + acquisition: \"v2.workflow.floor_pure_producer_share.carrier_a\",\n\ + checkout_input: \"fixture/carrier.jsonl\",\n\ + ground: \"fixture\",\n\ + measurement: \"fixture\"\n\ + }\n\ + ]\n\ + data floor_cross_claim_carried_input_warm_rows: List = []\n\ + type ShareRefusalVerdict =\n\ + MeasuredServeAboveRecompute\n\ + | NoMeasuredEffectOverItsConsumers\n\ + type RefusedShareCandidate {\n\ + producer: String\n\ + verdict: ShareRefusalVerdict\n\ + carrier_modules: List\n\ + measurement: String\n\ + next_trigger: String\n\ + }\n\ + data floor_cross_claim_refused_candidates: List = []\n", + )]); + let err = install_pure_producer_share(&prepared) + .expect_err("a non-nullary acquisition must stop the line"); + assert!( + err.contains("PreparedEffectInputAcquisitionFailed") && err.contains("NULLARY"), + "refusal must name the cause and the reason: {err}" + ); + v1_interpreter::clear_cross_claim_pure_memos(); + } + /// A warm row naming a producer the subject cannot resolve stops the line. #[test] fn a_stale_warm_row_stops_the_line() { @@ -9238,7 +9996,25 @@ mod pure_producer_share_tests { "workspace/src/v2/workflow/floor_pure_producer_share.dag", "module v2.workflow.floor_pure_producer_share\n\ data floor_cross_claim_pure_producers_warm: List = [\"v2.workflow.floor_pure_producer_share.tm_gone\"]\n\ - data floor_cross_claim_pure_producers_claim_forced: List = []\n", + data floor_cross_claim_pure_producers_claim_forced: List = []\n\ + type CarriedInputDependence =\n\ + BoundParameter { parameter: String }\n\ + | ImplicitAcquisition\n\ + type PreparedEffectInput {\n\ + acquisition: String\n\ + checkout_input: String\n\ + ground: String\n\ + measurement: String\n\ + }\n\ + type CarriedInputWarmRow {\n\ + producer: String\n\ + carried_input: String\n\ + dependence: CarriedInputDependence\n\ + measurement: String\n\ + }\n\ + data floor_cross_claim_prepared_effect_inputs: List = []\n\ + data floor_cross_claim_carried_input_warm_rows: List = []\n\ +", )]); let err = install_pure_producer_share(&prepared) .expect_err("a stale warm row must stop the line"); diff --git a/src/v1/stage0/src/v1_interpreter.rs b/src/v1/stage0/src/v1_interpreter.rs index 5e8e4d16c3d..424c9f92c11 100644 --- a/src/v1/stage0/src/v1_interpreter.rs +++ b/src/v1/stage0/src/v1_interpreter.rs @@ -1889,6 +1889,13 @@ pub fn clear_cross_claim_pure_memos() { CROSS_CLAIM_FN_KEEPALIVE.with(|k| k.borrow_mut().clear()); CROSS_CLAIM_PURE_ROSTER.with(|r| r.borrow_mut().clear()); CROSS_CLAIM_SHARE_OBSERVER.with(|o| *o.borrow_mut() = None); + // The prepared effect inputs are tier state too, and for the sharpest reason: a carry that + // outlived its subject would serve a later, differently-prepared evaluation a value acquired + // from ANOTHER COMMIT — a stale serve the key cannot catch, because the key represents the + // carried content and the carried content would be exactly what is wrong. + CROSS_CLAIM_PREPARED_INPUT.with(|m| m.borrow_mut().clear()); + CROSS_CLAIM_PREPARED_INPUT_PRESENT.with(|p| p.set(false)); + CROSS_CLAIM_IMPLICIT_CARRY.with(|m| m.borrow_mut().clear()); // The retained refusal is tier state too: leaving it across a reset is how a stale path // outlives the store that produced it (review 57554). CROSS_CLAIM_LAST_UNPORTABLE.with(|c| *c.borrow_mut() = None); @@ -2110,6 +2117,13 @@ fn try_cross_claim_pure_memo( if !cross_claim_pure_admitted(fn_node, func_name) { return None; } + // A nullary call of a producer bound to a carried input is keyed on that input's CONTENT, + // so the entry a claim serves is the one preparation stored for THIS carrier and no other. + let carried_key_args = cross_claim_key_args(fn_node, args); + let args: &[(Option, Value)] = match &carried_key_args { + Some(rows) => rows, + None => args, + }; let args_hash = cross_claim_args_hash(ctx, args)?; let memo_key = (Rc::as_ptr(fn_node) as usize, args_hash); // The per-ctx hit cache is verified the same way the global bucket is: hash first, then @@ -2213,6 +2227,13 @@ fn store_cross_claim_pure_memo( if !cross_claim_pure_admitted(fn_node, func_name) { return CrossClaimStoreOutcome::NotAdmitted; } + // The same substitution the lookup makes, in the same place in the fold, so a warm and a + // serve cannot disagree about what the key represents. + let carried_key_args = cross_claim_key_args(fn_node, args); + let args: &[(Option, Value)] = match &carried_key_args { + Some(rows) => rows, + None => args, + }; let Some(args_hash) = cross_claim_args_hash(ctx, args) else { return CrossClaimStoreOutcome::RefusedArgsNotHashable; }; @@ -2278,6 +2299,14 @@ fn store_cross_claim_pure_memo( outcome } +/// Why a plain nullary warm stored nothing. Typed apart so the floor names the cause: a +/// dispatched effect is a roster defect with its own remedy, not an evaluation failure. +#[derive(Debug)] +pub enum PureProducerWarmRefusal { + DispatchedEffect { effects: u64 }, + Failed(String), +} + /// Evaluate one rostered NULLARY producer in `ctx` and seed the cross-claim tier, under the /// same guard protocol as a claim-forced fill — so a preparation warm lands in the ledger as an /// outside-fold fill, not on the first claim. Returns the TYPED outcome: a servable tier @@ -2285,6 +2314,351 @@ fn store_cross_claim_pure_memo( pub fn warm_cross_claim_pure_producer( ctx: &InterpContext, qualified_fn: &str, +) -> Result { + with_active_ctx(ctx, || { + let fn_node = ctx + .lookup_fn(qualified_fn) + .ok_or_else(|| { + PureProducerWarmRefusal::Failed(format!( + "no declaration named '{qualified_fn}' in this frame" + )) + })? + .clone(); + let bare = qualified_fn.rsplit('.').next().unwrap_or(qualified_fn); + if !cross_claim_pure_admitted(&fn_node, bare) { + return Err(PureProducerWarmRefusal::Failed(format!( + "'{qualified_fn}' did not resolve to an installed cross-claim roster identity" + ))); + } + let guard = CrossClaimFillGuard::enter(bare); + let env = Env::empty(); + // THE SAME GUARD THE FOLD PATH HOLDS. The claim-time store refuses to publish a value + // whose evaluation dispatched an effect, because the key `(fn node, argument row)` cannot + // see what the effect read. The warm path stored without that guard, so an effectful + // nullary row rostered as a plain warm row was stored CONTENT-BLIND under the empty + // argument row — the key omitting an input the value depends on. A dispatch here is a + // roster defect (the row belongs in the prepared-effect-input rows, where the read is + // carried and keyed), so it stops the line rather than declining silently. + let effects_before = ctx.effect_dispatch_count.get(); + let value = with_lexical_base_env(&env, || call_function(ctx, &fn_node, &[], &env)) + .map_err(|e| PureProducerWarmRefusal::Failed(format!("{qualified_fn}: {e}")))?; + let effects = ctx + .effect_dispatch_count + .get() + .saturating_sub(effects_before); + if effects != 0 { + return Err(PureProducerWarmRefusal::DispatchedEffect { effects }); + } + Ok(store_cross_claim_pure_memo( + ctx, + &fn_node, + bare, + &[], + &value, + Some(&guard), + )) + }) +} + +/// ONE PREPARED EFFECT INPUT, ACQUIRED ONCE AND CARRIED. +/// +/// The floor acquires a committed carrier's content at PREPARATION and binds it for the +/// prepared subject's lifetime, so the pure fold over it is a warm row: nullary from the row's +/// point of view, because the input is bound before any claim runs. This is NOT a memo of an +/// effect. Hermetic evaluation already classifies a readonly `Filesystem.Read`/`List` of a path +/// `hermetic_checkout_input_disposition` confirms under the checkout root as INPUT ACCESS rather +/// than a host effect, so the value is a function of the commit the run prepared and is constant +/// across the whole subject; anything that wall cannot confirm is refused there and is therefore +/// never carryable here. +/// +/// `digest` is the carried CONTENT IDENTITY, minted through the same fnv1a64 structural family +/// as `std.content_hash.content_hash_atom` (`v1_rt::atom_identity_hash` / `hash_combine`) — not +/// a `DefaultHasher` hex wearing that carrier. `variant` is the outermost variant name when the +/// carried value is one, carried for the floor's phase line so a run whose carrier REFUSED is +/// diagnosable rather than silent: the floor never reads a domain type, but it can print which +/// arm it carried, and "all seven claims refused identically" then reads as a carrier problem +/// instead of a corpus one. +#[derive(Clone)] +pub struct PreparedEffectInputCarry { + pub identity: String, + pub digest: String, + pub variant: Option, + value: Value, +} + +impl PreparedEffectInputCarry { + /// The carried value's own disposition, for the receipt: the outermost variant name, or the + /// value's shape when it is not a variant. Never an interpretation of what the arm MEANS. + pub fn disposition(&self) -> String { + match &self.variant { + Some(v) => v.clone(), + None => "not-a-variant".to_string(), + } + } +} + +/// A structural digest over the portable form — total, like the reification it walks, so no +/// child can be silently excluded from the identity. Field and element ORDER is part of the +/// digest because the portable form's order is canonical (fields sort on process-global symbol +/// identity), so two equal values digest equally and two different ones do not collide by +/// construction of the fold rather than by luck. +/// A symbol's spelling without a context: `Symbol` is a process-canonical `&'static str`, so a +/// portable value's symbols are already interner-free and the digest can be taken without a +/// frame. That is the same property that lets a stored value be served to a later claim by `Rc` +/// clone rather than rebuilt per frame. +fn ctx_free_symbol_text(s: &Symbol) -> String { + s.0.to_string() +} + +fn portable_value_digest(v: &PortableValue) -> String { + use crate::v1_rt::{atom_identity_hash, hash_combine}; + let tagged = + |tag: &str, payload: String| hash_combine(atom_identity_hash(tag.to_string()), payload); + match v { + PortableValue::Null => atom_identity_hash("null".to_string()), + PortableValue::Unit => atom_identity_hash("unit".to_string()), + PortableValue::Bool(b) => tagged("bool", atom_identity_hash(b.to_string())), + PortableValue::Int(i) => tagged("int", atom_identity_hash(i.to_string())), + PortableValue::Float(f) => tagged("float", atom_identity_hash(format!("{f:?}"))), + PortableValue::Str(s) => tagged("str", atom_identity_hash(s.to_string())), + PortableValue::List(items) => tagged( + "list", + items + .iter() + .fold(atom_identity_hash("[]".to_string()), |acc, item| { + hash_combine(acc, portable_value_digest(item)) + }), + ), + PortableValue::Map(pairs) => tagged( + "map", + pairs + .iter() + .fold(atom_identity_hash("{}".to_string()), |acc, (k, val)| { + hash_combine( + acc, + hash_combine(portable_value_digest(k), portable_value_digest(val)), + ) + }), + ), + PortableValue::Set(items) => tagged( + "set", + items + .iter() + .fold(atom_identity_hash("set".to_string()), |acc, item| { + hash_combine(acc, atom_identity_hash(item.clone())) + }), + ), + PortableValue::Record { type_name, fields } => tagged( + "record", + fields.iter().fold( + atom_identity_hash(ctx_free_symbol_text(type_name)), + |acc, (name, field)| { + hash_combine( + acc, + hash_combine( + atom_identity_hash(ctx_free_symbol_text(name)), + portable_value_digest(field), + ), + ) + }, + ), + ), + PortableValue::Variant { + type_name, + variant_name, + fields, + } => tagged( + "variant", + fields.iter().fold( + hash_combine( + atom_identity_hash(ctx_free_symbol_text(type_name)), + atom_identity_hash(ctx_free_symbol_text(variant_name)), + ), + |acc, (name, field)| { + hash_combine( + acc, + hash_combine( + atom_identity_hash(ctx_free_symbol_text(name)), + portable_value_digest(field), + ), + ) + }, + ), + ), + } +} + +thread_local! { + /// ACQUISITION fn node -> the value acquired once at preparation. A claim's call of that + /// declaration is served this value instead of re-dispatching the read. Keyed on RESOLVED + /// NODE IDENTITY like every other admission here, so a bare-name homonym in another module + /// is a different declaration and is never served. + static CROSS_CLAIM_PREPARED_INPUT: RefCell>> = + RefCell::new(HashMap::new()); + /// Whether ANY prepared input is installed on this thread. `eval_call` consults the carry on + /// every nullary call, and a `RefCell` borrow plus a hash lookup per call is a cost-shape + /// defect on the interpreter's hottest path when the usual answer is "none installed" — + /// DESIGN section 6's bare-minimum-cost rule, which is not priced per site. A `Cell` + /// read answers the common case without touching the map, and is set only where the map is. + static CROSS_CLAIM_PREPARED_INPUT_PRESENT: std::cell::Cell = const { std::cell::Cell::new(false) }; + /// PRODUCER fn node -> the carried input its value depends on, for rows whose producer + /// reaches the acquisition INSIDE itself (`ImplicitAcquisition`). The carried content is + /// folded into the key on both the warm and the serve, so such an entry is content-keyed + /// exactly as a parameterised one is — an entry stored under the EMPTY argument row would + /// serve a stale value the moment the carrier changed, which is the defect this map exists + /// to make unwritable. + /// + /// IT HOLDS THE ACQUISITION NODE AND NOT THE CARRY, and the difference is a real stale serve + /// rather than a style preference: an earlier cut stored a CLONE of the carry here, so + /// re-binding the acquisition to a different content left this map pointing at the old value, + /// the key stayed the same, and the producer was SERVED a value derived from the PREVIOUS + /// carrier. Its own control caught it before this landed + /// (`a_changed_carrier_content_is_not_served_the_value_derived_from_the_old_one`). One + /// authority for the carried value — the acquisition's binding — read through at every key + /// derivation. + static CROSS_CLAIM_IMPLICIT_CARRY: RefCell> = + RefCell::new(HashMap::new()); +} + +/// Acquire one prepared effect input: evaluate the NULLARY acquisition once in `ctx`, reify its +/// value totally, and return the carry. Every failure is typed and located and none of them has +/// an empty default — an unreadable or absent carrier reaches this as an evaluation error or as +/// the domain's OWN refusal arm, and in the second case the refusal is what gets carried, so +/// every claim receives the identical typed value it would have computed for itself. +pub fn acquire_prepared_effect_input( + ctx: &InterpContext, + qualified_fn: &str, +) -> Result { + with_active_ctx(ctx, || { + let fn_node = ctx + .lookup_fn(qualified_fn) + .ok_or_else(|| format!("no declaration named '{qualified_fn}' in this frame"))? + .clone(); + if !fn_node.params.is_empty() { + return Err(format!( + "'{qualified_fn}' takes {} parameter(s): a prepared effect input must be NULLARY, \ + because a carried input WITH arguments is a different concept and must not \ + arrive under this one", + fn_node.params.len() + )); + } + let env = Env::empty(); + let value = with_lexical_base_env(&env, || call_function(ctx, &fn_node, &[], &env)) + .map_err(|e| format!("{qualified_fn}: {e}"))?; + // TOTAL reification is the portability check AND the identity walk in one pass: a value + // carrying any origin-bound child refuses here, located, rather than being discovered + // when a later claim is handed something frame-bound. + let portable = + portable_value_from_ctx_at(ctx, &value, &mut String::new()).map_err(|r| { + format!( + "{qualified_fn}: the acquired value is not portable at path {} (kind {})", + if r.path_into_value.is_empty() { + "".to_string() + } else { + r.path_into_value.clone() + }, + r.encountered_kind + ) + })?; + let variant = match &value { + Value::Variant { variant_name, .. } => Some(ctx.resolve(*variant_name).to_string()), + _ => None, + }; + Ok(PreparedEffectInputCarry { + identity: qualified_fn.to_string(), + digest: portable_value_digest(&portable), + variant, + value, + }) + }) +} + +/// Bind an acquired input to its acquisition node for the prepared subject's lifetime. Cleared +/// with the tier by `clear_cross_claim_pure_memos`, because a carry outliving its subject would +/// serve a later, differently-prepared evaluation a value acquired from another commit. +pub fn install_prepared_effect_input(acquisition_node: &Rc, carry: PreparedEffectInputCarry) { + let carry = Rc::new(carry); + CROSS_CLAIM_PREPARED_INPUT.with(|m| { + m.borrow_mut() + .insert(Rc::as_ptr(acquisition_node) as usize, carry); + }); + CROSS_CLAIM_PREPARED_INPUT_PRESENT.with(|p| p.set(true)); + keep_cross_claim_fn(acquisition_node); +} + +/// Declare that a producer's value depends on an already-installed carried input, for the +/// `ImplicitAcquisition` shape. +pub fn install_carried_input_producer( + producer_node: &Rc, + acquisition_node: &Rc, +) -> Result<(), String> { + if !prepared_effect_input_is_bound(acquisition_node) { + return Err( + "the carried input named by this row is not installed; acquire it first".to_string(), + ); + } + CROSS_CLAIM_IMPLICIT_CARRY.with(|m| { + m.borrow_mut().insert( + Rc::as_ptr(producer_node) as usize, + Rc::as_ptr(acquisition_node) as usize, + ); + }); + keep_cross_claim_fn(producer_node); + keep_cross_claim_fn(acquisition_node); + Ok(()) +} + +/// Whether an acquisition node currently has a carried value bound. The tier's lifetime is one +/// prepared subject, and this is how a caller (or a control) asks whether that is still true — +/// the binding must be gone once the tier is cleared, or a later differently-prepared evaluation +/// could be served a value acquired from another commit. +pub fn prepared_effect_input_is_bound(acquisition_node: &Rc) -> bool { + prepared_input_for(acquisition_node).is_some() +} + +fn prepared_input_for(fn_node: &Rc) -> Option> { + if !CROSS_CLAIM_PREPARED_INPUT_PRESENT.with(|p| p.get()) { + return None; + } + CROSS_CLAIM_PREPARED_INPUT.with(|m| m.borrow().get(&(Rc::as_ptr(fn_node) as usize)).cloned()) +} + +/// The CURRENT carried value a producer's key depends on, read through its acquisition's binding +/// rather than from a snapshot taken at install. +fn implicit_carry_for(fn_node: &Rc) -> Option> { + let acquisition = CROSS_CLAIM_IMPLICIT_CARRY + .with(|m| m.borrow().get(&(Rc::as_ptr(fn_node) as usize)).copied())?; + CROSS_CLAIM_PREPARED_INPUT.with(|m| m.borrow().get(&acquisition).cloned()) +} + +/// The KEY ARGUMENT ROW for a call: the caller's own arguments, except that a nullary call of a +/// producer declared to depend on a carried input is keyed on that input's CONTENT. The value +/// passed to the call is untouched — the producer is nullary and stays nullary; only the key +/// learns what the call read. +fn cross_claim_key_args( + fn_node: &Rc, + args: &[(Option, Value)], +) -> Option, Value)>> { + if !args.is_empty() { + return None; + } + implicit_carry_for(fn_node) + .map(|carry| vec![(Some(carry.identity.clone()), carry.value.clone())]) +} + +/// Evaluate one carried-input warm row at preparation and seed the tier under its content key. +/// +/// THE EFFECT WALL, and it is the check that separates "its only input is this carrier" from +/// "we hope its only input is this carrier": with the carry installed, an `ImplicitAcquisition` +/// producer's warm must dispatch NO effect. One that still reaches the world has a second input +/// the key does not represent, so a stored value would be servable under a key that cannot see +/// what it depended on — the stale serve this row kind exists to make unwritable. The floor +/// refuses the row rather than storing it. +pub fn warm_cross_claim_carried_input_producer( + ctx: &InterpContext, + qualified_fn: &str, + acquisition_fn: &str, + parameter: Option<&str>, ) -> Result { with_active_ctx(ctx, || { let fn_node = ctx @@ -2297,15 +2671,58 @@ pub fn warm_cross_claim_pure_producer( "'{qualified_fn}' did not resolve to an installed cross-claim roster identity" )); } + let acquisition_node = ctx + .lookup_fn(acquisition_fn) + .ok_or_else(|| format!("no declaration named '{acquisition_fn}' in this frame"))? + .clone(); + let carry = prepared_input_for(&acquisition_node).ok_or_else(|| { + format!( + "'{acquisition_fn}' has no acquired value installed; a carried-input warm row \ + must be bound to its prepared input before it is warmed" + ) + })?; + // THE TWO SHAPES DIFFER ONLY IN WHERE THE CONTENT ENTERS THE KEY, which is exactly the + // distinction the roster's `CarriedInputDependence` names. `BoundParameter` passes the + // carried value as the producer's own argument, so the ordinary key already represents + // it and a claim making the same call keys identically. `ImplicitAcquisition` calls the + // producer nullary and lets `cross_claim_key_args` fold the carried content into the key + // on the warm and on every serve — one substitution, made in one place, so a warm and a + // serve cannot disagree about what the key represents. + let call_args: Vec<(Option, Value)> = match parameter { + Some(param) => vec![(Some(param.to_string()), carry.value.clone())], + None => { + if implicit_carry_for(&fn_node).is_none() { + return Err(format!( + "'{qualified_fn}' has no installed carried input; an \ + ImplicitAcquisition row must be bound to its prepared input before it \ + is warmed" + )); + } + Vec::new() + } + }; let guard = CrossClaimFillGuard::enter(bare); let env = Env::empty(); - let value = with_lexical_base_env(&env, || call_function(ctx, &fn_node, &[], &env)) + let effects_before = ctx.effect_dispatch_count.get(); + let value = with_lexical_base_env(&env, || call_function(ctx, &fn_node, &call_args, &env)) .map_err(|e| format!("{qualified_fn}: {e}"))?; + let dispatched = ctx + .effect_dispatch_count + .get() + .saturating_sub(effects_before); + if dispatched != 0 { + return Err(format!( + "PreparedEffectInputProducerStillDispatchesEffect producer={qualified_fn} \ + effects={dispatched} — with its carried input installed this producer still \ + reached the world, so it has an input the stored key does not represent; the \ + row is refused rather than stored under a key that cannot see what it read" + )); + } Ok(store_cross_claim_pure_memo( ctx, &fn_node, bare, - &[], + &call_args, &value, Some(&guard), )) @@ -7822,6 +8239,28 @@ fn eval_call(node: &Rc, env: &Rc, ctx: &InterpContext) -> InterpResul }, }; + // A PREPARED EFFECT INPUT IS SERVED BEFORE EVERY OTHER TIER, and it sits HERE rather than in + // `eval_pure_named_call` for a reason that decides correctness: a declaration that reaches the + // world may declare `uses`, and a fn with non-empty `uses` never reaches the pure path at all. + // Serving it one tier down would leave exactly the acquisitions this mechanism exists for + // re-dispatching their read per claim while the receipt said they were carried. + // + // It is deliberately NOT the pure memo: that tier refuses to store any call that dispatched an + // effect, which is correct and stays. This is a different admission — a roster-declared + // binding, resolved to a node, installed for one prepared subject — and what it serves is the + // value the run already acquired from a committed checkout input, so the claim receives + // exactly what its own read would have returned. + if args.is_empty() { + if let Some(carry) = prepared_input_for(&fn_node) { + // NAMED APART IN THE LEDGER, because it is a different mechanism from a share hit and + // a reader counting `cross_claim_pure_share` rows must not read a carried-input serve + // as a rostered producer's hit. The row is still RECORDED — a carry invisible to the + // receipt would be a mechanism nobody could measure. + cross_claim_observe_hit(&format!("prepared-effect-input/{func_name}")); + return Ok(carry.value.clone()); + } + } + if let Some(result) = try_witness_evaluation_dispatch(ctx, node, &fn_node, &args, env) { return result; } diff --git a/src/v2/test/floor_prepared_effect_input_ladder_test.dag b/src/v2/test/floor_prepared_effect_input_ladder_test.dag new file mode 100644 index 00000000000..6206ba0f7ee --- /dev/null +++ b/src/v2/test/floor_prepared_effect_input_ladder_test.dag @@ -0,0 +1,80 @@ +module v2.test.floor_prepared_effect_input_ladder + +import v2.workflow.floor_prepared_effect_input_ladder { + carried_input_identities, carried_input_verdicts_after_the_carry, + carried_input_verdicts_before_the_carry, cross_claim_tier_retention, + every_carried_identity_is_a_single_demand_after_the_carry, + every_carried_identity_is_authored_duplication_before_the_carry, + the_minimized_demand_graph_is_green, prepared_effect_input_provider +} +import v2.workflow.floor_pure_producer_share { + carried_input_roster_collisions, carried_input_rows_without_a_prepared_input, + floor_cross_claim_admitted_producers, floor_cross_claim_carried_input_warm_rows, + floor_cross_claim_prepared_effect_inputs +} +import std.cache_interface { retention_growth_is_bounded, retention_has_exact_byte_bound } +import std.materialization_ladder { provider_is_content_keyed, provider_is_store_tier } +import v2.std.logic { Bool } + +// THE LADDER OBLIGATIONS ARE DECIDED BY THE FOLD, NOT ASSERTED IN PROSE. Each test below is +// answered by `std.materialization_ladder` or `std.cache_interface` over the LIVE rows rather than +// by a sentence in this file: the verdict transition the carry performs, and the three properties +// of the place the carried value is held while it is carried. + +// THE VERDICT TRANSITION, which is what this mechanism actually is. An earlier cut of this file +// asserted `Discharged` and the floor refused it by execution (run 34854251612): at a SHARED-STATE +// obligation LCA the ladder answers AuthoredDuplication and never reaches a provider at all, +// because DESIGN section 2 says the repair there is to CARRY the value and not to cache it. So the +// pair below states the transition the carry performs — the ladder naming the defect before, and +// no repetition left after. +test fn the_demand_is_authored_duplication_before_the_carry() -> Bool { + every_carried_identity_is_authored_duplication_before_the_carry() +} + +test fn the_demand_is_a_single_acquisition_after_the_carry() -> Bool { + every_carried_identity_is_a_single_demand_after_the_carry() + && the_minimized_demand_graph_is_green() +} + +// KEY represents every declared input the result depends on: the tier is CONTENT-keyed, which is +// what makes a changed carrier content a different key rather than a stale hit. +test fn the_provider_is_content_keyed_and_a_store_tier() -> Bool { + let p = prepared_effect_input_provider() + provider_is_content_keyed(p: p) && provider_is_store_tier(p: p) +} + +// RETENTION spans the obligated lifetime and no longer: released when the prepared subject's +// scope exits, with an exact byte ceiling — the two predicates `std.cache_interface` separates +// deliberately, because scope release is evidence about growth over time and never about peak. +test fn the_retention_is_scope_released_and_byte_bounded() -> Bool { + let r = cross_claim_tier_retention() + retention_growth_is_bounded(r: r) && retention_has_exact_byte_bound(r: r) +} + +// COVERAGE includes every enrolled identity: a row enrolled but uncovered would be refused by the +// fold above, so this states the population is nonempty — an empty coverage would make the +// discharge test vacuously true, which is the decoration DESIGN section 4b refuses. +test fn the_covered_population_is_not_empty() -> Bool { + length(xs: carried_input_identities()) > 0 + && length(xs: carried_input_verdicts_before_the_carry()) > 0 + && length(xs: carried_input_verdicts_after_the_carry()) > 0 +} + +// THE TWO ROSTER WALLS, over the live rows: every carried-input row names an input that is +// actually prepared, and no producer stands in both a plain roster and a carried-input row — +// the second is the one that matters, because a plain warm row stores under the EMPTY argument +// row while a carried-input row stores under the carried content, so a producer in both would be +// servable under a key that does not represent the carrier. +test fn every_carried_row_names_a_prepared_input() -> Bool { + length(xs: carried_input_rows_without_a_prepared_input( + rows: floor_cross_claim_carried_input_warm_rows, + inputs: floor_cross_claim_prepared_effect_inputs + )) == 0 +} + +test fn no_producer_is_both_carried_and_plainly_rostered() -> Bool { + length(xs: carried_input_roster_collisions( + rows: floor_cross_claim_carried_input_warm_rows, + admitted: floor_cross_claim_admitted_producers() + )) == 0 +} diff --git a/src/v2/workflow/floor_prepared_effect_input_ladder.dag b/src/v2/workflow/floor_prepared_effect_input_ladder.dag new file mode 100644 index 00000000000..cdfab04b479 --- /dev/null +++ b/src/v2/workflow/floor_prepared_effect_input_ladder.dag @@ -0,0 +1,255 @@ +module v2.workflow.floor_prepared_effect_input_ladder + +import std.cache_interface { + AtCapacityDisposition, ByteCapacity, CapacityBounded, CapacityLimit, CapacityPolicy, + CapacityValue, ExactLimit, ProviderRetention, ReleasePolicy, ReleasedAtProviderScopeExit, + RefuseNewStore +} +import std.materialization_ladder { + CacheCoverage, CacheKeying, CacheProvider, ContentKeyed, CoversIdentities, DemandNature, + Frame, FrameDemand, FrameKind, IsolatedChildrenFrame, LadderVerdict, MemoTier, + PureComputation, SharedStateFrame, WorldRead, ladder_verdict_is_green, materialization_ladder, + verdict_is_accepted_single_recompute, verdict_is_authored_duplication +} +import std.measure { byte_size } +import v2.std.collection { List } +import v2.workflow.floor_pure_producer_share { + CarriedInputWarmRow, PreparedEffectInput, carried_input_warm_producers, + floor_cross_claim_carried_input_warm_rows, floor_cross_claim_prepared_effect_inputs, + prepared_effect_input_acquisitions +} +import v2.std.text { String } + +// THE LADDER ANSWER FOR THE PREPARED-EFFECT-INPUT CARRY, AT THE LADDER'S OWN VOCABULARY. +// +// WHY THIS IS A MODULE AND NOT A PARAGRAPH IN THE ROSTER. DESIGN section 2 names +// `std.materialization_ladder` as the STRUCTURAL AUTHORITY over "another production may exist", +// and a citation that lives only in a plan document is a side channel: the next reader opens the +// roster declaration, not the plan (bright-boar-435's condition on the 2026-09-14 adjudication). +// So the obligations are carried as TYPED VALUES a fold decides, not as prose a reader is asked +// to believe. +// +// WHY IT IS NOT IN THE ROSTER MODULE ITSELF. `v2.workflow.floor_pure_producer_share` is a +// declared closure seed of the required floor, so every import it grows widens the subject every +// required run must frame — its own header says a wall that costs the floor a new module edge is +// a worse trade than one spelled in the kernel. This module imports the roster; the roster +// imports nothing new. The floor never frames this module, and the witness lane does. +// +// WHAT IS NOT RESTATED HERE. That a carry across an isolation boundary needs a STORE tier is +// derived by `std.materialization_ladder.tier_axes` from the addressing axis — an edge-addressed +// reference cannot span a boundary the edge does not cross. This module states the facts of THIS +// provider and lets that authority decide; restating the rule would be the fork the ladder exists +// to prevent. + +// THE FRAME PATH, and each frame's kind is a fact about the floor's own execution rather than a +// label. Preparation is a SHARED-STATE frame: one process, one prepared subject, and the carried +// value is bound in it. A claim is an ISOLATED-CHILDREN frame because the floor builds a fresh +// evaluation frame per claim deliberately — one witness must not contaminate the next — which is +// exactly why the eval-frame memo dies at every claim boundary and why the obligation LCA is +// preparation rather than any claim. +fn floor_preparation_frame() -> Frame { + Frame { name: "required-floor-preparation", kind: SharedStateFrame } +} + +fn floor_claim_frame(name: String) -> Frame { + Frame { name: name, kind: IsolatedChildrenFrame } +} + +fn floor_claim_site(name: String) -> List { + [floor_preparation_frame(), floor_claim_frame(name: name)] +} + +// THE PROVIDER: the cross-claim pure-producer tier, described as it actually behaves. +// +// scope — the preparation frame, which is the least common visible ancestor of the claims. +// coverage — the enrolled identities and nothing else; admission is a declared roster, never +// every pure call, because cross-claim retention is byte-unbounded by construction. +// tier — MemoTier { ContentKeyed }: an in-process store whose key is the resolved fn node +// plus the portable argument row, and the carried value IS that argument row. +// retention — released when the prepared subject is cleared, with the exact 256 MiB ceiling the +// tier enforces at publication and RefuseNewStore as its at-capacity disposition +// (an over-budget producer recomputes per claim as if never enrolled). +fn cross_claim_tier_retention() -> ProviderRetention { + ProviderRetention { + release_policy: ReleasedAtProviderScopeExit, + capacity: CapacityBounded { + limit: ByteCapacity { limit: ExactLimit { value: byte_size(count: 268435456) } }, + at_capacity: RefuseNewStore + } + } +} + +fn carried_input_identities() -> List { + concat( + prepared_effect_input_acquisitions(inputs: floor_cross_claim_prepared_effect_inputs), + carried_input_warm_producers(rows: floor_cross_claim_carried_input_warm_rows) + ) +} + +fn prepared_effect_input_provider() -> CacheProvider { + CacheProvider { + id: "floor-cross-claim-pure-share", + scope: [floor_preparation_frame()], + coverage: CoversIdentities { identities: carried_input_identities() }, + tier: MemoTier { keying: ContentKeyed }, + retention: cross_claim_tier_retention() + } +} + +// THE DEMANDS, one per consuming claim frame, at the two natures this carry actually has. +// +// The ACQUISITION is a `WorldRead` with its staleness envelope DECLARED, and the declaration is +// not a flag set to true: the envelope is the prepared subject itself. The path is a committed +// checkout input, confirmed under the checkout root by the same wall that refuses everything it +// cannot confirm, so the content cannot change within one prepared run — which is what makes one +// acquisition the same value every claim would have read for itself. +// +// The PRODUCER is a `PureComputation`, and it is pure BY EXECUTION rather than by assertion: an +// implicit-acquisition row whose warm dispatches any effect with the carry installed is refused +// by the floor, because a remaining effect is a second input the key does not represent. +fn acquisition_demand(acquisition: String, claim: String) -> FrameDemand { + FrameDemand { + identity: acquisition, + site: floor_claim_site(name: claim), + nature: WorldRead { staleness_envelope_declared: true } + } +} + +fn producer_demand(producer: String, claim: String) -> FrameDemand { + FrameDemand { + identity: producer, + site: floor_claim_site(name: claim), + nature: PureComputation + } +} + +// TWO DEMAND SHAPES, BEFORE AND AFTER THE CARRY, because the ladder's verdict for this mechanism +// is not one fact but a transition — and the first cut of this module asserted the wrong half of +// it, which the floor caught by execution (`the_carry_is_discharged_at_the_preparation_lca` +// returned false on run 34854251612). +// +// WHAT THE LADDER ACTUALLY SAYS, and it is DESIGN section 2's own sentence: when several demands +// share a least common ancestor that is a SHARED-STATE frame, the repetition is AUTHORED +// DUPLICATION and the repair is to CARRY, REWIRE OR SHARE THE FIRST VALUE — "caching a later +// request only makes redundant work cheap and suppresses the signal that would make it rank for +// deletion". `group_redundant_verdict` implements exactly that: it reaches `discharge_verdict` +// only when the obligation LCA's last frame is NOT shared state. So a provider can never +// discharge this shape, and asserting `Discharged` was asking the ladder to bless the move it +// exists to refuse. +// +// So the two shapes are stated and both are checked. BEFORE: each consuming claim demands the +// identity for itself, two isolated claim frames under preparation, and the ladder answers +// AuthoredDuplication at the preparation LCA — the ladder NAMING the defect this change removes. +// AFTER: the demand is rewired to preparation, where it happens ONCE, and the ladder answers +// AcceptedSingleRecompute — no obligation left, because there is no repetition left. The provider +// below is not thereby decoration: it is WHERE the carried value is held between the acquisition +// and the claims, and its own obligations (content keying, store tier, bounded retention) are +// checked in the witness against `std.cache_interface`'s predicates. + +// Two consuming claim frames is the minimum that makes a demand SHARED — one demand is a single +// recompute the ladder accepts and this roster refuses to enrol besides ("a single-consumer warm +// row is the per-claim budget relocated, not a recurrence removed"). The live population is +// larger; these two stand for the shape, and the roster's own measurement field names the +// instrument that re-derives the real one. +fn carried_input_demands_before_the_carry( + rows: List, + inputs: List +) -> List { + concat( + fold(inputs, init: [], f: fn(acc, prepared) { + concat(acc, [ + acquisition_demand(acquisition: prepared.acquisition, claim: "claim-a"), + acquisition_demand(acquisition: prepared.acquisition, claim: "claim-b") + ]) + }), + fold(rows, init: [], f: fn(acc, row) { + concat(acc, [ + producer_demand(producer: row.producer, claim: "claim-a"), + producer_demand(producer: row.producer, claim: "claim-b") + ]) + }) + ) +} + +// AFTER: one demand per identity, sited at preparation itself — the acquisition happens once +// there and the producer is folded once over the carried value. +fn acquisition_demand_at_preparation(acquisition: String) -> FrameDemand { + FrameDemand { + identity: acquisition, + site: [floor_preparation_frame()], + nature: WorldRead { staleness_envelope_declared: true } + } +} + +fn producer_demand_at_preparation(producer: String) -> FrameDemand { + FrameDemand { + identity: producer, + site: [floor_preparation_frame()], + nature: PureComputation + } +} + +fn carried_input_demands_after_the_carry( + rows: List, + inputs: List +) -> List { + concat( + fold(inputs, init: [], f: fn(acc, prepared) { + concat(acc, [acquisition_demand_at_preparation(acquisition: prepared.acquisition)]) + }), + fold(rows, init: [], f: fn(acc, row) { + concat(acc, [producer_demand_at_preparation(producer: row.producer)]) + }) + ) +} + +fn carried_input_verdicts_before_the_carry() -> List { + materialization_ladder( + demands: carried_input_demands_before_the_carry( + rows: floor_cross_claim_carried_input_warm_rows, + inputs: floor_cross_claim_prepared_effect_inputs + ), + providers: [prepared_effect_input_provider()], + cost_floor_exempt: [] + ) +} + +fn carried_input_verdicts_after_the_carry() -> List { + materialization_ladder( + demands: carried_input_demands_after_the_carry( + rows: floor_cross_claim_carried_input_warm_rows, + inputs: floor_cross_claim_prepared_effect_inputs + ), + providers: [prepared_effect_input_provider()], + cost_floor_exempt: [] + ) +} + +// Every enrolled identity is AUTHORED DUPLICATION before the carry, decided by the ladder fold +// rather than claimed here: two claim-sited demands whose LCA is the preparation frame. +fn every_carried_identity_is_authored_duplication_before_the_carry() -> Bool { + let verdicts = carried_input_verdicts_before_the_carry() + fold(carried_input_identities(), init: true, f: fn(acc, identity) { + acc && any(xs: verdicts, predicate: fn(v) { + verdict_is_authored_duplication(v: v, identity: identity, site_count: 2) + }) + }) +} + +// And every one of them is a SINGLE RECOMPUTE after it: the carry removed the repetition rather +// than making it cheap, which is the only move DESIGN section 2 admits at a shared-state LCA. +fn every_carried_identity_is_a_single_demand_after_the_carry() -> Bool { + let verdicts = carried_input_verdicts_after_the_carry() + fold(carried_input_identities(), init: true, f: fn(acc, identity) { + acc && any(xs: verdicts, predicate: fn(v) { + verdict_is_accepted_single_recompute(v: v, identity: identity) + }) + }) +} + +// The after-state carries no refusal of any kind: every verdict is green. +fn the_minimized_demand_graph_is_green() -> Bool { + fold(carried_input_verdicts_after_the_carry(), init: true, f: fn(acc, v) { + acc && ladder_verdict_is_green(v: v) + }) +} diff --git a/src/v2/workflow/floor_pure_producer_share.dag b/src/v2/workflow/floor_pure_producer_share.dag index 73f0ea2d062..b2b8bbf13ab 100644 --- a/src/v2/workflow/floor_pure_producer_share.dag +++ b/src/v2/workflow/floor_pure_producer_share.dag @@ -904,3 +904,205 @@ fn share_roster_pending_collisions( } })) } + +// ── A THIRD FILL DISPOSITION: A PREPARED EFFECT INPUT, CARRIED ──────────────────────────── +// +// THE ROW KIND THIS FILE COULD NOT SPELL. The two rosters above are the two dispositions a +// fill can have: a WARM row is nullary and preparation-forceable, a CLAIM-FORCED row has +// claim-shaped arguments and fills inside the fold. A producer whose value depends on ONE +// READ OF A COMMITTED CARRIER fits neither, and the reason is in the KEY rather than in +// anyone's taste: a stored entry is keyed on (resolved fn node, portable ARGUMENT ROW), and a +// nullary call that reaches a read contributes NOTHING about what it read to that key. Warming +// it would let two different carrier contents share one entry — the content form of the +// ctx-blind homonym class this file already refuses by resolving every spelling to a node. So +// such a producer could only ever be CLAIM-FORCED, where it re-derives once per claim frame: +// the rostered class `shared_precondition_re_derived_once_per_claim_frame`. +// +// THE LIVE INSTANCE. `gunbc.roadmap_authority.roadmap_authority_projection` is one +// `Filesystem.Read` of `dag/gunbc/roadmap/roadmap_acceptance_event_history.jsonl` followed by a +// pure fold, demanded by seven required-lane claims and by gunbc#10994 — whose merge path is +// blocked by an enrolment margin on exactly this shared precondition. +// +// WHY CARRYING IT IS BINDING AN INPUT AND NOT CACHING AN EFFECT, which is the whole licence for +// this row kind. Hermetic evaluation ALREADY classifies this read as INPUT ACCESS: the +// checkout-input carve-out in `v1_interpreter::eval_service_call` dispatches a readonly +// `Filesystem.Read`/`List` wet when `hermetic_checkout_input_disposition` confirms the path +// under the checkout root, and refuses — typed and located — everything it cannot confirm (an +// out-of-root path, a `.git`/`target` component, an unresolvable path). The value is therefore a +// function of the commit the run prepared, constant for the whole prepared subject, and +// ACQUIRING IT ONCE IS BINDING AN INPUT THE RUN ALREADY HOLDS FIXED. A producer reaching host +// state that wall cannot confirm is never carryable, because that wall refuses it first. +// +// WHAT PREPARATION DOES, and every arm of it stops the line rather than widening: +// 1. resolve each acquisition to its fn node in a frame over the prepared subject; +// 2. refuse any acquisition that is not nullary — a carried input WITH arguments is a +// different concept and must not arrive under this one; +// 3. evaluate it ONCE under the shared-build observation, so it is billed to preparation and +// adjudicated by the same preparation refusal as every other shared build; +// 4. reify the value TOTALLY to its portable form — the same total walk publication already +// performs — and take its structural digest as the carried CONTENT IDENTITY; +// 5. bind it for the prepared subject's lifetime, cleared with the tier. +// +// NO STALE SERVE IS UNWRITABLE RATHER THAN GUARDED. The carried value IS the key material: a +// changed carrier content produces a different portable argument row, the stored row fails to +// match, and the producer recomputes. There is no staleness check to forget to run, which is +// DESIGN section 5's construction-over-validation in the one place a cache usually gets it +// backwards. +// +// THE FLOOR NEVER READS A DOMAIN TYPE. When an acquisition SUCCEEDS and returns its own +// coproduct's refusal arm (`RoadmapAcceptanceEventHistoryLoadRefused` and its peers), the +// carried value is that refusal, faithfully, and every claim receives the IDENTICAL typed value +// it would have computed for itself. That is propagation, not widening: no claim passes where it +// would otherwise have failed, and the alternative — the floor stopping on a named domain +// variant — would make this module enumerate `gunbc.roadmap_authority`'s vocabulary, the section +// 3 layer inversion (adjudicated 2026-09-14: fierce-lark-661 and bright-boar-435, both +// approving, the second conditioning approval on the disposition being PRINTED so a run where +// the carrier refused is diagnosable rather than silent — the floor's phase line carries the +// carried value's outermost variant name and content digest for exactly that reason). +// +// SECTION 2's LADDER, WHICH IS THE STRUCTURAL AUTHORITY HERE AND IS CITED IN SOURCE RATHER THAN +// IN A PLAN DOC. `std.materialization_ladder` is the authority this row kind answers to, and the +// answer is stated at its own vocabulary: the demand's identity is the resolved declaration; the +// obligation LCA is required-floor PREPARATION, which is the least common visible ancestor of +// the consuming claims (each claim is an isolated frame, so the carry crosses an isolation +// boundary and only a STORE tier may discharge it — `std.materialization_ladder.tier_axes` +// derives that, this module does not restate it); the provider is the cross-claim tier, a +// `MemoTier { keying: ContentKeyed }` whose coverage is the enrolled identities below and whose +// retention is released at its scope's exit with an exact byte ceiling. The section 2 ordering is +// respected in the direction the text writes it: the demand graph is MINIMIZED FIRST — the +// repetition has a shared-state least common ancestor, so it is authored duplication whose repair +// is to CARRY the first value, and the tier is merely where the carried value is held. The typed +// THE FOUR OBLIGATIONS, EACH AS A TYPED VALUE DERIVED FROM THE ROW, and deliberately NOT as four +// more String fields beside it. A row already carries its computation identity — the resolved +// declaration in `acquisition` / `producer` — and the other three are properties of the provider, +// not of the row, so copying them per row would be one fact in two places (section 3) and the +// transcription section 6 forbids. They are derived and named here instead: +// computation identity -> the row's own `acquisition` / `producer`, consumed as the ladder +// demand's `identity` by `floor_prepared_effect_input_ladder.acquisition_demand` and +// `producer_demand`; +// declared inputs -> the carried content digest, which IS the stored key's argument row; +// stated to the ladder as `MemoTier { keying: ContentKeyed }` and printed per run on the +// `phase=prepared-effect-input-acquire` line as `content_digest=`; +// provider scope -> `floor_prepared_effect_input_ladder.floor_preparation_frame`, the +// obligation LCA of the consuming claims — and the ladder's verdict at a SHARED-STATE LCA is +// AuthoredDuplication rather than Discharged, which is the ladder refusing to let a provider +// stand in for the carry: section 2's repair there is to carry the first value, so the pair +// `every_carried_identity_is_authored_duplication_before_the_carry` / +// `every_carried_identity_is_a_single_demand_after_the_carry` states the transition this row +// kind performs instead of claiming a discharge the ladder would not give; +// retention -> `floor_prepared_effect_input_ladder.cross_claim_tier_retention`, +// released at the provider's scope exit with the tier's exact byte ceiling. +// The conformance rows and the fold that decides them live in +// `v2.workflow.floor_prepared_effect_input_ladder`, one module out, because THIS module is a +// declared closure seed of the required floor (`REQUIRED_FLOOR_RUNTIME_AUTHORITY_MODULES`) and +// every import it grows widens the subject every required run must frame. + +// HOW A WARM ROW DECLARES ITS DEPENDENCE ON A CARRIED INPUT, and there are exactly two shapes +// because there are exactly two ways a producer can reach the acquisition. +// +// `BoundParameter` — the producer TAKES the acquired value as a named argument, so a claim's own +// call already carries the content in its argument row and the stored key needs no help. This is +// the shape gunbc#11303 is moving the roadmap projections to. +// +// `ImplicitAcquisition` — the producer is nullary and reaches the acquisition INSIDE itself. The +// carried input's content identity is folded into the key on both the warm and the serve, so the +// entry is content-keyed exactly as the parameterised shape is. This arm carries one obligation +// the other does not, and it is enforced by execution rather than by this sentence: with the +// carry installed, the producer's warm must dispatch NO effect. A producer that still reaches +// the world has a second input the key does not represent, and the floor refuses the row — +// `PreparedEffectInputProducerStillDispatchesEffect` — rather than storing a value whose key is +// incomplete. That is the one check that separates "its only input is this carrier" from "we +// hope its only input is this carrier". +type CarriedInputDependence + = BoundParameter { parameter: String } + | ImplicitAcquisition + +// `acquisition` is the nullary declaration whose evaluation acquires the input; `checkout_input` +// is the committed path whose content IS the declared input, named so a reader can see WHAT the +// carried identity is a digest of without running the floor. `ground` states why this is a +// commit-determined input rather than host state; `measurement` names the instrument that +// re-derives the row's present-vs-absent verdict and never transcribes its output. +type PreparedEffectInput { + acquisition: String + checkout_input: String + ground: String + measurement: String +} + +type CarriedInputWarmRow { + producer: String + carried_input: String + dependence: CarriedInputDependence + measurement: String +} + +data floor_cross_claim_prepared_effect_inputs: List = [ + PreparedEffectInput { + acquisition: "gunbc.roadmap_authority.roadmap_acceptance_event_history_load", + checkout_input: "dag/gunbc/roadmap/roadmap_acceptance_event_history.jsonl", + ground: "A committed carrier under the checkout root, so hermetic evaluation already reads it as INPUT ACCESS rather than a host effect (v1_interpreter hermetic_checkout_input_disposition). Its content is fixed by the commit the run prepared, which is what makes one acquisition at preparation the same value every claim would have read for itself. Demanded by every claim that reaches the roadmap authority: the seven required-lane roadmap claims and gunbc#10994's forecast witness.", + measurement: "Present-vs-absent on this row, both arms by workflow_dispatch on a branch ref pinned to an exact sha per this module's corrected procedure, read over required_floor_claim_cost.tsv and the run's own [floor-shared-fill] ledger; the acquisition's own arm is the run's effect-dispatch count for this carrier, which is 1 with the row enrolled and one-per-consuming-claim without it." + } +] + +data floor_cross_claim_carried_input_warm_rows: List = [ + CarriedInputWarmRow { + producer: "gunbc.roadmap_authority.roadmap_authority_projection", + carried_input: "gunbc.roadmap_authority.roadmap_acceptance_event_history_load", + dependence: ImplicitAcquisition, + measurement: "The same sha-pinned present-vs-absent pair as its input row, normalised on claims in no consumer module of any enrolled key. Admitted only on serve-below-recompute at identity grain; a row that does not clear it is withdrawn into floor_cross_claim_refused_candidates rather than defended by a family aggregate. ImplicitAcquisition is the shape on main today: gunbc#11303 moves the live callers to the explicit-history spelling, at which point this row becomes BoundParameter and the producer's own nullary wrapper stops existing — the migration is a row edit, not a mechanism change." + } +] + +// The carried-input producers as names, folded exactly like `refused_share_producers` and +// `pending_share_producers`, for the reason those two state: the walls below need identities, and +// a third spelling of this fold would be the duplicate this file exists to price. +fn carried_input_warm_producers(rows: List) -> List { + reverse(fold(rows, init: [], f: fn(acc, row) { concat([row.producer], acc) })) +} + +fn prepared_effect_input_acquisitions(inputs: List) -> List { + reverse(fold(inputs, init: [], f: fn(acc, row) { concat([row.acquisition], acc) })) +} + +// THE WALL: A CARRIED-INPUT ROW MAY NOT NAME AN INPUT NOBODY PREPARES. +// +// A row whose `input` matches no `PreparedEffectInput.acquisition` declares a dependence on a +// value that will never be bound. The floor refuses it at install, so this fold is the same fact +// stated where a fixture can redden it: over the live rosters it is green and could be reddened +// only by editing the corpus it guards, which DESIGN section 4b calls a decoration — as a +// function of both populations the forbidden state is writable in a fixture and the live tree is +// the positive control. +fn carried_input_rows_without_a_prepared_input( + rows: List, + inputs: List +) -> List { + let prepared = prepared_effect_input_acquisitions(inputs: inputs) + reverse(fold(rows, init: [], f: fn(acc, row) { + if any(xs: prepared, predicate: fn(p) { p == row.carried_input }) { + acc + } else { + concat([row.producer], acc) + } + })) +} + +// THE SECOND WALL: A PRODUCER MAY NOT CARRY AN INPUT AND ALSO STAND IN A PLAIN ROSTER. +// +// The two enrolments are different keys for one identity — a plain warm row stores under the +// EMPTY argument row while a carried-input row stores under the carried content — so a producer +// in both would have one value servable under a key that does not represent the carrier, which is +// precisely the stale serve this row kind exists to make unwritable. One identity, one +// disposition. +fn carried_input_roster_collisions( + rows: List, + admitted: List +) -> List { + reverse(fold(carried_input_warm_producers(rows: rows), init: [], f: fn(acc, name) { + if any(xs: admitted, predicate: fn(d) { d == name }) { + concat([name], acc) + } else { + acc + } + })) +}