#3630·automq

[BUG] Unbalanced `// AutoMQ inject` markers in 10 files; build.gradle:298 mislabels a closing marker, misaligning 8 pairs

Author: dgexploresCreated Sep 28, 2026Updated Sep 28, 2026

AutoMQ Version

main at 642d0e19 (3.9.0-SNAPSHOT)

Operating System

Any. This is a source-marker issue, not OS-specific.

Installation Method

source

What Went Wrong?

// AutoMQ inject start and // AutoMQ inject end markers are unbalanced in 10 tracked files. The convention is documented in .agents/coding-conventions.md and .agents/review.md asks reviewers to check for it, but nothing enforces it in CI, so a typo silently survives.

The clearest case is build.gradle:298, which reads // AutoMQ inject start where it must read // AutoMQ inject end:

groovy
// build.gradle:295-298
    // AutoMQ inject start
    // TODO: remove me, when upgrade to 4.x
//    options.compilerArgs << "-Werror"
    // AutoMQ inject start          // <-- should be "inject end"

The AutoMQ-owned change here is 3 lines (disabling -Werror until the Kafka 4.x upgrade). Because the closing marker is mislabelled, the next inject end is not at 298 but at line 1013 — 715 lines later. Every marker pair after it is off by one:

  pair 4   start=295   end=1013    <-- 718 lines, should be 9
  pair 5   start=298   end=1374
  pair 6   start=988   end=1755
  pair 7   start=1344  end=1906
  pair 8   start=1751  end=2056
  pair 9   start=1903  end=2555
  pair 10  start=2053  end=3663
  pair 11  start=2542  end=<none>   <-- unterminated
  pair 12  start=3659  end=<none>   <-- unterminated

Under depth-tracking instead of pairwise matching, the region opened at 295 never closes and runs to EOF (3720 lines).

Full tally across the repo:

 start  end  file
   12   10  build.gradle
    0    2  clients/src/main/java/org/apache/kafka/common/protocol/Errors.java
    6    5  core/src/main/scala/kafka/log/LogManager.scala
   14   12  core/src/main/scala/kafka/server/KafkaApis.scala
    4    2  core/src/main/scala/kafka/server/KafkaRequestHandler.scala
   10    8  core/src/test/scala/unit/kafka/log/LogCleanerTest.scala
    0    1  gradle/spotbugs-exclude.xml
    9    8  metadata/src/main/java/org/apache/kafka/controller/QuorumController.java
    3    1  server-common/src/main/java/org/apache/kafka/server/config/QuotaConfigs.java
    3    2  tests/docker/ducker-ak

Three distinct failure modes are present:

  1. Mislabelled closing marker — build.gradle:298. Causes downstream pair misalignment.
  2. Orphan end (no matching start) — Errors.java:175 and :446, spotbugs-exclude.xml:651. These look like the opening marker was dropped during an upstream merge.
  3. Unclosed region to EOF — KafkaRequestHandler.scala:648, QuotaConfigs.java:182, KafkaApis.scala:4208.

What Should Have Happened Instead?

Every inject start should be paired with exactly one inject end in the same file, and each region should be narrow enough to identify the AutoMQ-owned behaviour, per .agents/coding-conventions.md:

Keep marker ranges small so future Kafka upstream merges can identify the AutoMQ-owned behavior.

Steps to Reproduce

bash
git clone https://github.com/AutoMQ/automq.git && cd automq

for f in $(git ls-files); do
  s=$(grep -c 'AutoMQ inject start' "$f" 2>/dev/null)
  e=$(grep -c 'AutoMQ inject end'   "$f" 2>/dev/null)
  [ -n "$s" ] && [ "$s" != "$e" ] && echo "start=$s end=$e  $f"
done

Or inspect the clearest case directly:

bash
sed -n '293,300p' build.gradle
grep -n 'AutoMQ inject' build.gradle

Why this is worth fixing rather than just tidying

These markers are load-bearing for the merge workflow, not decoration. When upstream Kafka 4.x lands, the merge is replayed around marker-delimited regions. A 718-line region silently marked "AutoMQ-owned" means an upstream change to any of those lines looks like a conflict against AutoMQ code that does not exist, and a real AutoMQ change inside that span can be mis-resolved as already-upstreamed.

There is also no guard: .agents/review.md relies on a human noticing, which is why this drifted.

Proposed fix

Two parts, and I'd like to agree on scope before opening a PR:

  1. Repair the 10 files. build.gradle:298 is a one-word change. The orphan end markers need judgement — I want to confirm whether the missing start belonged to a region that was intentionally dropped upstream, or whether an end is now spurious. I don't want to guess at those.

  2. Add a CI check so this cannot regress. A ~30-line script that fails the build when any tracked file's marker counts disagree. I'm happy to contribute this as tools/check-inject-markers.py wired into the existing rat / checkstyle gate block in build.gradle, or as a standalone script under tools/ if a CI workflow is preferred.

I deliberately have not opened a PR yet, per the contribution expectations. The repair needs review since some markers are ambiguous, and I'd rather agree on the CI mechanism first.

AI Disclosure

Tool: Claude (Anthropic). I wrote the detection script and audited all tracked files for marker imbalance; the script output above is reproducible. I have not yet modified any source, and any repair PR I open will be built and tested locally on JDK 17 first.