Skip to content

branch: a token inside a literal is not a decision; Java's ternary counts once - #4178

Merged
squid-protocol merged 4 commits into
mainfrom
fix/java-ternary-string-branches
Oct 2, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
fix/java-ternary-string-branches

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4170

The bug

The code stream keeps string literals, so every C-family branch rule counted tokens inside them.

  • A JDBC "INSERT ... values (?, ?, ?, ?, ?)" read as five ternaries, and "if" in a message read as an if.
  • Java also counted every :, so a ternary read as 2 decisions, a case 1: as 2, and labels, enhanced-for and assert colons as decisions. Generic wildcards (List<?>, <? extends T>) read as ternaries.
  • IBM's published WCA4Z Lgacdb01.java (one if/else) read 22 branch points; it now reads 3.

Root cause and fix

  1. Literal contents (shared by every brace-family language). branch matched raw string, char and text-block contents. The 18 brace-family languages (apex, c, cpp, csharp, dart, go, groovy, java, javascript, kotlin, objective-c, php, rust, scala, solidity, swift, typescript, zig) now opt branch into the existing outside_literals scope filter (vectorized_math fires on '@' inside Python string literals #4136).
    • For these languages the filter shields with _build_brace_safe_stream, the brace slicer's own literal syntax: char literals, raw and verbatim strings, text blocks and template literals. A Rust lifetime is not a literal.
    • Python's vectorized_math keeps the indentation-slicer shield it used before.
  2. Java : and ?. The bare : arm is removed: a ternary counts once at its ?, and case/default already count the arm (contract corollary 2). The ? arm excludes generic wildcards.
  3. ?? counted twice. typescript, javascript, dart, swift and apex listed \? before \?\?, so a ?? b read 2. \?\? now comes first.

docs/branch_rule_contract.md gains a "Literals" section (corollary 4). The stream contract in signal_contracts.py is updated and docs/signal_contracts.md regenerated.

Impact

before after
det ports (49), median Java branch count (COBOL median 27) 159 127
model ports (23), median Java branch count (COBOL median 54) 86 56
struct_branch ρ, COBOL vs det, 49 pairs 0.826 0.855
struct_branch ρ, committed 12-pair fixture 0.745 0.784
struct_branch ρ, COBOL vs model, 23 pairs 0.622 0.599
WCA4Z Lgacdb01.java branch points 22 3
  • Port invariance (Port invariance: the scanner readings that must survive a COBOL -> Java port #4167): struct_branch floors are set by the same rule (measurement less a margin): 0.75 for the 49 pairs and 0.65 for the fixture. The provisional marking is removed from the code and the doc. The other four readings didn't move.
  • Det parity (det_port: structural parity warning before the proof #4162): the branch model is refit with the same 49 programs and the same Theil-Sen method.
    • batch: 15.0 + 1.62x → 12.6 + 1.30x
    • CICS: 70.8 + 2.77x → 51.8 + 2.33x
    • Proven ports now sit at 0.73–1.58 of the prediction. The bands are unchanged and none of the 49 warns.
    • The refit is documented in det_port_design.md. The methods model didn't move.

Tests

  • New tests/extraction/languages/test_branch_literals.py: end-to-end cases through the real extractor (the bare regex never sees the filter):
    • one literal case per language for all 18;
    • the WCA4Z JDBC shape;
    • Java's colon, wildcard, label, assert and nested-ternary cases;
    • a check that every brace-family language declares the filter.
  • test_branch_contract_2822.py: Java negatives and positives, one-hit pins for a Java ternary and case labels and for ?? in five languages, and two new ReDoS payloads.
  • test_go_strict.py: the go _scope_filters pin now includes branch.
  • Results:
    • full suite: 13,635 passed;
    • ruff_audit.py --ci and signal_contract_audit.py --ci are clean;
    • the 49-pair port_invariance.py check holds with the new floors.

Golden masters (re-blessed, both modes)

test_golden_crucible failed on the first push with 21,314 differences per mode, which is expected for a counting change. I audited the drift before blessing:

  • I scanned the pinned crucible (v1.6.0) with main and with this branch and compared every raw per-file count in file_data.
  • The only raw count that changes is struct_branch, in 216 files: apex 1, c 33, cpp 15, csharp 5, dart 7, go 23, groovy 33, java 13, javascript 12, typescript 13, zig 11, objective-c 3, php 19, rust 15, scala 6 and swift 5.
  • The remaining 2 files are HTML: their embedded JavaScript had a ? inside a template-literal URL (`...redirect?url=${...}`).
  • Everything else in the audit JSON is that change rippling through repo-normalised exposures, masses, rankings and archetype distributions. That includes the python/cobol/sql directory groups, whose raw counts are identical.

Regenerated with tests/tools/update_golden_master.py:

  • full-precision in the dev environment;
  • zero-dependency in a PyYAML-only venv that matches CI's leg.

test_golden_crucible.py passes locally in both modes.

Known and accepted

  • A ?/: inside a JS/TS template literal's ${...} is shielded along with the literal, so it doesn't count.
  • TypeScript's optional marker (x?: T) and optional chaining (?.) still count. That's a separate question for the contract, not changed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ

squid-protocol and others added 3 commits October 2, 2026 17:15
…unts once

The code stream keeps string literals, so every C-family `branch` rule counted
them: a JDBC "values (?, ?, ?, ?, ?)" read as five ternaries, "if" in a message
as an if. IBM's WCA4Z Lgacdb01.insertCustomer (one if/else) scored complexity
21, 19 of it the `?` placeholders in its two INSERT strings.

- the 18 brace-family languages opt `branch` into `outside_literals`; for them
  the filter shields with the brace slicer's literal syntax (char literals, raw
  and verbatim strings, text blocks; a rust lifetime is not a literal)
- java: a `:` is never a decision (the ternary's own, case/default labels,
  statement labels, enhanced-for, assert); generic wildcards are types
- `??` is one hit in typescript/javascript/dart/swift/apex (`\?\?` now before `\?`)
- branch_rule_contract.md gains the "Literals" corollary; stream contract updated

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
- struct_branch rho: 49 pairs 0.826 -> 0.855 (floor 0.70 -> 0.75), committed
  12-pair fixture 0.745 -> 0.784 (floor 0.60 -> 0.65); provisional marking removed
  (port_invariance.py, port_invariance_contract.md). Other readings unchanged.
- det_parity branch model refit, same 49 programs and Theil-Sen method:
  batch 15.0 + 1.62x -> 12.6 + 1.30x, CICS 70.8 + 2.77x -> 51.8 + 2.33x;
  proven ports 0.73 .. 1.58 of the prediction, none of 49 warns (bands unchanged)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…ount

Audited before blessing: scanning the pinned crucible (v1.6.0) with main and with
this branch, the only raw per-file count that changes is struct_branch, in 216
files, every one a brace-family language or an HTML file's embedded JavaScript
(a `?` inside a template-literal URL). The 21,314 audit-JSON differences in each
mode are that change and its ripple through repo-normalised exposures, masses,
rankings and archetype distributions; no other raw count moved. Regenerated with
tests/tools/update_golden_master.py in each mode (full-precision; zero-dependency
in a PyYAML-only environment matching CI's leg), and test_golden_crucible.py
passes locally in both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ
@squid-protocol
squid-protocol merged commit 575c390 into main Oct 2, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/java-ternary-string-branches branch October 2, 2026 22:44
squid-protocol added a commit that referenced this pull request Oct 3, 2026
…1 (model-written, unedited, proven) (#4187)

Ports only, split from #4168; the loop fixes are #4186. Each is the porting
loop's answer on attempt 1 (claude-sonnet-5-5, no tools, ticket prompt only),
unedited, with provenance.json. Re-proven on main after #4178/#4180:
  cbsa-updacc      10 scenarios, 7/7 paragraphs, 5/6 branches
  genapp-lgicdb01  12 scenarios, 3/4 paragraphs, 4/12 branches
  genapp-lgapvs01   8 scenarios, 2/3 paragraphs, 5/9 branches


Claude-Session: https://claude.ai/code/session_01RZE6us7fUL6Hynk59rWLvZ

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

java: ? and : count as branches inside string literals, and a ternary counts twice

1 participant