Skip to content

fix(source-control): case-insensitive classification-token matching in babysit-readiness-gate - #1347

Merged
kyle-sexton merged 9 commits into
mainfrom
fix/619-babysit-readiness-gate-classify-case-insensitive
Jul 26, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
fix/619-babysit-readiness-gate-classify-case-insensitive

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #619

Summary

  • babysit-readiness-gate.sh's bash safe-tier degrade and babysit_classify.py's preferred Python
    classifier both matched classification tokens (VALID|INCORRECT|UNCERTAIN) exact-case only. A
    worker reply that wrote a natural-language disposition like "Valid (defer)" instead of the mandated
    all-caps VALID scored as unclassified, so the gate reported
    READINESS_BLOCKED reason=under-decomposed even though the finding genuinely was classified.
  • Made the token count and the self-row exclusion (which keeps a classification row's own embedded
    severity word from re-counting as a phantom finding) case-insensitive in both the bash degrade
    (grep -wiE) and the Python classifier (re.IGNORECASE on CLASSIFY_TOKEN_RE /
    CLASSIFY_ROW_RE) — kept whole-word, so "invalid"/"INVALID" still does not false-match
    "valid"/"VALID".
  • Bumped source-control to 0.26.3 with a CHANGELOG entry.

Test plan

  • bash plugins/source-control/scripts/babysit-readiness-gate.test.sh — 70/70 pass, including 3 new
    lowercase/natural-language-token regression cases and a new lowercase convergence fixture pinning
    the bash degrade to the same count as the Python classifier.
  • bash plugins/source-control/skills/babysit-prs/scripts/engine.test.sh (Python unittest
    discovery + ruff + guarded-wrapper checks) — 351/351 tests pass, ruff clean.
  • shellcheck and editorconfig-checker on every changed file — clean.

Related

Refs #534 — parent umbrella issue (shared authorship/finding/approval classifier this issue was folded under)

🤖 Generated with Claude Code

…n babysit-readiness-gate

babysit-readiness-gate.sh's bash degrade and babysit_classify.py's preferred
Python classifier both matched classification tokens (VALID|INCORRECT|
UNCERTAIN) exact-case only. A worker reply that wrote a natural-language
disposition like "Valid (defer)" instead of the mandated all-caps VALID
scored as unclassified, so the gate reported READINESS_BLOCKED
reason=under-decomposed even though the finding genuinely was classified.

Match both the token count and the self-row exclusion (which keeps a
classification row's own severity word from re-counting as a phantom
finding) case-insensitively, still whole-word so "invalid"/"INVALID" does
not false-match "valid"/"VALID". Add bash regression cases, a lowercase
convergence fixture pinning the bash degrade to the Python classifier, and
Python unit tests. Bump source-control to 0.26.3 with a CHANGELOG entry.

Closes #619

Co-Authored-By: Claude Sonnet 5 (claude-code-plugins work-loop) <[email protected]>
@claude

claude Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 55s —— View job


PR Review

  • Gather context and read changed files
  • Review bash degrade changes (babysit-readiness-gate.sh)
  • Review Python classifier changes (babysit_classify.py)
  • Review test coverage
  • Review versioning and changelog
  • Summarize findings

Summary

