fix(7716): the reply shape rides after the top two rule lines, so a compaction cannot push it out
CI & Build / Python lint (push) Successful in 1s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m28s
CI & Build / integration (push) Successful in 2m23s
CI & Build / Build & push image (push) Successful in 25s

A compaction sweeps the rule ledger as well as the shape ledger. On the
next prompt every rule the prompt arm reaches and every rule mounted on
reply.report comes back as a first mention with its statement (about 750
characters each), and the route placed all of them ahead of the shape. Six
fill the 4,500-character default budget, so the 2,343-character core was
left out on exactly the turn it is meant to return in full. Seen in a real
session: after 9 of 10 compactions the first prompt payload carried no
reply shape at all.

The prompt payload is now ordered as milestone 639 designed it: the first
two rule lines, the reply shape, the remaining rule lines, the reply's
lessons, the carried note, the records menu. Rules that do not fit stay off
the ledger and arrive on a later call.

The lesson-placement test now pins the lesson after the shape (a lesson
binds nothing; the shape is what the reply is written to). New test: six
full-length rule lines and the real core at the default budget; the shape
is kept and the later rules wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 10:03:46 -05:00
co-authored by Claude Opus 5.5
parent 3ad7d93386
commit a3c4cc5921
2 changed files with 79 additions and 22 deletions
+34 -20
View File
@@ -133,6 +133,10 @@ async def session_context():
# The longest carried note a prompt takes: the shape check's note names a
# few definitions and the call that lists the rest.
_CARRY_CHARS = 3000
# How many rule lines ride ahead of the reply shape in the prompt payload: the
# default budget (hook_payload.DEFAULT_BUDGET) is sized for the core shape
# beside two full rule lines.
_LEAD_RULES = 2
@plugin_bp.get("/retrieve")
@@ -183,12 +187,15 @@ async def autoinject_retrieve():
nobody has judged (/shape-check's `note`).
Fitted after the reply shape, before the records.
ONE PAYLOAD, IN ONE ORDER, UNDER ONE BUDGET (`hook_payload`): the rules
this prompt reaches and those mounted on `reply.report`, then the turn's
reply shape, then the records menu. Every turn ends in a reply and this
is the last point before it is written, so the shape rides every call;
what does not fit is left off the ledgers and can arrive on a later call.
Shape keys sent in full come back as `shape_keys` for the ledger.
ONE PAYLOAD, IN ONE ORDER, UNDER ONE BUDGET (`hook_payload`): the first
two of the rule lines this prompt reaches and those mounted on
`reply.report`, then the turn's reply shape, then the remaining rule
lines, the reply's lessons, and the records menu. Every turn ends in a
reply and this is the last point before it is written, so the shape rides
every call and is placed where a full set of rule statements cannot push
it out; what does not fit is left off the ledgers and can arrive on a
later call. Shape keys sent in full come back as `shape_keys` for the
ledger.
TWO ARMS, TWO SETS OF GATES. Rules ride the same hook and the same query
but nothing else: the notes menu can be disabled, thresholded and top-k'd
@@ -196,10 +203,10 @@ async def autoinject_retrieve():
here rather than inside either builder so neither one's early return can
silently suppress the other.
Rules come FIRST in the payload. A rule or preference governing the answer
is more consequential than a menu of things that might be worth reading,
and a reader who stops after the first block should have stopped after
the right one.
The top rules come FIRST in the payload. A rule or preference governing
the answer is more consequential than a menu of things that might be
worth reading, and a reader who stops after the first block should have
stopped after the right one.
"""
q = (request.args.get("q") or "").strip()
project_id, _repo, _unbound = await _project_scope()
@@ -224,24 +231,31 @@ async def autoinject_retrieve():
held=frozenset(held_rule_ids),
record=False,
)
# One payload, in the one order: the rules, then the reply shape, then
# what the last turn left unjudged, then the records menu, fitted to the
# budget.
# One payload, in the one order, fitted to the budget: the top rule lines,
# the reply shape, the remaining rule lines, the lessons recorded for the
# reply, what the last turn left unjudged, then the records menu.
#
# The shape sits after only the first _LEAD_RULES lines. A compaction
# sweeps the rule ledger as well as the shape ledger, so every rule then
# comes back as a first mention with its statement: six of those fill the
# default budget on their own, and with every rule ahead of it the shape
# was left out on exactly the turn it is meant to return in full.
carry = (request.args.get("carry") or "").strip()[:_CARRY_CHARS]
# Lessons recorded for the reply, once per session: booked in the record
# ledger only if the fit keeps their line.
record_deliveries_svc.record(g.user.id, turn.get("lesson_ids") or [], "lesson_situation")
turn_parts = (
[*turn["rule_parts"], *turn.get("lesson_parts", []), *turn["shape_parts"]]
if "shape_parts" in turn
else [hook_payload_svc.Part(text=turn.get("context") or "", ids={
prompt_rules = hook_payload_svc.parts_of(rules, {hook_payload_svc.RULE: "shown_rule_ids"})
if "shape_parts" in turn:
every_rule = [*prompt_rules, *turn["rule_parts"]]
lead = every_rule[:_LEAD_RULES]
ordered = [*lead, *turn["shape_parts"], *every_rule[_LEAD_RULES:], *turn.get("lesson_parts", [])]
else:
ordered = [*prompt_rules, hook_payload_svc.Part(text=turn.get("context") or "", ids={
hook_payload_svc.RULE: tuple(turn.get("rule_ids") or ()),
hook_payload_svc.SHAPE: tuple(turn.get("shape_forms") or ()),
})]
)
fitted = await hook_payload_svc.fit(g.user.id, [
*hook_payload_svc.parts_of(rules, {hook_payload_svc.RULE: "shown_rule_ids"}),
*turn_parts,
*ordered,
*([hook_payload_svc.Part(text=carry)] if carry else []),
*hook_payload_svc.parts_of(result, {hook_payload_svc.NOTE: "note_ids"}),
])