fix bench restore output handling#529
Conversation
|
| Filename | Overview |
|---|---|
| agent/utils.py | Adds parse_json_output utility that scans command output for JSON fragments, preferring a clean-trailing match and using a validator to disambiguate; logic is correct for all current call sites. |
| agent/site.py | Replaces four bare json.loads calls with parse_json_output plus specific validators, and adds --verbose to the restore command; all validators are tight enough to reject accidental log-line matches. |
| agent/tests/test_site.py | Adds seven tests covering noisy-log extraction, validator-driven disambiguation, ambiguity detection, verbose-restore flag, and end-to-end flows for uninstall_unavailable_apps, apps_as_json, and get_analytics. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[parse_json_output called] --> B{json.loads succeeds AND validator passes?}
B -- Yes --> C[Return value directly]
B -- No --> D[Scan output for JSON start chars]
D --> E{raw_decode + validator passes?}
E -- No --> F{More chars to scan?}
F -- Yes --> D
F -- No --> G{Any candidate found?}
E -- Yes --> H{Nothing after match?}
H -- Yes --> I{trailing_candidate already set?}
I -- Yes --> J[Raise Ambiguous JSON]
I -- No --> K[Set trailing_candidate, continue scan]
K --> F
H -- No --> L{dirty_candidate already set?}
L -- Yes --> M[Raise Ambiguous JSON]
L -- No --> N[Set dirty_candidate, continue scan]
N --> F
G -- trailing found --> O[Return trailing_candidate]
G -- dirty only --> P[Return dirty_candidate]
G -- none found --> Q[Raise original_error]
Reviews (4): Last reviewed commit: "narrow installed app payload validation" | Re-trigger Greptile
|
Hi, the PR is ready for review from my side. The Greptile review is passing and there are no merge conflicts. The only remaining item appears to be the GitHub Actions workflow waiting for maintainer approval to run on this fork PR. Please let me know if you’d like any changes. |
Closes #451
Closes #483
What changed
benchstdout--verboseduring restore so long-running backup restores show more progressWhy
Restores could fail when custom apps printed to stdout before the JSON payload, because the agent expected perfectly clean JSON. Heavy restore jobs also provided too little progress visibility.
Impact
Validation
python -m unittest agent.tests.test_site