Skip to content

fix(tooling): marker guard false-positives on changes deep inside a pre-existing block#904

Merged
anandgupta42 merged 1 commit into
mainfrom
fix/marker-guard-context-window
Jun 6, 2026
Merged

fix(tooling): marker guard false-positives on changes deep inside a pre-existing block#904
anandgupta42 merged 1 commit into
mainfrom
fix/marker-guard-context-window

Conversation

@anandgupta42

@anandgupta42 anandgupta42 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the Marker Guard CI job, which went red on main (commit 89699f6919, the #895 merge) by false-positiving on packages/opencode/src/cli/cmd/tui/worker.ts:183 — a line that is correctly wrapped in an altimate_change block.

Root cause: parseDiffForMarkerWarnings derived marker state only from the lines visible in each diff hunk (git diff -U5 → ±5 context lines). When a line is modified deep inside a large pre-existing altimate_change block, the block's start marker sits outside the context window and never appears in the hunk, so inMarkerBlock stays false and the change is mis-flagged as unmarked. The per-hunk marker-state reset compounded it.

Fix: compute marker coverage from the full post-change file and pass it into the parser:

  • computeMarkedLines(content) — full-file, depth-counted coverage set (handles nested start/end pairs, which a single openBlock would miss).
  • parseDiffForMarkerWarnings(file, diff, markedLines?) — a changed line is covered if the in-hunk tracker saw its start or the full-file map says it's inside a marked block. The map can only suppress false positives, never add new ones — so all existing warning behavior is preserved.
  • checkFileForMarkers reads git show HEAD:<file> (or the working tree for base-less runs) and feeds the map in.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Issue for this PR

Closes #876

How did you verify your code works?

  • 11 new unit tests in script/upstream/analyze.test.ts: nesting, unbalanced markers, and the exact context-window false positive (with/without coverage map, plus an end-to-end reconstruction). Full file: 29/29 pass.
  • Reproduced the real failure: analyze.ts --markers --base 7e909a9777 --strict (the exact base the CI job used) flags worker.ts:183 with the original code and passes with the fix. Reverting the fix reproduces the failure.

Checklist

  • My code follows the style guidelines of this project
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation (n/a — internal tooling)

Summary by cubic

Fix Marker Guard false positives when editing lines deep inside a pre-existing altimate_change block. CI no longer misflags valid changes, and genuine warnings are unchanged.

Written for commit d54778f. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Fixed false positive warnings for code changes occurring within pre-existing marked regions when the corresponding start marker is outside the diff context window.
  • Tests

    • Added comprehensive unit tests for marker coverage computation, including validation of nested marker pairs, edge cases, and integration testing to ensure marked regions are properly recognized across file contexts.

…inside a pre-existing block

The push-to-main Marker Guard went red on `89699f6919` (the #895 merge),
flagging `worker.ts:183` as "new code without altimate_change markers" even
though that line sits inside a correctly-marked block. CI was broken on main.

Root cause: `parseDiffForMarkerWarnings` derived marker state purely from the
lines visible in each diff hunk (`git diff -U5` → 5 context lines). When a line
is *modified* deep inside a large pre-existing `altimate_change` block, the
block's `start` marker is further than the context window, so it never appears
in the hunk; `inMarkerBlock` stays false and the change is mis-flagged. The
per-hunk marker-state reset compounded it.

Fix: compute marker coverage from the FULL post-change file (`computeMarkedLines`,
depth-counted so nested start/end pairs are handled) and pass it into the parser.
A changed line is covered if the in-hunk tracker saw its `start` OR the full-file
map says it's inside a marked block. The map can only *suppress* false positives,
never add new ones, so all existing warning behavior is preserved.

- `computeMarkedLines(content)` — full-file, nesting-aware coverage set.
- `parseDiffForMarkerWarnings(file, diff, markedLines?)` — optional coverage map.
- `checkFileForMarkers` reads `git show HEAD:<file>` (or the working tree) and
  feeds the map in.
- 11 new unit tests: nesting, unbalanced markers, and the exact context-window
  false positive (with/without coverage, plus an end-to-end reconstruction).

Verified: with the fix, `analyze.ts --markers --base 7e909a9 --strict` (the
exact base that failed) passes; reverting the fix reproduces the worker.ts:183
failure.

Closes #876

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: be2b158e-3266-4bbd-a6e5-2f11d7155b0f

📥 Commits

Reviewing files that changed from the base of the PR and between d2cf6b3 and d54778f.

📒 Files selected for processing (2)
  • script/upstream/analyze.test.ts
  • script/upstream/analyze.ts

Disabled knowledge base sources:

  • Jira integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Walkthrough

The PR extends marker-based change detection to fix false positives when altimate_change start markers fall outside diff context windows. A new computeMarkedLines function scans entire files to build full coverage maps, which are then fed into the updated parseDiffForMarkerWarnings parser to suppress warnings for changes within pre-existing marked blocks regardless of hunk boundaries.

Changes

Full-file marker coverage and false-positive suppression

Layer / File(s) Summary
Full-file marker coverage computation
script/upstream/analyze.ts
New computeMarkedLines(content) function scans file content, tracks nested altimate_change start/end markers via depth counter, and returns set of all line numbers within any marked region.
Parser signature extension for coverage map
script/upstream/analyze.ts
parseDiffForMarkerWarnings now accepts optional markedLines set parameter for full-file coverage in addition to diff-context marker tracking.
Marker violation logic with dual coverage
script/upstream/analyze.ts
Marker violation check updated to suppress warnings when a changed line is covered by either diff-context marker state or full-file coverage map, preventing false positives when start marker is outside context window.
Full-file coverage computation and integration
script/upstream/analyze.ts
Script now reads post-change file content (via git show or disk), computes full-file marked lines using computeMarkedLines, and passes coverage set into parseDiffForMarkerWarnings for each checked file.
Test coverage for marker detection
script/upstream/analyze.test.ts
Unit tests for computeMarkedLines covering basic blocks, nested marker pairs via depth tracking, and unbalanced end markers; integration tests for parseDiffForMarkerWarnings with coverage map parameter verifying suppression of false positives and retention of valid warnings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • #898: Addresses nested marker handling in script/upstream/analyze.ts with depth/stack tracking for altimate_change markers, related to the marker-depth logic in this PR.

Possibly related PRs

  • AltimateAI/altimate-code#782: Addresses the same underlying false-positive marker warning issue during bridge/upstream-merge commits but at the CI workflow level rather than in the detection algorithm itself.

Suggested labels

contributor, needs-review:blocked

Poem

🐰 Through nested markers deep and wide,
The coverage map becomes our guide—
No false alarms when blocks align,
Full-file scanning draws the line!
A hop, a skip, no context gaps—
Just marked lines tracked on coverage maps. 🎯

✨ 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 fix/marker-guard-context-window

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 and usage tips.

@anandgupta42 anandgupta42 merged commit db81d41 into main Jun 6, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(tooling): marker-guard false-positive across tags — carry marker state across diff hunks

1 participant