Filled in for the reference solution. Observations below come from running BugHound in
Heuristic mode on the four sample_code/ files (no Gemini key required); Gemini-mode notes
describe expected behavior.
Name: BugHound Purpose: Analyze a Python snippet, propose a fix, and run reliability checks before suggesting whether the fix should be auto-applied. Intended users: Students learning agentic workflows and AI reliability concepts.
BugHound runs a five-stage agent loop in BugHoundAgent.run():
PLAN (decide to scan + propose a fix) → ANALYZE (detect issues) → ACT (propose a
fix) → TEST (assess_risk scores the change) → REFLECT (decide whether to auto-apply).
- Heuristic mode (offline, deterministic):
_heuristic_analyzeflags exactly three patterns —print((Code Quality/Low), bareexcept:(Reliability/High),TODO(Maintainability/Medium) — and_heuristic_fixrewrites them. - Gemini mode: the analyzer/fixer prompts in
prompts/are sent to the LLM; if the call fails or the output doesn't match our contract, the agent falls back to heuristics.
The code, not the model, makes the trust decision — that's the whole point.
Inputs: the four sample files — cleanish.py (no issues), print_spam.py (prints),
flaky_try_except.py (bare except), mixed_issues.py (print + bare except + TODO).
Outputs (Heuristic mode):
| Input | Issues | Risk level | Score | Auto-fix? |
|---|---|---|---|---|
| cleanish.py | 0 | low | 100 | yes (nothing to change) |
| print_spam.py | 1 (Low) | low | 95 | yes |
| flaky_try_except.py | 1 (High) | medium | 55 | no |
| mixed_issues.py | 3 | high | 30 | no |
Two rules from assess_risk:
- High severity deducts 40 points. Checks: whether a serious issue (e.g. bare
except:) is present. Why it matters: serious issues shouldn't be silently auto-patched. False positive: a bareexcept:that is genuinely intentional (e.g. a top-level crash guard) still tanks the score. False negative: a subtle logic bug the heuristic never labels "High" sails through at full score. - Missing-return penalty (−30). Checks: the original had
returnbut the fix doesn't. Why it matters: dropping a return often changes behavior. False positive: a refactor that legitimately moves the return into a helper. False negative: a fix that keepsreturnbut returns the wrong value.
Added in this solution:
- [Part 3] No auto-fix when any issue is High severity, regardless of score — an explicit belt-and-suspenders policy.
- [Part 4] No auto-fix when the fix rewrites > 50% of the lines — large diffs need human eyes.
- Missed issue (false negative): the heuristic's reliability rule only matches a bare
except:. A broadexcept Exception:— which still swallows every error but names the class — slips through with 0 issues flagged, and more generally the analyzer is blind to anything outside its three patterns (print(/ bareexcept:/TODO), so real logic bugs, resource leaks, or overly-broad catches go unreported. - Risky/needless fix (over-editing): the heuristic fixer prepends
import loggingwhenever aprint(exists — even ifloggingis already imported — producing a duplicate import. On a file that already imports logging, the "fix" introduces a new problem. This is exactly the over-editing case the Part 4 guardrail now catches before auto-applying.
- Heuristic catches its three patterns consistently and never hallucinates — but it is blind to everything else (naming, logic bugs, security).
- Gemini typically finds more nuanced issues and writes more natural fixes, but on
cleanish.pyit tends to invent problems (flagginglogging.infoas verbose, proposing renames) — a false-positive failure mode heuristics don't have. - The risk scorer generally agreed with intuition on the samples: it correctly refused to
auto-fix
flaky_try_except.pyandmixed_issues.py, and allowed the tinyprint_spam.pyfix.
Scenario: BugHound should refuse to auto-fix when the proposed change rewrites most of the file, because a large diff can quietly change behavior.
- Trigger: proposed fix differs from the original by more than 50% of lines.
- Where implemented:
reliability/risk_assessor.py(MAX_AUTOFIX_CHANGE_RATIO), so the policy lives with the other guardrails and is inspectable/reversible. - Message to show: "This fix rewrites most of the file and needs human review before it can be applied."
Make the heuristic fixer idempotent: only add import logging if it isn't already imported (and
add it after any existing import block). This removes the duplicate-import failure mode from §5
with a one-line guard — low complexity, real reliability gain.