Repository navigation
Spatially verify Metaprogramming Hallucination Risk in Dev Agent Firewall (#106) - #360
Merged
squid-protocol merged 1 commit intoJul 24, 2026
Merged
Conversation
…wall (#106) Landing order per the #102 epic (#344 -> #346 -> #105 -> #106): with #348's persisted threat_locations ledger and correlate_against_ledger() already proven out by #105, #106 is a second, even simpler consumer -- both signals it needs ("reflection_metaprogramming" and "doc") are native detector.py rules, not security_lens-only, so no cross-worker merge dependency exists at all. Replaces dev_agent_firewall.py's rule 3 (Metaprogramming Hallucination Risk), which was fully dead code per #345: it read file_data["telemetry"]["doc_density"], a key no producer anywhere ever wrote, so the check could never fire. Even a working version of the old check had two structural blind spots described in #106: a global per-file doc-density average (a) misses undocumented metaprogramming buried in an otherwise well-documented file, and (b) false-positives on well-documented metaprogramming just because the rest of the file is sparse. correlate_against_ledger() fixes both by proving proximity directly: a "reflection_metaprogramming" hit only flags "hallucination_zone" if no "doc" hit falls within the SAME function and max_distance=10 lines -- reusing the exact fixture value test_spatial_correlation.py already anticipated for this signal pair in #348's own test suite. Also drops the now-fully-unused signal_schema/hit_vector reads in evaluate_ecosystem, and exposes the raw count as guardrails["undocumented_metaprogramming"] per #106's proposed telemetry export. Before landing, confirmed the underlying integration end to end rather than assuming it: satellite ranges are guaranteed non-overlapping by construction (_slice_by_braces/_slice_by_indentation track last_end_idx and skip any nested match), and threat_locations/functions demonstrably survive from the per-file worker through _calculate_risk_exposures (Phase 3, spread via **meta) and build_dependency_graph (Phase 4, confirmed in-place mutation by reading f.get("functions", []) itself) into the parsed_files DevAgentFirewall consumes in Phase 5. Tests: test_dev_agent_firewall.py's existing hallucination-zone test rewritten to drive the ledger instead of the dead doc_density key, plus two new tests proving both of #106's blind spots are fixed (locally documented metaprogramming is spared; a doc comment in a DIFFERENT function does not paper over undocumented metaprogramming). Full suite: 836 passed, 1 pre-existing xfail. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
squid-protocol
deleted the
feature/106-metaprogramming-hallucination-risk
branch
July 24, 2026 13:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #106, and resolves #345. Landing order per the #102 epic (#344 -> #346 -> #105 -> #106): with #348's persisted
threat_locationsledger andcorrelate_against_ledger()already proven out by #105, this is a second, even simpler consumer -- both signals it needs (reflection_metaprogramminganddoc) are nativedetector.pyrules, not security_lens-only, so there's no cross-worker merge dependency at all.Replaces
dev_agent_firewall.py's rule 3 (Metaprogramming Hallucination Risk), which was fully dead code per #345: it readfile_data["telemetry"]["doc_density"], a key no producer anywhere ever wrote, so the check could never fire. Even a working version of the old check had two structural blind spots #106 called out: a global per-file doc-density average (a) misses undocumented metaprogramming buried in an otherwise well-documented file, and (b) false-positives on well-documented metaprogramming just because the rest of the file is sparse.correlate_against_ledger()fixes both by proving proximity directly: areflection_metaprogramminghit only flagshallucination_zoneif nodochit falls within the same function andmax_distance=10lines -- reusing the exact fixture valuetest_spatial_correlation.pyalready anticipated for this signal pair. Also drops the now-fully-unusedsignal_schema/hit_vectorreads inevaluate_ecosystem, and exposes the raw count asguardrails["undocumented_metaprogramming"]per #106's proposed telemetry export.Architectural integration, confirmed rather than assumed
Before landing, I traced the underlying data path end to end:
_slice_by_braces/_slice_by_indentationtracklast_end_idxand skip anyfunc_startmatch nested inside the previous satellite, socorrelate_scoped()'s "sorted, non-overlapping" assumption is structurally enforced, not just documented.threat_locations/functionsdemonstrably survive from the per-file worker through_calculate_risk_exposures(Phase 3, spread via**meta) andbuild_dependency_graph(Phase 4, confirmed in-place mutation -- it already readsf.get("functions", [])itself) into theparsed_fileslistDevAgentFirewallconsumes in Phase 5.Test plan
test_dev_agent_firewall.py's hallucination-zone test rewritten to drive the ledger instead of the deaddoc_densitykey.test_hallucination_zone_spares_locally_documented_metaprogramming), and a doc comment in a different function does not paper over undocumented metaprogramming in another (test_hallucination_zone_ignores_documentation_in_a_different_function).python -m pytest tests/ -q-- full suite, 836 passed, 1 pre-existing xfail.🤖 Generated with Claude Code