Skip to content

feat(#154): flip use_heat_kernel + use_hrr_structural to default-on - #523

Merged
robotrocketscience merged 3 commits into
mainfrom
feat/issue-154-flag-flips
May 9, 2026
Merged

feat(#154): flip use_heat_kernel + use_hrr_structural to default-on#523
robotrocketscience merged 3 commits into
mainfrom
feat/issue-154-flag-flips

Conversation

@robotrocketscience

@robotrocketscience robotrocketscience commented May 9, 2026

Copy link
Copy Markdown
Owner

Closes #154.

Summary

  • Flips use_hrr_structural default FalseTrue (1st atomic commit).
  • Flips use_heat_kernel default FalseTrue (2nd atomic commit).
  • CHANGELOG [Unreleased] entry (3rd atomic commit).

The #154 composition tracker has gated these two default flips on the calibrated reproducibility-harness reaching 11/11. That gate cleared yesterday via PR #489 closing #437, so the tracker's status banner ("use_heat_kernel, use_hrr_structural stay opt-in pending the calibrated #437 reproducibility harness") no longer applies and the flips are due.

Behavior

Precedence (env > kwarg > TOML > default) is unchanged. Only the default value flips. The opt-out surface remains reachable for users who want parity with the v2.0.x ranking:

Flag Env opt-out TOML opt-out Kwarg
use_heat_kernel AELFRICE_HEAT_KERNEL=0 [retrieval] use_heat_kernel = false use_heat_kernel=False
use_hrr_structural AELFRICE_HRR_STRUCTURAL=0 [retrieval] use_hrr_structural = false use_hrr_structural=False

Each replaced default-off test is now a default-on assertion plus an explicit opt-out coverage test for the env / kwarg / TOML paths.

Test plan

Notes

  • Board status was flipped Blocked → Todo before claiming, with rationale recorded in issue comment 4413003364.
  • Three atomic commits, all signed.

Summary by Sourcery

Flip the retrieval flags for the heat-kernel authority lane and HRR structural-query lane to be enabled by default, while preserving existing opt-out mechanisms and documenting the behavior change.

Enhancements:

  • Update retrieval flag resolution logic so use_heat_kernel and use_hrr_structural now default to true when no env, kwarg, or TOML override is provided.
  • Clarify and align documentation describing the default-on behavior and precedence rules for the heat-kernel and HRR structural lanes, including configuration and feature docs.

Documentation:

  • Add an Unreleased changelog entry describing the default-on flip for use_heat_kernel and use_hrr_structural.

Summary by CodeRabbit

  • New Features

    • Added support for structured belief queries using <KIND>:<belief-id> syntax for targeted retrieval.
  • Behavior Changes

    • Heat-kernel scoring now defaults to enabled (previously opt-in).
    • Structural query retrieval now defaults to enabled (previously opt-in).
    • Both features can be disabled via configuration if needed.
  • Documentation

    • Updated configuration reference to reflect new default settings and opt-out options.

Review Change Stack

Closes the #154 composition-tracker default-on flip for the HRR
structural-query lane. The lane has shipped since v1.7.0 (#152) but
stayed opt-in pending the calibrated reproducibility-harness gate.
That gate cleared at 11/11 yesterday via PR #489 closing #437, so
the default flips per the tracker's status banner.

Behavior: precedence (env > kwarg > toml > default) is unchanged;
only the default value flips False → True. Opt-out paths are
preserved — env var AELFRICE_HRR_STRUCTURAL=0, the kwarg, and the
TOML key all still let users pin to the v2.0.x ranking.

Tests: full suite (3065 passed, 51 skipped) green with the flip.
The default-off assertion is replaced with a default-on assertion
plus an explicit opt-out coverage test for the env / kwarg / TOML
paths.
Closes the second of the two #154 composition-tracker default-on
flips. The heat-kernel authority-scoring lane (#150) shipped
v1.5.0–v1.7.0 but stayed opt-in pending the calibrated
reproducibility-harness gate. That gate cleared at 11/11 yesterday
via PR #489 closing #437, so the default flips per the tracker's
status banner.

Behavior: precedence (env > kwarg > toml > default) is unchanged;
only the default value flips False → True. Opt-out paths are
preserved — env var AELFRICE_HEAT_KERNEL=0, the kwarg, and the
TOML key all still let users pin to the v2.0.x ranking.

Tests: full suite (3066 passed, 51 skipped) green with both flips
landed. The default-off assertion is replaced with default-on +
explicit opt-out coverage.
…structural

[Unreleased] entry recording the two preceding atomic flag flips.
Cross-links #154 (composition tracker), #437/#489 (the gate that
cleared at 11/11), and the per-flag opt-out instructions.
@sourcery-ai

sourcery-ai Bot commented May 9, 2026

Copy link
Copy Markdown

Reviewer's Guide

Flips the retrieval flags use_heat_kernel and use_hrr_structural from default-off to default-on while preserving the env/kwarg/TOML precedence, updates docs/CHANGELOG to reflect the new defaults, and adjusts tests to assert default-on behavior plus explicit opt-out coverage.

Sequence diagram for retrieval flag resolution precedence

sequenceDiagram
  participant RetrievalClient
  participant RetrievalModule
  participant EnvConfig
  participant TomlConfig

  RetrievalClient->>RetrievalModule: call retrieve_v2(use_heat_kernel, use_hrr_structural)
  activate RetrievalModule

  Note over RetrievalModule: Resolve use_hrr_structural
  RetrievalModule->>EnvConfig: read AELFRICE_HRR_STRUCTURAL
  alt env var set
    EnvConfig-->>RetrievalModule: return truthy_or_falsy
    RetrievalModule-->>RetrievalClient: structural_enabled = env_value
  else env var not set
    RetrievalModule-->>RetrievalClient: structural_explicit_kwarg?
    alt explicit kwarg provided
      RetrievalModule-->>RetrievalClient: structural_enabled = kwarg_value
    else no explicit kwarg
      RetrievalModule->>TomlConfig: read [retrieval] use_hrr_structural
      alt toml key set
        TomlConfig-->>RetrievalModule: return toml_value
        RetrievalModule-->>RetrievalClient: structural_enabled = toml_value
      else toml key not set
        RetrievalModule-->>RetrievalClient: structural_enabled = True (default_on)
      end
    end
  end

  Note over RetrievalModule: Resolve use_heat_kernel
  RetrievalModule->>EnvConfig: read AELFRICE_HEAT_KERNEL
  alt env var set
    EnvConfig-->>RetrievalModule: return truthy_or_falsy
    RetrievalModule-->>RetrievalClient: heat_kernel_enabled = env_value
  else env var not set
    RetrievalModule-->>RetrievalClient: heat_kernel_explicit_kwarg?
    alt explicit kwarg provided
      RetrievalModule-->>RetrievalClient: heat_kernel_enabled = kwarg_value
    else no explicit kwarg
      RetrievalModule->>TomlConfig: read [retrieval] use_heat_kernel
      alt toml key set
        TomlConfig-->>RetrievalModule: return toml_value
        RetrievalModule-->>RetrievalClient: heat_kernel_enabled = toml_value
      else toml key not set
        RetrievalModule-->>RetrievalClient: heat_kernel_enabled = True (default_on)
      end
    end
  end

  RetrievalModule-->>RetrievalClient: run lanes with resolved flags
  deactivate RetrievalModule
Loading

File-Level Changes

Change Details Files
Flip retrieval feature flags from default-off to default-on while preserving precedence semantics.
  • Change is_hrr_structural_enabled default return from False to True and update inline docstring about the gate and opt-out paths.
  • Change is_heat_kernel_enabled default return from False to True and update inline docstring about the gate and opt-out paths.
  • Update HRR structural-index module docstring to describe default-ON behavior and opt-out mechanisms.
src/aelfrice/retrieval.py
src/aelfrice/hrr_index.py
Update configuration and feature docs to describe the new default-on behavior and reproducibility gate rationale.
  • Adjust CONFIG.md examples and prose for use_heat_kernel and use_hrr_structural to state default true, updated precedence, and how to opt out for pre-flip parity.
  • Update feature-hrr-vocab-bridge documentation to note HRR struct index is now default-ON behind use_hrr_structural after the gate.
  • Document the default flips and gate rationale in the Unreleased section of the changelog.
docs/CONFIG.md
docs/feature-hrr-vocab-bridge.md
CHANGELOG.md
Adjust tests to assert default-on behavior and explicitly cover opt-out paths via kwarg/TOML.
  • Rename and update heat-kernel tests to expect default-on behavior with no env/kwarg/TOML and add a new test that exercises kwarg and TOML opt-out paths.
  • Rename and update HRR structural-index tests to expect default-on behavior and add a new test that exercises kwarg and TOML opt-out paths.
tests/test_heat_kernel.py
tests/test_hrr_struct_index.py

Assessment against linked issues

Issue Objective Addressed Explanation
#154 Flip the use_heat_kernel and use_hrr_structural feature flags from default-off to default-on in the retrieval pipeline once the benchmark/reproducibility gate is satisfied.
#154 Preserve the existing feature-flag precedence (env var > explicit kwarg > TOML config > default) while keeping opt-out paths available for parity with pre-flip rankings.
#154 Update configuration docs, feature documentation, tests, and changelog to reflect the new default-on behavior for use_heat_kernel and use_hrr_structural and the fact that the #154 tracker gate has been cleared.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@robotrocketscience robotrocketscience added author-rogue1 PR coordination mutex attn:review Needs review (PR open, awaiting reviewer) labels May 9, 2026
@coderabbitai

coderabbitai Bot commented May 9, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR flips two retrieval feature flags from opt-in (default false) to opt-in (default true): use_heat_kernel and use_hrr_structural. It updates the feature-flag resolution logic in retrieval.py, adds a new HRR structural-index module with caching and persistence, updates configuration documentation, and revises test expectations to confirm both new defaults and intact opt-out mechanisms.

Changes

Default-on flip for HRR structural and heat kernel

Layer / File(s) Summary
Feature flag defaults
src/aelfrice/retrieval.py
is_hrr_structural_enabled() and is_heat_kernel_enabled() now return True instead of False when no env var, kwarg, or TOML override is provided.
HRR structural index implementation
src/aelfrice/hrr_index.py
New module adds parse_structural_marker() to detect structural queries; HRRStructIndex class to build and probe an in-memory HRR superposition index; and HRRStructIndexCache to wrap the index with store-invalidation-aware lazy rebuilding and versioned .npz persistence.
Configuration and documentation updates
docs/CONFIG.md, docs/feature-hrr-vocab-bridge.md
Update .aelfrice.toml schema example and detailed flag documentation to reflect default true for both use_heat_kernel and use_hrr_structural; align feature-bridge narrative to describe HRRStructIndex as default-ON.
Test updates
tests/test_heat_kernel.py, tests/test_hrr_struct_index.py
Replace prior default-off assertions with default-on tests; add opt-out coverage verifying explicit False kwargs and TOML config overrides disable the flags.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • robotrocketscience/aelfrice#152: The PR implements the HRR structural-query lane (parse_structural_marker, HRRStructIndex, HRRStructIndexCache) that was planned and scoped in this issue.
  • robotrocketscience/aelfrice#154: This PR flips the default-on state for use_heat_kernel and use_hrr_structural, realizing the v2.0+ gate completion milestone documented in this tracker.

Possibly related PRs

  • robotrocketscience/aelfrice#310: Both PRs touch heat-kernel feature-flag and composition logic in src/aelfrice/retrieval.py; this PR flips the default while #310 implements the initial heat-kernel plumbing.
  • robotrocketscience/aelfrice#503: Both PRs add and wire the HRR structural index and cache (parse_structural_marker, HRRStructIndex, HRRStructIndexCache) in the same modules.

Suggested labels

author-Kulili, attn:review

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely describes the main change: flipping two retrieval feature flags to default-on, and references the linked issue (#154) that drives this change.
Description check ✅ Passed The PR description comprehensively covers all required template sections: summary, linked issues, type of change (feat), verification checklist (partially complete), test plan, and notes for reviewer.
Linked Issues check ✅ Passed The PR fully implements the requirements from #154: flips use_hrr_structural and use_heat_kernel defaults from False to True after the #437 reproducibility harness gate cleared (achieving 11/11 on 2026-05-08), maintains precedence rules, preserves opt-out mechanisms, and updates documentation accordingly.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements of #154: default-flip logic in retrieval.py, documentation updates in CONFIG.md and feature docs, corresponding test updates, and CHANGELOG entry—no extraneous or unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-154-flag-flips

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In the new test_use_heat_kernel_opt_out_paths_intact and test_use_hrr_structural_opt_out_paths_intact tests, you mention env-var opt-out in the docstrings but only assert kwarg/TOML behavior; consider adding an explicit env-var override assertion to keep coverage aligned with the described opt-out surface.
  • The detailed historical explanation of the #154/#437 gate and 11/11 status is repeated in several docstrings and docs; consider tightening or centralizing this context to keep the configuration docs focused on current behavior and reduce repetition.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the new `test_use_heat_kernel_opt_out_paths_intact` and `test_use_hrr_structural_opt_out_paths_intact` tests, you mention env-var opt-out in the docstrings but only assert kwarg/TOML behavior; consider adding an explicit env-var override assertion to keep coverage aligned with the described opt-out surface.
- The detailed historical explanation of the #154/#437 gate and 11/11 status is repeated in several docstrings and docs; consider tightening or centralizing this context to keep the configuration docs focused on current behavior and reduce repetition.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/CONFIG.md (1)

12-12: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Stale "opt-in" labels in the summary blurb after the flip.

The detailed sections at lines 68-80 and 294-298 / 300-326 now describe use_heat_kernel and use_hrr_structural as default-ON, but the top-level [retrieval] knob list at line 12 still labels both as "opt-in". A reader skimming the summary will get the wrong default.

📝 Suggested rewording
-`use_heat_kernel` (authority scoring lane, opt-in), `use_hrr_structural` (HRR structural-query lane, opt-in), `use_type_aware_compression` (per-belief retention-class compression, opt-in since v2.1), `use_vocab_bridge` (HRR query-side vocabulary bridge, opt-in since v2.1).
+`use_heat_kernel` (authority scoring lane, default-on since `#154` bench gate), `use_hrr_structural` (HRR structural-query lane, default-on since `#154` bench gate), `use_type_aware_compression` (per-belief retention-class compression, opt-in since v2.1), `use_vocab_bridge` (HRR query-side vocabulary bridge, opt-in since v2.1).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/CONFIG.md` at line 12, The top-level [retrieval] summary incorrectly
labels use_heat_kernel and use_hrr_structural as "opt-in" despite detailed
sections showing they are now default-ON; update the summary blurb for the
retrieval knob list (the line containing use_heat_kernel and use_hrr_structural)
to remove the "(opt-in)" qualifier and, if useful, annotate them as "default-ON"
or include the version where the flip occurred to match the detailed sections;
ensure you touch the text that lists the flags (including use_signed_laplacian
and use_posterior_ranking) so the summary and the detailed descriptions are
consistent.
tests/test_heat_kernel.py (1)

15-15: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Stale acceptance-criteria docstring. AC7: feature-flag default is False (use_heat_kernel) directly contradicts test_use_heat_kernel_default_on below.

📝 Suggested fix
-- AC7: feature-flag default is False (use_heat_kernel)
+- AC7: feature-flag default is True (use_heat_kernel) since `#154`
+       flipped the default after the `#437` 11/11 reproducibility gate
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_heat_kernel.py` at line 15, Update the stale acceptance-criteria
docstring that reads "AC7: feature-flag default is False (use_heat_kernel)" to
match the actual test behavior in test_use_heat_kernel_default_on (i.e., change
it to indicate the default is True or remove AC7 entirely); locate the docstring
in tests/test_heat_kernel.py and edit the AC7 text so it no longer contradicts
the test_use_heat_kernel_default_on test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/aelfrice/retrieval.py`:
- Line 805: The docstring describing structural-marker behavior is stale because
_route_structural_query now returns early (via RetrievalResult(beliefs=out,
locked_ids=[...]) when structural markers are hit) and the structural lane
defaults to ON, so callers using temporal_sort, with_doc_anchors, or
use_type_aware_compression will receive an unprocessed result; update the
docstring on the public API that calls _route_structural_query to state the
structural lane default is ON, that structural hits bypass post-processing steps
(temporal_sort, compressed_beliefs, doc_anchors) and which flags are ignored,
and add/update tests covering a query matching the structural pattern
(^[A-Z][A-Z_]*:\S) combined with temporal_sort=True / with_doc_anchors=True /
use_type_aware_compression=True to assert the returned RetrievalResult is the
early structural form or change the implementation if a different behavior is
desired.

In `@tests/test_heat_kernel.py`:
- Around line 256-276: The tests rely on ambient env/cwd and must explicitly
isolate environment and working directory: in both
test_use_heat_kernel_default_on and test_use_heat_kernel_opt_out_paths_intact,
call monkeypatch.delenv("AELFRICE_HEAT_KERNEL", raising=False) at the start and
pass start=tmp_path into is_heat_kernel_enabled so the resolver doesn't pick up
ancestor TOML; also add a type annotation tmp_path: Path on the second test and
add from pathlib import Path to the module imports to keep signatures
consistent.

In `@tests/test_hrr_struct_index.py`:
- Around line 226-246: Tests can flake because they don't isolate environment
variables or current working directory; update both tests to ensure
AELFRICE_HRR_STRUCTURAL is absent (use
monkeypatch.delenv("AELFRICE_HRR_STRUCTURAL", raising=False)) and pass
start=tmp_path to is_hrr_structural_enabled so _read_toml_flag_for walks from
the temporary dir rather than the test runner's cwd; specifically modify
test_use_hrr_structural_default_on to delete the env var and call
is_hrr_structural_enabled(start=tmp_path) and modify
test_use_hrr_structural_opt_out_paths_intact so the explicit-kwarg assertion
runs after monkeypatch.delenv and uses start=tmp_path for calls that rely on
TOML lookup.

---

Outside diff comments:
In `@docs/CONFIG.md`:
- Line 12: The top-level [retrieval] summary incorrectly labels use_heat_kernel
and use_hrr_structural as "opt-in" despite detailed sections showing they are
now default-ON; update the summary blurb for the retrieval knob list (the line
containing use_heat_kernel and use_hrr_structural) to remove the "(opt-in)"
qualifier and, if useful, annotate them as "default-ON" or include the version
where the flip occurred to match the detailed sections; ensure you touch the
text that lists the flags (including use_signed_laplacian and
use_posterior_ranking) so the summary and the detailed descriptions are
consistent.

In `@tests/test_heat_kernel.py`:
- Line 15: Update the stale acceptance-criteria docstring that reads "AC7:
feature-flag default is False (use_heat_kernel)" to match the actual test
behavior in test_use_heat_kernel_default_on (i.e., change it to indicate the
default is True or remove AC7 entirely); locate the docstring in
tests/test_heat_kernel.py and edit the AC7 text so it no longer contradicts the
test_use_heat_kernel_default_on test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 34dccebb-59ac-404a-9c8c-5669a48eb9e4

📥 Commits

Reviewing files that changed from the base of the PR and between 7e6c3c0 and 523247f.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !**/CHANGELOG.md
📒 Files selected for processing (6)
  • docs/CONFIG.md
  • docs/feature-hrr-vocab-bridge.md
  • src/aelfrice/hrr_index.py
  • src/aelfrice/retrieval.py
  • tests/test_heat_kernel.py
  • tests/test_hrr_struct_index.py

Comment thread src/aelfrice/retrieval.py
if toml_value is not None:
return toml_value
return False
return True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Surface every retrieve_v2 call site to see whether any combine the
# bypassed kwargs with structural-shaped queries.
rg -nP --type=py -C4 '\bretrieve_v2\s*\('
# Look for any test that exercises the marker + temporal_sort/with_doc_anchors combo.
rg -nP --type=py -C3 'temporal_sort\s*=\s*True|with_doc_anchors\s*=\s*True'

Repository: robotrocketscience/aelfrice

Length of output: 45576


🏁 Script executed:

#!/bin/bash
# First, get the retrieve_v2 implementation and check line 1797
head -1850 src/aelfrice/retrieval.py | tail -100 | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 5490


🏁 Script executed:

#!/bin/bash
# Look at the actual retrieve_v2 function signature and implementation
sed -n '1699,1850p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 8448


🏁 Script executed:

#!/bin/bash
# Find _route_structural_query definition and understand the early return
rg -n '_route_structural_query' src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 158


🏁 Script executed:

#!/bin/bash
# Look at _route_structural_query to see what RetrievalResult it returns
sed -n '808,950p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 5981


🏁 Script executed:

#!/bin/bash
# Check if there's a test that combines structural queries with temporal_sort or with_doc_anchors
rg -n 'CONTRADICTS|CITES|SUPPORTS' tests/ | grep -E 'temporal_sort|with_doc_anchors|use_type_aware_compression' | head -20

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

#!/bin/bash
# Get the full retrieve_v2 function to see compressed_beliefs and doc_anchors handling
sed -n '1699,1850p' src/aelfrice/retrieval.py | tail -50 | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 2267


🏁 Script executed:

#!/bin/bash
# Check RetrievalResult dataclass to see default values
rg -n 'class RetrievalResult' src/aelfrice/retrieval.py -A 30

Repository: robotrocketscience/aelfrice

Length of output: 1777


🏁 Script executed:

#!/bin/bash
# Get the remaining lines of retrieve_v2 to see doc_anchors and compressed_beliefs handling
sed -n '1800,1900p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 4862


🏁 Script executed:

#!/bin/bash
# Check for any test that uses structural queries (CONTRADICTS, CITES, SUPPORTS, etc.)
# combined with temporal_sort, with_doc_anchors, or use_type_aware_compression
rg -n 'retrieve_v2.*temporal_sort|retrieve_v2.*with_doc_anchors|retrieve_v2.*use_type_aware_compression' tests/

Repository: robotrocketscience/aelfrice

Length of output: 1187


🏁 Script executed:

#!/bin/bash
# Check if use_hrr_structural is on by default
rg -n 'is_hrr_structural_enabled' src/aelfrice/retrieval.py -A 5

Repository: robotrocketscience/aelfrice

Length of output: 551


🏁 Script executed:

#!/bin/bash
# Check the is_hrr_structural_enabled implementation
rg -n 'def is_hrr_structural_enabled' src/aelfrice/ -A 10

Repository: robotrocketscience/aelfrice

Length of output: 797


🏁 Script executed:

#!/bin/bash
# Look for any existing tests that explicitly combine structural markers with temporal_sort, with_doc_anchors, or compression
rg -n 'use_hrr_structural.*True' tests/ -A 10 | head -100

Repository: robotrocketscience/aelfrice

Length of output: 4472


🏁 Script executed:

#!/bin/bash
# Get the full is_hrr_structural_enabled function to see the default
sed -n '775,806p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 1488


🏁 Script executed:

#!/bin/bash
# Check the retrieve_v2 docstring about defaults for use_hrr_structural
sed -n '1776,1790p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 1020


🏁 Script executed:

#!/bin/bash
# Check if there's a test combining structural marker + temporal_sort explicitly
rg -n 'CONTRADICTS|CITES|SUPPORTS' tests/test_retrieve_v2_hrr_structural.py -A 5 | grep -i 'temporal_sort\|with_doc_anchors\|compression'

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

#!/bin/bash
# Get absolute line numbers for _route_structural_query and its return
sed -n '808,875p' src/aelfrice/retrieval.py | grep -n 'return'

Repository: robotrocketscience/aelfrice

Length of output: 216


🏁 Script executed:

#!/bin/bash
# Confirm: on a structural marker hit, the RetrievalResult skips all post-processing
# by showing the exact return statement at line 61-64
sed -n '861,864p' src/aelfrice/retrieval.py | cat -n

Repository: robotrocketscience/aelfrice

Length of output: 209


The docstring at line 1776 is stale; the structural lane now defaults to ON (not OFF), confirming the concern.

On a structural-marker hit, _route_structural_query (lines 808–864) returns early with a minimal RetrievalResult(beliefs=out, locked_ids=[...]) that bypasses all post-processing: temporal_sort (line 1848), compressed_beliefs (lines 1852–1856), and doc_anchors (lines 1863–1866) remain empty. Pre-flip this only affected callers who explicitly set use_hrr_structural=True; post-flip (per line 31: default return True), any caller combining temporal_sort=True / with_doc_anchors=True / use_type_aware_compression=True with a query matching ^[A-Z][A-Z_]*:\S that resolves to a known kind will silently receive the unprocessed structural result. No existing tests cover this combination; the contract should be documented and the docstring corrected to reflect the current default-ON state.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/aelfrice/retrieval.py` at line 805, The docstring describing
structural-marker behavior is stale because _route_structural_query now returns
early (via RetrievalResult(beliefs=out, locked_ids=[...]) when structural
markers are hit) and the structural lane defaults to ON, so callers using
temporal_sort, with_doc_anchors, or use_type_aware_compression will receive an
unprocessed result; update the docstring on the public API that calls
_route_structural_query to state the structural lane default is ON, that
structural hits bypass post-processing steps (temporal_sort, compressed_beliefs,
doc_anchors) and which flags are ignored, and add/update tests covering a query
matching the structural pattern (^[A-Z][A-Z_]*:\S) combined with
temporal_sort=True / with_doc_anchors=True / use_type_aware_compression=True to
assert the returned RetrievalResult is the early structural form or change the
implementation if a different behavior is desired.

Comment thread tests/test_heat_kernel.py
Comment on lines +256 to +276
def test_use_heat_kernel_default_on() -> None:
"""Per #154 the default flipped to ON after the #437 11/11 gate
cleared. No env, no kwarg, no toml → True."""
from aelfrice.retrieval import is_heat_kernel_enabled

# No env, no kwarg, no toml → default False
assert is_heat_kernel_enabled() is False
assert is_heat_kernel_enabled() is True


def test_use_heat_kernel_opt_out_paths_intact(tmp_path) -> None:
"""The opt-out surface (kwarg, TOML key) remains reachable for
users who want the pre-flip ranking. Replaces the v1.7-era
default-off check."""
from aelfrice.retrieval import is_heat_kernel_enabled

# Explicit kwarg
assert is_heat_kernel_enabled(False) is False

# TOML key
cfg = tmp_path / ".aelfrice.toml"
cfg.write_text("[retrieval]\nuse_heat_kernel = false\n")
assert is_heat_kernel_enabled(start=tmp_path) is False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Same env/cwd-isolation concern as tests/test_hrr_struct_index.py.

test_use_heat_kernel_default_on calls is_heat_kernel_enabled() with no start= and no env scrub — ambient AELFRICE_HEAT_KERNEL=0 or an ancestor .aelfrice.toml containing [retrieval] use_heat_kernel = false will fail the assertion. The kwarg branch at line 271 is similarly vulnerable to AELFRICE_HEAT_KERNEL=1 because env beats kwarg in the resolver. Apply the same monkeypatch.delenv(...) + start=tmp_path treatment as suggested in the parallel test file. Also consider type-annotating tmp_path: Path for consistency with the rest of the file.

🛡️ Suggested isolation
-def test_use_heat_kernel_default_on() -> None:
+def test_use_heat_kernel_default_on(
+    tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
     """Per `#154` the default flipped to ON after the `#437` 11/11 gate
     cleared. No env, no kwarg, no toml → True."""
     from aelfrice.retrieval import is_heat_kernel_enabled

-    assert is_heat_kernel_enabled() is True
+    monkeypatch.delenv("AELFRICE_HEAT_KERNEL", raising=False)
+    assert is_heat_kernel_enabled(start=tmp_path) is True


-def test_use_heat_kernel_opt_out_paths_intact(tmp_path) -> None:
+def test_use_heat_kernel_opt_out_paths_intact(
+    tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
     """The opt-out surface (kwarg, TOML key) remains reachable for
     users who want the pre-flip ranking. Replaces the v1.7-era
     default-off check."""
     from aelfrice.retrieval import is_heat_kernel_enabled

+    monkeypatch.delenv("AELFRICE_HEAT_KERNEL", raising=False)
+
     # Explicit kwarg
-    assert is_heat_kernel_enabled(False) is False
+    assert is_heat_kernel_enabled(False, start=tmp_path) is False

     # TOML key
     cfg = tmp_path / ".aelfrice.toml"
     cfg.write_text("[retrieval]\nuse_heat_kernel = false\n")
     assert is_heat_kernel_enabled(start=tmp_path) is False

from pathlib import Path will need to be added to the module imports if you adopt the annotation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_heat_kernel.py` around lines 256 - 276, The tests rely on ambient
env/cwd and must explicitly isolate environment and working directory: in both
test_use_heat_kernel_default_on and test_use_heat_kernel_opt_out_paths_intact,
call monkeypatch.delenv("AELFRICE_HEAT_KERNEL", raising=False) at the start and
pass start=tmp_path into is_heat_kernel_enabled so the resolver doesn't pick up
ancestor TOML; also add a type annotation tmp_path: Path on the second test and
add from pathlib import Path to the module imports to keep signatures
consistent.

Comment on lines +226 to +246
def test_use_hrr_structural_default_on() -> None:
"""Per #154 the default flipped to ON after the #437 11/11 gate
cleared. No env, no kwarg, no toml → True."""
from aelfrice.retrieval import is_hrr_structural_enabled

assert is_hrr_structural_enabled() is False
assert is_hrr_structural_enabled() is True


def test_use_hrr_structural_opt_out_paths_intact(tmp_path: Path) -> None:
"""The opt-out surface (env var, kwarg, TOML key) remains
reachable for users who want the pre-flip ranking. Replaces the
v1.7-era default-off check."""
from aelfrice.retrieval import is_hrr_structural_enabled

# Explicit kwarg
assert is_hrr_structural_enabled(False) is False

# TOML key
cfg = tmp_path / ".aelfrice.toml"
cfg.write_text("[retrieval]\nuse_hrr_structural = false\n")
assert is_hrr_structural_enabled(start=tmp_path) is False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether a project-wide autouse fixture already clears AELFRICE_* env
# vars before each test (would invalidate the concern above).
fd -t f conftest.py tests
rg -nP -C3 'AELFRICE_(HEAT_KERNEL|HRR_STRUCTURAL|BM25F|BFS|VOCAB_BRIDGE)' tests

Repository: robotrocketscience/aelfrice

Length of output: 872


🏁 Script executed:

cat -n tests/conftest.py

Repository: robotrocketscience/aelfrice

Length of output: 3160


🏁 Script executed:

cat -n tests/test_hrr_struct_index.py | sed -n '220,260p'

Repository: robotrocketscience/aelfrice

Length of output: 1743


🏁 Script executed:

fd -t f "retrieval.py" src

Repository: robotrocketscience/aelfrice

Length of output: 97


🏁 Script executed:

cat -n src/aelfrice/retrieval.py | head -100

Repository: robotrocketscience/aelfrice

Length of output: 4732


🏁 Script executed:

rg -n "def is_hrr_structural_enabled" -A 20 src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 1064


🏁 Script executed:

rg -n "def is_hrr_structural_enabled" -A 40 src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 1603


🏁 Script executed:

rg -n "_env_hrr_structural_override\|_read_toml_flag_for" -B 2 -A 10 src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

rg -n "_env_hrr_structural_override|_read_toml_flag_for" src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 925


🏁 Script executed:

rg -n "def _env_hrr_structural_override\|def _read_toml_flag_for" -A 15 src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

sed -n '345,365p' src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 768


🏁 Script executed:

sed -n '405,435p' src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 1203


🏁 Script executed:

grep -n "monkeypatch\|delenv\|environ" tests/conftest.py

Repository: robotrocketscience/aelfrice

Length of output: 115


🏁 Script executed:

sed -n '1,100p' tests/test_hrr_struct_index.py | grep -i "memorystorm\|mock\|patch"

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

rg -n "MemoryStore\|unittest.mock" tests/test_hrr_struct_index.py | head -20

Repository: robotrocketscience/aelfrice

Length of output: 53


🏁 Script executed:

head -50 tests/test_hrr_struct_index.py

Repository: robotrocketscience/aelfrice

Length of output: 1597


🏁 Script executed:

sed -n '1,30p' tests/test_hrr_struct_index.py

Repository: robotrocketscience/aelfrice

Length of output: 1161


🏁 Script executed:

grep -n "def _toy_store\|MemoryStore" tests/test_hrr_struct_index.py | head -10

Repository: robotrocketscience/aelfrice

Length of output: 256


Tests don't isolate env/cwd; can flake on a developer or CI environment that sets AELFRICE_HRR_STRUCTURAL or has an ambient .aelfrice.toml.

is_hrr_structural_enabled() consults os.environ[AELFRICE_HRR_STRUCTURAL] first and _read_toml_flag_for walks upward from Path.cwd(). Both test_use_hrr_structural_default_on (no start=, no env clear) and the kwarg branch of test_use_hrr_structural_opt_out_paths_intact (env beats kwarg) will produce wrong results if the ambient env or any ancestor .aelfrice.toml of the test runner pins the flag.

Use monkeypatch.delenv(...) and pass start=tmp_path consistently:

🛡️ Suggested isolation
-def test_use_hrr_structural_default_on() -> None:
+def test_use_hrr_structural_default_on(
+    tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
     """Per `#154` the default flipped to ON after the `#437` 11/11 gate
     cleared. No env, no kwarg, no toml → True."""
     from aelfrice.retrieval import is_hrr_structural_enabled

-    assert is_hrr_structural_enabled() is True
+    monkeypatch.delenv("AELFRICE_HRR_STRUCTURAL", raising=False)
+    assert is_hrr_structural_enabled(start=tmp_path) is True


-def test_use_hrr_structural_opt_out_paths_intact(tmp_path: Path) -> None:
+def test_use_hrr_structural_opt_out_paths_intact(
+    tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
+) -> None:
     """The opt-out surface (env var, kwarg, TOML key) remains
     reachable for users who want the pre-flip ranking. Replaces the
     v1.7-era default-off check."""
     from aelfrice.retrieval import is_hrr_structural_enabled

+    monkeypatch.delenv("AELFRICE_HRR_STRUCTURAL", raising=False)
+
     # Explicit kwarg
-    assert is_hrr_structural_enabled(False) is False
+    assert is_hrr_structural_enabled(False, start=tmp_path) is False

     # TOML key
     cfg = tmp_path / ".aelfrice.toml"
     cfg.write_text("[retrieval]\nuse_hrr_structural = false\n")
     assert is_hrr_structural_enabled(start=tmp_path) is False
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_hrr_struct_index.py` around lines 226 - 246, Tests can flake
because they don't isolate environment variables or current working directory;
update both tests to ensure AELFRICE_HRR_STRUCTURAL is absent (use
monkeypatch.delenv("AELFRICE_HRR_STRUCTURAL", raising=False)) and pass
start=tmp_path to is_hrr_structural_enabled so _read_toml_flag_for walks from
the temporary dir rather than the test runner's cwd; specifically modify
test_use_hrr_structural_default_on to delete the env var and call
is_hrr_structural_enabled(start=tmp_path) and modify
test_use_hrr_structural_opt_out_paths_intact so the explicit-kwarg assertion
runs after monkeypatch.delenv and uses start=tmp_path for calls that rely on
TOML lookup.

@robotrocketscience

Copy link
Copy Markdown
Owner Author

[claim:review:Kulili:2026-05-09T16:48:40Z]

@robotrocketscience
robotrocketscience merged commit 523247f into main May 9, 2026
29 of 43 checks passed
@robotrocketscience
robotrocketscience deleted the feat/issue-154-flag-flips branch May 9, 2026 16:50
@robotrocketscience

Copy link
Copy Markdown
Owner Author

[release:review:Kulili:2026-05-09T16:50:13Z]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attn:review Needs review (PR open, awaiting reviewer) author-rogue1 PR coordination mutex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[retrieval] Pipeline composition tracker — unified retrieve() with feature-flag gate

1 participant