From 4e3e3f767c831731247038caa2d2c25a2c27b3cb Mon Sep 17 00:00:00 2001 From: Gabby Morgan Date: Fri, 9 Oct 2026 10:25:57 +0000 Subject: [PATCH] add previous skill result to semif context for successive requeues --- AGENTS.md | 4 +- semif_agent/scheduler.py | 4 ++ semif_agent/skill.py | 25 +++++++- tests/integration/test_pipeline.py | 40 ++++++++++++- tests/test_skills.py | 96 ++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2841165..04afc11 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -132,7 +132,9 @@ skill.py loop: observe -> act -> observe -> assess; the body is a single summary is deterministic (no generation), built from category.skill + ok/failed + action_log — the body writes only the result, the runner adds the `category.name:` ref; the assess state carries - the resolved inputs (secrets redacted); a `DETERMINISTIC_CATEGORIES` + the skill's declared action, the goal, and the resolved inputs + (secrets redacted), and the requeue state flags a retry that would + reproduce the identical observed result as a no-op; a `DETERMINISTIC_CATEGORIES` run (housekeeping) skips assessment/repair — it is an internal mechanical action with a known result, not an external run; a run paused for input is resumed by re-invoking act with the diff --git a/semif_agent/scheduler.py b/semif_agent/scheduler.py index 0964303..b71e669 100644 --- a/semif_agent/scheduler.py +++ b/semif_agent/scheduler.py @@ -713,6 +713,10 @@ class Scheduler: requeued = False if outcome.updated_request and request.reentries < self.max_reentries: child = _requeue(request, outcome.updated_request) + # Remember what this attempt observed so the next assessment can + # tell a genuine retry (the result changed) from a guaranteed + # repeat against unchanged state. + child.meta["prev_result"] = outcome.action_log or outcome.new_state self.queue.push(child) self.trace.append("requeued", request.id, text=outcome.updated_request) if self.on_request_requeued is not None: diff --git a/semif_agent/skill.py b/semif_agent/skill.py index 3783831..ae291e7 100644 --- a/semif_agent/skill.py +++ b/semif_agent/skill.py @@ -295,15 +295,19 @@ class SkillRunner: then offered to `assess:requeue`, which picks complete/retry. On retry the original request text is re-dispatched (the scheduler bounds it by `max_reentries`). Both are real logged decision rows. The state carries - the resolved inputs so a wrong resolution is visible to the decision. - The engine is always real: EngineUnavailable propagates to the - scheduler, which marks the app fatal. + the skill's declared action, the goal, and the resolved inputs so the + decision sees what the skill was meant to do and how its inputs + resolved; the requeue state additionally flags a retry that would + reproduce the identical observed result as a no-op. The engine is always + real: EngineUnavailable propagates to the scheduler, which marks the app + fatal. """ label = f"{skill.category}.{skill.name}" resolved = _resolved_inputs(skill, ctx.config) outcome = DecisionRequest( state=( f"skill: {label}\n" + f"skill action: {skill.description}\n" f"goal: {request.text}\n" f"resolved inputs:\n{resolved}\n" f"action log:\n{action.action_log}" @@ -334,13 +338,28 @@ class SkillRunner: if success: return True, None + # A retry that would reproduce the identical observed result is a + # guaranteed no-op run (the request, config, and external state are + # unchanged), so the requeue decision is told before it can pick + # `retry` again — otherwise a deterministic failure loops through the + # reentry ladder and ends in a repair offer for a working skill. + observed = action.action_log or action.new_state + prev = request.meta.get("prev_result") + no_progress = "" + if prev is not None and prev == observed: + no_progress = ( + "\nAttempts so far produced the identical result; retrying " + "would repeat the same run against unchanged state." + ) requeue = DecisionRequest( state=( f"skill: {label}\n" + f"skill action: {skill.description}\n" f"goal: {request.text}\n" f"resolved inputs:\n{resolved}\n" f"action log:\n{action.action_log}\n" "outcome: failed" + f"{no_progress}" ), question="Is the request complete, or should it run again?", options=[ diff --git a/tests/integration/test_pipeline.py b/tests/integration/test_pipeline.py index edf7a1d..44c9a1e 100644 --- a/tests/integration/test_pipeline.py +++ b/tests/integration/test_pipeline.py @@ -727,4 +727,42 @@ def test_empty_result_is_assessed_as_success(tmp_path): assert "assess:outcome" in phases assert "assess:requeue" not in phases, ( "an empty discovery must not be retried or repaired" - ) \ No newline at end of file + ) + + +def test_read_result_is_assessed_as_success(tmp_path): + """A correctly-read result is a successful run, not a failure. + + The assessment must see the skill's declared action; with only the skill + label the real model marked a truthful read failed for ambiguous phrasings + (e.g. "What's my next simplex message?"), which then looped the retry ladder + and offered to repair a working skill. This exercises the real engine, since + only it produces the probabilities. + """ + config = load_config() + require_real(config) + engine = SemIfEngine(build_engine_config(config)) + + def act(ctx, request): + return ActionResult( + action_log="SimpleX message from pepper: hello", + new_state="SimpleX message from pepper: hello", + ) + + skill = Skill( + name="next_message", + category="simplex", + description="Read the next unread SimpleX message.", + act=act, + ) + log = DecisionLog(str(tmp_path / "decisions.jsonl")) + runner = SkillRunner(ActionContext(engine=engine, config={}), log) + outcome = runner.run(skill, Request("What's my next simplex message?")) + print(f"[{outcome.success}] {outcome.summary}") + + assert outcome.success is True, outcome.summary + phases = [row["extra"]["phase"] for row in log.read()] + assert "assess:outcome" in phases + assert "assess:requeue" not in phases, ( + "a truthful read must not be retried or repaired" + ) diff --git a/tests/test_skills.py b/tests/test_skills.py index 78ff805..a2c5aac 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -612,6 +612,80 @@ def test_canned_response_runs_without_assessment(tmp_path): assert log.read() == [] +def test_assessment_state_carries_skill_action(tmp_path): + """The assessment decision must see what the skill was meant to do. + + Regression: with only `skill: