Skip to content

Test(fuzz): Fuzz the triage proposal checks - #54

Merged
ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-53
Nov 19, 2026
Merged

ModeSevenIndustrialSolutions merged 5 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-53

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #53

Authored by an AI agent; human review required
Command Exit
python -B -m unittest discover -s tests 0
python -B -m unittest tests.test_fuzz (new test against the old harness, expected to fail) 1
prek run --files fuzz/fuzz_triage_policy.py tests/test_fuzz.py (ruff format rewrote tests/test_fuzz.py) 1
prek run --files fuzz/fuzz_triage_policy.py tests/test_fuzz.py 0
AISLOP_NO_TELEMETRY=1 aislop scan --base c9fe48effb134a51dd649077465fb4c8cfa88714 --json (ruff on PATH) 0
python fuzz/fuzz_triage_policy.py -max_total_time=60 corpus (Atheris venv) 0
python fuzz/fuzz_triage_policy.py -runs=0 0
python fuzz/fuzz_triage_policy.py seed.json 0
git commit --amend -s -F msg.txt (hooks and gitlint) 0
git log --raw --format=%h c9fe48effb134a51dd649077465fb4c8cfa88714..HEAD 0

The github-code-monkey-bot workflow opened this pull request.
Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.

Round 7 of revision, on its base.


Adds two Atheris fuzz harnesses meeting harness contract v1 (#53), and fixes the one_line defects they found.

Commits

  1. Test(apply): Add expected-fail one_line log tests
  2. Fix(apply): Fold C1 control characters in logs
  3. Fix(apply): Escape lone surrogates in log lines
  4. Fix(apply): Escape report lines whole
  5. Test(fuzz): Add Atheris harnesses for triage

Harnesses

  • fuzz/fuzz_triage_policy.py runs an agent message through extract_proposal, apply_triage.process and report against a fixed fake GitHub (fuzz/triage_world.py). It judges each applied action against that world and the DESIGN.md section 6 rules, never against the code's own answer. An input that is a JSON document stands for the final block: the harness fences it, decodes it with json.loads itself and requires the extractor to return exactly that. The extraction oracle requires a valid final block to win, and an unusable final block to be refused instead of falling back to an earlier one.
  • fuzz/fuzz_triage_output.py checks triage_evidence.verify against digests, shapes and size caps it computes itself, and that one_line prints one inert line to a strict UTF-8 stream.

import atheris sits inside each main(), so the modules import without Atheris. tests/test_fuzz.py replays every seed in the normal suite and shows each oracle rejecting a deliberately wrong result. Left out: the five shared modules (lfreleng-actions/bots-template#63) and the workflow contract tests.

This round (7)

  • Copilot found that the extraction oracle missed an extractor that falls back to an earlier valid proposal when the final block is invalid or not JSON. check_extraction now appends four final blocks the extractor must refuse ({}, [], non-JSON, a non-json fence) and requires a refusal for each. A new test patches in a fallback extractor and fails on the old harness.

Validation

  • python -B -m unittest discover -s tests: 282 tests pass.
  • prek run --files on the changed files, and gitlint: pass.
  • aislop against the base: score 100, no diagnostics, all engines ran.
  • Fuzzing: this round, policy harness 61 s, 312k inputs, no failure. Earlier rounds: policy harness up to 1.42M inputs in 61 s; output harness 177k inputs in 60 s, plus 15k with inputs up to 1 MiB. No failure. The one_line defects in commits 2 to 4 are the findings, each with a regression test.
  • python <harness> -runs=0 and python <harness> <seed file> exit 0.

For the reviewer

  • Nothing under .github/workflows/ changes, and no dependency, lock file or hook configuration changes.
  • Each extraction now runs four more refusal checks, so policy-harness throughput is lower than in earlier rounds.

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.

🟡 Changes recommended

The fuzz verifier’s expected verdict omits both evidence-file size limits, causing correct refusals of oversized inputs to be reported as false fuzz failures.

1 open issue
What changed in this PR

Adds fuzz testing for untrusted triage proposals, evidence verification, and log output toward issue #53, alongside fixes for three output-sanitization defects.

Changes:

  • Adds two Atheris harnesses with independent checks, a fake GitHub environment, and shared utilities.
  • Adds seed replay and tests showing the checks reject deliberately incorrect results.
  • Hardens report output against control characters, lone surrogates, and runner commands formed by joining fields.
File Description
tests/​test_fuzz.py Replays seeds and checks that faulty results are detected.
tests/​test_apply_triage.py Adds output-sanitization regression tests.
scripts/​apply_triage.py Sanitizes Unicode and escapes complete report lines.
README.md Documents fuzz targets and manual invocation.
fuzz/​triage_world.py Provides fixed GitHub state and network guards.
fuzz/​fuzz_triage_policy.py Fuzzes proposal extraction, policy enforcement, and reports.
fuzz/​fuzz_triage_output.py Fuzzes evidence verification and safe text rendering.
fuzz/​fuzz_support.py Shares seed handling and strict UTF-8 output capture.
docs/​development/​DESIGN.md Adds fuzz harnesses to the repository layout.

Review effort: Balanced

Comment thread fuzz/fuzz_triage_output.py Resolved
zxiiro
zxiiro previously approved these changes Nov 19, 2026

@zxiiro zxiiro 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.

🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. Log-escaping hardening in apply_triage.py (C1 controls folded, lone surrogates escaped, whole report lines escaped so fields can't join into ::/##[ commands) plus test-only fuzz harnesses; no change to which labels are applied, and no workflow, permission or secret changes.

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.

🟡 Changes recommended

The fuzz harnesses cannot reach key size boundaries with their current selector and seeds, and shared mutable proposal inputs can let incorrect validator behavior pass the policy oracle.

3 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_triage_output.py Resolved
Comment thread fuzz/fuzz_triage_output.py Resolved
Comment thread fuzz/fuzz_triage_policy.py Resolved

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.

🟡 Changes recommended

The harness can report false crashes on deeply nested valid input, and its oracle can miss invalid priorities when the priority field is unavailable.

2 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_triage_policy.py Resolved
Comment thread fuzz/fuzz_triage_policy.py Resolved

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.

🟡 Changes recommended

The fuzz oracle misses invalid raw types when issue types are unavailable and non-boolean flag coercions, allowing validation regressions to go undetected.

2 open issues

Review effort: Balanced

Comment thread fuzz/fuzz_triage_policy.py Resolved
Comment thread fuzz/fuzz_triage_policy.py Resolved

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.

🟡 Changes recommended

The fuzz oracle accepts object-shaped labels, allowing a regression in label list-shape validation to go undetected.

1 open issue

Review effort: Balanced

Comment thread fuzz/fuzz_triage_policy.py Resolved

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.

🟡 Changes recommended

The outcome oracle derives expected items from the extractor under test, allowing consistent priority rewrites such as Urgent to High to evade detection and admit invalid proposals.

1 open issue

Review effort: Balanced

Comment thread fuzz/fuzz_triage_policy.py Resolved

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.

🟡 Changes recommended

The fuzz oracle misses extractors that incorrectly fall back to an earlier valid proposal when the final block is invalid or non-JSON, leaving this acceptance bug undetected.

1 open issue

Review effort: Balanced

Comment thread fuzz/fuzz_triage_policy.py Resolved
lf-releng-code-monkey-bot Bot and others added 5 commits November 19, 2026 19:03
one_line promises to render untrusted text "without control
characters", yet its pattern stops at C0 and DEL, so NEL (U+0085)
and the rest of the C1 range reach the runner log. It also passes
lone surrogates through: a JSON escape such as \ud800 in a proposal
decodes to one, and printing it to the runner's strict UTF-8 stdout
raises UnicodeEncodeError, crashing the report after
apply-result.json is written.

Both tests are marked as expected failures until the fixes land.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
one_line documents that it renders untrusted text without control
characters, but its pattern covered only C0 and DEL. NEL (U+0085)
and the other C1 controls reached the runner log unchanged, where a
viewer may treat NEL as a line break. Widen the pattern to the C1
range and drop the expected-failure marker from the test that shows
it.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
json.loads turns an escape such as \ud800 in the agent's proposal
into a lone surrogate. one_line passed it through, and print() to
the runner's strict UTF-8 stdout then raised UnicodeEncodeError, so
a label or rationale carrying one crashed report() after the run's
writes and apply-result.json. Render the surrogate as a backslash
escape so the line stays printable and the original stays in the
JSON evidence.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
report escaped each untrusted field on its own, then joined the
fields with "#" and ": ". The join could rebuild what escaping
removed: repository "owner/rep#" and issue "[1]" printed
"owner/rep##[1]", and an issue ending in ":" printed "1::". The
runner's legacy parser finds "##[" anywhere in a line.

Escape each assembled line once instead. The Atheris policy
harness found the "##[" case; the regression test covers both
joins.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
Add two harnesses meeting harness contract v1:

- fuzz_triage_policy.py runs an agent message through
  extract_proposal, apply_triage.process and report against a fixed,
  fake GitHub (triage_world.py), and judges each applied action
  against that world and the DESIGN.md section 6 rules.
- fuzz_triage_output.py checks triage_evidence.verify against
  digests, file shapes and sizes it chooses itself, and that one_line
  prints one inert line to a strict UTF-8 stream.

import atheris sits inside main(), so the modules import without
Atheris. tests/test_fuzz.py replays every seed in the offline suite
and shows each oracle rejecting a deliberately wrong result. The
README and the design layout name the harnesses.

Review: the verify oracle ignored the per-file byte caps, so a
correct refusal of exclusions over 1 MiB was reported as a breach.
The expected verdict now applies the caps DESIGN.md states (16 MiB
snapshot, 1 MiB exclusions), kept apart from triage_evidence's own
constants, and a test replays an oversized exclusions file.

Review, round 2:
- The split selector was a single byte modulo the body, so the
  snapshot never exceeded 255 bytes and its 16 MiB cap was out of
  reach. split_contents now scales that byte over the whole body.
- No seed reached the 1 MiB exclusions cap, and libFuzzer truncates
  any seed past 1 MiB unless given -max_len. A seed one byte over
  the cap joins SEEDS, and libfuzzer_arguments raises -max_len to
  the largest seed when one exceeds that ceiling and the caller set
  none. A 16 MiB seed is left out: it would push every run's inputs
  to 16 MiB; a test replays an oversized snapshot instead.
- process received the proposal objects the oracle later judges, so
  a validator that rewrote Urgent to High in place could pass. It
  now gets a deep copy, and a test patches in such a validator.

Review, round 3:
- Where the scope stores no Priority, the oracle accepted an applied
  action from an Urgent proposal once the action dropped the grade,
  yet validate refuses Urgent and unknown grades before that drop.
  check_action now checks the raw grade against GRADES in every
  scope; a test and a seed cover the scope without a Priority field.
- copy.deepcopy recursed deeper than json.loads and raised
  RecursionError on a valid proposal with 600 nested arrays in an
  unused field, a harness crash rather than a triage defect. process
  now gets its own parse of the message per scope, and the nested
  input joins SEEDS.

Review, round 4:
- The oracle read a flag as "is True", so a validator that coerced
  migrate_enhancement or escalate "yes" to False passed. raw_flag
  now defaults only an absent flag to False and treats any other
  non-boolean as a breach; a test shows both coercions caught.
- Where the scope has no issue types, the oracle accepted a dropped
  type whatever its raw value, yet validate refuses a non-string
  type before that drop. check_action now checks the raw type in
  every scope; a test covers the scope without types, and seeds
  carry the malformed flags and type.

Review, round 5:
- The oracle iterated the applied labels, so labels shaped as an
  object, such as {"bug": "not a list"}, passed on their keys alone,
  though check_labels refuses anything but a list of strings.
  check_action now requires a list of strings first; a test feeds
  object, string and mixed labels, and a seed carries object labels.

Review, round 6:
- The outcome oracle took its raw items from extract_proposal, the
  code under test, so an extractor that rewrote Urgent to High on
  every parse passed and the invalid proposal was judged applied.
  An input that is itself a JSON document now stands for the final
  block: the harness fences it, decodes it with json.loads on its
  own, requires the extractor's answer to match in type and value,
  and judges process against its own decode. Outcome seeds become
  bare blocks; fenced seeds stay for extraction. A test makes the
  extractor rewrite the priority, and a flag to a number.

Review, round 7:
- The extraction oracle checked only that a valid final block wins,
  so an extractor that fell back to an earlier valid proposal when
  the final block was unusable passed. check_extraction now appends
  final blocks the extractor must refuse (no proposals, not an
  object, not JSON, not a json fence) and requires a refusal for
  each; a test patches in such a fallback extractor.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>

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.

🟢 Approval recommended

No active review issues remain for the fuzz harnesses and log-sanitization changes.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.

No actionable defects found. The log-sanitization changes address the documented failure cases, and the fuzz harnesses are consistent with the policy and evidence-verification contracts.

Antagonistic round 1 of 3.


Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.

@zxiiro zxiiro 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.

🤖 Auto-approved by agent: reviewed workflow/code change for security and CI/CD impact, found low risk. apply_triage.py log escaping folds C1 controls, escapes lone surrogates and escapes whole lines, with label logic unchanged; the rest is fuzz harnesses and tests, with no workflow changes.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 14b2edc into lfreleng-actions:main Nov 19, 2026
22 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-53 branch November 19, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-quality Updates to code-quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Fuzz the triage proposal checks

3 participants