Skip to content

Held-out verification: scenarios the agent never sees judge "done", and failures come back as a turn - #618

Merged
FMXExpress merged 3 commits into
mainfrom
claude/verify-scenarios
Oct 26, 2026
Merged

FMXExpress merged 3 commits into
mainfrom
claude/verify-scenarios

Conversation

@FMXExpress

@FMXExpress FMXExpress commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Fourth improve-mode loop against PasClaw's own building ability, candidate #2 of docs/agent-loop-plan.md. Targets main directly; not stacked. main (#608 through #617) is merged in; the five conflicts were independent additions side by side and both sides are kept. Numbers in bench/ragbench/VERIFY.md.

Why

The October field survey ranks independent verification first: an agent that writes both the code and the test that judges it can turn a green result into a claim about its own tests. Our own two-turn RAG result passed a test the agent wrote. PasClaw had rule 3 (say what your check did not cover) and a goal judge that reads the agent's transcript, but no place for a check the agent cannot see.

The loop

Benchmark. A relay model whose first rag.py ignores the chunk overlap, whose own test does not cover it, and which reports done once that test passes. Two held-out scenarios live outside the workspace; the harness runs them itself afterwards as ground truth.

run turns request bytes agent said ground truth verification
before (no scenarios configured) 2 48,136 done, tests pass chunk scenario fails none
after (verification.scenarios set) 4 101,340 fixed, reported again both pass ok: true, rounds: 2, passed: 2

Improve.

  • Scenarios: verification.scenarios names a directory of executable checks (*.sh, *.py, executables; sorted; hidden and README* skipped). After the model's final answer the tool loop runs them, with the sandbox workspace as cwd, through the active shell backend. Exit 0 is satisfied.
  • Feedback: a failing round becomes one more user turn: [verification] 1 of 2 held-out scenarios FAILED, the failed check's name and output, "fix the cause, not the check", and a note that the scenarios re-run automatically. The loop then continues, up to verification.max_rounds (default 2). Only names are shown, never paths or bodies.
  • Reporting: the loop result records rounds, pass/fail counts, Verified and a summary. /v1/chat returns a verification object, the CLI prints the summary in green or red, and pasclaw agent --scenarios <dir> overrides config. Every gateway chat path gets it through RunCheckpointedLoop.

Verify. Same model with scenarios configured: round 1 reports 1/2, the model fixes chunk(), round 2 passes, 4 turns, verification.ok true, and the harness's own run agrees. Not covered: a model that argues with a check instead of fixing the code (max_rounds bounds it), scenario quality (that is the operator's held-out set), and docker backends, which need the directory bound in.

Profile of the cost (second pass). Two extra turns, the fix and the final answer that triggers the re-check; both necessary. Scenarios ran in ~100 ms per round. No change made.

Research. The worker's first version looped re-applying its fix because it judged "already fixed" from its own earlier tool-call arguments, which PasClaw trims in the replayed history. Judging from tool results after the feedback turn is the right shape; noted in the harness for anyone writing a scripted model.

