OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: Agent Evolution "Application impact" is architecturally disconnected from real trajectory lineage — narrative backlinks and search_tags come from unrelated signals, and most genuine reads never get tagged at all

Open arspesk opened this issue 2 months ago • 3 comments

Issue Origin

Observed and reproduced in a real, long-running self-hosted deployment (OpenViking 0.4.19, local FAISS-backed single-user instance, running behind Hermes Agent as the memory client). Confirmed with live API calls, a manual set_tags A/B test, and full session/commit-history tracing — not a guess from reading code alone.

Summary

The Agent Evolution "Application impact" feature (GET /api/v1/agent-evolution/experiences/{trajectories,outcomes}) is supposed to let you see which Trajectory memories were produced by sessions that actually read a given Experience. In practice, across 211 real Experience files accumulated over ~2 weeks of real usage, only 1 ever returns a non-zero result from these endpoints — even though narrative derived_from backlinks recorded inside 207 of those 211 Trajectory files' own MEMORY_FIELDS.backlinks claim a relationship to a specific Experience.

This is not the previously-fixed #4709 (raw-URI-as-tag-key 400 error) — our server is past that fix and correctly returns 200 OK with total: 0 instead of erroring. The remaining failure is silent and much harder to notice, which is why it's still live.

I traced this down to two separate, compounding root causes, both confirmed with direct evidence, not inference.

Root cause 1: narrative backlinks and search_tags lineage are fed by two independent, uncorrelated retrieval steps

  • The queryable lineage mechanism (search_tags on the Trajectory's vikingdb record, filtered by experience_source_tag() in openviking/service/agent_evolution_service.py / openviking/session/memory/experience_lineage.py) is supposed to be driven by collect_read_experience_uris(), which scans the original session's actual committed tool-call parts for a completed read/multi_read on an Experience URI.
  • But the narrative backlinks array embedded in a Trajectory's own markdown (rendered as derived_from links, and what a human/dashboard would visually read as "this trajectory came from reading that experience") comes from an entirely different code path: ExtractLoop's own WikiLink resolution (openviking/session/memory/extract_loop.py), fed by page_id_map, which is populated from the extraction pass's own separate context_provider.prefetch() retrieval — i.e. the extraction LLM's own semantic search over memory while summarizing a session, run independently of whatever the original conversation actually did.

Direct proof these are decoupled, not just occasionally stale:

I found a real Trajectory (revoke_ssh_key_cleanup_20260912200356.md) whose backlinks claims derived_from a specific Experience (gateway_stale_provider_list.md). The Trajectory's own source_archive_uri field shows it was created from a session on 2026-09-08. But scanning every read/multi_read tool call ever issued against that Experience URI (via the client's full tool-call history), the earliest real read of that Experience happened on 2026-09-13 — five days after the Trajectory citing it was created. The narrative link cannot possibly be provenance; it is a semantic-similarity guess made independently by the extraction pass, rendered in a format (derived_from, backlinks) that looks exactly like tool-call-verified lineage but isn't.

Root cause 2: even a genuine, verified read is silently and permanently dropped if the extraction pass doesn't judge that turn "trajectory-worthy"

Separately, I traced a real session (multi-hour, 6 commits, 288 messages) where 3 Experience files were genuinely read via completed tool calls partway through the session (on a debugging tangent). The session's trajectory-extraction step, across all 6 of its commits, produced exactly 3 Trajectory memories total for the entire session — none related to the 3 reads. The extraction pass apparently judged that particular exchange not worth turning into its own Trajectory memory. Because collect_read_experience_uris()'s output only ever gets attached to a Trajectory if one gets written in that same commit, the read evidence for those 3 Experiences is discarded with no persistence, no retry, and (per the existing "no retroactive backfill" design, confirmed in an internal note referencing this exact constraint) no way to ever recover it. A real, verified read of an Experience produces zero lineage record forever, purely because the extraction model didn't also decide to write a Trajectory about it.

Live A/B test confirming the read-path is otherwise correct

