Commit f883360
committed
fix: harden JSON misformat handling to prevent infinite loops and crashes
Three interrelated fixes for the misformat handling pipeline:
1. extract_json_object_string: replace rfind with brace-depth tracking
that respects string literals and escape sequences, preventing
false JSON extraction when model output contains incidental braces.
2. process_tools: add consecutive misformat counter on LoopData with
a circuit breaker at 5 attempts, raising HandledException to stop
the agent instead of looping indefinitely.
3. validate_tool_request: return early for None (already handled by
the misformat path) and raise RepairableException instead of
ValueError so the agent can retry instead of crashing.
Also improves fw.msg_misformat.md to show the expected JSON format
explicitly instead of the vague original one-liner.1 parent 36f26c1 commit f883360
3 files changed
Lines changed: 61 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
341 | 341 | | |
342 | 342 | | |
343 | 343 | | |
| 344 | + | |
344 | 345 | | |
345 | 346 | | |
346 | 347 | | |
| |||
943 | 944 | | |
944 | 945 | | |
945 | 946 | | |
946 | | - | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
947 | 953 | | |
948 | 954 | | |
949 | 955 | | |
950 | 956 | | |
951 | | - | |
| 957 | + | |
952 | 958 | | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
953 | 967 | | |
954 | 968 | | |
955 | 969 | | |
| 970 | + | |
| 971 | + | |
956 | 972 | | |
957 | | - | |
| 973 | + | |
958 | 974 | | |
959 | | - | |
| 975 | + | |
960 | 976 | | |
961 | | - | |
| 977 | + | |
962 | 978 | | |
963 | 979 | | |
964 | 980 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
36 | 54 | | |
37 | 55 | | |
38 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
0 commit comments