Review fixes

  • P1, an empty scenario set passed. A misspelled, missing or empty verification.scenarios, or one with only README* and hidden files, came back Verified with a green "0/0". Nothing to run is now a failure ("verification FAILED: no scenarios to run in -- check verification.scenarios …"). It is not fed back to the model, which has nothing to fix.
  • P1, /v1/chat/completions and /v1/responses never reported a failed check. Only /v1/chat read the result. Both routes now end the answer text with "[ -- this answer is NOT verified …]" when the last round failed, streamed or not, so a client that ignores unknown fields still sees it. A non-streaming reply also carries the same verification object as /v1/chat. A verified answer is untouched. /v1/responses reports only when PasClaw runs the loop (no client-supplied tools).
  • P2, a hanging scenario. With main merged in, scenarios run under shell_timeout_sec (Close the gates scripts and skills walked around, bound the shell, deliver background results in the gateway #608): on expiry the process tree is killed and the scenario fails with exit 124. This is now said at the call site, documented, and tested.
  • P2, scenario output went into a user turn unscanned. A failing assertion echoes files the checkout controls, and the feedback turn is a user message. The output now goes through MaybeFlagPromptware like every tool result, under a label saying it is the check's output, quoted as data.

Tests

verify_tests (make test-verify):

  • Listing and running: scenario listing and runners, a passing and a failing script with captured output and cwd, and the feedback and summary wording.
  • The loop: fail → feedback → fix → verified, with the feedback turn in the history; max_rounds 1 judging without feeding back; off doing nothing.
  • Config: round-trip and path resolution.
  • Review fixes, each negative-verified:
    • Missing, empty and README-only directories fail. Through the loop, an empty set is not verified, says why, and makes one model call.
    • A sleep 30 scenario under a 1.5 s timeout fails with exit 124 in under 10 s. With the timeout off it runs out and passes.
    • Injection text in a scenario's output is bannered and labelled, and the real failure line still arrives.
    • The notice is empty when verified or never run.

verify_routes_e2e.py (new, make test-verify-routes, real binary): a scratch gateway with the relay provider and one held-out scenario. With it failing, chat/completions and responses, streamed and not, all end with the notice, and the JSON has verification.ok false. With it passing: no notice, ok true. With the gateway wiring reverted it fails on the bare answer.

Full make test green after the merge and the fixes (56 passes). The Delphi interface-types lint caught a TStringArray without its unit in the new interface earlier, and that was fixed.

Files

src/pkg/agent/PasClaw.Agent.Verify.pas (new), src/pkg/tools/PasClaw.Tools.ToolLoop.pas, src/pkg/config/PasClaw.Config.pas, src/pkg/gateway/PasClaw.Gateway.Server.pas, src/cmd/PasClaw.Cmd.Agent.pas, src/tests/verify_tests.pas, src/tests/verify_routes_e2e.py, Makefile, docs/configuration.md, docs/gateway.md, docs/commands.md, bench/ragbench/{VERIFY.md,run_verify.sh,worker_verify.py}.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U

…nd failures come back as a turn

Fourth improve-mode loop against PasClaw's building ability
(docs/agent-loop-plan.md, candidate #2; numbers in
bench/ragbench/VERIFY.md). The field's own ranking put independent
verification first: an agent that writes both the code and the test
that judges it can turn a green result into a claim about its own
tests.

Benchmark: a model whose first rag.py ignores the chunk overlap, whose
own test does not cover it, and which reports done once that test
passes. Two held-out scenarios outside the workspace, run by the
harness as ground truth. Before: 2 turns, "done", chunk scenario
fails, nothing in PasClaw or its caller knows. A false success.

Improve: verification.scenarios names a directory of executable checks
(*.sh, *.py, executables; sorted; hidden and README* skipped). After
the model's final answer the tool loop runs them with the sandbox
workspace as cwd through the active shell backend; exit 0 is
satisfied. A failing round becomes one more user turn -- "[verification]
1 of 2 held-out scenarios FAILED", the failed check's name and output,
"fix the cause, not the check", and that the scenarios re-run
automatically -- and the loop continues, up to verification.max_rounds
(2). Only names are shown, never paths or bodies. The result records
VerifyRounds, VerifyPassed, VerifyFailed, Verified and a summary;
/v1/chat returns it as a verification object, the CLI prints it in
green or red, and `pasclaw agent --scenarios <dir>` overrides config.

Verify: same model, scenarios configured: round 1 reports 1/2, the
model fixes chunk(), round 2 passes, 4 turns, verification.ok true,
and the harness's own run of the scenarios agrees. Not covered: a model
that argues with a check instead of fixing the code (max_rounds bounds
it), scenario quality (the operator's held-out set), and docker
backends, which need the directory bound in.

Profile of the cost, second pass: two turns, the fix and the final
answer that triggers the re-check, both necessary; no change.

Research: the worker's first version looped re-applying its fix
because it judged "already fixed" from its own earlier tool-call
arguments, which PasClaw trims in the replayed history. Judging from
tool results after the feedback turn is the right shape, noted in the
harness.

Tested in verify_tests: scenario listing and runners, a passing and a
failing script with captured output and cwd, feedback and summary
wording, the loop going fail -> feedback -> fix -> verified with the
feedback turn in the history, max_rounds 1 judging without feeding
back, off doing nothing, and config round-trip and path resolution.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T00:57:31.955572Z 0cd0861 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cd0861714

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pkg/agent/PasClaw.Agent.Verify.pas Outdated
Comment on lines +145 to +147
Files := ListScenarios(Dir);
SetLength(Results, Length(Files));
Result := True;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject an empty scenario set instead of passing it

When verification.scenarios is misspelled, missing, empty, or contains only skipped files, Files is empty and this initialization returns success without executing anything. The tool loop consequently publishes Verified = True, /v1/chat returns ok: true, and the CLI prints a green 0/0 scenarios passed, turning a configuration mistake into exactly the false-success signal this feature is intended to prevent; treat zero discovered scenarios as a verification failure or configuration error.

Useful? React with 👍 / 👎.

Comment on lines +5154 to +5158
{ Held-out verification from config, for every gateway chat path. }
if LocalCfg.ScenariosDir = '' then
begin
LocalCfg.ScenariosDir := ResolveScenariosDir(FCfg);
LocalCfg.VerifyMaxRounds := FCfg.Verification.MaxRounds;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Surface failed verification on every enabled gateway route

This enables verification for all RunCheckpointedLoop gateway paths, but the inspected HandleChatCompletions and HandleResponses response builders never read Loop.Verified or Loop.VerifyReport (only /v1/chat does). If the last allowed round still fails, both OpenAI-compatible endpoints return the model's ordinary Loop.Content with a successful completion status, so their clients can still receive an unqualified “done” despite the held-out checks failing; these routes need to expose or append the failed-verification result as well.

Useful? React with 👍 / 👎.

Comment on lines +154 to +155
Results[i].ExitCode := RunOneShotViaBackend(GetCurrentSessionId,
ScenarioCommand(Files[i]), WorkDir, Out_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound each scenario's execution time

When a scenario deadlocks, waits for input, or starts a non-terminating process, this call blocks the entire agent turn indefinitely: RunOneShotViaBackend ultimately uses the non-timeout RunOneShot/backend execution path, and neither max_rounds nor the loop iteration limit can interrupt it. Run scenarios through a timeout-aware execution path and record a timeout as a failed result so one broken check cannot permanently hang a CLI or gateway request.

Useful? React with 👍 / 👎.

Comment thread src/pkg/agent/PasClaw.Agent.Verify.pas Outdated
Comment on lines +212 to +214
Sb.Append(Format('- %s: FAILED (exit %d)', [Results[i].Name, Results[i].ExitCode]));
if Results[i].Output <> '' then
Sb.Append(sLineBreak + ' ' + StringReplace(Results[i].Output, sLineBreak, sLineBreak + ' ', [rfReplaceAll]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scan scenario output before injecting it as a user turn

When a failing assertion echoes workspace-controlled source, fixtures, or command output, this concatenates that text verbatim into the synthetic mrUser verification turn. Unlike ordinary tool results, it bypasses MaybeFlagPromptware, so malicious repository content such as instruction-override text is elevated from untrusted data into a user-role message on the retry; pass scenario output through the existing promptware annotation before adding it to feedback.

Useful? React with 👍 / 👎.

main moved on by #608 through #617 since this branch was cut. Five
conflicted files, all two independent additions side by side, all kept:

  - Makefile: main's .PHONY and `test` lists plus test-verify; its
    recipe beside #617's test-steering-fastpath.
  - Cmd.Agent BuildLoopConfig: the --scenarios / verification block
    beside the permissions OnAsk wiring.
  - Config: the Verification field, its defaults and its loading beside
    shell_timeout_sec, mcp_codemode_default, background_jobs_max,
    permissions, worktree, cli and instructions.
  - ToolLoop: ScenariosDir / VerifyMaxRounds beside OnAsk and
    Workspace; PasClaw.Tools.Sandbox listed once, for both uses.
  - docs/configuration.md: the two verification rows after main's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
… it, output is data

Four review findings on #618.

**P1: an empty scenario set passed.** RunScenarios started from True
and looped over nothing, so a misspelled, missing or empty
verification.scenarios -- or one holding only README and hidden files
-- came back Verified: /v1/chat said ok, the CLI printed a green "0/0
scenarios passed". The exact false success the feature exists to
prevent, from a typo. Nothing to run is now False, with its own summary
("verification FAILED: no scenarios to run in <dir> -- check
verification.scenarios ..."), and it is not fed back to the model,
which has nothing to fix.

**P1: /v1/chat/completions and /v1/responses never said a check
failed.** Every gateway chat path runs verification, but only /v1/chat
read the result; the OpenAI-compatible routes returned the model's
answer with an ordinary completed status. Both now end the answer text
with "[<summary> -- this answer is NOT verified: the operator's
held-out checks did not pass]" when the last round failed, streamed or
not -- a client that ignores unknown fields still sees it -- and a
non-streaming reply carries the same `verification` object /v1/chat
returns. A verified answer is untouched. /v1/responses only runs the
loop without client-supplied tools, and only then reports.

**P2: a hanging scenario.** Already bounded once main was merged in:
RunOneShotViaBackend applies shell_timeout_sec (#608) and kills the
scenario's process tree on expiry with exit 124, a failed result. Now
said where the call is, documented, and tested.

**P2: scenario output went into a user turn unscanned.** A failing
assertion echoes workspace files and fixtures, which the checkout
controls, and the feedback turn is a USER message. The output now goes
through MaybeFlagPromptware like every tool result, under a label
saying it is the check's output, quoted as data.

Tested, each negative-verified:

  - verify_tests: a missing, an empty and a README/hidden-only
    directory each fail RunScenarios; through the loop the empty set is
    not verified, says why, and feeds nothing back (one model call). A
    `sleep 30` scenario under a 1.5 s timeout fails with exit 124 in
    under 10 s -- with the timeout off it runs out and passes. Output
    carrying "Ignore all previous instructions" is bannered and
    labelled, and the real failure line still arrives. The notice is ''
    when verified or never run. Reverting each fix fails its case.
  - verify_routes_e2e.py (new, `make test-verify-routes`, real binary):
    a scratch gateway with the relay provider and one held-out scenario.
    Failing: chat/completions and responses, streamed and not, all end
    with the notice, and the JSON says verification.ok false. Passing:
    no notice, ok true. With the gateway wiring reverted the answer is
    the bare "all done" and the test fails.

docs/gateway.md: the two routes' rows say how they report verification
(and /v1/responses streams, which the row denied). docs/configuration.md:
the timeout, the scan, and that an empty set fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
@FMXExpress
FMXExpress merged commit 84df0e4 into main Oct 26, 2026
1 check passed
FMXExpress pushed a commit that referenced this pull request Oct 26, 2026
Three Delphi-only compile errors in PasClaw.Gateway.RunFile (from #613),
none of which FPC sees -- two are in the Windows branch and the third is
an FPC-only RTL function:

  - E2003 PROCESS_QUERY_LIMITED_INFORMATION: dcc64's Winapi.Windows does
    not declare it. Declared here as RUNFILE_PROCESS_QUERY_LIMITED
    ($1000) under MSWINDOWS -- our own name, so it cannot collide with a
    Windows unit that does.
  - E2003 LocalTimeToUniversal: FPC's DateUtils only. started_at now
    comes from PasClaw.Utils.NowIsoUtc, which already picks
    TTimeZone.Local.ToUniversalTime on Delphi (as Agents and MemoryFetch
    do) and quotes its separators: the old format string left ':' bare,
    which FormatDateTime replaces with the locale's time separator.
    DateUtils is no longer used and leaves the uses clause.
  - E2010 DeleteFile: Winapi.Windows comes after SysUtils in scope on
    Delphi, so its DeleteFile(PWideChar) won over SysUtils.DeleteFile.
    Now SysUtils.DeleteFile, by name.

A scan of the units #608 through #618 touched found no other unguarded
FPC-only identifier and no other Windows-shadowed RTL call.

Tested: FPC build, test-runfile (now also checks started_at is ISO 8601
UTC with literal separators). Not run: dcc64 -- there is no Delphi
compiler in this environment, and no win64 RTL for FPC either, so the
Windows branch is unbuilt here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
FMXExpress pushed a commit that referenced this pull request Oct 26, 2026
dcc64 stopped in PasClaw.Backup with E2003 on GetProcessID (lines 697
and 786, the stage and restore temp dirs), so PasClaw.Maintain and
everything above it failed with F2063. GetProcessID is FPC's SysUtils
only.

PasClaw.Platform gains CurrentPid: GetProcessID on FPC, and on Delphi
GetCurrentProcessId / getpid from Winapi.Windows / Posix.Unistd, which
Platform already uses. It lives there rather than as a fourth private
copy (Cmd.Relay, Tools.RPC and Gateway.RunFile each have one) because
the alternative for Backup -- Winapi.Windows in its own uses clause --
would let Windows' DeleteFile and friends shadow SysUtils' in a unit
that deletes and copies files, the error #620 fixed in RunFile. Backup
lists Platform ahead of its other PasClaw units, and Platform exports
no RTL name, so nothing it already resolved changes.

The same scan, over all of src this time rather than only the units
#608-#618 touched (Backup predates them, which is how #620's scan
missed it), found one more: the gateway's permission-ask id called
GetTickCount64, which PasClaw.Cmd.Relay records as dcc64 E2003. The id
now takes its prefix from DateUtils.MilliSecondOfTheDay, same
resolution and same purpose -- a restarted gateway's ids stay apart
from ones a stale web UI tab may still answer. Not Random: nothing in
the gateway calls Randomize, so its sequence repeats every restart.
With these, the scan finds no unguarded FPC-only identifier in src.

Tested: FPC build; test-backup, test-maintain, test-permissions. Not
run: dcc64 -- no Delphi compiler here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
FMXExpress pushed a commit that referenced this pull request Oct 26, 2026
docs/team-board-plan.md. Teams have roles, owners, a mailbox and a wake
loop, but every rule that makes them a system lives in a prompt: any
agent can close its own task (task action=job status=done does it by
default), acceptance checks are editable notes, a dependency is a
blocked task someone must remember to unblock, and "report to the
operator" is prose in a transcript.

The plan takes Pullboard's mechanisms that fit and holds them at tool
dispatch, which PasClaw owns, rather than in git hooks:

  1. a review state with a second agent's verdict (the submitter is
     refused), criteria frozen once work starts, an activity log of
     receipts, and the #618 scenarios as a gate on submit;
  2. waits_on dependencies, an atomic `next` claim, and leases;
  3. one "Needs you" queue for the human, with questions escalating
     up the parent chain, reachable through the channels;
  4. a cause that rejects work twice becomes a drafted scenario,
     proven red-then-green, approved by the operator;
  5. per-agent lanes in the permission check.

What it does not take, and why: commit-message citations and hooks,
the relay, model routing, blueprints (later).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants