Skip to content

Canonical severity ordering invariants for config_version_hash determinism #123

Description

@usmanimamu17-create

or re-orders severity tiers (i.e., the issue #29 implementation).
Cross-references: Blocks; informs #29; co-document in
docs/CODEX_CONTEXT.md and event_schema.rs.

Problem Statement. compute_config_version_hash in
apexchainx_calculator/src/lib.rs iterates an internal severities
array:

let severities = [
    symbol_short!("critical"),
    symbol_short!("high"),
    symbol_short!("medium"),
    symbol_short!("low"),
];

and feeds each threshold_minutes, penalty_per_minute, and
reward_base into a deterministic rolling hash. The iteration
order is load-bearing
for backend parity — backends rely on
identical input configs producing identical hashes so they can detect
config drift cheaply. Today nothing in the test suite enforces this
invariant; a contributor re-ordering those four symbol constants, or
moving one of them into a different module during the #8 refactor,
would silently break parity across all backends forever.

There is also no test asserting that adding a 5th severity (e.g.,
the custom severity from #29) — either at init time or at runtime —
does not break the determinism guarantee.

Why It Matters. The whole point of config_version_hash is to
make a config-state-equality check cheap on the backend. A silent
breakage of the iteration-order assumption means backends see
"configs differ" for identical configurations — false-positive
reconciliation rollouts.

Expected Outcome.

  1. Introduce a pub fn canonical_severity_order() -> [Symbol; 4] in
    lib.rs (or in moduleMap.ts-derived config.rs) that returns
    the authoritative canonical ordering.
  2. compute_config_version_hash MUST consume that array as the
    iteration source (no inline literal duplicate).
  3. Add a regression test test_config_version_hash_invariant_under_reorder:
    • Hash identical when computed twice.
    • Hash changes when ANY field of ANY severity changes.
    • Hash is identical if a future contributor mutates
      canonical_severity_order in a way that doesn't change the
      visible ordering — i.e., asserts that visible ordering, not
      internal literal identity, is the invariant.
  4. Add a unit test pairing each severity with the next in the canonical
    order to anchor backward-compatible re-orderings.
  5. Document the invariant in event_schema.rs and
    docs/CODEX_CONTEXT.md next to the schema spec.

Acceptance Criteria.

  • New unit tests live under tests.rs (or per-module #[cfg(test)]).
  • A new check runs in CI: pre-build the hash on a known config and
    assert it matches a baseline in
    apexchainx_calculator/.config-version-hash.baseline.
  • Document explicitly: "Severity iteration order is public ABI.
    Re-ordering requires an RESULT_SCHEMA_VERSION bump."

Files: apexchainx_calculator/src/lib.rs,
apexchainx_calculator/src/tests.rs,
docs/CODEX_CONTEXT.md, event_schema.rs.


End of file.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26apiImported from ISSUES.mdcorrectnessImported from ISSUES.mdreliabilityImported from ISSUES.mdsorobanImported from ISSUES.md

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions