Skip to content

Reliability and correctness fixes from TECHNICAL-REVIEW (P0/P1) - #15

Merged
mmcky merged 2 commits into
mainfrom
refactor/technical-review-fixes
May 25, 2026
Merged

mmcky merged 2 commits into
mainfrom
refactor/technical-review-fixes

Conversation

@mmcky

@mmcky mmcky commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Eight P0/P1 fixes from sections 1–3 of TECHNICAL-REVIEW.md, bundled into a single squashed commit for easy revert. Common theme: surface failures loudly instead of degrading silently, and don't trust the LLM's quoted text for blind string replacement.

What changed

# Section File Change
1 §1.5 fix_applier.py Replace dead whitespace fallback with a clear "current_text not found verbatim" warning
2 §3.1 fix_applier.py Slice-based substitution at the captured position; anchor re-check guards against overlapping fixes from sequential rule processing
3 §1.6 action.py Bulk review now actually computes lectures_with_issues and errors_count (the bulk summary previously printed "Lectures with issues: 0" unconditionally because the key was never set)
4 §3.5 action.py Bulk review raises when >25% of lectures error out, so the action fails loudly instead of reporting "0 issues found" for a broken run
5 §2.2 reviewer.py Anthropic(timeout=300, max_retries=3) — a hung connection no longer holds the action hostage until the 6h job-level timeout
6 §2.3 reviewer.py Narrow except Exception to except anthropic.APIError; programmer bugs (AttributeError, KeyError, …) now bubble up — same failure mode that hid v0.7.2's temperature=0 regression behind "0 issues found"
7 §3.2 github_handler.py Deleted two unreachable lectures/-prefixed regex patterns
8 §3.6 github_handler.py create_branch appends a 6-char random suffix on collision and retries, instead of silently committing onto whatever pre-existing branch shared the name
9 §3.7 github_handler.py base_branch is resolved from repo.default_branch at startup — repos using master/develop/etc. work without the hardcoded 'main' fallback

Diff: 5 files, +213 / −108. Two new regression tests added in tests/test_fix_applier.py:

  • test_descending_position_preserves_earlier_positions — multi-fix with length-changing replacements
  • test_overlapping_fixes_second_skipped — anchor re-check catches the overlap

Out of scope

This PR covers only P0/P1 correctness/security items from sections 1–3. Larger architectural items (§4: delete prompt_loader.py, consolidate VALID_CATEGORIES, structural guardrails) and packaging/test improvements (§5–§8) are tracked in TECHNICAL-REVIEW.md for follow-up.

Test plan

  • Unit tests pass: uv run pytest tests/ -v --no-cov -m "not integration" → 93 passed
  • Imports cleanly: all five modified modules import without error
  • Smoke-test on a real lecture via qestyle after merge (requires ANTHROPIC_API_KEY)
  • Smoke-test the GitHub Action end-to-end via test-action-style-guide repo

Revert plan

Single squashed commit — git revert <merge-sha> if anything regresses in production.

🤖 Generated with Claude Code

Bundles eight items from sections 1-3 of TECHNICAL-REVIEW.md. The
common theme: surface failures loudly instead of silently degrading,
and don't trust the LLM's quoted text for blind string replacement.

fix_applier.py (§1.5, §3.1):
  Replace the str.replace()-based fix application with slice-based
  substitution at the position found by str.find(). The old code
  tracked positions but then ignored them (always replacing the first
  occurrence), and its whitespace-tolerant fallback computed an index
  into a normalized string but tried to replace against the original,
  so it silently failed every time. New code uses the captured
  position, verifies the anchor still matches before slicing (defends
  against overlapping fixes from sequential rule processing), and
  surfaces a clear "current_text not found verbatim" warning when the
  LLM paraphrased whitespace. Added two regression tests:
  test_descending_position_preserves_earlier_positions (multi-fix with
  length-changing replacements) and test_overlapping_fixes_second_skipped.

action.py (§1.6, §3.5):
  review_bulk_lectures now actually computes lectures_with_issues and
  errors_count (the bulk summary previously printed
  "Lectures with issues: 0" unconditionally because the key was never
  set). When >25% of lectures error out, the function now raises so
  the GitHub Action fails loudly instead of reporting "0 issues found"
  for a broken run.

reviewer.py (§2.2, §2.3):
  AnthropicProvider configures the SDK client with timeout=300s and
  max_retries=3, so a hung connection no longer holds the action
  hostage until the 6h job-level timeout. The bare `except Exception`
  in the per-rule loop is narrowed to `except anthropic.APIError`;
  programmer bugs (AttributeError, KeyError, …) now bubble up so the
  action fails loudly — the same failure mode that hid the v0.7.2
  temperature=0 regression silently behind "0 issues found".

