From ddbe5f167df84aab372ff1db4ad1781bf7679d68 Mon Sep 17 00:00:00 2001 From: Gabby Morgan Date: Tue, 6 Oct 2026 09:36:00 +0000 Subject: [PATCH] assess empty query results as success, not failure A query skill whose correct answer is "nothing" (no unread SimpleX messages, no upcoming events) was marked failed by assess:outcome: the option text framed the decision as literal goal-achievement, so the model read "no messages" as the goal not being met. The run then offered a repair and could rewrite a working skill. Reword the assess:outcome options so a definitive "nothing found / nothing to do" result counts as success and only an error, refusal, or unresolved action is failure. Option ids and the question are unchanged, so the decision-log schema, dream labels, and existing unit tests are unaffected. Real-engine scores: empty inbox 0.145 -> 0.969, no events 0.132 -> 0.959, while unreachable/HTTP-401/discovery failures stay failure. Add an integration regression test and a CODEGEN.md note that an explicit empty/none result is a successful run. --- CODEGEN.md | 6 +++- semif_agent/skill.py | 14 ++++++++-- tests/integration/test_pipeline.py | 44 ++++++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CODEGEN.md b/CODEGEN.md index 361e884..18321a1 100644 --- a/CODEGEN.md +++ b/CODEGEN.md @@ -422,7 +422,11 @@ Rules: action skill reports the service's real response. A generic "done" that omits the result is a broken output. - **Never an empty or placeholder output.** If there is genuinely nothing (empty - inbox, no matching event), say so explicitly — that is a real result. + inbox, no matching event), say so explicitly — that is a real result, and a + **successful** run: the `assess:outcome` step treats a definitive "nothing + found / nothing to do" result as success. Phrase it as the answer the user + asked for ("checked the inbox: no unread messages"), not as an absence or an + error, so the assessment does not read a healthy empty result as a failure. - **Never claim success you did not observe.** If the action failed, put the real failure in `action_log` and set `new_state` back to `request.text` (see the hard requirements). diff --git a/semif_agent/skill.py b/semif_agent/skill.py index 5cbdfa2..3783831 100644 --- a/semif_agent/skill.py +++ b/semif_agent/skill.py @@ -310,8 +310,18 @@ class SkillRunner: ), question="Did the skill achieve the user's goal?", options=[ - Option("success", "Yes — the goal was met."), - Option("failure", "No — the goal was not met."), + Option( + "success", + "Yes — the skill carried out the request and produced a " + "truthful result. A definitive 'nothing found' or 'nothing " + "to do' result (empty inbox, no unread messages, no " + "matching event) counts as success.", + ), + Option( + "failure", + "No — the request was not carried out, or the result is an " + "error, a refusal, or an unresolved action.", + ), ], ) result = self.ctx.engine.call(outcome) diff --git a/tests/integration/test_pipeline.py b/tests/integration/test_pipeline.py index 6e5c47d..9ff3ab9 100644 --- a/tests/integration/test_pipeline.py +++ b/tests/integration/test_pipeline.py @@ -27,10 +27,13 @@ from semif_agent.codegen import ( ) from semif_agent.decisions import Request from semif_agent.dream import dream -from semif_agent.engine import EngineUnavailable +from semif_agent.engine import EngineUnavailable, SemIfEngine +from semif_agent.log import DecisionLog from semif_agent.scheduler import SkillWrite +from semif_agent.skill import SkillRunner from semif_agent.skills import ( ActionResult, + ActionContext, CategoryDraft, CreateCategory, Skill, @@ -634,4 +637,41 @@ def test_skill_pauses_for_input_and_resumes(tmp_path): rows = scheduler.trace.read() kinds = [e["kind"] for e in rows] - assert "needs_input" in kinds and "answered" in kinds and "assessed" in kinds \ No newline at end of file + assert "needs_input" in kinds and "answered" in kinds and "assessed" in kinds + + +def test_empty_result_is_assessed_as_success(tmp_path): + """A query skill whose correct answer is "nothing" is a successful run. + + The `assess:outcome` options must treat a definitive empty/none result + (empty inbox, no matching event) as success; otherwise a healthy read is + marked failed and the repair loop offers to rewrite 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.next_message: no unread SimpleX messages.", + new_state="no unread SimpleX messages", + ) + + 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, ( + "an empty discovery must not be retried or repaired" + ) \ No newline at end of file