To rule out a query-side bug (tag escaping, filter construction, auth), I manually attached the exact expected tag to an existing Trajectory record via POST /api/v1/content/set_tags:

curl -s -X POST 'http://localhost:1933/api/v1/content/set_tags' \
  -H 'X-API-Key: <user-api-key>' -H 'Content-Type: application/json' \
  -d '{"uri": "viking://user/default/memories/trajectories/revoke_ssh_key_cleanup_20260912200356.md", "tags": ["viking://user/default/memories/experiences/gateway_stale_provider_list.md=1"], "mode": "append"}'

Immediately after, GET /api/v1/agent-evolution/experiences/trajectories?experience_uri=viking://user/default/memories/experiences/gateway_stale_provider_list.md correctly returned total: 1 with the right item, and the outcomes endpoint correctly reported the outcome distribution. The read/query side of the API is completely correct. The bug is entirely in the write path — specifically, in the assumption that search_tags and narrative backlinks describe the same relationship, when they don't, and in the fact that verified read evidence is discarded rather than persisted independently of whether a Trajectory gets written.

Why I'm not attaching a PR

I did dispatch an attempt at a code-level fix first (isolated unit test against _apply_trajectory_operations → MemoryUpdater.apply_operations → _vectorize_memories), which confirmed the tag-building and enqueue logic itself works correctly when a Trajectory is written and given consumed_experience_uris — so there is no simple, localized bug to patch there. The actual gap is architectural: (a) two features share a UI/API surface that implies they measure the same thing but don't, and (b) verified tool-call evidence has no durable home independent of a Trajectory being written for that same turn. Fixing this well requires a design decision from the maintainers (e.g.: should search_tags lineage also credit viking_search hits, not just read? should read-evidence for an Experience persist as its own lightweight record even when no Trajectory is written for that turn? should the dashboard clearly separate "verified read lineage" from "semantic similarity backlinks"?) rather than a patch I could confidently scope and test myself.

Expected Behavior

Either:

  1. search_tags-based lineage should reliably populate whenever a genuine, completed read/multi_read of an Experience occurs in a committed session (independent of whether that same commit also produces a Trajectory memory referencing it), so the Application Impact dashboard reflects real usage; or
  2. If the current strict "only credits reads that also produced a Trajectory in the same commit" semantics is intentional, the dashboard/API/docs should clearly disclose that narrative backlinks/derived_from relationships are a separate, unverified, LLM-semantic-similarity signal and not proof of an actual read, so they aren't confused with the mechanically-verified lineage the API is named after.

Actual Behavior

  • 207 of 211 real Experience files have narrative derived_from backlinks in Trajectory files, implying real usage.
  • Only 1 of 211 shows any result via the actual Agent Evolution API/dashboard.
  • A live A/B test proves the query path is correct; the gap is in what gets written, and the two "lineage" signals (narrative backlinks vs. search_tags) come from architecturally independent retrieval steps that can and do disagree by days on when/whether an Experience was actually consulted.

OpenViking Version

0.4.19

Additional Context

  • Related, already-fixed issue: #4709 (raw-URI-as-search-tag-key rejection) — that fix is confirmed live in our version; this is a distinct, deeper issue that #4709's fix does not address.
  • Related PR: #4322 (fix(server): bound the tag list on set_tags and reindex) — its description independently documents that experience_source_tag() produces long percent-escaped tag keys (79-183 chars on real URIs), which is useful context on how fragile/unusual this particular tagging mechanism is, though I did not find evidence that the length caps introduced there are the cause of this issue (the tags I manually set were well within the documented caps and worked immediately).
  • Happy to provide the exact session/trajectory URIs, timestamps, and full trace used to build this report if that helps triage — kept them generic/redacted here since they reference a personal deployment's real content, but the mechanism and timeline gap are exactly as described.

arspesk avatar Sep 16 '26 23:09 arspesk

