Skip to content

Return use guidance with retrieved knowledge - #1510

Open
krishnadobhal wants to merge 18 commits into
ClickHouse:mainfrom
krishnadobhal:feat/retrieved-use-guidance
Open

krishnadobhal wants to merge 18 commits into
ClickHouse:mainfrom
krishnadobhal:feat/retrieved-use-guidance

Conversation

@krishnadobhal

@krishnadobhal krishnadobhal commented Nov 26, 2026 •

Copy link
Copy Markdown

Closes: #1230

Changelog category

  • New Feature

Changelog entry

Loom suggests how to use retrieved memories, documents, procedures, and code lessons. Dashboard search shows the suggested step and the reasons behind it.

Why

A relevant result can still be out of date, disputed, or waiting for review. Loom now uses the lifecycle, review, freshness, and dispute evidence available to the caller to recommend what to do with the result.

Scope and risk

  • Search checks the current revision and caller access before serving parked hits. A replacement with the same version and different content cannot inherit the parked hit’s guidance. Older cursors without a content hash cannot inherit review approval.
  • If search replaces a hit’s text with a source passage, it drops the original guidance. An expanded memory body keeps guidance only when its version and content hash match.
  • memory.verify now mirrors the exact attestation version to embeddings that still match the reviewed content. The mirror runs asynchronously, and search still requires matching revisions before attaching review evidence.
  • Postgres-backed stacks check the authoritative head before serving pinned or recent entries from ClickHouse. File recall, code lessons, and stacks account for procedure status, including quarantine.
  • Source freshness respects caller access. A readable citation without a recorded source revision stays unknown. Context packs attach guidance to the citations they render.

Compatibility, rollout and rollback

  • memory.search, memory.for_file, knowledge.search, procedure.match, and memory.stack add optional use_guidance. search.query types its memory and knowledge sections and preserves guidance in compact MCP responses. Reader blocks can include the suggested step.
  • context.pack returns guidance keyed by section, citation, and item index. Code lessons add optional guidance in code.callees, code.callers, code.context_pack, code.enclosing, code.grep, code.impact, code.outline, code.read, code.search, and code.symbol.
  • The code operations listed above now return typed CodeLesson rows in the Python and TypeScript SDKs. In Python, pass dict(row) to helpers that require dict[str, Any], or change read-only helpers to accept Mapping[str, Any]. In TypeScript, use row[key] with a key typed as keyof CodeLesson. For an arbitrary string key, copy the row into const fields: Record<string, unknown> = { ...row }, then narrow fields[key] before using it. Rust lesson rows remain maps.
  • Generated clients include the new types and accept responses from older servers that omit guidance. No operator steps or data migrations are required. Reverting removes the guidance fields and dashboard labels.

Tests

  • The final review fixes passed 125 focused unit tests, targeted Ruff and mypy checks, and git diff --check. The Windows unit run used temporary stand-ins for two Unix-only imports.
  • Earlier validation passed 580 focused Python tests and 27 focused dashboard tests, along with the Linux dashboard build and bundle budget. The full Windows frontend run hit a filename case collision.
  • Before the attestation fix, live ClickHouse checks reproduced the search and file recall mismatch after both process and human verification. Focused unit tests cover the exact version and content hash guard. The live lifecycle test still needs a rerun with auth off and on.
  • Earlier live probes passed for parked-page revocation and erasure, withholding freshness for unreadable sources, compact MCP guidance, and review becoming stale after a content edit. Those probes have not been rerun on the current head. Live Postgres and dashboard checks are pending.

AI assistance in the code

  • AI-generated. I designed and reviewed the change. Codex assisted with implementation and testing.

Checklist

  • Local format, lint, type checks and focused tests pass.
  • Applicable generated files were regenerated and checked.
  • Frontend build and tests pass on the submitted commit.
  • Docs describe use guidance, and this description names the operator steps and wire changes.
  • Commits are signed off.

Note

Medium Risk
Touches core retrieval, context assembly, and attestation/revision checks across many ops; incorrect precedence or revision binding could mislead agents, but changes are additive and backward compatible.

Overview
Adds use_guidance on maintained retrieval results: a deterministic next_step (e.g. follow_if_applicable, recheck_source, validate_lead) plus ordered reasons, derived from lifecycle, review, attestation, source/code freshness, and dispute evidence for the served revision after authorization.

The field is wired through memory search, unified search, knowledge search, file recall, procedure match, memory stack, context.pack (per citation), and code lessons on code ops. API references and generated Python/TypeScript/Rust clients introduce UseGuidance, CodeLesson, and related types; lessons move from loose dicts to CodeLesson.

Dashboard search and Recall Lab show suggested use via GuidanceLabel; opening a hit uses exact writer identity (verifyWriter / inspectedScope) so namesake keys do not load the wrong row. Docs add “Using retrieved guidance” with the precedence table and cross-links from search docs.

Compatibility: guidance is optional on the wire; older servers and clients without the field keep working.

Reviewed by Cursor Bugbot for commit acf18cc. Bugbot is set up for automated code reviews on this repo. Configure here.

@cla-assistant

cla-assistant Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 26, 2026 7:45pm UTC
loom-telemetry Ready Ready Preview Nov 26, 2026 7:45pm UTC

Request Review

@krishnadobhal
krishnadobhal force-pushed the feat/retrieved-use-guidance branch from cd4010a to e78e001 Compare November 26, 2026 05:52
@krishnadobhal
krishnadobhal marked this pull request as ready for review November 26, 2026 05:52
Copilot AI balanced review requested due to automatic review settings November 26, 2026 05:53

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/use_guidance.py Resolved
Comment thread server/memory/app/search/output.py Resolved
Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/use_guidance.py Resolved
Comment thread server/memory/app/stack.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The current head drops eligible historical results from continuation pages and can give search and file recall different review states for the same attested content. The inline findings cover these regressions and other read and client paths. The existing source-freshness thread also still applies. Source freshness discussion

Verified against the exact head by tracing the read paths and checking the existing regression assertions. Full integration results are pending.

Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/code_link_reads.py Resolved
Comment thread server/memory/app/use_guidance.py Resolved
Comment thread server/memory/app/path_lessons.py Resolved
Comment thread server/memory/app/for_file.py Resolved
Comment thread frontend/src/components/SearchWhy.tsx Resolved
Comment thread server/code/api/models_common.py Resolved
Comment thread sdk/python/loom/memory.py Resolved

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/handlers.py Resolved
Comment thread server/memory/store/pg_memory.py Resolved
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member

plz fix merge conflicts

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The current head returns expired facts on as_of continuation pages. The history lookup failure and Postgres history metadata also need changes before this can merge.

Comment thread server/memory/app/search/guidance.py Resolved

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/search/output.py Resolved
Comment thread frontend/src/views/RecallLab.tsx Resolved
Comment thread server/memory/app/context_pack.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The head fixes the live-row expiry check. An edited historical revision can still pass after its own expiry, and memory.touch skips the expiry mirror for rows written before content hashes. Both cases were reproduced against this head.

The format job also fails on docs/features/memory/history-and-provenance.md. Format job

Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/handlers.py Resolved
Comment thread server/transport/mcp_tools.py Resolved
@zlareb1

zlareb1 commented Nov 26, 2026

Copy link
Copy Markdown
Member

The tunable-constant check reports the same five constants on this PR and on clean main. The check passes with the tracked repair. Failed job · Repair #1503

Comment thread server/memory/store/history.py Resolved
Comment thread sdk/python/loom/memory.py Resolved
Comment thread server/memory/app/use_guidance.py Resolved
Comment thread server/memory/app/handlers.py Resolved

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/search/guidance.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The expiry and hashless-touch fixes are present. The search verdict can still describe a hit the response discarded, and the generated Python and TypeScript clients change existing code-lesson types. The decision pack and Recall Lab threads still apply. The format job failed on a document whose contents and formatter inputs are unchanged.

Comment thread server/memory/app/search/output.py Resolved
Comment thread server/code/domain/lesson.py Resolved
A head recheck can remove evidence after the verdict is computed. Recompute confidence and abstention from retained hits. Verify that a single-key touch reads live embeddings with the full identity in the batch query.

Signed-off-by: Krishna Dobhal <[email protected]>
Recount support for the surviving evidence when the verdict pool shrinks. Keep the same fallback when the support lookup fails.

Signed-off-by: Krishna Dobhal <[email protected]>
Bind namespace and memory key as a pair so a dropped hit cannot contribute support through two surviving hits in different namespaces.

Signed-off-by: Krishna Dobhal <[email protected]>

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/search/verdict.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Search can lose an extended TTL or drop guidance from a matching result, and code.symbol drops an existing lesson field. The decision-pack finding also remains. It compares the clipped search excerpt to the full statement and drops the structured decision fields when they differ. The Python and TypeScript lesson migrations are documented at this head.

Comment thread server/memory/app/handlers.py Resolved
Comment thread server/memory/app/search/payload.py Resolved
Comment thread server/code/domain/lesson.py Resolved
Comment thread server/memory/store/code_plane_reads.py Resolved
Carry authoritative expiry through verification, keep guidance on matching tier bodies, and preserve structured decisions and linked symbols in serialized results.

Signed-off-by: Krishna Dobhal <[email protected]>
Match the full served text when a guided hit has no content digest. A clipped excerpt still needs a matching hash before structured fields are attached.

Signed-off-by: Krishna Dobhal <[email protected]>

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread server/memory/app/handlers.py Resolved
Comment thread server/memory/app/search/guidance.py Resolved
Comment thread server/memory/app/search/guidance.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Guidance still loses current review evidence after a metadata-only write, and recall reads entire bodies to classify matches. Recall Lab still opens a different memory for same-key hits. The decision-pack digest fix is present.

denied.add(i)
continue
digest = hash_text(row.get("content_sha256"))
if int(row.get("version") or 0) == version or (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — memory.lock and memory.unlock advance the authoritative row version without changing the body, review, or vector. A dense search then sees the older vector version and drops the review, while memory.for_file still shows it. Bind review to verified content identity across metadata-only revisions and extend the parity test through lock and unlock.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 43a91ac4. Search keeps the review through lock and unlock as long as the content hash still matches. The parity test passed against local ClickHouse and confirmed that editing the body makes the review stale.

Comment thread server/knowledge/app/document_reads.py Resolved
Comment thread server/memory/app/for_file.py Outdated
SELECT
memory_key, memory_type,
if({{full_values:UInt8}}, value, substring(value, 1, {_READ_BYTES})) AS value,
{PROCEDURE_GUIDANCE_VALUE},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — The procedural projection transfers full JSON despite the 600-byte limit on the display projection. A file recall can read up to 50 large values to classify a handful of fields. Project the fields the classifier needs and retain the display bound.

Comment thread server/memory/app/context_pack.py Resolved
Bind review to matching content across metadata writes. Project source and procedure evidence for recall and keep Recall Lab results tied to their writer.

Signed-off-by: Krishna Dobhal <[email protected]>

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 43a91ac. Configure here.

valid_at=_iso_date(str(r.get("valid_at", ""))),
status=str(r.get("status") or ""),
version=int(r.get("version") or 0),
content_sha256=str(r.get("content_sha256") or ""),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Vector digest uses str not hash_text

High Severity

Search records the embedding content_sha256 with str() instead of hash_text(). On the native client a FixedString(64) arrives as bytes, so the stored digest becomes a Python repr and is not a content hash. Live guidance then treats a version match as unbound content, and a lock or unlock that only bumps the head version cannot match the older vector, so dense search drops a still-valid review.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 43a91ac. Configure here.

Require the closing citation bracket in the rendered pack. Cover cutoffs inside a citation at both budget limits.

Signed-off-by: Krishna Dobhal <[email protected]>
@krishnadobhal

Copy link
Copy Markdown
Author

still making changes don't review it now

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The digest finding is confirmed on this head. The native driver returns FixedString as bytes, so str() leaves the b'…' wrapper and review drops after a metadata-only lock revision. Decode the digest consistently across retrieval legs. The current head also needs to preserve page inclusion and bind dashboard guidance to the selected row.

def _status_kept(
status: str, hit: _MemorySearchHit, input: MemorySearchInput, *, parked: bool
) -> bool:
if parked and hit.status and hit.status == status:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — An anchor hit selected with include_superseded=true is parked without its status because the anchor SQL does not select it. Continuing with only the returned page handle then drops the unchanged hit. Carry the selected status or original diagnostic options into the parked page and cover a handle-only continuation.

# requested, so the key is dropped.
data: dict[str, Any] = handler(self)
if self._row_identity is not None:
data["agent"], data["user_id"], data["session_id"] = self._row_identity

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — user_id is injected during serialization but has no field on _MemorySearchHit. The response schema and generated SDKs therefore omit the field that the dashboard uses to identify the row. Declare the optional output field and regenerate the contracts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

test_writer_serialization_honors_projection fails on this head too. A hit requested with only memory_key still serializes agent, user_id, and session_id because this serializer adds them after projection. Keep the writer fields subject to the same projection as other hit fields. Failed unit job

<div className="flex min-w-0 flex-wrap items-center gap-1.5">
<button
type="button"
disabled={!hasWriter(row.writer)}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — This disables inspection of ranked-only results from an older replica during a rolling upgrade, since its search hits omit user_id. Keep inspection available when the returned identity and key resolve to one verified row, and keep ambiguous namesakes unselectable. Cover both cases.

{hit.use_guidance && (
<>
<p>Matched text: {hit.content_excerpt}</p>
<GuidanceLabel hit={hit} reasons />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

P2 — Memories stores ranked hits by memory_key, so two visible same-key rows from different sessions receive the same guidance even if only one was ranked. Header search also opens the selected hit by key and agent without its session. Carry the selected row's identity through both paths and test two same-key rows with one ranked match.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tell agents how retrieved knowledge may be used

3 participants