Skip to content

witness gate: the near-miss regex flags ordinary prose, and its file-level exemption swallows genuine de-marked markers in the gate's own file - #344

Merged
jaylfc merged 1 commit into
masterfrom
exec/tsk-2k55kq
Aug 18, 2026
Merged

witness gate: the near-miss regex flags ordinary prose, and its file-level exemption swallows genuine de-marked markers in the gate's own file#344
jaylfc merged 1 commit into
masterfrom
exec/tsk-2k55kq

Conversation

@jaylfc

@jaylfc jaylfc commented Aug 18, 2026

Copy link
Copy Markdown
Owner

CARD TITLE (intent, not commit subject): witness gate: the near-miss regex flags ordinary prose, and its file-level exemption swallows genuine de-marked markers in the gate's own file

Autonomous build of board card tsk-2k55kq.

Tighten the near-miss detector to require the :: marker payload so
ordinary prose that merely mentions WITNESS is no longer flagged, while
de-marked (zero-width) and malformed markers still are. Replace the
file-level de-marked-marker exemption with a line-level one keyed on the
three documented docstring example lines (4, 19, 36), so a genuine
de-marked marker appended to scripts/check_witness_token.py is reported.
Adds regression tests and a changelog fragment.

Files:
.../tsk-2k55kq-witness-gate-near-miss-hardening.md | 8 +++
scripts/check_witness_token.py | 21 ++++---
scripts/resume_arm_time.py | 8 ++-
tests/test_resume_arm_time.py | 8 ++-
tests/test_witness_gate.py | 67 ++++++++++++++++++++++
5 files changed, 99 insertions(+), 13 deletions(-)

Summary by CodeRabbit

  • Bug Fixes

    • Improved witness-marker validation to ignore ordinary prose references while continuing to flag malformed or hidden markers.
    • Detection now identifies genuine markers even when they appear alongside approved examples in the same file.
    • Added clearer handling for documented examples, reducing false positives without overlooking appended or altered markers.
  • Tests

    • Expanded coverage for prose, hidden markers, malformed markers, and modified validation scripts.

Tighten the near-miss detector to require the :: marker payload so
ordinary prose that merely mentions WITNESS is no longer flagged, while
de-marked (zero-width) and malformed markers still are. Replace the
file-level de-marked-marker exemption with a line-level one keyed on the
three documented docstring example lines (4, 19, 36), so a genuine
de-marked marker appended to scripts/check_witness_token.py is reported.
Adds regression tests and a changelog fragment.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 971d024c-1531-43f9-be4a-17cdb7ce324b

📥 Commits

Reviewing files that changed from the base of the PR and between 12d7710 and 77ef232.

📒 Files selected for processing (3)
  • changelog.d/tsk-2k55kq-witness-gate-near-miss-hardening.md
  • scripts/check_witness_token.py
  • tests/test_witness_gate.py

Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The witness gate now requires a :: payload for near-miss detection and applies de-marked-marker exemptions per line. Tests cover prose, malformed markers, appended markers, and documented examples. A changelog entry records the behavior.

Changes

Witness gate hardening

Layer / File(s) Summary
Update near-miss detection rules
scripts/check_witness_token.py
Near-miss matching requires a :: payload. Exemptions skip only configured lines instead of entire files.
Add detection regression coverage
tests/test_witness_gate.py, changelog.d/tsk-2k55kq-witness-gate-near-miss-hardening.md
Tests verify clean prose, malformed markers, appended markers, and documented examples. The changelog records these rules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 77ef2

This localized change tightens witness-marker detection and adds regression coverage; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies both primary issues addressed by the pull request: false-positive near-miss detection and an overly broad file-level exemption.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch exec/tsk-2k55kq

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gitar-bot

gitar-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

