You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "davsclaus (via GitHub)" <gi...@apache.org> on 2026/10/18 06:33:45 UTC

[PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

davsclaus opened a new pull request, #28040:
URL: https://github.com/apache/camel/pull/28040

   CAMEL-25744: in the overnight benchmark of Oct 17-18 (ten runs of a local model on the example ladder), the hardest step asks for a timer that fires twice and picks a file on the first fire with `CamelTimerCounter`.
   
   - **The mistake:** in 8 of the 10 runs, the model compared the counter with 0. The counter counts the fires from 1 (`TimerConsumer` uses `incrementAndGet()`), so `== 0` is never true, and both fires took the second file.
   - **Why the model did not catch it:** the option description says so since CAMEL-25530, but the model looked it up in only 2 of the runs. And `camel_validate_source` accepted the route.
   
   ## What
   
   - `HeaderChecks` reports a comparison of `CamelTimerCounter` that can never be true (`== 0`, `<= 0`, `< 1`) or never be false (`!= 0`).
   - The message: "CamelTimerCounter counts the fires from 1 (the first fire is 1), so == 0 is never true: compare with 1 to pick the first fire".
   - It covers the Simple forms (`${exchangeProperty.CamelTimerCounter} == 0`, `${header.CamelTimerCounter == 0 ? ...}`) and the Groovy one (`exchange.getProperty('CamelTimerCounter', Integer) == 0`).
   
   Reading the counter as `${header.CamelTimerCounter}` stays valid: a header lookup in Simple falls back to the exchange properties, and the validator already accepts it when `includeMetadata` is true.
   
   ## Tests
   
   - `SourceValidatorEndpointTest`: three comparisons are reported (`== 0`, `!= 0`, `< 1`), and comparisons with 1 pass.
   - All camel-jbang-core tests pass (2531), `CatalogDocExamplesTest` included: no documentation example compares the counter with 0.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #28040:
URL: https://github.com/apache/camel/pull/28040#discussion_r4306039807


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -57,6 +57,15 @@ private HeaderChecks() {
      */
     static final Map<String, String> METADATA_OPTION = Map.of("timer", "includeMetadata");
 
+    /**
+     * A comparison of the timer's counter with a number: the counter counts the fires from 1, so {@code == 0} is never
+     * true (CAMEL-25744: in 8 of 10 benchmark runs a model compared it with 0 to pick the first fire). The Simple forms
+     * (${exchangeProperty.CamelTimerCounter} == 0, ${header.CamelTimerCounter == 0 ? ...}) and the Groovy ones
+     * (exchange.getProperty('CamelTimerCounter', Integer) == 0).
+     */
+    static final Pattern TIMER_COUNTER_COMPARISON = Pattern.compile(
+            "CamelTimerCounter(?:\\}|['\"]\\s*(?:,\\s*[\\w.]+\\s*)?\\))?\\s*(==|!=|<=|<)\\s*['\"]?(\\d+)['\"]?");

Review Comment:
   ⚠️ **Missing operators:** The regex alternation covers `==|!=|<=|<` but not `>` or `>=`. `CamelTimerCounter > 0` is always true (counter ≥ 1), as are `>= 0` and `>= 1`. A model writing `CamelTimerCounter > 0` as a guard won't be flagged. These are the symmetric "always true" counterparts of the `== 0` / `<= 0` / `< 1` cases already handled.
   
   ```suggestion
               "CamelTimerCounter(?:\\}|['\"]\\ *(?:,\\ *[\\w.]+\\ *)?\\))?\\s*(==|!=|<=|<|>=|>)\\s*['\"" + ""]?(\\d+)['\"" + ""]?");
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -106,11 +115,36 @@ static String intentHint(String name) {
         return null;
     }
 
+    /**
+     * The comparisons of CamelTimerCounter that can never be true (== 0, <= 0, < 1) or never be false (!= 0), as the
+     * counter is 1 on the first fire.
+     */
+    static List<String> timerCounterComparisons(String content) {
+        List<String> msgs = new ArrayList<>();
+        String[] lines = content.split("\n", -1);
+        for (int i = 0; i < lines.length; i++) {
+            Matcher m = TIMER_COUNTER_COMPARISON.matcher(lines[i]);
+            while (m.find()) {
+                String op = m.group(1);
+                int n = Integer.parseInt(m.group(2));
+                boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
+                boolean always = "!=".equals(op) && n == 0;

Review Comment:
   ⚠️ **Missing `>` / `>=` cases in the condition:** if `>` and `>=` are added to the regex, extend the `always` predicate to cover `> 0` (always true, since counter ≥ 1), `>= 0` (always true), and `>= 1` (always true):
   
   ```suggestion
                   boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
                   boolean always = "!=".equals(op) && n == 0
                                    || ">".equals(op) && n == 0 || ">=".equals(op) && n <= 1;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #28040:
URL: https://github.com/apache/camel/pull/28040#issuecomment-6246612701

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #28040:
URL: https://github.com/apache/camel/pull/28040#discussion_r4306153383


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -57,6 +57,15 @@ private HeaderChecks() {
      */
     static final Map<String, String> METADATA_OPTION = Map.of("timer", "includeMetadata");
 
+    /**
+     * A comparison of the timer's counter with a number: the counter counts the fires from 1, so {@code == 0} is never
+     * true (CAMEL-25744: in 8 of 10 benchmark runs a model compared it with 0 to pick the first fire). The Simple forms
+     * (${exchangeProperty.CamelTimerCounter} == 0, ${header.CamelTimerCounter == 0 ? ...}) and the Groovy ones
+     * (exchange.getProperty('CamelTimerCounter', Integer) == 0).
+     */
+    static final Pattern TIMER_COUNTER_COMPARISON = Pattern.compile(
+            "CamelTimerCounter(?:\\}|['\"]\\s*(?:,\\s*[\\w.]+\\s*)?\\))?\\s*(==|!=|<=|<)\\s*['\"]?(\\d+)['\"]?");
+

Review Comment:
   Right: `> 0`, `>= 0` and `>= 1` are always true as well. Added in 0428ceaf55d7, with a test (`aTimerCounterComparisonThatIsAlwaysTrueIsReported`). `> 1` and `>= 2` stay quiet. This also covers the suggestion in the other thread.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #28040:
URL: https://github.com/apache/camel/pull/28040#discussion_r4306039807


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -57,6 +57,15 @@ private HeaderChecks() {
      */
     static final Map<String, String> METADATA_OPTION = Map.of("timer", "includeMetadata");
 
+    /**
+     * A comparison of the timer's counter with a number: the counter counts the fires from 1, so {@code == 0} is never
+     * true (CAMEL-25744: in 8 of 10 benchmark runs a model compared it with 0 to pick the first fire). The Simple forms
+     * (${exchangeProperty.CamelTimerCounter} == 0, ${header.CamelTimerCounter == 0 ? ...}) and the Groovy ones
+     * (exchange.getProperty('CamelTimerCounter', Integer) == 0).
+     */
+    static final Pattern TIMER_COUNTER_COMPARISON = Pattern.compile(
+            "CamelTimerCounter(?:\\}|['\"]\\s*(?:,\\s*[\\w.]+\\s*)?\\))?\\s*(==|!=|<=|<)\\s*['\"]?(\\d+)['\"]?");

Review Comment:
   ⚠️ **Missing operators:** The regex alternation covers `==|!=|<=|<` but not `>` or `>=`. `CamelTimerCounter > 0` is always true (counter ≥ 1), as are `>= 0` and `>= 1`. A model writing `CamelTimerCounter > 0` as a guard won't be flagged. These are the symmetric "always true" counterparts of the `== 0` / `<= 0` / `< 1` cases already handled.
   
   ```suggestion
               "CamelTimerCounter(?:\\}|['\"]\\ *(?:,\\ *[\\w.]+\\ *)?\\))?\\s*(==|!=|<=|<|>=|>)\\s*['\"" + ""]?(\\d+)['\"" + ""]?");
   ```



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -106,11 +115,36 @@ static String intentHint(String name) {
         return null;
     }
 
+    /**
+     * The comparisons of CamelTimerCounter that can never be true (== 0, <= 0, < 1) or never be false (!= 0), as the
+     * counter is 1 on the first fire.
+     */
+    static List<String> timerCounterComparisons(String content) {
+        List<String> msgs = new ArrayList<>();
+        String[] lines = content.split("\n", -1);
+        for (int i = 0; i < lines.length; i++) {
+            Matcher m = TIMER_COUNTER_COMPARISON.matcher(lines[i]);
+            while (m.find()) {
+                String op = m.group(1);
+                int n = Integer.parseInt(m.group(2));
+                boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
+                boolean always = "!=".equals(op) && n == 0;

Review Comment:
   ⚠️ **Missing `>` / `>=` cases in the condition:** if `>` and `>=` are added to the regex, extend the `always` predicate to cover `> 0` (always true, since counter ≥ 1), `>= 0` (always true), and `>= 1` (always true):
   
   ```suggestion
                   boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
                   boolean always = "!=".equals(op) && n == 0
                                    || ">".equals(op) && n == 0 || ">=".equals(op) && n <= 1;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #28040:
URL: https://github.com/apache/camel/pull/28040#issuecomment-6246783067

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `dsl/camel-jbang/camel-jbang-core`
   
   ---
   
   <details><summary>:microscope: Scalpel shadow comparison — Scalpel: 5 of 706 tested, 8 compile-only — current: 5 all tested</summary>
   
   [Maveniverse Scalpel](https://github.com/maveniverse/scalpel) detected **5 affected modules** (current approach: 5).
   
   **Skip-tests mode would test 5 modules** (1 direct + 5 downstream), **skip tests for 8** (generated code, meta-modules)
   
   <details><summary>Modules Scalpel would test (5)</summary>
   
   - `camel-jbang-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-mcp` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-tui` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-jbang-plugin-validate` ← downstream of org.apache.camel:camel-jbang-core
   - `camel-launcher-container` ← downstream of org.apache.camel:camel-launcher
   
   </details>
   
   <details><summary>Modules with tests skipped (8)</summary>
   
   - `camel-jbang-it`
   - `camel-jbang-main`
   - `camel-jbang-plugin-edit`
   - `camel-jbang-plugin-generate`
   - `camel-jbang-plugin-kubernetes`
   - `camel-jbang-plugin-test`
   - `camel-launcher`
   - `coverage`
   
   </details>
   
   > :information_source: Shadow mode — Scalpel observes but does not affect test execution. [Learn more](https://github.com/maveniverse/scalpel)
   
   </details>
   
   :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
   
   - `dsl/camel-jbang/camel-jbang-core`: 2 test(s) disabled on GitHub Actions
   
   :bulb: **Manual integration tests recommended:**
   
   > You modified `dsl/camel-jbang/camel-jbang-core`. The related integration tests in `dsl/camel-jbang/camel-jbang-it` are excluded from CI. Consider running them manually:
   > ```
   > mvn verify -f dsl/camel-jbang/camel-jbang-it -Djbang-it-test
   > ```
   
   <details><summary>All tested modules (14 modules, 2m 50s total)</summary>
   
   **Total reactor time:** 2m 50s
   
   | Module | Duration | Status |
   | --- | --- | --- |
   | Camel :: Launcher | 50.8s | SUCCESS |
   | Camel :: JBang :: MCP | 44.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: Validate | 30.0s | SUCCESS |
   | Camel :: JBang :: Plugin :: Testing | 17.3s | SUCCESS |
   | Camel :: JBang :: Plugin :: Kubernetes | 15.0s | SUCCESS |
   | Camel :: Coverage | 4.6s | SUCCESS |
   | Camel :: JBang :: Plugin :: Edit | 1.5s | SUCCESS |
   | Camel :: JBang :: Plugin :: MCP | 1.4s | SUCCESS |
   | Camel :: JBang :: Plugin :: Generate | 1.4s | SUCCESS |
   | Camel :: JBang :: Main | 1.2s | SUCCESS |
   | Camel :: JBang :: Integration tests | 1.1s | SUCCESS |
   | Camel :: Launcher :: Container | 0.6s | SUCCESS |
   | Camel :: JBang :: Core | n/a |  |
   | Camel :: JBang :: Plugin :: TUI | n/a |  |
   
   **Top 20 slowest modules:**
   - `Camel :: Launcher` (50.8s)
   - `Camel :: JBang :: MCP` (44.6s)
   - `Camel :: JBang :: Plugin :: Validate` (30.0s)
   - `Camel :: JBang :: Plugin :: Testing` (17.3s)
   - `Camel :: JBang :: Plugin :: Kubernetes` (15.0s)
   - `Camel :: Coverage` (4.6s)
   - `Camel :: JBang :: Plugin :: Edit` (1.5s)
   - `Camel :: JBang :: Plugin :: MCP` (1.4s)
   - `Camel :: JBang :: Plugin :: Generate` (1.4s)
   - `Camel :: JBang :: Main` (1.2s)
   - `Camel :: JBang :: Integration tests` (1.1s)
   - `Camel :: Launcher :: Container` (0.6s)
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/39104476580)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #28040:
URL: https://github.com/apache/camel/pull/28040


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25744: camel-jbang - the AI validator reports a comparison of CamelTimerCounter that can never be true, as the counter starts at 1 [camel]

Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #28040:
URL: https://github.com/apache/camel/pull/28040#discussion_r4306042849


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -57,6 +57,15 @@ private HeaderChecks() {
      */
     static final Map<String, String> METADATA_OPTION = Map.of("timer", "includeMetadata");
 
+    /**
+     * A comparison of the timer's counter with a number: the counter counts the fires from 1, so {@code == 0} is never
+     * true (CAMEL-25744: in 8 of 10 benchmark runs a model compared it with 0 to pick the first fire). The Simple forms
+     * (${exchangeProperty.CamelTimerCounter} == 0, ${header.CamelTimerCounter == 0 ? ...}) and the Groovy ones
+     * (exchange.getProperty('CamelTimerCounter', Integer) == 0).
+     */
+    static final Pattern TIMER_COUNTER_COMPARISON = Pattern.compile(
+            "CamelTimerCounter(?:\\}|['\"]\\s*(?:,\\s*[\\w.]+\\s*)?\\))?\\s*(==|!=|<=|<)\\s*['\"]?(\\d+)['\"]?");
+

Review Comment:
   ⚠️ **Missing operators:** The regex covers `==|!=|<=|<` but not `>` or `>=`. `CamelTimerCounter > 0` is always true (counter ≥ 1), as are `>= 0` and `>= 1`. These are the symmetric "always true" counterparts of the `== 0` / `<= 0` / `< 1` cases already handled.



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/HeaderChecks.java:
##########
@@ -106,11 +115,36 @@ static String intentHint(String name) {
         return null;
     }
 
+    /**
+     * The comparisons of CamelTimerCounter that can never be true (== 0, <= 0, < 1) or never be false (!= 0), as the
+     * counter is 1 on the first fire.
+     */
+    static List<String> timerCounterComparisons(String content) {
+        List<String> msgs = new ArrayList<>();
+        String[] lines = content.split("\n", -1);
+        for (int i = 0; i < lines.length; i++) {
+            Matcher m = TIMER_COUNTER_COMPARISON.matcher(lines[i]);
+            while (m.find()) {
+                String op = m.group(1);
+                int n = Integer.parseInt(m.group(2));
+                boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
+                boolean always = "!=".equals(op) && n == 0;

Review Comment:
   ⚠️ **Extend condition for `>` / `>=`:** if `>` and `>=` are added to the regex, extend `always` to cover `> 0` (counter ≥ 1), `>= 0`, and `>= 1`:
   
   ```suggestion
                   boolean never = ("==".equals(op) || "<=".equals(op)) && n == 0 || "<".equals(op) && n <= 1;
                   boolean always = "!=".equals(op) && n == 0
                                    || ">".equals(op) && n == 0 || ">=".equals(op) && n <= 1;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org