Skip to content

fix(core): use Observation.permalink in build_context to match the search index#946

Merged
phernandez merged 1 commit into
mainfrom
fix/issue-929
Jun 10, 2026
Merged

fix(core): use Observation.permalink in build_context to match the search index#946
phernandez merged 1 commit into
mainfrom
fix/issue-929

Conversation

@groksrc

@groksrc groksrc commented Jun 10, 2026

Copy link
Copy Markdown
Member

Fixes #929

Summary

build_context rebuilt the synthetic observation permalink inline:

generate_permalink(f"{primary_item.permalink}/observations/{obs.category}/{obs.content}")

with no 200-char truncation (#446) and no content digest (#931), so for observations longer than 200 chars it returned permalinks that don't exist in the search index.

As suggested in the issue: use the Observation.permalink model property instead, so there is exactly one place that defines the synthetic observation permalink format. No lazy-load hazard — ObservationRepository.get_load_options() already eager-loads Observation.entity, and execute_query applies those options to the find_by_entities query that feeds build_context.

Test plan

  • New regression test test_build_context_observation_permalinks_match_search_index: a >200-char observation's permalink from build_context must equal both the model property and the indexed row's permalink. Verified it fails against the previous inline construction.
  • tests/services/test_context_service.py — 13 passed (SQLite), 12 passed / 1 pre-existing skip (Postgres via testcontainers)
  • test-int/mcp/test_build_context_validation.py + test_build_context_underscore.py — 8 passed
  • ruff check, ruff format --check, ty check src tests test-int — clean

Not included

The issue's second item — release notes for the #931-shipping version mentioning that pre-existing search_index rows keep digest-less permalinks until re-sync or bm reindex --search — belongs to the release runbook, not this change.

🤖 Generated with Claude Code

…atch the search index

build_context rebuilt the synthetic observation permalink inline with no
200-char truncation (#446) and no content digest (#931), so for long
observations it returned permalinks that don't exist in the search
index. Use the Observation.permalink model property instead — the single
definition of the format; the parent entity is already eager-loaded by
ObservationRepository's load options.

Regression test asserts the permalink returned by build_context equals
the model property and the indexed row's permalink for a >200-char
observation; it fails against the previous inline construction.

Fixes #929

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Drew Cain <groksrc@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@phernandez phernandez merged commit 7bb7664 into main Jun 10, 2026
23 of 25 checks passed
@phernandez phernandez deleted the fix/issue-929 branch June 10, 2026 19:05
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.

build_context returns digest-less observation permalinks that diverge from the search index

2 participants