Commit 8afc6a4
committed
revert(hooks): drop loop_detector builtin, keep inline tool-loop detector
Reverts the loop-detector portion of the builtin extraction. The
behavior change from per-batch to per-call detection turned out to be
the wrong trade-off: alternating multi-tool batches like `[A,B] [A,B]`
are a real failure mode that the inline detector caught and the per-call
builtin missed.
Surgical revert \u2014 keeps the rest of the work intact:
* post_tool_use / before_llm_call deny contract widening stays
(general feature, no behavior change without an explicit hook).
* max_iterations builtin stays (separate from loop detection, no
change to the existing agent.MaxIterations UX).
* The five context-injecting builtins stay.
* The duplicate-dispatch fix and simplifications stay.
## Removed
* pkg/hooks/builtins/loop_detector.go and its test.
* pkg/hooks/builtins/json.go (canonicalToolInput / sortKeys were
only consumed by the loop_detector builtin).
* `builtins.LoopDetector` constant.
* `AgentDefaults.MaxConsecutiveToolCalls` and `ExemptLoopTools`
fields, plus the auto-injection branch in ApplyAgentDefaults.
* `State.loopDetector` field.
## Restored from origin/main
* pkg/runtime/tool_loop_detector.go (per-batch signature detector).
* pkg/runtime/tool_loop_detector_test.go.
* Inline `loopDetector := newToolLoopDetector(...)` setup at the top
of RunStream's goroutine.
* `if loopDetector.record(res.Calls)` block emitting Error +
notifyError after a tool batch in loop.go.
* `MaxConsecutiveToolCalls` is once again read straight from the
session, with the historic threshold-of-5 default.
## Tests
* hooks_wiring_test.go: "no flags: no implicit hooks, no executor"
case is back; loop_detector-specific assertions removed.
* builtins_test.go: removed LoopDetector from the registration roster.
## Validation
go build ./... -> ok
go test ./... -> all packages pass
go test -race ./pkg/hooks/... ./pkg/runtime/... -> clean
golangci-lint run ./... -> 0 issues
Assisted-By: docker-agent1 parent c54be36 commit 8afc6a4
10 files changed
Lines changed: 392 additions & 496 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | | - | |
| 19 | + | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
30 | 26 | | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
34 | | - | |
35 | 30 | | |
36 | 31 | | |
37 | 32 | | |
| |||
40 | 35 | | |
41 | 36 | | |
42 | 37 | | |
43 | | - | |
44 | 38 | | |
45 | 39 | | |
46 | 40 | | |
| |||
50 | 44 | | |
51 | 45 | | |
52 | 46 | | |
53 | | - | |
54 | 47 | | |
55 | 48 | | |
56 | 49 | | |
57 | 50 | | |
58 | 51 | | |
59 | 52 | | |
60 | 53 | | |
61 | | - | |
62 | 54 | | |
63 | 55 | | |
64 | 56 | | |
| |||
70 | 62 | | |
71 | 63 | | |
72 | 64 | | |
73 | | - | |
74 | 65 | | |
75 | 66 | | |
76 | 67 | | |
| |||
79 | 70 | | |
80 | 71 | | |
81 | 72 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 73 | + | |
89 | 74 | | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
95 | 78 | | |
96 | 79 | | |
97 | 80 | | |
| |||
110 | 93 | | |
111 | 94 | | |
112 | 95 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | 96 | | |
121 | 97 | | |
122 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| |||
This file was deleted.
This file was deleted.
0 commit comments