Skip to content

docs(feature-type-aware-compression): spec memo for #434 - #450

Merged
robotrocketscience merged 1 commit into
mainfrom
docs/issue-434-type-aware-compression-spec
May 5, 2026
Merged

docs(feature-type-aware-compression): spec memo for #434#450
robotrocketscience merged 1 commit into
mainfrom
docs/issue-434-type-aware-compression-spec

Conversation

@yoshi280

@yoshi280 yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Spec memo for #434 — Type-aware compression. Closes the recovery-inventory line at docs/ROADMAP.md row 162 (Type-aware compression | v2.0.0).

What this PR is

Docs-only. New file at docs/feature-type-aware-compression.md that converts the bare issue acceptance sketch into a buildable contract: compress_for_retrieval() signature, per-retention-class strategy table, pack-loop integration points, configuration plumbing, bench-gate, determinism gate, and out-of-scope list.

No code, no schema, no flag wiring yet — those land in a follow-up implementation PR. This PR moves #434 from needs-spec to bench-gated.

Strategy table (per retention class)

Class locked=False locked=True
fact verbatim verbatim
snapshot headline (first sentence, 240-char cap) verbatim
transient stub ([stub: belief={id} class=transient]) verbatim
unknown verbatim (migration safety) verbatim

Locks override retention class — same rule as L0-never-trimmed at retrieval.py:950 and the lock-bypasses-hibernation rule at #196.

Determinism

Issue acceptance #3 makes byte-stable output a hard requirement. The compressor is pure: no LLM, no clock, no random, no store reads. A property test plus a fixture-pinned regression test cover it.

Substrate

