provenance: track agent phase, use task_local + thread_local

Split TASK_PROVENANCE into TASK_AGENT (task_local, set once per agent
run) and TASK_PHASE (thread_local, updated between steps). Provenance
now reports "agent:surface-observe:observe" instead of just
"agent:surface-observe", making it possible to identify which pipeline
phase created a node.

Priority: task_local agent + thread_local phase > POC_PROVENANCE env
var > "manual".

Also includes memory_search catchup throttle and pipelining fixes
from the surface-observe refactor.
This commit is contained in:
ProofOfConcept 2026-03-27 15:11:17 -04:00
parent b1efdf0b9a
commit 85302c11d4
5 changed files with 79 additions and 53 deletions

View file

@ -237,9 +237,9 @@ pub fn call_api_with_tools_sync(
.enable_all()
.build()
.map_err(|e| format!("tokio runtime: {}", e))?;
let prov = format!("agent:{}", agent);
let agent_name = format!("agent:{}", agent);
rt.block_on(
crate::store::TASK_PROVENANCE.scope(prov,
crate::store::TASK_AGENT.scope(agent_name,
call_api_with_tools(agent, prompts, temperature, bail_fn, log))
)
}).join().unwrap()

View file

@ -339,6 +339,11 @@ fn run_one_agent_inner(
}
log("\n=== CALLING LLM ===");
// Set initial phase for provenance tracking
if let Some(first_phase) = step_phases.first() {
crate::store::set_phase(first_phase);
}
// Bail check: if the agent defines a bail script, run it between steps.
// The script receives the pid file path as $1, cwd = state dir.
let bail_script = def.bail.as_ref().map(|name| {
@ -349,9 +354,10 @@ fn run_one_agent_inner(
let state_dir_for_bail = state_dir.clone();
let pid_path_for_bail = pid_path.clone();
let bail_fn = move |step_idx: usize| -> Result<(), String> {
// Update phase
// Update phase in pid file and provenance tracking
if step_idx < step_phases.len() {
write_pid(&step_phases[step_idx]);
crate::store::set_phase(&step_phases[step_idx]);
}
// Run bail script if defined
if let Some(ref script) = bail_script {