Skip to content

[Epic] Recurring pattern: keys read by a consumer that no producer ever writes #325

Closed
15 of 15 issues completed

Description

@squid-protocol

Pattern observed

In one review pass, we found six independent instances of the same failure
shape: a consumer reads a dict/schema key that no producer ever writes,
under either the exact name or a near-miss rename.

  1. SecurityLens.evaluate_risk() vs SignalProcessor's _calc_* methods --
    two full disagreeing implementations of the same five risk categories (Two independent, disagreeing implementations of the same risk-scoring logic #249)
  2. supply_chain_firewall.py reading dependency_network -- key never written
    anywhere; real data lives at telemetry.network_metrics (found during Two independent, disagreeing implementations of the same risk-scoring logic #249)
  3. signal_processor.py reading ghost_meta["aperture_reason"] -- real key
    is reason, and even that only gets copied on the opposite branch condition
    from the one that matters (the "CRITICAL LEAK" shunt case)
  4. statistical_auditor.py reading artifact["lang_mix"] -- never written
    anywhere, silently disabling polyglot-file detection
  5. language_standards.py's AI/LLM SDK names hand-pasted into 2 of 57
    language blocks instead of using the established GLOBAL_ pattern (AI/LLM detection sensor cluster (llm_api, llm_orchestrator, ai_tools, etc.) is entirely non-functional -- no rule ever produces these signals #313
    follow-up)
  6. AIAppSecSensor reading 7 of 8 inputs from a telemetry namespace that
    nothing populates (companion issue)

That's a strong enough pattern to treat as a process problem, not a string
of unlucky typos. All six were invisible at runtime (no exceptions, no
crashes -- code just silently computed nothing, or the wrong thing) and were
only found by manually grepping every .get("key"...) call against every
["key"] = / "key": assignment across the codebase.

Proposed fix: automate the manual diff

A one-time investment: a small static-analysis script that:

  1. Walks every .get("some_key" (and equivalent dict-access patterns)
    across the repo.
  2. Cross-references each key against every place it's ever assigned
    (["key"] =, dict-literal construction, .setdefault(, etc.).
  3. Flags any read key with zero matching writes anywhere in the codebase.
  4. Runs as a CI check (or pre-commit hook), not just an ad-hoc audit.

Expect real noise on the first pass (config constants from external files,
legitimate external JSON schema keys like lockfile fields, keys that are
genuinely optional by design) -- the first sub-task is tuning it down to a
low-noise signal, not just writing the walker.

Sub-tasks

  • Build the key-read vs key-write static analysis script
  • Tune out false positives (external config constants, legitimate
    optional keys, third-party JSON schema fields)
  • Wire into CI as a required check
  • Fix each of the 6 enumerated instances above (linked once individually filed)

Workflow context

Several of these instances (at least #249's duplicate-math case and the
AIAppSecSensor telemetry mismatch) trace back to AI-assisted coding sessions
(Gemini) producing plausible-looking consumer code against a producer that
was never actually built or was renamed later without updating the consumer.
Worth keeping this epic open as the place that documents the pattern, even
as individual instances get fixed piecemeal.

Sub-issues

Sub-issues

15 of 15 Issues completed
Loading 15 sub-issues

Activity

  1. added
    enhancement
    epic
    metrics
    testing
    on Jul 23, 2026
  2. squid-protocol commented on Jul 24, 2026

    @squid-protocol
    OwnerAuthor

    Found a 7th instance of this pattern while scoping #102/#106: dev_agent_firewall.py's "Metaprogramming Hallucination Risk" rule reads telemetry["doc_density"], which no producer anywhere in the codebase ever writes — the .get(..., 1.0) default always wins, so the < 0.2 check can never fire. Filed as #345, since it's being superseded by #106's rework rather than patched in isolation.

  3. 5 remaining items

  4. squid-protocol commented on Jul 24, 2026

    @squid-protocol
    OwnerAuthor

    All 4 sub-tasks complete:

    1. Build the key-read vs key-write static analysis script -- tests/dead_key_audit.py (Build and tune the dead key auditor (#325) #362), an AST-based walker with f-string prefix-write matching for the sec_{key} pattern.
    2. Tune out false positives -- 33 confirmed false positives allowlisted with documented reasons (external manifests, ML model headers, YAML config, dynamically-keyed dicts, etc.) (Build and tune the dead key auditor (#325) #362).
    3. Wire into CI as a required check -- baseline-gated regression check, both as a pytest test and a dedicated dead-key-audit.yml workflow (Wire the dead key auditor into CI as a baseline-gated required check (#325) #363).
    4. Fix each enumerated instance -- grew from 6 originally-described instances to 15 confirmed findings once the tool ran for real. All 15 filed as individual issues ([BUG/DATA-INTEGRITY] Every recorder reads "AI Threat Score", but the producer writes "AI Threat Confidence" #364-[CHORE/CORE-ENGINE] prism.py's "mechanical_families" read -- unverified lead, needs scoping #378) and all 15 fixed:

    tests/dead_key_audit_baseline.json is now {} -- zero outstanding findings. The CI check will fail on any NEW instance of this pattern from here on.

    One related item intentionally left open as a candidate for separate future work: AIAppSecSensor's "companion issue" reference and ai_appsec_sensor.py more broadly weren't audited beyond the ai_tools fix in #365 -- worth a dedicated pass if useful.

    Closing.

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

    enhancementepicmetricspriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions