hindsight icon indicating copy to clipboard operation
hindsight copied to clipboard

A re-retain without `observation_scopes` takes the bank's default scope off the facts it keeps

Open Cosmonaut79 opened this issue 2 weeks ago • 0 comments

Seen on a self-hosted Hindsight 1.2.1 (API image by digest, PostgreSQL 16) and checked against main at 31d5556 (19 Nov 2026). Paths are under hindsight_api/; line numbers are those of the 1.2.1 image.

What happens

A bank has default_observation_scopes: "shared" in its config.

  1. A document is retained under a fixed document_id. Its facts carry observation_scopes = "shared", whether the request named the scope or left it out: _apply_default_observation_scopes gives the bank's default to freshly extracted facts (engine/retain/fact_extraction.py 3822 to 3833).
  2. The same document_id is retained again, and the request does not name observation_scopes.
  3. Chunks whose text changed are extracted again. Their facts get the default, "shared".
  4. Chunks whose text did not change keep their facts, and those facts are relabelled with the request's own value, which is None: engine/retain/orchestrator.py hands retain_params.get("observation_scopes") to fact_storage.update_memory_units_metadata_and_tags at 1406, 4555, 4739 and 4789, and the store writes it over the survivors (engine/retain/fact_storage.py 553 to 562).

After a partial change the document has two kinds of facts: re-extracted ones in the bank's scope, and kept ones without a scope. After a re-retain of the identical text (the "DELTA RETAIN (no changes)" path, orchestrator 4739 and 4789) every fact of the document is relabelled.

Because the scope of the kept facts changed, the same function deletes the observations built on them and marks the facts as not consolidated (fact_storage.py 563 to 573). They are then consolidated again, without the bank's scope, so their observations are built apart from the rest of the bank.

Why it looks like a fault and not a choice

  • The relabel exists, in the words of its docstring, so that the optimised delta retain "matches a full replace" (fact_storage.py 490 to 494). A full replace gives every fact the bank's default.
  • The comment above the call at orchestrator.py 1398 to 1402 names the aim: without the relabel a partial re-retain left "a document whose units disagreed on their labels by whether their chunk happened to change". For the scope, the relabel now causes exactly that.
  • The request field's own description says: "When omitted, the bank's default_observation_scopes applies" (api/http.py 1315).

Who meets it

  • Every MCP client. mcp_tools.py does not contain the name observation_scopes. Its retain and sync_retain tools (1024, 1085, 1148, 1210) take content, context, timestamp, tags, metadata, document_id, strategy and update_mode. An MCP client that stores an existing document again, in a bank with a default scope, cannot avoid the loss.
  • Any API client that leaves the field out on a re-retain.

A document of one chunk whose text changes is extracted afresh and keeps the scope, so small notes do not show it.

Numbers from this server

  • Reproduced on a copy of the production database, through the HTTP retain without observation_scopes: a made-up note of two chunks, sent twice with one line changed. After the first send: 33 facts, all "shared". After the second: the 17 facts of the unchanged chunk had no scope, and the count of facts outside the bank's scope went from 0 to 17. With observation_scopes: "shared" named in both requests the kept facts stayed "shared" (two more runs).
  • The MCP tools were not used in that test. They cannot name the field, so they send the same request.
  • The identical-text path, on production (the bank's default was already "shared"): a same-text re-retain of 213 documents, made to add a timestamp and sent without the field, wrote "no scope" over "shared". 264 observations were deleted and 307 facts were queued for consolidation again. No LLM call was made by the retains themselves.
  • Exposure in one bank: 47 of 437 documents have more than one chunk; they hold 1,177 of 3,007 facts.
  • Cost of one loss: the kept facts are consolidated twice, once after the loss and once after the repair.

To reproduce

  1. Create a bank and set default_observation_scopes to "shared" in its config.
  2. Retain a text long enough for two chunks under a fixed document_id, without observation_scopes.
  3. select observation_scopes, count(*) from memory_units where bank_id = '<bank>' and document_id = '<id>' and fact_type <> 'observation' group by 1 gives one row, "shared".
  4. Change one line in the second chunk and retain the text again under the same document_id, again without observation_scopes (or through the MCP retain tool).
  5. The query of step 3 now gives two rows: "shared" for the facts of the changed chunk, NULL for the facts of the unchanged one.

Retaining the identical text in step 4 is the shorter way: every fact of the document is kept, so every fact loses the scope, and no LLM call is made (seen on production, see above).

What would fix it

  • Resolve the scope for kept facts as for fresh ones: where the orchestrator hands retain_params.get("observation_scopes") to the relabel, fall back to the bank's default_observation_scopes when the request names none. Or leave the scope of kept facts untouched when the request names none.
  • Give the MCP retain and sync_retain tools an observation_scopes argument.

What is done here meanwhile

  • Writers that use the HTTP API name observation_scopes in every retain.
  • An hourly count of facts whose scope differs from their bank's default, with an alert.
  • The repair is the document PATCH that sets the scope again; nothing is extracted again.

Related

  • #6452: the same relabel in update_memory_units_metadata_and_tags, seen for tags.
  • On main at 31d5556 the four call sites still pass retain_params.get("observation_scopes") (engine/retain/orchestrator.py 1414, 4563, 4747, 4797), and mcp_tools.py does not contain the name.

Cosmonaut79 avatar Nov 19 '26 09:11 Cosmonaut79