Commit 8fc4e5e
feat(hooks): silently abort on HookAbortError in run_agent + 3rd-party runner
Patch AstrBotDevs#2 added fail_closed=True semantics to the 6 LLM filter decorators
and a HookAbortError catch in agent_sub_stages/internal.py. But two other
sites still let the abort fall through their broad `except Exception`:
- astr_agent_run_util.py:303 — the local agent runner's main loop. The
broad catch built `Error occurred during AI execution. Error Type:
HookAbortError. Error Message: ...` and called on_agent_done with that
string as the LLMResponse, which (a) leaked the hook name + plugin
path + reason to the user, and (b) re-fired the on_llm_response hook
chain — the same chain that had just aborted — causing a cascade.
- third_party.py:82 — same pattern in the third-party agent runner.
Yields the error string to the user via the response chain.
Fix: add a dedicated `except HookAbortError` ahead of the broad catch in
both sites. On abort:
- log the hook / plugin / handler / reason at error level (operator-
facing only — never user-facing)
- do NOT call on_agent_done (avoid the cascade)
- send the persona's custom_error_message as a polite refusal if set;
otherwise stay silent
- in run_agent: stop the event so the respond stage doesn't wrap and
forward an empty result
This is the third in the SuperX governance hook safety suite (Patches
AstrBotDevs#1=signature, AstrBotDevs#2=fail_closed, AstrBotDevs#3=silent-abort).
Existing test_hook_fail_closed.py still passes (9/9). Worth adding a
test for the run_agent path in a follow-up — the current suite covers
context_utils.call_event_hook directly but not the runner's outer catch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ce676e4 commit 8fc4e5e
2 files changed
Lines changed: 45 additions & 0 deletions
File tree
- astrbot/core
- pipeline/process_stage/method/agent_sub_stages
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
300 | 301 | | |
301 | 302 | | |
302 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
303 | 334 | | |
304 | 335 | | |
305 | 336 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
82 | 96 | | |
83 | 97 | | |
84 | 98 | | |
| |||
0 commit comments