Repository navigation
Description
Same pass as #2769–#2771 (2026-09-05, engine 3b3568e0, corpus main 6183c4b). risk_state_flux is the worst gated metric in the corpus, 42%, with twenty red cells. #2765 covers one of its two inputs. This is the other one, and it is the reason the metric's low side exists.
The formula
raw_flux = raw_signals["state_mutation"]
freeze_hits = raw_signals["immutability_locks"]
net_volatility = max(0.0, raw_flux - (freeze_hits * 0.5)) # signal_processor.py, _calc_state_flux
if net_volatility == 0: return 0.0
density = (net_volatility / (self._mass_loc(loc) + 0)) * 100.0
return min(self._sigmoid(density, 15.0, 0.2) * 100.0 * mp, 100.0)immutability_locks is a direct subtrahend at half weight. It is unplanted, ungated, and sits at 67% consistency itself.
What each language actually counts
Corpus totals on the identical 12-probe program (SPEC plants no immutability construct at all — every hit below is idiomatic residue from how the shell had to be written):
| language | hits | rule |
|---|---|---|
| javascript | 17 | \b(const|readonly|final|Object\.freeze|Object\.seal)\b |
| typescript | 14 | same |
| swift | 11 | \b(let|final|static|readonly|Immutable|Sendable)\b |
| kotlin | 6 | \b(val|const|immutable|readonly)\b |
| scala / zig | 3 | val|final|sealed|… / \bconst\b |
| dart | 2 | const|final|readonly|@immutable |
| abap, c, cpp, fortran, html, php, ruby | 1 | — |
| rust, go, java, python, csharp, and 27 others | 0 | rules exist, match nothing |
The split is not "which languages enforce immutability". It is whether the language's ordinary local-declaration keyword happens to be in its own rule:
- swift's rule matches
let, andletis how Swift declares every immutable local — so ordinary Swift code is maximally "locked". - kotlin's matches
val, same argument. - javascript/typescript match
const, which since ES6 is how you declare essentially every local. - rust's rule does not match
let. It matchesconst|static|immutable|readonly— the three items Rust uses for globals and none of the ones it uses for locals. Rust's immutable-by-default local, the single strongest immutability guarantee in the corpus, is invisible. rust reads 0; swift reads 11. - java's matches
final, go's matchesconst, python's matchesFinal|frozenset— all real constructs, all rare in ordinary code.
So the rule is inverted between the two languages that make the same guarantee (rust let uncounted, swift let counted), and it rewards a notation rather than a property.
What it does to the score
Among the languages whose state_mutation is on plant (2) and whose only difference is this signal:
| language | state_mutation |
immutability_locks |
risk_state_flux |
vs median |
|---|---|---|---|---|
| python, java, ruby, csharp, … | 2 | 0 | 7.751 | — |
| javascript | 2 | 17 | 5.787 | −25% |
| kotlin, scala, typescript | 2 | 6 / 3 / 14 | 4.200 | −46% |
| swift | 2 | 11 | 2.980 | −62% |
Same two planted mutations. The score halves because the shell was written with let/val/const instead of var. risk_state_flux's low tail is entirely this; its high tail is #2765's.
Candidate shape
The contract sentence, in #2730's form: an immutability lock is a construct that prevents a binding or value from being changed after initialisation, where the language's default is mutable. The "where the default is mutable" clause is what makes the rule comparable, and it is exactly the clause missing today:
- A language whose bindings are immutable by default counts the escape hatch, not the default. rust counts
mut— which its ownstate_mutationrule already does, so rust's honestimmutability_locksisfunctions − mut sites, or the rule isNonewith a ledgered absence. - A language whose bindings are mutable by default counts the explicit lock. java
final, csharpreadonly, cconst— as today. - swift/kotlin/javascript/typescript/dart are case 1 wearing case 2's clothes:
let/val/constis the default declaration form. Either they drop it (matching rust/go), or every language in case 1 adds its default form (matching swift) — but the two cannot coexist, and today they do.
Whichever way the audit resolves, the second half of the fix is in the formula: a raw count of locks subtracted from a raw count of mutations compares two quantities with different denominators. A file with 17 consts and 2 mutations is not "less volatile than zero"; it is a file whose mutations are 2/19 of its bindings. If the intent is a ratio, _calc_state_flux should compute one.
Corpus pairing
immutability_locks is one of the eight unplanted risk inputs SPEC.md declines to plant, and the ledger entry markdown-prose-nonplanted-inputs and its siblings record it as such. Once the rule has a contract, planting it becomes possible and the corpus can hold the mitigation term equal the same way it holds state_mutation equal — worth deciding in the same PR, since risk_state_flux cannot reach the green band while one of its two inputs is uncontrolled.
Part of #2669. Pairs with #2765 (state_mutation, the other input); same contract shape as #2730 / #2766.
Activity
ci(rosetta-audit): the n/a review gate honors rosetta:rebless-owed
immutability_locks contract (#2772, rule half): the ordinary binding …
Engine: COBOL rules ignore keywords inside hyphenated words; included…