All on main as of 68dafc0:

  • models.pyRETENTION_* constants, Belief.retention_class (Rebuild redesign: belief typing + aging policy #290, v1.6.0)
  • retrieval.py:215_belief_tokens() reused on rendered
  • retrieval.py:118-131 — flag-resolution convention
  • retrieval.py:1048-1085 + :1197-1232 — pack loops to rewrite
  • context_rebuilder.py — A4 consumer
  • tests/corpus/v2_0/, tests/bench_gate/ — corpus + harness

No new dependencies. No schema changes.

Test plan

  • Discretion grep on diff vs github/main — clean.
  • Commit SSH-signed (G).
  • CI matrix green (docs-only).
  • Reviewer: read end-to-end, confirm A1–A5 are buildable as specified.

Refs

Summary by Sourcery

Document the specification for a deterministic, type-aware retrieval compression feature, defining its contract, placement in the retrieval pipeline, and acceptance criteria.

New Features:

  • Add a feature spec for type-aware compression that varies compression strategy by belief retention class and lock state.
  • Define a CompressedBelief abstraction and configuration flag to control use of type-aware compression in retrieval.
  • Specify retrieval result shape changes to support both raw and compressed beliefs without altering current defaults.

Enhancements:

  • Clarify how type-aware compression composes with existing tail-trim, ranking, and context rebuilder mechanisms.
  • Establish bench-gated acceptance, determinism requirements, and out-of-scope boundaries for the future implementation of type-aware compression.

Documentation:

  • Introduce docs/feature-type-aware-compression.md describing the design, configuration, and benchmarks required for type-aware compression in v2.0.0.

Summary by CodeRabbit

  • Documentation
    • Added specification for type-aware compression in retrieval packs with configurable strategies that optimize token usage and improve result rendering based on content attributes.

@yoshi280 yoshi280 added the attn:review Needs review (PR open, awaiting reviewer) label May 5, 2026
@sourcery-ai

sourcery-ai Bot commented May 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new feature specification document for type-aware retrieval compression, defining a deterministic compress_for_retrieval() contract, per-retention-class compression strategies, integration points with existing retrieval/packing logic, configuration flag resolution, test/bench-gate requirements, and explicitly scoped non-goals, without touching runtime code or schemas.

Sequence diagram for type-aware compression in retrieval pipeline

sequenceDiagram
    actor Operator
    participant Client as retrieval_client
    participant Retrieval as retrieval_module
    participant Compressor as compression_module
    participant Rebuilder as context_rebuilder

    Operator->>Client: call_retrieval(use_type_aware_compression flag)
    Client->>Retrieval: retrieve(query, use_type_aware_compression)

    Retrieval->>Retrieval: resolve_use_type_aware_compression
    Retrieval->>Retrieval: lane_fan_out_and_rank

    alt use_type_aware_compression is true
        loop for each belief in ranked_candidates
            Retrieval->>Compressor: compress_for_retrieval(belief, locked)
            Compressor-->>Retrieval: CompressedBelief
        end
        Retrieval->>Retrieval: pack_loop_over_compressed_beliefs
        Retrieval->>Client: RetrievalResult(beliefs, compressed_beliefs)
    else use_type_aware_compression is false
        Retrieval->>Retrieval: pack_loop_over_raw_beliefs
        Retrieval->>Client: RetrievalResult(beliefs)
    end

    opt context rebuilder enabled
        Client->>Rebuilder: run_rebuilder(RetrievalResult)
        Rebuilder->>Rebuilder: apply_token_budget_with_compressed_output
        Rebuilder-->>Operator: continuation_fidelity_report
    end
Loading

Class diagram for CompressedBelief and retrieval result shape

classDiagram
    class Belief {
        +str id
        +str content
        +str retention_class
        +str belief_type
        +str source_kind
        +str lock_state
    }

    class CompressedBelief {
        +Belief belief
        +str rendered
        +int rendered_tokens
        +str strategy
    }

    class RetrievalResult {
        +list~Belief~ beliefs
        +list~CompressedBelief~ compressed_beliefs
    }

    class CompressionModule {
        +CompressedBelief compress_for_retrieval(Belief belief, bool locked)
    }

    class TokenEstimator {
        +int _belief_tokens(Belief belief)
        +int _estimate_tokens(str rendered)
    }

    Belief <.. CompressedBelief : wraps
    RetrievalResult o-- Belief : beliefs
    RetrievalResult o-- CompressedBelief : compressed_beliefs
    CompressionModule ..> Belief : input
    CompressionModule ..> CompressedBelief : output
    CompressionModule ..> TokenEstimator : uses
    TokenEstimator ..> Belief : measures

    class ConfigFlagResolution {
        +bool resolve_use_type_aware_compression(bool kwarg, bool env_flag, bool config_flag)
    }

    ConfigFlagResolution ..> RetrievalResult : controls_shape
Loading

File-Level Changes

Change Details Files
Introduce a formal spec document for type-aware compression, defining the compression contract, strategies, and data shapes.
  • Define compress_for_retrieval(belief, *, locked) contract and CompressedBelief dataclass shape including rendered text, token count, and strategy label.
  • Specify per-retention-class compression strategies (verbatim, headline, stub) and the determinism requirement for byte-stable, pure compression.
  • Document placement of compression in the retrieval pipeline, including how compressed beliefs interact with token budgets and pack loops, and options for representing compressed beliefs in retrieval results.
docs/feature-type-aware-compression.md
Document configuration, benchmarking, and acceptance criteria for enabling type-aware compression in v2.0.0.
  • Describe the use_type_aware_compression configuration hierarchy (kwargs, env var, config file, default OFF) and its interaction with existing retrieval flags.
  • Define acceptance criteria A1–A5, including corpus setup, recall uplift, determinism tests, rebuilder fidelity benchmarks, and composition tracker updates.
  • Clarify bench-gate / ship-or-defer policy and list out-of-scope items and open questions to be resolved in the implementation PR.
docs/feature-type-aware-compression.md

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

@github-actions github-actions Bot added the docs label May 5, 2026
@coderabbitai

coderabbitai Bot commented May 5, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@robotrocketscience has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 6 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ee1ef17a-b421-4fcd-add0-31411cdbf4a7

📥 Commits

Reviewing files that changed from the base of the PR and between 5c1ec42 and 34ddfb8.

📒 Files selected for processing (1)
  • docs/feature-type-aware-compression.md
📝 Walkthrough

Walkthrough

Adds a comprehensive documentation specification for type-aware compression in retrieval packs, defining the API contract (compress_for_retrieval), CompressedBelief data shape, strategy selection rules by retention class, pipeline placement, configuration mechanism, and acceptance criteria.

Changes

Type-Aware Compression Specification

Layer / File(s) Summary
API Contract & Data Shape
docs/feature-type-aware-compression.md (lines 1–71)
Defines the compress_for_retrieval(belief, *, locked) signature, the CompressedBelief wrapper with belief, rendered, rendered_tokens, and strategy fields, and core compressor guarantees (deterministic, total, monotone token cost).
Strategy Rules & Rendering
docs/feature-type-aware-compression.md (lines 48–70)
Strategy selection table maps retention_class (fact, snapshot, transient, unknown) to strategy choice; locked=True forces "verbatim"; details "headline" and "stub" rendering behaviors with character and token cost estimation logic.
Pipeline Integration & Configuration
docs/feature-type-aware-compression.md (lines 73–116)
Specifies placement after lane fan-out and ranking in the retrieval flow; pack token accounting switches to rendered_tokens; defines use_type_aware_compression configuration flag with kwarg/env/toml precedence and OFF behavior; describes RetrievalResult shape changes for parallel compressed renders.
Impact & Reconciliation
docs/feature-type-aware-compression.md (lines 119–149)
States storage/schema impact as none; reconciles with existing tail-trim, ranking, context rebuilder, and retention promotion mechanisms; clarifies compressor reads only retention_class.
Acceptance Criteria & Implementation
docs/feature-type-aware-compression.md (lines 152–227)
Lists five acceptance criteria including corpus benchmark gates, positive uplift verification, determinism tests, rebuilder fidelity comparisons, and composition tracker updates; enumerates implementation prerequisites and open review questions (stub format, shape choice, code-only content handling, retention promotion interaction).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a spec memo document for issue #434 on type-aware compression.
Description check ✅ Passed The PR description comprehensively covers all required template sections: summary, linked issues, type of change (docs), verification checklist completion, test plan, and reviewer notes with detailed context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/issue-434-type-aware-compression-spec

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:

  • The contract currently guarantees rendered_tokens ≤ _belief_tokens(belief), but the spec never states how this is enforced or validated for each strategy (especially headline truncation and stubs); consider adding a brief rationale per strategy so future implementations don’t accidentally violate this invariant during refactors.
  • It may be useful to clarify edge cases for CompressedBelief.rendered, e.g., how empty-content beliefs or all-code-fence beliefs are handled and whether rendered is ever allowed to be an empty string, so downstream consumers can rely on a well-defined minimum shape.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The contract currently guarantees `rendered_tokens ≤ _belief_tokens(belief)`, but the spec never states how this is enforced or validated for each strategy (especially headline truncation and stubs); consider adding a brief rationale per strategy so future implementations don’t accidentally violate this invariant during refactors.
- It may be useful to clarify edge cases for `CompressedBelief.rendered`, e.g., how empty-content beliefs or all-code-fence beliefs are handled and whether `rendered` is ever allowed to be an empty string, so downstream consumers can rely on a well-defined minimum shape.

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.

@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[claim:review:Toug:2026-05-05T19:43:44Z]

@github-actions github-actions Bot added the attn:merge-conflict PR branch needs rebase label May 5, 2026
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

This PR is now behind main. Rebase locally so your commit signatures stay intact:

git fetch origin && git checkout 'docs/issue-434-type-aware-compression-spec' && git rebase origin/main
# resolve conflicts if any, then
git push --force-with-lease

Auto-rebase was removed because the bot has no signing key; rebasing as the bot strips author signatures and the required_signatures rule on main then blocks the merge. See #341.

@robotrocketscience
robotrocketscience force-pushed the docs/issue-434-type-aware-compression-spec branch from f68f270 to 5c1ec42 Compare May 5, 2026 19:44
@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[claim:review:Kulili:2026-05-05T19:45:32Z]

@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[release:review:Kulili:2026-05-05T19:45:37Z]

@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[claim:review:Kulili:2026-05-05T19:48:02Z]

@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[release:review:Kulili:2026-05-05T19:48:07Z]

@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: 2

🧹 Nitpick comments (3)
docs/feature-type-aware-compression.md (3)

162-164: 💤 Low value

Optional: Add language marker to fenced code block.

The fenced code block at lines 162-164 is missing a language specifier. While the content is a comparison expression rather than executable code, adding ```text or ```python would satisfy the markdownlint rule and improve consistency.

🤖 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/feature-type-aware-compression.md` around lines 162 - 164, The fenced
code block containing the expression `recall@k(use_type_aware_compression=ON)  >
recall@k(use_type_aware_compression=OFF)` needs a language marker to satisfy
markdownlint; edit the block around that expression (the triple-backtick fence
enclosing the `recall@k(...)` line) and add a language specifier such as ```text
(or ```python) immediately after the opening ``` so the block becomes ```text
... ```.

226-226: 💤 Low value

Clarify the code-fence example.

The phrase "one python ... ``` `` block" has ambiguous backtick escaping that makes it hard to parse. Consider rephrasing to:

  • "A belief whose entire content is a single fenced code block (e.g., ```python\n...\n```)"
  • "A belief consisting solely of a code fence with no surrounding prose"
🤖 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/feature-type-aware-compression.md` at line 226, The sentence describing
the code-fence example is ambiguous due to backtick escaping; update the
phrasing in the "Headline-strategy on code-fence-only content" paragraph to a
clearer form such as "A belief whose entire content is a single fenced code
block (e.g., `` ```python\n...\n``` ``)" or "A belief consisting solely of a
code fence with no surrounding prose" so the example is unambiguous and easy to
parse; edit the sentence that currently reads 'one ``` ```python ... ``` ``
block' to one of these clearer alternatives.

61-63: ⚡ Quick win

Specify edge cases for headline strategy.

Two edge cases are not fully specified:

  1. Unbalanced code fences: Line 61 mentions splitting "outside a balanced code-fence span" but does not specify behavior when fences are unbalanced (e.g., opening ``` without closing). Should the algorithm attempt to balance them, treat them as not-fences, or fail gracefully?

  2. No whitespace in first 240 chars: Line 62 says "hard-truncate at the last whitespace boundary ≤ 240" but does not specify behavior when there is no whitespace in the first 240 characters (e.g., a 250-char continuous URL or code identifier).

Consider adding a fallback rule: if no whitespace ≤ 240, either truncate at exactly 240 or render verbatim.

🤖 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/feature-type-aware-compression.md` around lines 61 - 63, The headline
strategy lacks rules for unbalanced code fences and for when no whitespace
exists within MAX_HEADLINE_CHARS (MAX_HEADLINE_CHARS = 240); update the spec to
(1) define that unbalanced triple-backtick spans are treated as non-fences
(i.e., ignore opening-only or closing-only ``` and allow splitting within them)
rather than trying to auto-balance or failing, and (2) add a deterministic
fallback for the "last whitespace ≤ MAX_HEADLINE_CHARS" rule: if no whitespace
exists in the first MAX_HEADLINE_CHARS, hard-truncate at exactly
MAX_HEADLINE_CHARS and append an ellipsis (…) (or explicitly state to render
verbatim if you prefer that behavior), and reference MAX_HEADLINE_CHARS and the
“split on first `. ` or `.\n` outside a balanced code-fence span” rule so
implementers can apply these two edge-case policies consistently.
🤖 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 `@docs/feature-type-aware-compression.md`:
- Around line 173-177: The test test_compress_deterministic is tautological
because it compares two identical calls; change it to call
compress_for_retrieval(b, locked=locked) multiple times (e.g., N=10) and assert
all .rendered results are identical, or otherwise restructure the Hypothesis
property to produce a list of results and assert len(set(results)) == 1; update
references to compress_for_retrieval and the .rendered attribute in the test to
implement this non-tautological determinism check.
- Line 40: Update the documentation to use the correct attribute and remove the
incorrect classification mechanism: change the description for `locked: bool` to
state it is True when `belief.lock_level == LOCK_USER` (not `belief.lock_state`)
and remove any mention of an "otherwise classified as L0" mechanism; also keep
the note that locks always render `"verbatim"` regardless of `retention_class`.

---

Nitpick comments:
In `@docs/feature-type-aware-compression.md`:
- Around line 162-164: The fenced code block containing the expression
`recall@k(use_type_aware_compression=ON)  > 
recall@k(use_type_aware_compression=OFF)` needs a language marker to satisfy
markdownlint; edit the block around that expression (the triple-backtick fence
enclosing the `recall@k(...)` line) and add a language specifier such as ```text
(or ```python) immediately after the opening ``` so the block becomes ```text
... ```.
- Line 226: The sentence describing the code-fence example is ambiguous due to
backtick escaping; update the phrasing in the "Headline-strategy on
code-fence-only content" paragraph to a clearer form such as "A belief whose
entire content is a single fenced code block (e.g., `` ```python\n...\n``` ``)"
or "A belief consisting solely of a code fence with no surrounding prose" so the
example is unambiguous and easy to parse; edit the sentence that currently reads
'one ``` ```python ... ``` `` block' to one of these clearer alternatives.
- Around line 61-63: The headline strategy lacks rules for unbalanced code
fences and for when no whitespace exists within MAX_HEADLINE_CHARS
(MAX_HEADLINE_CHARS = 240); update the spec to (1) define that unbalanced
triple-backtick spans are treated as non-fences (i.e., ignore opening-only or
closing-only ``` and allow splitting within them) rather than trying to
auto-balance or failing, and (2) add a deterministic fallback for the "last
whitespace ≤ MAX_HEADLINE_CHARS" rule: if no whitespace exists in the first
MAX_HEADLINE_CHARS, hard-truncate at exactly MAX_HEADLINE_CHARS and append an
ellipsis (…) (or explicitly state to render verbatim if you prefer that
behavior), and reference MAX_HEADLINE_CHARS and the “split on first `. ` or
`.\n` outside a balanced code-fence span” rule so implementers can apply these
two edge-case policies consistently.
🪄 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: 90a2cae9-b2ee-4bcd-b1bc-831e9ada1459

📥 Commits

Reviewing files that changed from the base of the PR and between e646383 and 5c1ec42.

📒 Files selected for processing (1)
  • docs/feature-type-aware-compression.md

Inputs:

- `belief: Belief` — the belief as returned by the lane fan-out.
- `locked: bool` — `True` when `belief.lock_state == LOCK_USER` or the caller has otherwise classified the belief as L0. Locks always render `"verbatim"` regardless of `retention_class`.

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
# Description: Find L0 classification logic and lock conditions in retrieval.py

# Search for L0 lane classification and lock_state checks
rg -nP -C5 '\bL0\b|lock_state|LOCK_USER' --type=py src/aelfrice/retrieval.py

Repository: robotrocketscience/aelfrice

Length of output: 7822


🏁 Script executed:

#!/bin/bash
# Read the feature-type-aware-compression.md file to understand the context around line 40
cat -n docs/feature-type-aware-compression.md | sed -n '35,50p'

Repository: robotrocketscience/aelfrice

Length of output: 861


🏁 Script executed:

#!/bin/bash
# Search for how L0 classification is determined in the codebase
# Look for Belief class definition and lock-related attributes
rg -nP 'class Belief|lock_state|LOCK_USER|LOCK_NONE' --type=py src/ -A2

Repository: robotrocketscience/aelfrice

Length of output: 11136


🏁 Script executed:

#!/bin/bash
# Check for any other mechanisms that classify beliefs as L0 or locked
# Search in models.py and context_rebuilder.py
fd -e py -path '*models.py' -o -path '*context_rebuilder.py' | xargs rg -l 'L0|lock_state' 2>/dev/null || echo "Files not found or no matches"

Repository: robotrocketscience/aelfrice

Length of output: 2128


🏁 Script executed:

#!/bin/bash
# Verify the exact attribute name in Belief dataclass
grep -A 30 "^class Belief:" src/aelfrice/models.py | head -40

Repository: robotrocketscience/aelfrice

Length of output: 1444


🏁 Script executed:

#!/bin/bash
# Confirm there are only these two lock levels
rg -n "LOCK_" src/aelfrice/models.py | grep "Final"

Repository: robotrocketscience/aelfrice

Length of output: 213


Fix attribute name and remove non-existent classification mechanism.

Line 40 contains two errors: (1) the attribute is belief.lock_level, not belief.lock_state, and (2) there is no "otherwise classified as L0" mechanism. The codebase defines exactly two lock levels (LOCK_NONE and LOCK_USER), and L0 beliefs are determined solely by belief.lock_level == LOCK_USER. Rewrite as:

locked: boolTrue when belief.lock_level == LOCK_USER. Locks always render "verbatim" regardless of retention_class.

🤖 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/feature-type-aware-compression.md` at line 40, Update the documentation
to use the correct attribute and remove the incorrect classification mechanism:
change the description for `locked: bool` to state it is True when
`belief.lock_level == LOCK_USER` (not `belief.lock_state`) and remove any
mention of an "otherwise classified as L0" mechanism; also keep the note that
locks always render `"verbatim"` regardless of `retention_class`.

Comment on lines +173 to +177
@hypothesis.given(belief_strategy(), st.booleans())
def test_compress_deterministic(b, locked):
assert compress_for_retrieval(b, locked=locked).rendered \
== compress_for_retrieval(b, locked=locked).rendered
```

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 | 🟠 Major | ⚡ Quick win

Fix tautological determinism property test.

The proposed property test assertion is tautological:

assert compress_for_retrieval(b, locked=locked).rendered \
    == compress_for_retrieval(b, locked=locked).rendered

This calls the same pure function twice with identical inputs and compares the results, which will always pass. It does not meaningfully test determinism (byte-stability across processes, time, or environment).

Consider one of these alternatives:

  1. Multiple calls: Assert that calling the function N times (e.g., 10) on the same input yields identical results:

    results = [compress_for_retrieval(b, locked=locked).rendered for _ in range(10)]
    assert len(set(results)) == 1, "Non-deterministic output detected"
  2. Explicit property: The test as written might be a placeholder. Clarify that the property test should verify that Hypothesis-generated random beliefs always compress deterministically.

The fixture-based regression test mentioned at line 179 is the real determinism gate; this property test should complement it by covering a broader input space.

🤖 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/feature-type-aware-compression.md` around lines 173 - 177, The test
test_compress_deterministic is tautological because it compares two identical
calls; change it to call compress_for_retrieval(b, locked=locked) multiple times
(e.g., N=10) and assert all .rendered results are identical, or otherwise
restructure the Hypothesis property to produce a list of results and assert
len(set(results)) == 1; update references to compress_for_retrieval and the
.rendered attribute in the test to implement this non-tautological determinism
check.

Per-retention-class compression of retrieved beliefs at fixed
token_budget. Strategy table:

  fact      -> verbatim
  snapshot  -> headline (first sentence, 240-char truncation cap)
  transient -> stub ("[stub: belief={id} class=transient]")
  unknown   -> verbatim (migration safety)
  locked    -> verbatim regardless of retention_class

Pure deterministic transform — no LLM. Bench-gates: strictly positive
recall@k uplift on a labeled compression_uplift fixture, and
continuation-fidelity uplift through the v1.4 context rebuilder
(#141).

Substrate prereqs all on main: retention_class column and per-source
defaults (#290, v1.6.0); pack loops at retrieval.py:1048-1085 +
:1197-1232; flag-resolution convention at retrieval.py:118-131.
@robotrocketscience
robotrocketscience force-pushed the docs/issue-434-type-aware-compression-spec branch from 5c1ec42 to 34ddfb8 Compare May 5, 2026 19:50
@robotrocketscience
robotrocketscience merged commit 34ddfb8 into main May 5, 2026
15 checks passed
@robotrocketscience
robotrocketscience deleted the docs/issue-434-type-aware-compression-spec branch May 5, 2026 19:51
@yoshi280

yoshi280 commented May 5, 2026

Copy link
Copy Markdown
Collaborator Author

[release:review:Toug:2026-05-05T19:51:23Z]

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

Labels

attn:merge-conflict PR branch needs rebase attn:review Needs review (PR open, awaiting reviewer) docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants