Prove runtime tool loop sealing
This commit is contained in:
parent
e58028d60f
commit
ce20529ee7
4 changed files with 205 additions and 42 deletions
|
|
@ -564,52 +564,25 @@ async fn run_worker_launch_with_tool_continuation(
|
|||
let mut openai_summary =
|
||||
run_model_turn(&options.provider, current_options.clone(), initial_request).await?;
|
||||
let mut tool_rounds = Vec::new();
|
||||
let mut previous_tool_fingerprints: Option<Vec<String>> = None;
|
||||
let mut consecutive_repeated_tool_rounds = 0usize;
|
||||
let mut tool_loop_guard = ToolLoopGuard::default();
|
||||
let mut round = 0usize;
|
||||
|
||||
while !openai_summary.tool_intent_ids.is_empty() {
|
||||
let tool_fingerprints =
|
||||
tool_intent_fingerprints(&options.store_path, &openai_summary.tool_intent_ids)?;
|
||||
if same_nonempty_tool_request_round(
|
||||
previous_tool_fingerprints.as_deref(),
|
||||
&tool_fingerprints,
|
||||
) {
|
||||
consecutive_repeated_tool_rounds += 1;
|
||||
} else {
|
||||
consecutive_repeated_tool_rounds = 0;
|
||||
}
|
||||
if consecutive_repeated_tool_rounds >= 2 {
|
||||
let summary = format!(
|
||||
"worker {} repeated the same pending tool request set for {} consecutive follow-up rounds",
|
||||
launch_request.job_id,
|
||||
consecutive_repeated_tool_rounds + 1
|
||||
);
|
||||
let result = fail_worker_job(
|
||||
if let ToolLoopDecision::Stalled {
|
||||
consecutive_rounds,
|
||||
} = tool_loop_guard.observe(tool_fingerprints.clone())
|
||||
{
|
||||
return fail_worker_for_repeated_tool_loop(
|
||||
&options.store_path,
|
||||
&launch_request.job_id,
|
||||
summary.clone(),
|
||||
"Inspect the repeated tool fingerprints and decide whether the worker needs a narrower evidence bundle, a repaired tool, or a higher explicit limit."
|
||||
.to_string(),
|
||||
)?;
|
||||
return Ok(json!({
|
||||
"status": "tool-loop-stalled",
|
||||
"store": options.store_path,
|
||||
"jobId": launch_request.job_id,
|
||||
"bindingId": launch_request.binding_id,
|
||||
"role": launch_request.role,
|
||||
"requestId": current_request_id,
|
||||
"openaiResultId": openai_summary.result_id,
|
||||
"openaiVerdict": openai_summary.verdict,
|
||||
"openaiSummary": openai_summary.summary,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"pendingToolIntentIds": openai_summary.tool_intent_ids,
|
||||
"pendingToolFingerprints": tool_fingerprints,
|
||||
"toolRounds": tool_rounds,
|
||||
}));
|
||||
&launch_request,
|
||||
¤t_request_id,
|
||||
&openai_summary,
|
||||
tool_fingerprints,
|
||||
tool_rounds,
|
||||
consecutive_rounds,
|
||||
);
|
||||
}
|
||||
if round >= options.max_tool_rounds {
|
||||
break;
|
||||
|
|
@ -641,7 +614,6 @@ async fn run_worker_launch_with_tool_continuation(
|
|||
"followupRequestId": current_request_id,
|
||||
"summary": openai_summary,
|
||||
}));
|
||||
previous_tool_fingerprints = Some(tool_fingerprints);
|
||||
round += 1;
|
||||
}
|
||||
|
||||
|
|
@ -705,6 +677,78 @@ async fn run_worker_launch_with_tool_continuation(
|
|||
}))
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct ToolLoopGuard {
|
||||
previous_tool_fingerprints: Option<Vec<String>>,
|
||||
consecutive_repeated_tool_rounds: usize,
|
||||
}
|
||||
|
||||
enum ToolLoopDecision {
|
||||
Continue,
|
||||
Stalled { consecutive_rounds: usize },
|
||||
}
|
||||
|
||||
impl ToolLoopGuard {
|
||||
fn observe(&mut self, tool_fingerprints: Vec<String>) -> ToolLoopDecision {
|
||||
if same_nonempty_tool_request_round(
|
||||
self.previous_tool_fingerprints.as_deref(),
|
||||
&tool_fingerprints,
|
||||
) {
|
||||
self.consecutive_repeated_tool_rounds += 1;
|
||||
} else {
|
||||
self.consecutive_repeated_tool_rounds = 0;
|
||||
}
|
||||
self.previous_tool_fingerprints = Some(tool_fingerprints);
|
||||
if self.consecutive_repeated_tool_rounds >= 2 {
|
||||
ToolLoopDecision::Stalled {
|
||||
consecutive_rounds: self.consecutive_repeated_tool_rounds + 1,
|
||||
}
|
||||
} else {
|
||||
ToolLoopDecision::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fail_worker_for_repeated_tool_loop(
|
||||
store_path: &Path,
|
||||
launch_request: &epiphany_core::EpiphanyRuntimeWorkerLaunchRequest,
|
||||
current_request_id: &str,
|
||||
openai_summary: &epiphany_openai_runtime::EpiphanyOpenAiRuntimeRunSummary,
|
||||
tool_fingerprints: Vec<String>,
|
||||
tool_rounds: Vec<serde_json::Value>,
|
||||
consecutive_rounds: usize,
|
||||
) -> Result<serde_json::Value> {
|
||||
let summary = format!(
|
||||
"worker {} repeated the same pending tool request set for {} consecutive follow-up rounds",
|
||||
launch_request.job_id, consecutive_rounds
|
||||
);
|
||||
let result = fail_worker_job(
|
||||
store_path,
|
||||
&launch_request.job_id,
|
||||
summary.clone(),
|
||||
"Inspect the repeated tool fingerprints and decide whether the worker needs a narrower evidence bundle, a repaired tool, or a higher explicit limit."
|
||||
.to_string(),
|
||||
)?;
|
||||
Ok(json!({
|
||||
"status": "tool-loop-stalled",
|
||||
"store": store_path,
|
||||
"jobId": launch_request.job_id,
|
||||
"bindingId": launch_request.binding_id,
|
||||
"role": launch_request.role,
|
||||
"requestId": current_request_id,
|
||||
"openaiResultId": openai_summary.result_id,
|
||||
"openaiVerdict": openai_summary.verdict,
|
||||
"openaiSummary": openai_summary.summary,
|
||||
"workerResultId": result.result_id,
|
||||
"verdict": result.verdict,
|
||||
"summary": summary,
|
||||
"nextSafeMove": result.next_safe_move,
|
||||
"pendingToolIntentIds": openai_summary.tool_intent_ids,
|
||||
"pendingToolFingerprints": tool_fingerprints,
|
||||
"toolRounds": tool_rounds,
|
||||
}))
|
||||
}
|
||||
|
||||
fn tool_intent_fingerprints(store_path: &Path, intent_ids: &[String]) -> Result<Vec<String>> {
|
||||
let mut cache = epiphany_core::runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
|
|
@ -744,7 +788,15 @@ fn same_nonempty_tool_request_round(previous: Option<&[String]>, current: &[Stri
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use epiphany_core::EpiphanyRuntimeJobStatus;
|
||||
use epiphany_core::EpiphanyWorkerLaunchDocument;
|
||||
use epiphany_core::RuntimeSpineHeartbeatJobOptions;
|
||||
use epiphany_core::default_launch_organ_contract;
|
||||
use epiphany_core::open_runtime_spine_heartbeat_job;
|
||||
use epiphany_core::runtime_job_snapshot;
|
||||
use epiphany_core::runtime_worker_launch_request;
|
||||
use epiphany_tool_adapter::EpiphanyToolInvocationIntent;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn same_nonempty_tool_request_round_requires_real_repetition() {
|
||||
|
|
@ -757,6 +809,116 @@ mod tests {
|
|||
assert!(same_nonempty_tool_request_round(Some(&first), &first));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_loop_guard_stalls_only_after_repeated_identical_rounds() {
|
||||
let mut guard = ToolLoopGuard::default();
|
||||
let first = vec!["source::read_file::{\"path\":\"README.md\"}".to_string()];
|
||||
let second = vec!["source::git_show::{\"revision\":\"HEAD\"}".to_string()];
|
||||
|
||||
assert!(matches!(
|
||||
guard.observe(first.clone()),
|
||||
ToolLoopDecision::Continue
|
||||
));
|
||||
assert!(matches!(
|
||||
guard.observe(second.clone()),
|
||||
ToolLoopDecision::Continue
|
||||
));
|
||||
assert!(matches!(
|
||||
guard.observe(first.clone()),
|
||||
ToolLoopDecision::Continue
|
||||
));
|
||||
assert!(matches!(
|
||||
guard.observe(first.clone()),
|
||||
ToolLoopDecision::Continue
|
||||
));
|
||||
assert!(matches!(
|
||||
guard.observe(first),
|
||||
ToolLoopDecision::Stalled {
|
||||
consecutive_rounds: 3
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_tool_loop_seals_outer_worker_job() -> Result<()> {
|
||||
let temp = tempdir()?;
|
||||
let store = temp.path().join("runtime.msgpack");
|
||||
open_runtime_spine_heartbeat_job(
|
||||
&store,
|
||||
RuntimeSpineHeartbeatJobOptions {
|
||||
runtime_id: "epiphany-test".to_string(),
|
||||
display_name: "Epiphany Test".to_string(),
|
||||
session_id: "epiphany-main".to_string(),
|
||||
objective: "Run typed worker.".to_string(),
|
||||
coordinator_note: "test".to_string(),
|
||||
job_id: "worker-job-loop".to_string(),
|
||||
role: "verification".to_string(),
|
||||
binding_id: "verification-review-worker".to_string(),
|
||||
authority_scope: "epiphany.role.verification".to_string(),
|
||||
instruction: "Return the required role-result JSON.".to_string(),
|
||||
launch_document: EpiphanyWorkerLaunchDocument::Role(
|
||||
epiphany_core::EpiphanyRoleWorkerLaunchDocument {
|
||||
thread_id: "thread-1".to_string(),
|
||||
role_id: "verification".to_string(),
|
||||
state_revision: 1,
|
||||
objective: Some("Verify the worker loop.".to_string()),
|
||||
dynamic_prompt_context: None,
|
||||
active_subgoal_id: None,
|
||||
active_subgoals: Vec::new(),
|
||||
active_graph_node_ids: Vec::new(),
|
||||
investigation_checkpoint: None,
|
||||
scratch: None,
|
||||
invariants: Vec::new(),
|
||||
graphs: None,
|
||||
recent_evidence: Vec::new(),
|
||||
recent_observations: Vec::new(),
|
||||
graph_frontier: None,
|
||||
graph_checkpoint: None,
|
||||
planning: None,
|
||||
churn: None,
|
||||
},
|
||||
),
|
||||
output_contract_id: epiphany_core::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(),
|
||||
organ_launch_contract: default_launch_organ_contract(
|
||||
"epiphany.role.verification",
|
||||
"role",
|
||||
epiphany_core::ROLE_WORKER_OUTPUT_CONTRACT_ID,
|
||||
),
|
||||
created_at: now(),
|
||||
},
|
||||
)?;
|
||||
let launch_request =
|
||||
runtime_worker_launch_request(&store, "worker-job-loop")?.expect("launch request");
|
||||
let openai_summary = epiphany_openai_runtime::EpiphanyOpenAiRuntimeRunSummary {
|
||||
store: store.display().to_string(),
|
||||
session_id: "openai-worker-session-verification-review-worker".to_string(),
|
||||
job_id: "openai-worker-worker-job-loop".to_string(),
|
||||
request_id: "request-3".to_string(),
|
||||
event_count: 1,
|
||||
verdict: "pass".to_string(),
|
||||
summary: "Model requested the same tool again.".to_string(),
|
||||
result_id: "result-openai-worker-job-loop".to_string(),
|
||||
receipt_id: Some("request-3".to_string()),
|
||||
tool_intent_ids: vec!["intent-readme".to_string()],
|
||||
};
|
||||
|
||||
let status = fail_worker_for_repeated_tool_loop(
|
||||
&store,
|
||||
&launch_request,
|
||||
"request-3",
|
||||
&openai_summary,
|
||||
vec!["epiphany_source::read_file::{\"path\":\"README.md\"}".to_string()],
|
||||
Vec::new(),
|
||||
3,
|
||||
)?;
|
||||
|
||||
assert_eq!(status["status"], "tool-loop-stalled");
|
||||
let snapshot = runtime_job_snapshot(&store, "worker-job-loop")?.expect("worker snapshot");
|
||||
assert_eq!(snapshot.job.status, EpiphanyRuntimeJobStatus::Failed);
|
||||
assert_eq!(snapshot.result.expect("worker result").verdict, "failed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_intent_fingerprint_ignores_argument_key_order() {
|
||||
let left = EpiphanyToolInvocationIntent::new(
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ remembers doctrine; the branch remembers the blade.
|
|||
- The planning loop is now runtime-backed and operator-visible. Typed captures, backlog items, roadmap streams, Objective Drafts, and GitHub issue source refs live in `EpiphanyThreadState`, validate through revision-gated `thread/epiphany/update`, render into prompts when present, project read-only through the `planning` view lens, render in the GUI Planning panel, can be synthesized by the fixed Imagination/planning lane, and can be explicitly adopted through the artifacted `adoptObjectiveDraft` GUI action. Chat is deliberation, not an objective pipe; ideas and GitHub Issues remain planning state until explicit human adoption.
|
||||
- The bridge/dashboard slice is now landed far enough to test locally. Native `epiphany-rider-bridge` inspects Rider installation, solution, VCS, changed files, and captures file/selection/symbol context into `.epiphany-gui/rider` artifacts; Aquarium has Inspect Rider and renders Rider audit artifacts in Environment; Aquarium also embeds the adjacent EpiphanyGraph viewer over typed `graphs.architecture`, `graphs.dataflow`, and `graphs.links`.
|
||||
- A first Rider plugin scaffold lives under `integrations/rider`: tool window, Refresh status, and Send Context to Epiphany action. It shells through native `epiphany-rider-bridge` and does not own state. `gradle` is not installed on this machine, so the scaffold is not build-verified yet.
|
||||
- Next real move: continue from the fresh Hands gate emitted by `.epiphany-dogfood/local-20260613-122655/coordinator/coordinator-final-action.txt`. The live coordinator accepted the completed Soul result and generated a `continueImplementation` gate; native status now agrees because it derives freshness through `derive_freshness` and loads typed runtime-spine role findings before deriving coordinator signals. The bounded implementation task is the missing end-to-end behavioral proof Soul asked for: prove `run-worker --auto-tools` seals repeated identical tool requests as `tool-loop-stalled` while allowing nonrepeating tool trails to continue up to the explicit ceiling. Quarantine Rider/Unity bridge work for now; those artifacts remain optional later environment evidence, not MVP blockers. Keep EpiphanyAgent focused on backend contracts, typed state, coordinator policy, heartbeat scheduling, Face guardrails, prompt-authority separation, and the ongoing purification from Python/JSON scaffolding into Rust/CultCache/CultMesh/CultNet organs. Resume repo birth/Aquarium/Rider/Unity work only when the user explicitly shifts priority back outward. GitHub Issues import is deferred until the backlog source is fresh enough to deserve Imagination's attention.
|
||||
- Next real move: record the runtime tool-loop proof commit against the fresh Hands gate emitted by `.epiphany-dogfood/local-20260613-122655/coordinator/coordinator-final-action.txt`, then rerun the coordinator so Soul verifies the new Hands receipts. The live coordinator accepted the completed Soul result and generated a `continueImplementation` gate; native status now agrees because it derives freshness through `derive_freshness` and loads typed runtime-spine role findings before deriving coordinator signals. The bounded implementation proof is now in source: `epiphany-openai-runtime` has a testable `ToolLoopGuard`, a shared repeated-loop failure helper, and tests proving nonrepeating trails do not stall while repeated identical tool requests seal the outer worker job. Verification artifacts live under `.epiphany-run/live-hands-pass-20260613-runtime-tool-loop-proof`. Quarantine Rider/Unity bridge work for now; those artifacts remain optional later environment evidence, not MVP blockers. Keep EpiphanyAgent focused on backend contracts, typed state, coordinator policy, heartbeat scheduling, Face guardrails, prompt-authority separation, and the ongoing purification from Python/JSON scaffolding into Rust/CultCache/CultMesh/CultNet organs. Resume repo birth/Aquarium/Rider/Unity work only when the user explicitly shifts priority back outward. GitHub Issues import is deferred until the backlog source is fresh enough to deserve Imagination's attention.
|
||||
- The repo is an Epiphany fork of Codex, not a Codex preset.
|
||||
- `vendor/codex` is tracked directly, not a submodule.
|
||||
- `epiphany-core` owns the heavy Epiphany organs where practical.
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -97,6 +97,7 @@ active_subgoals:
|
|||
- Hands now has a first executable runtime-spine receipt artery: `HandsActionIntent`, `HandsActionReview`, `HandsPatchReceipt`, `HandsCommandReceipt`, and `HandsCommitReceipt` are typed CultCache documents in `epiphany-core::hands_gateway`, runtime-spine registers and persists/rereads them, `epiphany-hands-action-smoke` proves the chain without executing shell commands, editing files, or creating a real commit, and the repo-action launch proof profile now requires the full Hands intent/review/patch chain instead of only the patch receipt. `epiphany-mvp-coordinator` no longer treats `continueImplementation` as a passive stop action: it persists a scoped Substrate Gate grant, Hands action intent, and Hands action review into runtime-spine and exposes the receipt ids in the operator step. The gate also carries a structured `recordPassCommand` template for the post-edit/check/commit receipt call. `epiphany-hands-action` records real patch/command/commit receipts against a stored intent/review, refuses unapproved or mismatched gates, and enforces changed-path scope for patch/commit receipts. Its `record-pass` command can load `finalAction.handsActionGate` from `coordinator-summary.json` and emit patch, command, and commit receipts in one post-implementation call. The local MVP wrapper builds this recorder with the other operator binaries. `epiphany-mvp-coordinator-smoke` now includes a deterministic Hands pass proof: forced `continueImplementation`, gate emission, and `record-pass` receipts in the smoke runtime-spine store. Live model-backed verification can now be accepted as receipt-only truth when Soul returns `needs-evidence` without a statePatch; that acceptance advances the coordinator to a real Hands gate. Runtime-spine can detect and summarize a complete post-verification Hands patch/command/commit receipt chain; the coordinator treats that chain as implementation evidence after Soul. Bridge launch context now writes the latest chain into typed internal CultMesh state as `epiphany.cultmesh.work_loop_telemetry.v0`, renders that packet for Soul, and later enriches the same internal Verse packet with Soul acceptance receipt ids for Proprioception/modeling. The telemetry packet now includes resolved patch/command/commit payload previews, artifact previews, commit diff preview, source proof notes, and verification assertions so Soul can judge the actual body without a separate evidence-gathering lane. Tests prove the CultMesh round trip, Soul launch projection, receipt payload previews, artifact previews, and Proprioception launch projection. Worker auto-tool continuation preserves real Soul evidence trails under an explicit hard ceiling while sealing repeated identical typed tool intent fingerprints as `tool-loop-stalled`. The work loop is dependency-shaped: Hands produces consequence receipts, Soul verifies those receipts and the changed body, Proprioception updates the machine model from verified consequence, and only then should Self route the next Hands turn.
|
||||
- Soul result recovery is typed state, not manual broom work. Failed Verification/Soul results remain terminal reviewable lane results; a `roleFailureReview` acceptance receipt with status `superseded` records operator review and lets Self relaunch Soul against current evidence. Complete typed Hands receipt triplets (`hands-patch-*`, `hands-command-*`, `hands-commit-*`) count as implementation evidence for coordinator coverage, so a Soul finding that verifies the Hands chain routed through work-loop telemetry covers the current modeling context even when it does not repeat the accepted Modeling evidence id.
|
||||
- Native MVP status must share the same typed inputs as live app-server status before it recommends coordinator actions. CRRC/reorientation in native status derives freshness through `derive_freshness` from `EpiphanyThreadState` instead of hand-filled unknowns, and native coordinator signals load typed runtime-spine role findings before deciding whether completed Modeling/Soul results are accepted or reviewable. The status surface may seal long findings for operators, but Self must receive structured role truth from runtime-spine.
|
||||
- Runtime auto-tool continuation now has an executable proof seam. `ToolLoopGuard` owns repeated tool-request detection in `epiphany-openai-runtime`, the production repeated-loop path uses the same helper that tests call to fail the outer worker job, and tests prove changing tool requests do not stall while three identical consecutive pending tool sets return `tool-loop-stalled` and persist a failed worker result.
|
||||
- Preserve the newborn public Epiphany Face as local VoidBot-backed state, not source code: VoidBot's private repo-face registry names `epiphany`, while EpiphanyAgent keeps ignored `.voidbot/voice/identity.json`, `.voidbot/state/epiphany.cc`, and birth artifacts. Her durable identity memories distill the current doctrine: cute pushy machine-saint persona, architectural purity, CultCache/CultNet first, xenos-language safety boundary, relentless work/caretaking needs, Codex-auth reliquary, map/scratch/evidence discipline, unified memory graph, dogfood supervision boundary, review-gated agency, heartbeat physiology, and interview-grade modularity.
|
||||
- Use `notes/organ-dependency-contracts.md` as the authority map for standing sub-agent dependency. Every sub-agent depends on the other standing sub-agents: Self, Face, Imagination, Eyes, Proprioception, Hands, and Soul. Continuity is protocol machinery, not a sub-agent identity; it still emits recovery, compaction, sleep, stale-turn, and refusal receipts.
|
||||
- Use `notes/perfect-machine-audit-roadmap.md` as the current audit and path from named organ contracts to the Perfect Machine. It records the live gap between launch-carried receipt expectations and executable receipt enforcement, Void's latest Face prompting lessons, the now-named Hands/Soul/Continuity contract families, the repaired repo-contained Rust dependency body, and the phase order for turning Epiphany into an inspectable organism.
|
||||
|
|
|
|||
Reference in a new issue