Repository navigation
hooks: recover PR #111 + #112 review fixes onto main - #113
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
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
There was a problem hiding this comment.
💡 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; |
There was a problem hiding this comment.
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 👍 / 👎.
| 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])); |
There was a problem hiding this comment.
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 👍 / 👎.
hooks: fix PR #113 review — preserve history mrSystem + catch provider exceptions
Recovery — bring PR #111 + #112 review fixes into main
PR #110 merged to
mainbefore 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 onclaude/hooks-and-steeringwithout ever reachingmain.This PR fast-forwards the four stranded commits across:
4382019LiveOptions.SystemPrompt(not in-historymrSystem) + wireHooksOnError(hsProviderCall, hsDuringToolCall)3ad3436StatusCode > 0guard so DNS/TLS/socket failures (status -1) also fireOnError8cad3b0a795363Why the merge order matters
TPasClawAgentpath withCfg.Options.SystemPromptpopulated) currently see steering messages silently dropped because PR agent: hooks system + steering (picoclaw + nanobot parity) #110 routes them through in-historymrSystemwhich the OpenAI/Anthropic/Gemini builders skip whenSystemPromptis non-empty. PR hooks: fix PR #110 review — steering via SystemPrompt + wire OnError #111 fixes this.HooksOnErrorwas declared but unused. PR hooks: fix PR #110 review — steering via SystemPrompt + wire OnError #111 wires it; PR hooks: fix PR #111 review — OnError fires for status ≤ 0 too #112 widens the trigger to include non-HTTP failures (TLS handshake refusal, DNS misses, OpenSSL absent).Without this recovery, both fixes stay in the branch graveyard and
mainships hooks that don't actually deliver steering or error notifications for the common case.Verification
Tests run against
claude/hooks-and-steeringHEAD when PR #111 / #112 were opened:make smoke11/11 green.https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code