This is a minimal, well-targeted fix for a real false-BLOCKED scenario (#619). When a worker's classification table row used natural-language casing like Valid (defer) instead of mandated all-caps VALID, the gate miscounted it as unclassified. The fix is a two-place change applied symmetrically in both the bash degrade and the Python classifier.

Overall verdict: LGTM — no blocking issues.


Correctness

The paired nature of the fix is the key invariant, and it's handled correctly.

There are two places that must move together:

  1. The token counter (counts classified rows) — needs -i / re.IGNORECASE so Valid, valid, VALID all count.
  2. The row exclusion (strips self classification rows from the finding corpus before counting findings) — needs -i / re.IGNORECASE for the exact same set of rows, or a lowercase row leaks through and its embedded severity word re-counts as a phantom finding.

Both the bash and Python paths apply the change in both places:

Whole-word safety is preserved:

  • Bash: -w is retained alongside -i, so invalid/INVALID cannot false-match valid/VALID.
  • Python: \b word boundaries in CLASSIFY_TOKEN_RE are unaffected by re.IGNORECASE (boundaries are position-based, not character-case-based). For CLASSIFY_ROW_RE, the [^A-Za-z] guards achieve the same effect — INVALID doesn't match because the N before VALID is a letter, failing [^A-Za-z].

The asymmetry between CLASSIFY_TOKEN_RE (\b) and CLASSIFY_ROW_RE ([^A-Za-z]) is pre-existing and intentional — the row exclusion pattern predates this PR and uses explicit character class guards for a different reason. The fix correctly adds re.IGNORECASE to both without changing their boundary semantics.


Test Coverage

Coverage is thorough and correctly structured. Each new behavior has a dedicated case:

Scenario Bash test Python unittest
Lowercase token counts as classified lowercase-classify (line 246) test_lowercase_natural_language_disposition_counts
"invalid" still does NOT false-match "valid" lowercase-invalid (line 259) test_lowercase_invalid_does_not_false_match_valid
Lowercase self row doesn't leak into finding corpus self-row-severity-lowercase (line 269) test_lowercase_self_classification_row_does_not_mint_phantom_finding
Bash degrade and Python agree on lowercase input conv-lowercase convergence fixture (line 440) — (covered by convergence test)

One minor gap: count_effective_classified (the per-surface bucketed variant) has no dedicated lowercase test. However, since count_effective_classified → _capped_credit → count_classified, and count_classified is directly tested, the fix propagates correctly without a separate test.


Changelog / Version

0.26.2 → 0.26.3 is the correct patch bump for a behavior fix with no API surface change. The CHANGELOG entry accurately describes both the root cause and the fix, including the phantom-finding dimension.


Observations (non-blocking)

  1. CLASSIFY_ROW_RE note on re.IGNORECASE + [^A-Za-z]: With re.IGNORECASE set, [A-Za-z] already covers both cases explicitly, so IGNORECASE doesn't change the semantics of the character class — it's redundant but harmless. The comment in the PR correctly explains the reasoning.

  2. Missing Uncertain/uncertain test variants: The new tests only exercise Valid/invalid. Since the same re.IGNORECASE flag governs all three tokens (VALID|INCORRECT|UNCERTAIN) uniformly, this is fine — no token-specific behavior to guard.

@claude

claude Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 34s —— View job


Security Review — PR #1347

  • Fetch PR diff
  • Read changed source files
  • Analyze for security vulnerabilities
  • Post findings

No security issues found.

Reviewed all 6 changed files for injection surfaces, logic flaws, authorization gaps, unsafe data handling, and dangerous patterns. Findings below by area:

Command/Regex Injection — Clean

babysit-readiness-gate.sh

CLASSIFY_RE='VALID|INCORRECT|UNCERTAIN' is a hardcoded constant; the two changed grep invocations use it as a fixed pattern against a piped data stream, not via shell expansion into a command argument. No user-controlled content reaches the pattern slot.

babysit_classify.py

CLASSIFY_TOKEN_RE and CLASSIFY_ROW_RE are compiled from hardcoded string literals — re.IGNORECASE is the only change. PR comment bodies are processed as data through these patterns, never interpolated into the pattern string.

ReDoS — Clean

The changed patterns are fixed-string alternations inside word-boundary anchors. The .* in CLASSIFY_ROW_RE is bounded left by ^[ \t]*\| and right by a literal alternation; worst-case backtracking on a non-matching pipe row is O(N) per line. Not catastrophic. Identical structure existed before this PR; no new risk introduced.

Authorization / Gate-bypass Logic — Clean

Classifications are counted exclusively from self_bodies / is_self_login() paths — neither changed. Making the token match case-insensitive only affects whether a self-authored lowercase disposition (Valid (defer)) counts as a classification; a non-self (reviewer) comment writing "valid" in a table row cannot contribute to the classification total. The trust boundary between self and non-self authors is unchanged.

The whole-word guards (-w in bash, \b in Python) correctly prevent invalid/INVALID from false-matching valid/VALID after the case flag is added. The new test cases (test_lowercase_invalid_does_not_false_match_valid, lowercase-invalid) pin this boundary explicitly.

Path Traversal / File Handling — Clean

No new file reads introduced. The --comments-json and --checklist path handling is pre-existing and unchanged.

GitHub Actions / Secrets / Supply Chain — N/A

No workflow files, dependency pins, or secret-handling changed in this PR.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7263e7bbb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ness-gate-classify-case-insensitive

# Conflicts:
#	plugins/source-control/.claude-plugin/plugin.json
#	plugins/source-control/CHANGELOG.md
…ition cell

Case-folding the classification token while scanning a whole `|`-prefixed line
made ordinary table prose score as a disposition: with two findings, one real
`VALID` row, and an unrelated self row such as `| CI check | result is valid |`,
both the bash degrade and the Python classifier reported classified=2 and let
the second, genuinely unclassified finding past the under-decomposition gate.

Both paths now require the token to OPEN a table cell -- a `|`, then only
non-letter decoration (`**`, a checkmark), then the token. Real dispositions
still count in any case ("Valid (defer)", "**VALID**"); prose does not. The
row-exclusion predicate is built by concatenating the row anchor onto the SAME
cell pattern, so the rows stripped from the finding corpus and the rows credited
as classified cannot drift apart.

Both tightenings fail closed: a disposition buried mid-cell now scores
unclassified (BLOCKED) rather than passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 570ee76d2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ness-gate-classify-case-insensitive

# Conflicts:
#	plugins/source-control/.claude-plugin/plugin.json
#	plugins/source-control/CHANGELOG.md
#	plugins/source-control/scripts/babysit-readiness-gate.sh
@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Automated review did not complete — this is an infrastructure failure, not a review verdict.

Treat any Claude comment on this PR (including a placeholder like "I'll analyze this and get back to you") as incomplete, not "no findings."

Re-running the job, or pushing a new commit, will retry the review.

@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Automated security review did not complete — this is an infrastructure failure, not a review verdict.

Treat any Claude comment on this PR (including a placeholder like "I'll analyze this and get back to you") as incomplete, not "no findings."

Re-running the job, or pushing a new commit, will retry the review.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c39f450b92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…t its start

Anchoring the classification token to the START of a table cell still credited
prose: `| 2 | c2 | Valid cache entries are rejected | | |` opens a cell with a
disposition word, so two findings and one real VALID row scored classified=2 and
passed the under-decomposition gate. A letters-only boundary also accepted
`valid2`, `2valid` and `VALID_TOKEN`, since digits and underscores are not
letters -- and such a row is credited AND stripped from the finding corpus,
turning one unclassified finding into READINESS_OK.

A cell now counts only when the token IS the cell: decoration (`**`, a
checkmark) may surround it, and a parenthesised or bracketed aside is removed
first so "Valid (defer)" reads as the bare token. The decoration class excludes
word characters on both sides.

Chosen over parsing the table header for a Classification column: a
header-driven rule still credits prose written INTO that column, and it needs a
header row at all, which a single-row reply does not carry.

The bash path moves its predicate into one `classify_rows` function so the count
and the corpus-strip share it; the strip evaluates the predicate on a normalized
copy and emits the ORIGINAL line, since aside removal would otherwise delete a
`[P1]` severity marker from the corpus it only filters.
…ness-gate-classify-case-insensitive

# Conflicts:
#	plugins/source-control/.claude-plugin/plugin.json
#	plugins/source-control/CHANGELOG.md
@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

…ness-gate-classify-case-insensitive

# Conflicts:
#	plugins/source-control/CHANGELOG.md

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a619f8f6dd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 530ad06aae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Requiring the token to be the WHOLE cell rejected `VALID — fixing` and
`VALID — fix now`, which reference/review-discipline.md specifies as canonical
disposition values -- so a reply written exactly as documented scored
unclassified and the gate reported a false READINESS_BLOCKED.

A cell now counts when it OPENS with the token, optionally followed by an
annotation introduced by PUNCTUATION. The punctuation requirement is the
discriminator the whole-cell rule was standing in for: `VALID — fixing` and
`VALID (defer)` count; `Valid cache entries are rejected` does not, because a
bare space before more letters is prose, not an annotation. `valid2`, `2valid`
and `VALID_TOKEN` still fail on the word-character boundary.

Removes the aside-stripping normalization: the punctuation branch matches
`(defer)` directly, so the third pattern that had to stay in sync between the
bash and Python paths is gone.
@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@claude

claude Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@kyle-sexton
kyle-sexton merged commit 67d9fea into main Jul 26, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the fix/619-babysit-readiness-gate-classify-case-insensitive branch July 26, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant