fix(6252): a prompt that names nothing gets no notes menu
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / integration (push) Successful in 1m3s
CI & Build / Python tests (push) Failing after 1m26s
CI & Build / Build & push image (push) Skipped

"keep going", "yes please do", "is it deployed?": with no word of its own the
auto-inject query was the previous reply's tail alone, and the menu handed
back the records that reply was built from. In a sample of 59 logged calls,
28 came from short prompts; those with a subject of their own ("continue into
DRY 14", "fix the Windows gate") led with the record meant, while the ones
without were finished tasks already in context, with an open on 2 of about 15.

_has_subject checks the operator's words against a list of words that name
nothing; without one, the ranked menu is skipped and records named by number
are still shown. The prompt rule arm is unchanged and still searches with the
tail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 19:51:58 -04:00
co-authored by Claude Opus 5.5
parent 1fa9245bbf
commit dac4c59e07
4 changed files with 126 additions and 22 deletions
+61 -19
View File
@@ -402,11 +402,13 @@ _CONCEPT_MIN_CHARS = 16
_AUTOINJECT_MAX_TOP_K = MAX_BUDGET
# THE CONVERSATION BESIDE THE PROMPT. The operator's message alone is a weak
# query mid-session: it is mostly a follow-up — "yes do that", "now fix the
# filter" — that names nothing a record could match. The hook sends the tail of the last assistant reply as `context`, and it is
# appended to a SHORT prompt only: a prompt that already says what it is about
# is the better query on its own, and diluting it is the one way this can make
# retrieval worse.
# query mid-session: it is mostly a follow-up — "now fix the filter" — that
# names too little for a record to match. The hook sends the tail of the last
# assistant reply as `context`, and it is appended to a SHORT prompt only: a
# prompt that already says what it is about is the better query on its own,
# and diluting it is the one way this can make retrieval worse. A prompt that
# names nothing at all ("yes do that") gets no notes menu (`_has_subject`);
# the prompt rule arm still searches it with the tail.
#
# Neither number costs a model token. The query is embedding input; what the
# session pays for is the menu, and the budget bounds that unchanged.
@@ -418,6 +420,42 @@ _AUTOINJECT_CONTEXT_PROMPT_MAX = 280
_AUTOINJECT_CONTEXT_MAX = 600
# WORDS THAT NAME NO SUBJECT. A prompt made only of these ("keep going", "yes
# please do", "1. yes 2. yes", "is it deployed?", "what is next?") is a turn of
# the conversation, not a question about anything. Its query would be the
# previous reply's tail alone, and the menu would hand back the records that
# reply was built from, which the session already has in context. One word
# outside this list ("now fix the filter") is a subject, and the prompt is
# searched as usual.
_NO_SUBJECT_WORDS = frozenset("""
a about above after again agreed ahead all already also am an and any
anything approved are as asked at awesome back be been before both build
but by can carry ci commit continue continuing could cool correct
deploy deployed described did do does done each else every everything
fine finish first fix for from get go going good got great green had has
have he here hold how i if im in instead into is it its just keep know
last left let lets like looks loose lgtm make may maybe me mentioned merge
milestone more move my next nice no not now of off ok okay on one open or
order other our out over pass passes passing perfect please previous
proceed project proposed push ready really recommended redeploy rest right
said same see she ship should so some sounds stack stacking start step
steps still stop suggested sure task tasks thank thanks that the them then
there these they thing things this those through to try up us waiting
want was we well were what whats when where which while who why will with
work would yeah yep yes yet you your
""".split())
def _has_subject(prompt: str) -> bool:
"""Does the operator's message name anything a record could be about?
Numbers are left out: a record named by number is looked up by id, not
matched, so it never needs the ranked menu to be found.
"""
words = re.findall(r"[a-z]+", prompt.lower().replace("'", ""))
return any(w not in _NO_SUBJECT_WORDS for w in words)
def _autoinject_query(prompt: str, context: str) -> str:
"""The prompt, with recent conversation appended when the prompt is thin.
@@ -612,10 +650,6 @@ async def build_autoinject_hint(
# left to a ranking that can only match the words around them.
named = await _named_records(user_id, record_refs_svc.named_record_ids(q))
named_ids = [int(n.id) for n in named]
# Everything below searches, logs and fills its slots on the ENRICHED
# query, so the telemetry row records what was actually asked.
q = _autoinject_query(q, context)
# THE LEDGER IS A RENDERING FACT, NOT A RETRIEVAL ONE. Excluding seen ids
# from the search would make the second time a note is the best answer
# SILENCE, indistinguishable from "nothing matched", and would measure
@@ -629,15 +663,23 @@ async def build_autoinject_hint(
# lesson slots in that order, and the surfacing rows are written there.
# What is decided HERE is what makes this moment this moment — the query
# the operator's words became, and the records they named by number.
result = await rp.run_note_arm(
rp.AUTO_INJECT,
rp.NoteMoment(
user_id=user_id, query=q, project_id=project_id,
seen=frozenset(already), named=frozenset(named_ids),
),
floor=cfg["threshold"], budget=cfg["top_k"], io=_note_io(),
)
kept = result.menu
if not _has_subject(q):
# Nothing to search for: the menu would answer the previous reply,
# not the operator. Records named by number are still shown.
kept, chunks = [], {}
else:
# Everything below searches, logs and fills its slots on the ENRICHED
# query, so the telemetry row records what was actually asked.
q = _autoinject_query(q, context)
result = await rp.run_note_arm(
rp.AUTO_INJECT,
rp.NoteMoment(
user_id=user_id, query=q, project_id=project_id,
seen=frozenset(already), named=frozenset(named_ids),
),
floor=cfg["threshold"], budget=cfg["top_k"], io=_note_io(),
)
kept, chunks = result.menu, result.chunks
if not kept and not named:
return empty
@@ -739,7 +781,7 @@ async def build_autoinject_hint(
# a reason, and a reader cannot tell the two apart once indented alike.
passage = "" if nid in already else _menu_passage(
document_title(note.title, note.note_type, note.data, note.body),
(result.chunks.get(nid) or {}).get("text"), name,
(chunks.get(nid) or {}).get("text"), name,
)
who = _shared_by(note)
lines.extend(menu_entry(