Skip to content

fix(issue-pr-context): floor token estimate at chars/4 for compressible inputs - #2035

Merged
stranske merged 1 commit into
mainfrom
fix/issue-pr-context-token-cap-bound
May 6, 2026
Merged

stranske merged 1 commit into
mainfrom
fix/issue-pr-context-token-cap-bound

Conversation

@stranske

@stranske stranske commented May 6, 2026

Copy link
Copy Markdown
Owner

Source: Issue #7

Closes #7

Automated Status Summary

Scope

  • 10 Python test files in tests/workflows/ are excluded from CI and local runs because they import modules from Trend_Model_Project that don't exist in this repository (e.g., scripts.mypy_return_autofix, scripts.fix_cosmetic_aggregate, scripts.update_autofix_expectations). This represents ~50% of the Python test suite being skipped.

Tasks

  • Identify the exact imports needed by examining the excluded test files.
  • Create minimal stub modules that provide the expected interfaces (functions that return sensible defaults or raise NotImplementedError).
  • Remove the corresponding entries from [tool.ruff] exclude in pyproject.toml.
  • Remove the --ignore flags from selftest-ci.yml Python test step.
  • Run the full test suite and fix any remaining import or interface issues.

Acceptance criteria

  • - All 10 previously excluded test files are now included in CI runs.

  • - python -m pytest tests/workflows/ -v runs without collection errors.

  • - Test count increases from ~196 to include the previously skipped tests.

  • - CI workflow passes with expanded test coverage.

  • Head SHA: 976b4e8

  • Latest Runs: ✅ success — Gate

  • Required: gate: ✅ success

  • | Workflow / Job | Result | Logs |

  • |----------------|--------|------|

  • | Agents PR meta manager | ❔ in progress | View run |

  • | CI Autofix Loop | ✅ success | View run |

  • | Gate | ✅ success | View run |

  • | Health 40 Sweep | ✅ success | View run |

  • | Health 44 Gate Branch Protection | ✅ success | View run |

  • | Health 45 Agents Guard | ✅ success | View run |

  • | Health 50 Security Scan | ✅ success | View run |

  • | Maint 52 Validate Workflows | ✅ success | View run |

  • | PR 11 - Minimal invariant CI | ✅ success | View run |

  • | Selftest CI | ✅ success | View run |

Head SHA: d7822a3
Latest Runs: ✅ success — Gate
Required: gate: ✅ success

Workflow / Job Result Logs
Auto-label Dependabot PRs ⏭️ skipped View run
Copilot code review ✅ success View run
Gate ✅ success View run
Health 40 Sweep ❔ startup failure View run
Health 44 Gate Branch Protection ✅ success View run
Health 45 Agents Guard ✅ success View run
Health 50 Security Scan ✅ success View run
Maint 52 Validate Workflows ✅ success View run
PR 11 - Minimal invariant CI ✅ success View run
Selftest CI ✅ success View run

…t on compressible inputs

Wave 2 Fix #7 (PR #2026) merged with `tests/scripts/test_issue_formatter.py::test_format_issue_body_caps_oversized_input` failing — a 60K-char body of repeating x's was passing through unchanged, leaving the formatter's preamble and "[truncated: …]" suffix to push the wrapped output to 64K (greater than the input).

Root cause: `estimate_tokens()` returns tiktoken's BPE token count when tiktoken is available, but BPE aggressively compresses repeated patterns. 60K identical x's encodes to a handful of tokens, well under the 4000 default budget — so `_cap_block` decides "fits in budget" and returns the body unchanged. Wrappers then push total length above the input.

Fix: floor the estimate at chars/4 (the existing fallback when tiktoken is missing), so compressible inputs are still capped against the budget. tiktoken's accurate count still wins for normal prose; only highly-repetitive inputs hit the floor.

The consumer-template path `templates/consumer-repo/scripts/langchain/` is gitignored — sync-manifest pulls from this canonical path, so no template lockstep needed.

32 issue_pr_context/issue_formatter tests now pass on Python 3.12. Issue #862 regression test (60K x body → must shrink) now passes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 6, 2026 12:30
@stranske
stranske temporarily deployed to agent-standard May 6, 2026 12:30 — with GitHub Actions Inactive
@stranske-keepalive

Copy link
Copy Markdown
Contributor

Automated Status Summary

Head SHA: 8598fb2
Latest Runs: ⏳ pending — Gate
Required contexts: Gate / gate, Health 45 Agents Guard / guard
Required: core tests (3.12): ⏳ pending, core tests (3.13): ⏳ pending, docker smoke: ⏳ pending, gate: ⏳ pending

Workflow / Job Result Logs
(no jobs reported) ⏳ pending

Coverage Overview

  • Coverage history entries: 1

Coverage Trend

Metric Value
Current 93.12%
Baseline 85.00%
Delta +8.12%
Minimum 70.00%
Status ✅ Pass

Top Coverage Hotspots (lowest coverage)

File Coverage Missing
src/cli_parser.py 81.8% 4
src/percentile_calculator.py 95.0% 1
src/aggregator.py 95.0% 2
src/__init__.py 100.0% 0
src/ndjson_parser.py 100.0% 0

Updated automatically; will refresh on subsequent CI/Docker completions.


Keepalive checklist

Scope

No scope information available

Tasks

  • No tasks defined

Acceptance criteria

  • No acceptance criteria defined

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adjusts token estimation in issue_pr_context to prevent highly-compressible inputs (e.g., long runs of a single character) from bypassing token-budget truncation when tiktoken is installed, which was causing CI failures in the issue formatter truncation test.

Changes:

  • Add a chars/TOKEN_CHARS (rounded up) floor to estimate_tokens() when using tiktoken.
  • Expand the estimate_tokens() docstring to explain why the floor is needed for compressible inputs.

Comment on lines +42 to +46
Returns ``max(tiktoken_count, chars/4)``: tiktoken's BPE encoding aggressively
compresses repeated patterns (e.g. 60K of the same character collapses to a
handful of tokens), which would let oversized inputs slip past token-budget
truncation. The chars/4 floor keeps the cap honest against compressible
inputs while preserving accurate counts on normal prose.
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