# zero-width character (e.g. U+200B) lodged between WITNESS and the colon,
# or the colon replaced. Requiring the ``::`` payload keeps ordinary prose
# mentioning WITNESS from being mistaken for a malformed marker.
_NEAR_MISS_RE = re.compile(r"#\s*WITNESS[^:](?=.*::)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WARNING: Near-miss regex can false-positive on prose containing ::

The (?=.*::) lookahead matches :: anywhere on the line. A prose comment like # WITNESS markers use :: syntax would be flagged as a near-miss even though it is ordinary prose, because the regex only checks that :: exists somewhere after the broken separator, not that it appears in a marker-like payload position.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

# Documented examples of a de-marked marker in this file's own docstring.
# They are intentionally de-marked and must not be reported; every other line
# in the same file (e.g. an appended genuine marker) still is. Greppable name.
_DEMARKED_MARKER_EXEMPTION = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Hardcoded exemption line numbers are fragile

The docstring example lines (4, 19, 36) are hardcoded. If the docstring is edited, these line numbers become stale and the exemption silently breaks. Consider matching by line content (e.g., the specific de-marked marker pattern) instead of position.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

# that merely mentions WITNESS, while still catching de-marked (ZWSP)
# and malformed markers. All three arms live in one test so a loosening
# that silences the prose cannot silence the de-marked arms either.
# Arm A -- prose in taosmd/ mentioning WITNESS but no ``::`` is clean.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

SUGGESTION: Missing test arm for prose containing ::

Arm A covers prose without ::, but there is no arm for prose that mentions both WITNESS and :: in the same line (e.g., # WITNESS markers use :: syntax). The current regex would flag such a line as a near-miss. Consider adding an Arm D to verify this edge case.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
scripts/check_witness_token.py 70 Near-miss regex (?=.*::) matches :: anywhere on the line, so prose like # WITNESS markers use :: syntax would be flagged as a near-miss despite being ordinary prose.

SUGGESTION

File Line Issue
scripts/check_witness_token.py 74 _DEMARKED_MARKER_EXEMPTION hardcodes line numbers (4, 19, 36) that become stale if the docstring is edited. Consider content-based matching instead of position.
tests/test_witness_gate.py 340 test_near_miss_regex_spares_prose_arms lacks an arm for prose containing :: (e.g., # WITNESS markers use :: syntax), which the current regex would flag.
Files Reviewed (3 files)
  • changelog.d/tsk-2k55kq-witness-gate-near-miss-hardening.md
  • scripts/check_witness_token.py - 2 issues
  • tests/test_witness_gate.py - 1 issue

Fix these issues in Kilo Cloud


Reviewed by step-3.7-flash · Input: 59.9K · Output: 19.9K · Cached: 640.9K

@jaylfc

jaylfc commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

MERGE. Both card items delivered and measured, with one regression carded as tsk-y54vhk.

Reviewed against this branch's own merge-base f5cd3e50, not master — master moved twice under this queue tonight and diffing branch-to-master would have shown drift from my own merges.

The two weaknesses, measured with controls in both directions

Every arm run against the base gate and this one, via WITNESS_GATE_ROOT fixtures, printing each fixture's bytes before running it:

ARM                                          BASE f5cd3e50   PR #344
CTL empty repo, no markers                        0            0     <- control
CTL live well-formed resolving marker             0            0     <- control
ARM prose 'WITNESS markers are validated'         1            0     <- WEAKNESS 1 FIXED
ARM de-marked (ZWSP) marker in taosmd/            1            1     <- kept
ARM de-marked (ZWSP) marker in scripts/           1            1     <- kept
ARM gate's own file, unmodified                   0            0     <- kept clean
ARM genuine marker APPENDED to gate copy          0            1     <- WEAKNESS 2 FIXED

Both controls sit at 0 on both sides, so the arms are readings rather than noise. Item 1 and item 2 both flip in the intended direction, and nothing else moves.

Item 3, reconciled against what the diff touched

tests/test_witness_gate.py   23 -> 25       (base 23 passed, branch 25 passed)
full suite on trial merge    1554 passed, 12 skipped
baseline                     1552 passed, 12 skipped   + exactly the 2 new tests

Clean trial merge into 5796bc26, no conflict markers, and git diff origin/master..HEAD — what a squash actually lands — is exactly the 3 files, nothing swept in. check_witness_token.py, normalise_handle_gate.py and check_deleted_symbols.py --base origin/master all clean on the merged tree (output read, not exit code).

The tests are non-vacuous, and the three-arms-in-one-test structure the card asked for is real

test_near_miss_regex_spares_prose_arms holds the prose, the taosmd de-marked and the scripts de-marked arms in one body, so a loosening that silences the prose cannot silence the other two without turning the test red. That is the structure the card specified and it is worth keeping.

I checked the hardcoded exemption line numbers rather than assuming they were brittle

_DEMARKED_MARKER_EXEMPTION became {"scripts/check_witness_token.py": frozenset({4, 19, 36})}. Magic line numbers look fragile, so I measured the drift case: inserting one blank line into the docstring gives

SHIFTED gate -> exit 1, 3 hits, now at lines 5, 20, 37

It fails loud on itself rather than silently swallowing, and test_gate_does_not_swallow_appended_near_miss copies the REAL gate text and asserts the unmodified copy is clean — so drift turns that test red too. No action needed; recorded here so the next reviewer does not re-triage it.

What I am carding rather than blocking: tsk-y54vhk

The lookahead that spares prose also drops a shape the base gate caught:

fixture: x = 1  # WITNESS<ZWSP>: tests/test_foo.py      (ZWSP, no :: payload)
  BASE -> exit 1, 'de-marked or malformed marker'
  PR   -> exit 0, SILENT                                <- regression

control: x = 1  # WITNESS: tests/test_foo.py            (REAL colon, no :: payload)
  BASE -> exit 1        PR -> exit 1                     <- still caught elsewhere

It needs two coincident defects — separator de-marked AND payload missing — so it is narrow. It is not a blocker because the card's two items are fully delivered and this shape is not one of them. It is worth a card anyway because it is in the silent direction, which is the direction this whole chain exists to close, and because the gate's own docstring argues a path-only witness is exactly the mistake it must catch.

Two smaller things went onto the same card. The changelog fragment claims "de-marked (zero-width) and malformed markers still are [flagged]" — accurate for the first half, wrong for the second, and it ships into the changelog. And prose that quotes the marker syntax (# WITNESS markers use the form path::token) still trips the gate at exit 1 on both sides, so WEAKNESS 1 is narrowed rather than closed; that one fails loud, which is why it rides along instead of blocking.

Merging. The regression is real but strictly narrower than what this PR fixes, and holding a correct, well-tested hardening over a corner shape its card never named would leave the two proven weaknesses live in the meantime.

— @taOSmd-dev

@jaylfc
jaylfc merged commit 4175edf into master Aug 18, 2026
8 checks passed
jaylfc added a commit that referenced this pull request Aug 18, 2026
…inside methods (#350)

Revision of #343. Fixes a false positive inherited from #341 that I missed in
my own review of it: a class defined inside a METHOD collapsed to the bare scope
`class Foo` and collided with a real module-level class of the same name,
because the FunctionDef branch resets class_path while the scope still starts
with "class ".

Fix is the one-line guard `if scope == "module" or " > " not in scope:`.

16 scope shapes, each measured against master, the pre-fix rebase commit
e6b270a, and this HEAD:

    SHAPE                                    master   e6b270a   PR350   want
    CTL module fn dup                          FIRE     FIRE      FIRE   FIRE
    CTL method dup in one class                FIRE     FIRE      FIRE   FIRE
    CTL no dup at all                        silent   silent    silent  silent
    CTL same method name, 2 module classes   silent   silent    silent  silent
    class-in-METHOD vs module class          silent   *FIRE*    silent  silent
    class-in-METHOD, dup method inside       silent     FIRE      FIRE   FIRE
    same class-in-method in 2 methods        silent   *FIRE*    silent  silent
    class-in-CLOSURE vs module class         silent   silent    silent  silent
    class-in-closure dup method              silent     FIRE      FIRE   FIRE
    same class-in-closure, 2 closures        silent   silent    silent  silent
    nested class, same method name           silent   silent    silent  silent
    nested class dup method                    FIRE     FIRE      FIRE   FIRE
    closure fn dup in one parent               FIRE     FIRE      FIRE   FIRE
    same closure fn, 2 parents               silent   silent    silent  silent
    if/else sibling arms                     silent   silent    silent  silent
    try/except ImportError fallback          silent   silent    silent  silent
                                mismatches:     2        2         0

master misses two real duplicates; e6b270a gains those and adds two false
positives; this HEAD keeps both gains with zero mismatches. The second false
positive (same class name in two sibling methods) was not on the card and is
fixed here too.

New tests proven non-vacuous by running them unchanged against the OLD gate
(both copies md5-verified): 3 failed / 48 passed, failing exactly
test_class_in_method_does_not_collide_with_module_class,
test_same_class_in_two_sibling_methods_is_silent and test_scope_parity_corpus.

Suite 1561 passed / 12 skipped = 1554 baseline + exactly the 7 new test
functions (test_normalise_handle_gate.py 44 -> 51). Re-measured on the new
master after my own #344 merge moved it. All three gates clean.

Duplicate changelog fragment (tsk-lvxars) removed; an md5 sweep of changelog.d
finds no byte-identical pair. ImportError docstring sentence restored byte-exact.

STATED LIMITATION, carded as tsk-sgia5s rather than smoothed over: the stray
docstring space FIX 4 asked about was not removed, it moved up one line onto the
new `function body.` continuation. The closing triple-quote is clean, so the
acceptance item as written is satisfied; master, the control, has no leading
space on any docstring line.
jaylfc added a commit that referenced this pull request Aug 18, 2026
… a defect survived two reviews because the probes covered only the shapes the change named

Post-clear #32 and #33. Merged #344 (4175edf), #350 (769f98d), #348 (17ea02a).
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.

1 participant