github_handler.py (§3.2, §3.6, §3.7):
  - Deleted the two unreachable `lectures/`-prefixed regex patterns
    from extract_lecture_from_comment; the generic `\S+` alternative
    already accepted those paths and the body strip handled the
    prefix removal.
  - create_branch now appends a 6-char random suffix on collision
    and retries instead of silently committing onto whatever branch
    already existed under that name.
  - base_branch is resolved from repo.default_branch at startup so
    repos using master/develop/etc. work without hardcoding "main"
    everywhere.
Copilot AI review requested due to automatic review settings May 25, 2026 04:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR bundles multiple P0/P1 reliability and correctness fixes across the GitHub Action and core engine to ensure failures are surfaced loudly (instead of silently degrading) and that programmatic fix application is anchored correctly.

Changes:

  • Reworked apply_fixes to apply slice-based substitutions in descending position order with clear warnings when anchors don’t match / overlap.
  • Improved bulk review reporting and failure behavior (track lectures-with-issues and error counts; abort bulk runs when too many lectures error).
  • Hardened GitHub integration (remove dead comment-regex paths; resolve default branch dynamically; avoid branch-name collisions) and Anthropic client configuration (timeout + retry; narrower exception handling).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
style_checker/fix_applier.py Switches from str.replace to position-based slice edits with overlap/anchor checks and clearer “current_text not found” warnings.
tests/test_fix_applier.py Updates warning assertions and adds regression tests for descending-order application and overlap skipping.
style_checker/action.py Computes lectures_with_issues / errors_count and adds a bulk-run abort threshold when too many lectures error.
style_checker/reviewer.py Configures Anthropic client timeouts/retries and narrows exception handling to API-level errors.
style_checker/github_handler.py Uses repo default branch instead of hardcoded main, removes dead comment patterns, and retries branch creation with collision-avoidance suffixes.

Comment thread style_checker/github_handler.py Resolved
Comment thread style_checker/action.py Resolved
Comment thread style_checker/reviewer.py Resolved
Comment thread tests/test_fix_applier.py Resolved
- action.py: capture returned branch name from create_branch at both
  call sites. Previously the collision-avoidance suffix was silently
  discarded — on collision the suffixed branch was created but commits
  and the PR still targeted the (colliding) original name, the exact
  failure mode the collision handling was meant to prevent.
- action.py: replace ad-hoc `max(2, len(lectures) // 4)` threshold
  with `max(2, math.ceil(len(lectures) / 4))` and a comment that
  accurately documents the small-batch floor behavior. Includes the
  threshold value in the abort message.
- reviewer.py: drop dead `try/except ImportError` in AnthropicProvider
  — anthropic is now a hard dep imported at module top, so a missing
  install fails on module import before the class is ever instantiated.
- tests/test_fix_applier.py: tighten test_overlapping_fixes_second_skipped
  to assert the exact deterministic result (descending order applies
  inner first, outer is skipped) and remove the chatty inline reasoning.
@mmcky

mmcky commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all 4 Copilot review comments in 8327259:

  1. create_branch return value not used by callers — real bug, thanks Copilot. Both call sites in action.py (review_single_lecture, review_bulk_lectures) now capture the returned name and use it for commit_changes + create_pull_request. On a name collision the suffixed branch is now actually committed to, instead of silently falling back to the colliding pre-existing branch we were trying to avoid.

  2. Bulk-error threshold math didn't match the comment — replaced max(2, len(lectures) // 4) with max(2, math.ceil(len(lectures) / 4)). Updated the comment to accurately describe the small-batch floor behavior. Verified:

      1 lecture  → threshold 2 (never fires; needs both errors when n=2)
      8 lectures → threshold 2 (~25%)
     20 lectures → threshold 5 (25%)
    100 lectures → threshold 25 (25%)
    

    Abort message now includes the threshold for diagnosability.

  3. Dead try/except ImportError in AnthropicProvider.__init__ — removed. anthropic is a hard dep in pyproject.toml and now imported at module top (needed for the except anthropic.APIError block from this PR), so a missing install fails at import time long before that fallback could run.

  4. Overlap regression test too permissive — tightened test_overlapping_fixes_second_skipped to assert the exact deterministic outcome ("the quick red fox", inner applied + outer skipped) and removed the conversational inline reasoning comment.

All 93 tests still pass.

@mmcky
mmcky merged commit ba2d09d into main May 25, 2026
4 checks passed
@mmcky
mmcky deleted the refactor/technical-review-fixes branch May 25, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants