Skip to content

safety has no stated contract: 2 open cells are token-double-counts and one-owner misfires, and haskell's rule counts pure, return and type constructors as runtime guards #2869

Closed

Description

@squid-protocol

Roadmap Phase 3 (docs/contract_roadmap.md, epic #2812), next by the mechanical audit after the raw_state_unreferenced census (#2866): the safety row is draft and carries 2 of the report's 19 open-defect cells (embedded_python 4 vs median 2, haskell 3 vs 2; both extraction in the cause table).

_c("safety", "safety", "site", "Defensive programming constructs that prevent crashes at runtime", planted=True)

Consumers: the high_risk×safety proximity pair's silencer dampeners (spatial_correlation.py:215 — safety positions dampen amplified-RCE hits), _calc_safety (WEIGHT_DEFENSE, fidelity-weighted), the safety_score formula (verification·fid_test + safety·fid_safety − bypassed·2.0), FIDELITY_SIGNALS, the "Error & Exception Exposure" report row, the statistical_auditor extraction-density group.

The two open cells (finditer verdicts against corpus main)

  • embedded_python = 4 (a.py 2 + b.py 2) — two diseases:
    1. a.py's single planted guard assert isinstance(value, int) records 2: the rule's bare assert and bare isinstance both fire on one statement. One defensive statement is one site.
    2. b.py's two bare except: — the safety_bypasses plant, the anti-safety marker — also count as safety (except sits in both rules; manifest records the dual safety: 2, safety_bypasses: 2). A swallowed exception is the opposite of a runtime guard; one owner.
  • haskell = 3 (a.hs 2 + c.hs 1) — two diseases:
    1. a.hs's "plant" is only a type signature: probeSafety :: Maybe Int -> Either Int Int (body = 0, nothing defensive at the value level) records 2 via the Maybe/Either type constructors. A type annotation is not a runtime defensive construct — the ledger already states this from the typescript side (typescript-type-keywords-count-as-safety: unknown|never|void counted as guards, explicitly deferred to be "audited with" this family) and it is state_mutation corollary 2's shape (IORef Int in a signature is not a write). The plant was authored to the old rule and needs a genuine value-level guard.
    2. c.hs's finally — cleanup's plant — double-counts as safety (ledger haskell-finally-dual-cleanup-safety, keyword-overlap, still reproduces).

Also visible from main without a red cell: haskell's rule counts bare pure and return (the two most common words in any Haskell file) and the bare data constructors Just|Nothing|Right|Left (a constructor in an ordinary expression, not a handled-absence site); embedded_python's bare getattr/hasattr are reflection reads, not guards. The full 46-language rule_probe sweep lands in docs/safety_rule_contract.md's audit table.

What the contract must state

  1. One hit is a site that handles or forestalls a runtime failure — a guarded region (try/catch/bracket), a runtime assertion or validation call, a handled-absence branch, a watchdog — at the value level, in a form an ordinary identifier cannot match.
  2. Statement, not tokens (the a.py shape): a guard statement with a validation call inside it is one site.
  3. Value level, not type level (the a.hs/typescript shape): a type annotation (Maybe, Either, unknown, never) is invisible; the handled-absence branch (fromMaybe, a total case with the Nothing arm, a null-check) is the site.
  4. One owner (the b.py/c.hs shape): a bare/broad except is safety_bypasses'; a cleanup combinator (finally, ensure, defer) is cleanup's; the runtime guard the language ships (assert) is safety's, never test's (test has no stated contract: c and embedded_python count safety's planted assert, and perl's Test::More::ok( fires the rule twice #2852's boundary, from the other side).
  5. The ambiguity anchor: everyday words (try, catch, mask, pure, return) fire only in their guard form.
  6. Stated absence where the language has no runtime-failure surface (markdown is the existing n/a; the audit decides if any join it).

Done in the #2765/#2841/#2852/#2858/#2866 shape

docs/safety_rule_contract.md, the sheet row → stated, one cross-language test_safety_contract_<N>.py, engine PR labelled rosetta:rebless-owed, corpus PR with the re-plants (haskell's value-level guard; embedded_python's single-count guard) and both cells' ledger entries resolved. Expected: safety open defects 2 → 0, every corpus language reading 2. Watch the layer boundary: safety positions feed the proximity dampeners, so the bless scope must name only safety + the dampened pair's formulas; and safety_bypasses (planted, same files) must not move.

Activity

  1. added
    metrics
    core-engine
    on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions