Add /graph G0: serial graph engineering mode over the goal engine
A deterministic DAG scheduler layered on the existing goal engine: /graph <objective> decomposes the objective via a graph-planner subagent, gates the result through Agentproof-style static validation (cycles, unknown deps, duplicate slugs, caps), appends a structural final-verification node, then executes each node as one ordinary goal — planner, worker loop, adversarial verifier, budget and pause machinery all reused verbatim. The in-turn loop advances nodes within the same turn (multi-loop closed loop); goal-side auto-pauses cascade to the graph at a single chokepoint; node goals are armed with the remaining graph budget so mid-node overruns trip graph-wide. Gated by KIGI_GRAPH=1 (default off) + the goal harness. State persists to <session_dir>/graph/state.json with a clear-tombstone; per-version immutable baselines and per-node artifact archives live under graph/<graph_id>/. Restore demotes Active->UserPaused and Running->Ready (verifier-gated re-run). Review hardening (adversarial multi-agent pass, 24 confirmed findings fixed): the goal-inactive loop break now consults the graph seam (mid-turn classifier-disabled completions can no longer strand an Active graph), the pause cascade fires even when no node goal is in flight (cancel during planning), node bookkeeping precedes the long setup await, /graph clear only resets the engine it owns, budget trips terminally fail the in-flight node, and the pause transitions in /goal pause + /graph pause no longer hide inside debug_assert! (a release-build no-op inherited from upstream). Tests: 4908 kigi-shell lib tests green, including a serial 4-node closed-loop e2e, restore/resume, cascade, mutual-exclusion, planning-retry, persistence round-trip + tombstone, and status rendering.
This commit is contained in:
@@ -305,15 +305,57 @@ impl SessionActor {
|
||||
objective,
|
||||
token_budget,
|
||||
} => {
|
||||
// The graph owns the goal engine while set: a
|
||||
// manual /goal would corrupt the running node.
|
||||
if self.graph_owns_goal_engine() {
|
||||
self.send_slash_command_output(
|
||||
"A graph owns the goal engine. Use /graph status, or /graph \
|
||||
clear before /goal.",
|
||||
)
|
||||
.await;
|
||||
return ok_end_turn(0, None);
|
||||
}
|
||||
let reminder = self.setup_goal(&objective, token_budget).await;
|
||||
vec![text_block(reminder), text_block(objective)]
|
||||
}
|
||||
BuiltinAction::GoalResume => match self.resume_goal().await {
|
||||
GoalResumeOutcome::Inference { reminder, user_msg } => {
|
||||
BuiltinAction::GoalResume => {
|
||||
if self.graph_owns_goal_engine() {
|
||||
self.send_slash_command_output(
|
||||
"A graph owns the goal engine. Use /graph resume instead.",
|
||||
)
|
||||
.await;
|
||||
return ok_end_turn(0, None);
|
||||
}
|
||||
match self.resume_goal().await {
|
||||
GoalResumeOutcome::Inference { reminder, user_msg } => {
|
||||
self.send_slash_command_output(&user_msg).await;
|
||||
vec![text_block(reminder)]
|
||||
}
|
||||
GoalResumeOutcome::Message(msg) => {
|
||||
self.send_slash_command_output(&msg).await;
|
||||
return ok_end_turn(0, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
BuiltinAction::GraphSet {
|
||||
objective,
|
||||
token_budget,
|
||||
} => match self.setup_graph(&objective, token_budget).await {
|
||||
super::graph::GraphSetupOutcome::Inference { reminder, user_msg } => {
|
||||
self.send_slash_command_output(&user_msg).await;
|
||||
vec![text_block(reminder), text_block(objective)]
|
||||
}
|
||||
super::graph::GraphSetupOutcome::Message(msg) => {
|
||||
self.send_slash_command_output(&msg).await;
|
||||
return ok_end_turn(0, None);
|
||||
}
|
||||
},
|
||||
BuiltinAction::GraphResume => match self.resume_graph().await {
|
||||
super::graph::GraphSetupOutcome::Inference { reminder, user_msg } => {
|
||||
self.send_slash_command_output(&user_msg).await;
|
||||
vec![text_block(reminder)]
|
||||
}
|
||||
GoalResumeOutcome::Message(msg) => {
|
||||
super::graph::GraphSetupOutcome::Message(msg) => {
|
||||
self.send_slash_command_output(&msg).await;
|
||||
return ok_end_turn(0, None);
|
||||
}
|
||||
@@ -688,13 +730,35 @@ impl SessionActor {
|
||||
self.goal_tracker.lock().status(),
|
||||
);
|
||||
if !goal_active {
|
||||
break round;
|
||||
// The node goal may have resolved MID-round without a
|
||||
// graph cascade (e.g. a classifier-disabled completion
|
||||
// applied by the mid-turn drainer). Consult the graph
|
||||
// seam before ending the turn so the graph advances or
|
||||
// settles loudly instead of stranding Active forever.
|
||||
match self.run_graph_round_end().await {
|
||||
Some(node_reminder) => {
|
||||
self.inject_goal_continuation_message(node_reminder).await;
|
||||
continue;
|
||||
}
|
||||
None => break round,
|
||||
}
|
||||
}
|
||||
match self.run_goal_round_end().await {
|
||||
GoalRoundDecision::Continue(directive) => {
|
||||
self.inject_goal_continuation_message(directive).await;
|
||||
}
|
||||
GoalRoundDecision::EndTurn => break round,
|
||||
GoalRoundDecision::EndTurn => {
|
||||
// Graph seam: when the node goal resolved, the
|
||||
// graph may advance to the next node inside the
|
||||
// SAME turn (multi-loop closed loop). None ends
|
||||
// the turn for real (graph done/paused/absent).
|
||||
match self.run_graph_round_end().await {
|
||||
Some(node_reminder) => {
|
||||
self.inject_goal_continuation_message(node_reminder).await;
|
||||
}
|
||||
None => break round,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user