Skip to content

hooks: recover PR #111 + #112 review fixes onto main - #113

Merged
FMXExpress merged 4 commits into
mainfrom
claude/hooks-and-steering
Jun 1, 2026
Merged

FMXExpress merged 4 commits into
mainfrom
claude/hooks-and-steering

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Recovery — bring PR #111 + #112 review fixes into main

PR #110 merged to main before its review-fix PRs (#111, #112) existed. When those landed they each targeted the PR #110 / PR #111 branches respectively, so the four resulting commits ended up stranded on claude/hooks-and-steering without ever reaching main.

This PR fast-forwards the four stranded commits across:

Commit Origin
4382019 PR #111 — steering folds into LiveOptions.SystemPrompt (not in-history mrSystem) + wire HooksOnError(hsProviderCall, hsDuringToolCall)
3ad3436 PR #112 — drop StatusCode > 0 guard so DNS/TLS/socket failures (status -1) also fire OnError
8cad3b0 merge of #112 into the #111 branch
a795363 merge of #111 into the hooks branch

Why the merge order matters

Without this recovery, both fixes stay in the branch graveyard and main ships hooks that don't actually deliver steering or error notifications for the common case.

Verification

Tests run against claude/hooks-and-steering HEAD when PR #111 / #112 were opened:

=== Test 1: steering folds into SystemPrompt ===
  PASS — steering in SystemPrompt, no stray mrSystem
=== Test 2a: hsDuringToolCall fires ===
  PASS — fired 1 time(s), last msg: tool "fail_tool": simulated tool failure
=== Test 2b: hsProviderCall fires ===
  PASS — fired 1 time(s), last msg: provider returned status=502

--- probe status=-1  ---  PASS — provider returned status=-1
--- probe status=0   ---  PASS — provider returned status=0
--- probe status=429 ---  PASS — provider returned status=429
--- probe status=502 ---  PASS — provider returned status=502
--- probe status=401 ---  PASS — provider returned status=401

make smoke 11/11 green.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

claude and others added 4 commits June 1, 2026 13:31
Two Codex P-level findings on PR #110, both legitimate.

P1 — Steering messages invisible under the default component
configuration. PR #110 appended each batch's accumulated
SteeringMessages as an mrSystem entry in Hist before the next
LLM round. But the OpenAI / Anthropic / Gemini provider builders
explicitly DROP in-history mrSystem entries whenever the
ChatOptions.SystemPrompt slot is non-empty — they ship one
consolidated system prompt via that slot, not via the messages
array. TPasClawAgent.ChatHistory always populates
Cfg.Options.SystemPrompt via BuildSystemPrompt, so the default
component path always hits this case. Steering was silently
dropped before reaching the model.

Fix: fold BatchSteering into LiveOptions.SystemPrompt (which
DOES get shipped to the model on the next provider.Chat call)
instead of appending an mrSystem to Hist. Two newlines as a
separator preserves the original BuildSystemPrompt content's
formatting. Side effect: steering accumulates across iterations
through to end of loop — the picoclaw semantic (each new tool
result builds on prior steering). Embedders that want
ephemeral per-batch steering can reset SystemPrompt in
BeforeTurn.

P2 — HooksOnError dispatcher declared but never invoked. The
helper existed in PasClaw.Agent.Hooks; nothing in RunToolLoop
called it. None of the documented stages (hsBeforeTurn /
hsBeforeToolCall / hsDuringToolCall / hsAfterToolResult /
hsProviderCall) could reach an embedder's audit hook.

Fix: wired HooksOnError into two failure paths in
RunToolLoop:

  hsProviderCall   After the fallback walk completes, if the
                   final response carries a non-2xx status code
                   (every fallback also failed, or a primary 4xx
                   we don't retry on like 400/401/403/404 came
                   back), fire OnError with the status. Loop
                   continues so OnText / the legacy event path
                   still get a chance.

  hsDuringToolCall Per batch slot in phase 3, if
                   Dispatches[j].Err is non-empty after dispatch,
                   fire OnError with "tool '<name>': <err>". Covers
                   both PreflightToolCall rejections and
                   worker-caught handler exceptions.

The other stages (hsBeforeTurn, hsBeforeToolCall,
hsAfterToolResult) currently have no failure modes RunToolLoop
catches — hook methods that raise propagate up since hooks run
on the main thread. Those stages stay in the API for future
use without requiring callers to enum-match against a smaller
set today.

Verified end-to-end with a focused three-part test (built + run
+ removed, not committed):

  === Test 1: steering folds into SystemPrompt ===
    PASS — steering in SystemPrompt, no stray mrSystem
  === Test 2a: hsDuringToolCall fires ===
    PASS — fired 1 time(s), last msg: tool "fail_tool": simulated tool failure
  === Test 2b: hsProviderCall fires ===
    PASS — fired 1 time(s), last msg: provider returned status=502

  all PR #110 review-fix tests passed.

make smoke 11/11 green.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Codex P2 on PR #111: the OnError(hsProviderCall) dispatcher
gated on `Resp.StatusCode > 0`, so DNS / TLS / socket /
no-OpenSSL failures (the HTTP helper flags those as StatusCode
:= -1) silently slipped past the audit-hook path. Exactly the
outage modes an embedder running unattended would want to alert
on.

Fix: drop the StatusCode > 0 guard. The condition is now
"anything that isn't 2xx" — covers -1 (network/TLS), 0 (pre-HTTP
unclassified failure), 4xx (auth/bad-request), and 5xx (server)
in one check.

  before:
    if (Resp.StatusCode > 0) and
       ((Resp.StatusCode < 200) or (Resp.StatusCode >= 300)) then

  after:
    if (Resp.StatusCode < 200) or (Resp.StatusCode >= 300) then

Verified with a focused probe test (built + run + removed,
not committed) — fires OnError on the right stages for status
codes {-1, 0, 429, 502, 401}:

  --- probe status=-1  ---  PASS — provider returned status=-1
  --- probe status=0   ---  PASS — provider returned status=0
  --- probe status=429 ---  PASS — provider returned status=429
  --- probe status=502 ---  PASS — provider returned status=502
  --- probe status=401 ---  PASS — provider returned status=401

  PASS — all non-2xx statuses now reach OnError hooks.

make clean && make smoke 11/11 green.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
hooks: fix PR #111 review — OnError fires for status ≤ 0 too
hooks: fix PR #110 review — steering via SystemPrompt + wire OnError
@FMXExpress
FMXExpress merged commit 90e156a into main Jun 1, 2026

@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: a7953636e2

ℹ️ 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".

+ sLineBreak + sLineBreak
+ BatchSteering
else
LiveOptions.SystemPrompt := BatchSteering;

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 Preserve history system prompts when folding steering

When a direct RunToolLoop embedder supplies its policy as one or more mrSystem messages and leaves Cfg.Options.SystemPrompt empty, the first steering contribution moves only the steering text into LiveOptions.SystemPrompt. On the next round, the OpenAI builder skips every in-history mrSystem whenever that option is non-empty (PasClaw.Providers.OpenAI.pas:150-151), and Anthropic similarly drops all system messages from the message array while preferring the option (PasClaw.Providers.Anthropic.pas:110-115,130). The original caller policy therefore disappears after a hook steers the loop. Fold the existing history system text into the option as well, or retain a representation that does not cause those messages to be discarded.

Useful? React with 👍 / 👎.

Comment on lines +533 to +536
if (Length(Cfg.Hooks) > 0) and
((Resp.StatusCode < 200) or (Resp.StatusCode >= 300)) then
HooksOnError(Cfg.Hooks, hsProviderCall,
Format('provider returned status=%d', [Resp.StatusCode]));

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 Report provider exceptions before propagating them

When Cfg.Provider.Chat or a fallback provider's Chat raises instead of returning a status code, execution never reaches this newly added HooksOnError call, so registered hooks receive no hsProviderCall notification. This can occur with custom ILLMProvider implementations and with exceptions raised while a built-in provider constructs a request; it also contradicts the documented hsProviderCall meaning in PasClaw.Agent.Hooks.pas:71. Wrap each provider call so the hook is notified before the exception is re-raised.

Useful? React with 👍 / 👎.

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