@arspesk Thanks for the detailed investigation. There are two distinct relationships here that are important to separate:

  • Source lineage (derived_from) means an Experience was distilled from a Trajectory.
  • Application impact (search_tags) associates Trajectories with Experiences successfully read in the committed conversation. A derived_from backlink on a Trajectory therefore does not mean that the original execution read that Experience. A Trajectory from September 8 can be the source of an Experience that is first read on September 13; that ordering is expected. Consequently, the difference between source-link counts and application-impact counts does not by itself demonstrate a bug. Your second observation identifies a real limitation of the current metric: Application impact measures trajectories and outcomes associated with reads, not every read event. If an extraction batch produces no Trajectory, there is no Trajectory record to carry the application tags. Making every successful read independently queryable would require separate read-event tracking. One implementation detail also matters: the code attaches the collected Experience tags to every Trajectory upsert in that extraction batch. It does not require the extraction model to judge each Trajectory semantically related to the Experience. To establish an actual missing-lineage bug, we would need a specific commit where:
  1. A successful Experience read was recorded in a supported ToolPart format.
  2. The same extraction batch wrote a Trajectory.
  3. After indexing completed, that Trajectory remained absent from the correctly scoped application-impact query. Could you share a redacted example containing those tool records and the resulting Trajectory URI? The report raises a valid concern about metric clarity, but source lineage and application impact should not be expected to have matching counts.

heaoxiang-ai avatar Sep 17 '26 08:09 heaoxiang-ai

Thanks for the correction on derived_from. You're right, and my root cause 1 doesn't hold.

I went back and checked our data rather than argue the point. Scanning every committed session in our deployment for completed read/multi_read calls against Experience URIs: only 2 archives in the entire corpus contain one. Not 211.

The "1 of 211" figure in my report used the wrong denominator. It compared against every Experience file that exists, but most of those were never read via a tool call at all, so there was never anything for the lineage tag to record.

Of those 2 archives, one produced no memories at all (empty memory_diff, zero adds/updates). The other is exactly the case you asked for:

  1. Committed archive containing a completed read of viking://user/default/memories/experiences/upstream_issue_report_search.md (tool_name: "read", tool_status: "completed")
  2. The same extraction batch wrote viking://user/default/memories/trajectories/upstream_error_report_check_20260912220049.md
  3. After indexing, the scoped query returns it:
GET /api/v1/agent-evolution/experiences/trajectories?experience_uri=<upstream_issue_report_search.md>
-> total: 1, correct trajectory URI

GET /api/v1/agent-evolution/experiences/outcomes?experience_uri=<same>
-> success: 1

The path works end to end. 1 of 1 possible, not 1 of 211.

I should also correct something in the original report. The other non-zero result I cited, gateway_stale_provider_list.md, is the trajectory I tagged by hand during the set_tags A/B test. I used my own test artifact as evidence. That was careless and I should have caught it before filing.

That leaves only your second point, which you had already identified before I confirmed anything: reads in a batch that writes no Trajectory have nowhere to land. Our corpus has exactly one instance of that, so I can't offer it as evidence of a widespread defect either.

Fine by me to close this as not-a-bug.

If any part is worth keeping, it's the metric-clarity note. Application impact counts Experiences read as explicit tool calls, so a client that surfaces Experiences through semantic search or injected recall context instead of an explicit read will show an empty dashboard while still using the memory heavily. That was our situation, and working out the difference took a while. A line in the docs would have saved me this issue.

Thanks for the fast and precise response.

arspesk avatar Sep 17 '26 16:09 arspesk

Closing this out. Both root causes didn't survive scrutiny: derived_from and search_tags measure different relationships as you described, and the one real case we have of a same-batch read + Trajectory write gets tagged correctly end to end (1 of 1, not a defect).

For anyone else who lands here with the same symptom: check whether your client surfaces Experiences to the model via an explicit read/multi_read tool call, or only through semantic search / injected recall context. Application impact only counts the former, so heavy real usage through the latter still shows up as a near-empty dashboard. Not a bug, just a metric-clarity gap that would've saved me this issue if it were documented somewhere.

Closing as not-a-bug per the discussion above. Thanks again for the quick, precise response.

arspesk avatar Sep 17 '26 16:09 arspesk