Skip to content

Commit b123ac8

Browse files
committed
run: under an egress policy, rehydrate only what a model produced (#350)
`Runner::rehydrate_from_model` ran over the input of every dispatch, so a host or code tool whose input carried a `[PERSON_1]`-shaped marker no model produced was refused ("the model produced placeholder this run cannot resolve"), and one matching an older mapping key was silently rewritten to that mapping's value. Rehydration and its fail-closed refusal now cover only tokens emitted by a model turn of the run (LLM effects, conservatively plus subgraph results), read off the journaled outcomes so resume agrees with a fresh run. Host-written text passes verbatim; an LLM turn's own input is no longer rehydrated. The manifest froze bound Tool Definitions through the egress-bounded `get`, pinning `hosts: ["http://127.0.0.1:7792"]` as `http://[IPV4_1]:7792` and refusing the tool's first brokered call with RUN-E022. New `Areev::get_stored` (no egress boundary) is used for the manifest's bindings/config/input_ref, shadow's arg-schema load and the trigger connector Definition. Closes #350.
1 parent 7818b7c commit b123ac8

12 files changed

Lines changed: 363 additions & 25 deletions

File tree

‎ARCHITECTURE.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,11 @@ corrupt record — so pseudonymizing the tool seam would break the workflows the
10431043
feature exists to serve.
10441044

10451045
So the run driver pseudonymizes an abstract node's prompt and rehydrates the
1046-
model's tool-call arguments before dispatch. Rehydration is for dispatch only:
1046+
model's tool-call arguments before dispatch — only placeholders a model turn
1047+
of the run actually produced (#350): host-written text of the same shape
1048+
passes verbatim, and the run's own configuration (Tool Definitions, the
1049+
manifest) is read from the stored grain, not through the egress rewrite.
1050+
Rehydration is for dispatch only:
10471051
the journal keeps the pseudonymized form and the idempotency key derives from
10481052
it, so `verify` replays byte-identically whether or not a policy is live. An
10491053
unresolvable placeholder fails the node rather than sending itself to a vendor.

‎CHANGELOG.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- **With an egress policy live, only what a model produced is rehydrated**
12+
(#350). `areev run` used to run placeholder rehydration over the input of
13+
every dispatch, so a host or code tool whose input carried a
14+
`[PERSON_1]`-shaped marker no model produced failed with `the model
15+
produced placeholder this run cannot resolve` — every run of a
16+
model-free pseudonymizing pipeline failed once the floor was on — and a
17+
marker that happened to match an older mapping key was silently rewritten
18+
to that mapping's value. Rehydration (and its fail-closed refusal) now
19+
covers only placeholders emitted by a model turn of the run (or a
20+
subgraph's result); anything else is dispatched verbatim. An LLM turn's own
21+
input is no longer rehydrated, so a refused tool call no longer also fails
22+
the model's next turn.
23+
- **Run configuration is frozen from the stored grain, not through the egress
24+
rewrite** (#350). The manifest resolved bound Tool Definitions with the
25+
egress-bounded `get`, so a `wasm32-areev-io` Definition declaring
26+
`hosts: ["http://127.0.0.1:7792"]` was pinned as `http://[IPV4_1]:7792` and
27+
its first brokered call refused with `RUN-E022`. The manifest (bindings,
28+
stored config, input by reference), the shadow argument-schema load and the
29+
trigger connector Definition now read through the new `Areev::get_stored`.
30+
931
## [1.9.4] — 2026-09-23
1032

1133
### Added

‎crates/areev-run/src/manifest.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl RunManifest {
397397
let h = Hash::from_hex(hash_str).map_err(|_| RunError::UnresolvedRef {
398398
what: format!("binding for node '{node}' is not a content address"),
399399
})?;
400-
let g = m.get(&h).map_err(|e| RunError::UnresolvedRef {
400+
let g = m.get_stored(&h).map_err(|e| RunError::UnresolvedRef {
401401
what: format!("binding for node '{node}': {e}"),
402402
})?;
403403
if g.grain_type == areev_core::types::GrainType::Workflow {
@@ -749,7 +749,7 @@ impl RunManifest {
749749
.ok_or_else(|| RunError::ManifestMismatch {
750750
why: "manifest link carries no config hash".into(),
751751
})?;
752-
let config = m.get(&config_hash).map_err(|e| RunError::ManifestMismatch {
752+
let config = m.get_stored(&config_hash).map_err(|e| RunError::ManifestMismatch {
753753
why: format!("manifest config unreadable: {e}"),
754754
})?;
755755
let manifest = config
@@ -782,7 +782,7 @@ impl RunManifest {
782782
let h = Hash::from_hex(&hex).map_err(|_| RunError::ManifestMismatch {
783783
why: format!("input_ref {hex:?} is not a content address"),
784784
})?;
785-
let grain = m.get(&h).map_err(|_| RunError::UnresolvedRef {
785+
let grain = m.get_stored(&h).map_err(|_| RunError::UnresolvedRef {
786786
what: format!(
787787
"run '{}' stores its input as grain {hex}, which is no longer readable \
788788
— the input a run replays from cannot be reconstructed, so verify and \

‎crates/areev-run/src/runner.rs‎

Lines changed: 112 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,48 @@ fn substitute_strings(v: &Value, next: &mut std::vec::IntoIter<String>) -> Value
290290
}
291291
}
292292

293+
/// Every placeholder-shaped token a model turn of this run produced — the
294+
/// set [`Runner::rehydrate_from_model`] is allowed to resolve or refuse.
295+
///
296+
/// Read off the journaled outcomes, not accumulated from live calls, so a
297+
/// resumed run and a fresh one agree: `results` holds every settled effect
298+
/// the journal records, replayed or not. "Model turn" means an LLM effect,
299+
/// and — conservatively — a subgraph's result, which may carry a child
300+
/// model's output into the parent.
301+
#[derive(Default)]
302+
struct ModelTokens {
303+
scanned: std::collections::BTreeSet<JournalKey>,
304+
tokens: std::collections::BTreeSet<String>,
305+
}
306+
307+
impl ModelTokens {
308+
fn refresh(
309+
&mut self,
310+
results: &BTreeMap<JournalKey, EffectOutcome>,
311+
model_origin: &dyn Fn(&JournalKey) -> bool,
312+
template: &str,
313+
) -> Result<(), String> {
314+
let none = BTreeMap::new();
315+
for (key, outcome) in results {
316+
if self.scanned.contains(key) || !model_origin(key) {
317+
continue;
318+
}
319+
self.scanned.insert(key.clone());
320+
let EffectOutcome::Completed { result, .. } = outcome else { continue };
321+
let mut strings = Vec::new();
322+
collect_strings(result, &mut strings);
323+
for s in strings {
324+
// Against an empty mapping every placeholder is a leftover,
325+
// in the policy's own shape.
326+
let r = areev_core::anon::rehydrate_with_template(&s, &none, template)
327+
.map_err(|e| e.to_string())?;
328+
self.tokens.extend(r.unmatched);
329+
}
330+
}
331+
Ok(())
332+
}
333+
}
334+
293335
/// The anonymization boundary between run state and a model.
294336
///
295337
/// ## Why this seam and not the tool seam
@@ -307,14 +349,24 @@ fn substitute_strings(v: &Value, next: &mut std::vec::IntoIter<String>) -> Value
307349
/// ## The round trip
308350
///
309351
/// Out, in [`Runner::pseudonymize_for_model`]: every string in the LLM effect's input is
310-
/// pseudonymized. Back, in [`Runner::rehydrate_from_model`]: the tool-call arguments the
311-
/// model produced are rehydrated *before* dispatch, so the tool sees real
312-
/// values again.
352+
/// pseudonymized. Back, in [`Runner::rehydrate_from_model`]: placeholders a
353+
/// MODEL produced are rehydrated *before* dispatch, so the tool sees real
354+
/// values again — whether they arrive as a model's tool-call arguments or as
355+
/// its output flowing into a downstream node's input.
356+
///
357+
/// ## Only what a model produced (#350)
358+
///
359+
/// A token is rehydrated — or refused — only when it appears in the output of
360+
/// a model turn in this run ([`ModelTokens`]). Text a host or code tool wrote
361+
/// itself is dispatched verbatim, even when it has the placeholder's shape: a
362+
/// deterministic pipeline that pseudonymizes a record before it leaves writes
363+
/// `[PERSON_1]` markers no model produced, and neither failing them as
364+
/// "unresolvable" nor splicing in an older mapping's value for them is right.
313365
///
314366
/// Rehydration **fails closed**. `rehydrate` leaves a token it cannot resolve
315367
/// intact and reports it; dispatching a partially rehydrated call would post a
316-
/// literal `[PERSON_A4F2]` to a vendor, so an unresolved token fails the node
317-
/// instead.
368+
/// literal `[PERSON_A4F2]` to a vendor, so an unresolved model-produced token
369+
/// fails the node instead.
318370
impl Runner {
319371
/// Is a model-facing anonymization policy live for this run's namespace?
320372
fn anon_boundary_active(&self) -> Result<bool, RunError> {
@@ -341,19 +393,27 @@ impl Runner {
341393
Ok(substitute_strings(input, &mut values.into_iter()))
342394
}
343395

344-
/// Rehydrate what came back, or say exactly which token could not be.
396+
/// Rehydrate the placeholders a model produced, or say exactly which one
397+
/// could not be.
398+
///
399+
/// Scoped to [`ModelTokens`]: a placeholder-shaped string no model turn of
400+
/// this run emitted is host-written text and passes through verbatim —
401+
/// never failed as unresolvable, never rewritten to whatever an older
402+
/// mapping of the namespace holds under that key (#350).
345403
///
346404
/// `Err` here is the fail-closed case: the caller turns it into a failed
347405
/// effect rather than dispatching a call with a placeholder still in it.
348-
fn rehydrate_from_model(&self, input: &Value) -> Result<Value, String> {
406+
fn rehydrate_from_model(
407+
&self,
408+
input: &Value,
409+
model: &mut ModelTokens,
410+
results: &BTreeMap<JournalKey, EffectOutcome>,
411+
model_origin: &dyn Fn(&JournalKey) -> bool,
412+
) -> Result<Value, String> {
349413
let active = self.anon_boundary_active().map_err(|e| e.to_string())?;
350414
if !active {
351415
return Ok(input.clone());
352416
}
353-
let mapping = self
354-
.facade
355-
.with_store(|m| m.anon_mapping_for(&self.ns))
356-
.map_err(|e| e.to_string())?;
357417
// The policy's OWN template, not the default. Scanning for the default
358418
// silhouette while the memory mints another shape would report no
359419
// leftovers and fail open — the exact inversion of what this check is
@@ -368,12 +428,26 @@ impl Runner {
368428
if values.is_empty() {
369429
return Ok(input.clone());
370430
}
431+
model.refresh(results, model_origin, &template)?;
432+
if model.tokens.is_empty() {
433+
// No model turn produced a placeholder: nothing here is ours to
434+
// resolve, whatever its shape.
435+
return Ok(input.clone());
436+
}
437+
let mapping: BTreeMap<String, String> = self
438+
.facade
439+
.with_store(|m| m.anon_mapping_for(&self.ns))
440+
.map_err(|e| e.to_string())?
441+
.into_iter()
442+
.filter(|(k, _)| model.tokens.contains(k))
443+
.collect();
371444
let mut out = Vec::with_capacity(values.len());
372445
let mut unmatched: Vec<String> = Vec::new();
373446
for v in values {
374447
let r = areev_core::anon::rehydrate_with_template(&v, &mapping, &template)
375448
.map_err(|e| e.to_string())?;
376-
for u in r.unmatched {
449+
// A leftover no model produced is host-written text, left as is.
450+
for u in r.unmatched.into_iter().filter(|u| model.tokens.contains(u)) {
377451
if !unmatched.contains(&u) {
378452
unmatched.push(u);
379453
}
@@ -1788,6 +1862,19 @@ impl Runner {
17881862
.iter()
17891863
.filter_map(|(k, e)| e.result.as_ref().map(|(_, o)| (k.clone(), o.clone())))
17901864
.collect();
1865+
// What a model produced, for the egress round trip (#350).
1866+
let mut model_tokens = ModelTokens::default();
1867+
let model_origin = |k: &JournalKey| {
1868+
k.kind == areev_run_core::EffectKind::Llm
1869+
|| plan
1870+
.nodes
1871+
.iter()
1872+
.position(|n| *n == k.node)
1873+
.and_then(|i| executors.get(i))
1874+
.is_some_and(|e| {
1875+
matches!(e, areev_run_core::NodeExecutor::Subgraph { .. })
1876+
})
1877+
};
17911878
let mut prev_ckpt: Option<Hash> = view.checkpoints.last().map(|c| c.hash);
17921879
let mut input_cursor = view.cursor;
17931880
// The host-pause state (#344): the standing request, if any, polled
@@ -2192,7 +2279,19 @@ impl Runner {
21922279
// Rehydrate for the tool, never for the record: the
21932280
// intent above journaled the pseudonymized input and
21942281
// `idem` derives from it, so verify replays identically.
2195-
let input = match self.rehydrate_from_model(&input) {
2282+
// An LLM turn is exempt: what it sends is `to_model`,
2283+
// prepared above from the unrehydrated input.
2284+
let rehydrated = if key.kind == areev_run_core::EffectKind::Llm {
2285+
Ok(input)
2286+
} else {
2287+
self.rehydrate_from_model(
2288+
&input,
2289+
&mut model_tokens,
2290+
&results,
2291+
&model_origin,
2292+
)
2293+
};
2294+
let input = match rehydrated {
21962295
Ok(v) => v,
21972296
Err(why) => {
21982297
// Fail the node, not the run: a plan's retries

‎crates/areev-run/src/shadow.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ pub(crate) fn arg_schemas_for(
10731073
}
10741074
let h = Hash::from_hex(&p.tool_hash).map_err(|e| RunError::Storage { detail: e.to_string() })?;
10751075
let def = facade
1076-
.with_store(|m| m.get(&h))
1076+
.with_store(|m| m.get_stored(&h))
10771077
.map_err(|e| RunError::Storage { detail: e.to_string() })?
10781078
.to_tool()
10791079
.map_err(|e| RunError::Storage { detail: e.to_string() })?;

0 commit comments

Comments
 (0)