feat(lock): inject reference-tier locks as a bounded manifest (#1016-B) - #1037
Conversation
Second slice of layered locks: at the hook injection paths (UPS + SessionStart) a reference-tier lock renders as a one-line manifest entry (ref <id>: "<topic>") inside an <aelfrice-locks-manifest> block instead of full text; the agent reads full text on demand via aelf locked/search. retrieve() gains manifest_reference_locks (hook paths pass it): reference locks then cost only their manifest line, freeing relevance budget fat locks otherwise consume (#1014/#1015). Topic is a deterministic string transform (first sentence or 80-char cap, no ML). Frozen locks unchanged; byte-identical until a lock is demoted to reference (default flag off), so existing stores, the rebuilder, aelf search, and benches are unaffected. Rebuild-block + search-tool formatters still render reference verbatim (follow-up).
Reviewer's GuideImplements bounded injection for reference-tier locks by rendering them as a one-line manifest in hook formatters and updating retrieval budgeting to treat reference locks as manifest-sized instead of verbatim, with behavior gated by a new manifest_reference_locks flag and covered by acceptance tests. Sequence diagram for bounded manifest injection of reference-tier lockssequenceDiagram
actor User
participant hook as hook
participant retrieval as retrieval
participant lock_tokens as lock_injection_tokens
participant manifest_line as lock_manifest_line
User->>hook: _format_hits / _format_hits_with_session_start
hook->>retrieval: retrieve(store, prompt, token_budget, manifest_reference_locks=True)
retrieval->>lock_tokens: lock_injection_tokens(belief, manifest_reference_locks=True)
alt is_reference_lock(belief)
lock_tokens->>manifest_line: lock_manifest_line(belief)
lock_tokens-->>retrieval: token cost of manifest line
retrieval-->>hook: hits with reference locks bounded
hook->>hook: _split_belief_lines(hits)
hook->>hook: _manifest_block_lines(manifest_lines)
hook-->>User: memory/baseline with <aelfrice-locks-manifest>
else not is_reference_lock(belief)
lock_tokens-->>retrieval: _belief_tokens(belief)
retrieval-->>hook: hits with full content
hook-->>User: memory/baseline with verbatim <belief> lines
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
PR-size soft capThis PR is over the advisory size threshold:
Bigger PRs collide with more open work, which under the parallel-session workflow tends to produce repeated This is advisory only — nothing is blocked. If the size is intentional (large refactor, module removal, generated code), apply the |
|
Warning Review limit reached
Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The token budgeting for reference locks only accounts for the manifest line itself; if you want tighter alignment with actual injection size, consider also including the manifest block wrapper tags in the locked token cost.
- The
_lock_topicsentence splitting is limited to'. ','? ', and'! '; if lock content often uses different punctuation (e.g. line breaks, colon, semicolon) for sentence boundaries, you may want to broaden the delimiter handling to keep topics semantically sharper.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The token budgeting for reference locks only accounts for the manifest line itself; if you want tighter alignment with actual injection size, consider also including the manifest block wrapper tags in the locked token cost.
- The `_lock_topic` sentence splitting is limited to `'. '`, `'? '`, and `'! '`; if lock content often uses different punctuation (e.g. line breaks, colon, semicolon) for sentence boundaries, you may want to broaden the delimiter handling to keep topics semantically sharper.
## Individual Comments
### Comment 1
<location path="src/aelfrice/retrieval.py" line_range="562-570" />
<code_context>
+_LOCK_TOPIC_MAX: Final[int] = 80
+
+
+def _lock_topic(content: str) -> str:
+ """Deterministic one-line topic for a reference lock's manifest entry.
+
+ Whitespace-collapsed; the first sentence if it ends within the cap,
+ else a hard char-cap with an ellipsis. No ML — a pure string
+ transform so the manifest is reproducible. Internal double-quotes are
+ flattened to single so the `"<topic>"` wrapper stays unambiguous.
+ """
+ collapsed = " ".join(content.split()).replace('"', "'")
+ if not collapsed:
+ return ""
</code_context>
<issue_to_address>
**🚨 issue (security):** Manifest topic generation does not escape `<` / `&`, which may break the surrounding XML-like hook block.
Because `lock_manifest_line` is written directly into `<aelfrice-locks-manifest>` and `_lock_topic` only normalizes whitespace and quotes, any tag-like or entity-prefixed content (e.g. starting with `<script>` or `&...`) can be interpreted as markup rather than text. Please apply the same escaping as `_escape_for_hook_block` (or reuse that helper) when building `lock_manifest_line` so manifest entries are treated as literal content and cannot inject markup into the hook block.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…review) Run the manifest line through _escape_for_hook_block like belief content, so a reference lock cannot spoof the <aelfrice-memory>/<aelfrice-baseline> envelope via a framing tag in its topic. Addresses Sourcery security note.
|
merge-train: merged e306ef5 → |
Part of #1016 — the second slice of #1016-B, building on the
lock_tierfield (PR #1036). This is the behavior-delivering slice: it actually bounds reference-lock injection and frees relevance budget. Does not close the umbrella.What
At the two hook injection paths — per-prompt
UserPromptSubmitandSessionStart— areference-tier lock now renders as a one-line manifest entry instead of full text:retrieve()gainsmanifest_reference_locks(the hook paths pass it): reference locks then cost only their manifest line in the budget, freeing relevance budget that fat locks otherwise consume (the #1014/#1015 starvation the bound targets). The topic is a deterministic string transform (first sentence, or an 80-char cap with ellipsis — no ML, per the locked determinism philosophy #605).Safety: byte-identical until demotion
lock_injection_tokens(frozen) == _belief_tokens, themanifest_reference_locksdefault is off, and every lock isfrozenuntil the user demotes it. So existing stores, the rebuilder,aelf search, the search-tool hook, and all benchmarks are byte-identical — the new path only activates for locks explicitly demoted toreference.Scope kept tight to the two always-injected formatters +
retrieve(). The rebuild-block and search-tool formatters still render reference locks verbatim (their ownretrievecalls keep the default-off budget, so they stay consistent — verbatim render + verbatim cost); folding them into the manifest is a follow-up.Tests
tests/test_lock_manifest_injection.py: deterministic topic + cap, manifest-line shape, token accounting (reference < full when flagged; frozen always full),is_reference_lock, formatter manifestizes reference / byte-identical without reference locks, and aretrieve()budget-freed assertion under budget pressure.Verification
5463 passed, 66 skipped, 75 xfailed(core retrieval/injection path — no regressions).uvx vulture … --min-confidence 80→ clean.uvx typos→ clean.🤖 Generated with Claude Code
Summary by Sourcery
Render reference-tier locks as bounded manifest entries at hook injection paths and account for their reduced injection cost in retrieval budgeting, while keeping behavior byte-identical until locks are demoted.
New Features:
ref <id>: "<topic>"entries in UserPromptSubmit and SessionStart hook outputs.retrieve()with amanifest_reference_locksflag to treat reference-tier locks as manifest-sized for budgeting in specific injection paths.Enhancements:
Documentation:
Tests: