Repository navigation
hooks: fix PR #110 review — steering via SystemPrompt + wire OnError - #111
Conversation
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
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 438201924e
ℹ️ 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".
| if (Length(Cfg.Hooks) > 0) and | ||
| ((Resp.StatusCode > 0) and ((Resp.StatusCode < 200) or (Resp.StatusCode >= 300))) then |
There was a problem hiding this comment.
Report non-HTTP provider failures to hooks
When the primary provider and every fallback fail before receiving an HTTP response, the final status is negative and this guard skips HooksOnError. The shipped HTTP helper explicitly returns StatusCode := -1 for failures such as unavailable TLS support (PasClaw.Providers.HTTP.pas:204), and the loop already treats every StatusCode <= 0 as a retryable provider failure in IsRetryableStatus. As a result, an embedder's audit or alerting hook remains silent for DNS/TLS/socket-style outages after the fallback walk is exhausted. Include negative statuses in the hsProviderCall reporting path while preserving the intended handling for legacy unset statuses if needed.
Useful? React with 👍 / 👎.
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
Stacks on PR #110. Targets
claude/hooks-and-steeringso the diff is just the review fixes; once #110 merges, GitHub will auto-retarget tomain.Summary
Two Codex findings on PR #110.
P1 — Steering messages invisible under the default component config
PR #110 appended each batch's
SteeringMessagesas anmrSystementry inHistbefore the next LLM round. But the OpenAI / Anthropic / Gemini provider builders explicitly drop in-historymrSystementries wheneverChatOptions.SystemPromptis non-empty — they ship one consolidated system prompt via that slot, not via the messages array.TPasClawAgent.ChatHistoryalways populatesCfg.Options.SystemPromptviaBuildSystemPrompt, so the default component path always hit this case. Steering was silently dropped before reaching the model.Fix: fold
BatchSteeringintoLiveOptions.SystemPrompt(which does get shipped to the model on the nextProvider.Chat) instead of appending anmrSystemtoHist. Two newlines as a separator preserves the originalBuildSystemPromptcontent's formatting.Side effect: steering accumulates across iterations through end of loop — the picoclaw semantic (each new tool result builds on prior steering). Embedders wanting ephemeral per-batch steering can reset
SystemPromptinBeforeTurn.P2 —
HooksOnErrordispatcher declared but never invokedThe helper existed in
PasClaw.Agent.Hooks; nothing inRunToolLoopcalled it. None of the documented stages could reach an embedder's audit hook.Fix: wired
HooksOnErrorinto two failure paths:hsProviderCallhsDuringToolCallDispatches[j].Erris non-empty after dispatch. Covers bothPreflightToolCallrejections and worker-caught handler exceptions.The other stages (
hsBeforeTurn,hsBeforeToolCall,hsAfterToolResult) currently have no failure modesRunToolLoopcatches — hook methods that raise propagate up since hooks run on the main thread. Those stages stay in the API for future use.Verification
Three-part end-to-end test (built + run + removed):
Test 1 asserts the steering text appears in
Loop.FinalSystemPromptand that nomrSystemmessage with the steering text leaked intoLoop.FinalMessages. Tests 2a/2b register an audit hook + a deliberately-failing tool / provider and check the audit hook recorded the right stage + message.make smoke11/11 green.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code