Skip to content

memory: entry provenance and per-agent trust scores (#309) - #329

Merged
currentbits merged 3 commits into
mainfrom
coder/memory-provenance-and-per-agent-trust-sc-c75041
Aug 17, 2026
Merged

currentbits merged 3 commits into
mainfrom
coder/memory-provenance-and-per-agent-trust-sc-c75041

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Closes #309.

Why

The entries.agent column was written on every store and then never read — not as a filter, not as a ranking signal. That left two questions unanswerable: who wrote this memory and should I believe them. Without the second one, a single agent that keeps writing wrong memories quietly outranks the agents writing right ones (the memory-poisoning case in OWASP ASI06).

What changed

Provenance. New entries.source column recording the write surface. agent and source are persisted by store() and supersede(), accepted at both the MCP and REST write surfaces (defaulting to mcp / rest respectively), and returned on every read path — FTS, graph, vector, the fused re-score, get(), recent() and bootstrap(). memory_search and GET /api/search now take an optional agent filter, so "show me what this agent wrote" is finally answerable.

Trust. agentTrust(db) rolls up each writer's helpful / harmful / invalidated evidence in one grouped query. trustFactor() turns that into a multiplier clamped to [0.5, 1.5], weighting a wrong memory heavier than a right one earns. The factor is exposed to SQLite as agent_trust(agent) and multiplied into BASE_SCORE_SQL.

Two constraints the implementation holds to:

  • Cheap. The rollup is computed once and cached on the Memory instance, not re-run per row. A feedback verdict drops the cache (that is the evidence that actually moves the number); a 5s TTL covers invalidation and raw SQL writes that bypass feedback().
  • No silent reshuffle. agent_trust(NULL) returns exactly 1.0, so the many existing entries with no recorded writer score precisely as they do today. There is a test asserting the two score expressions are equal for a NULL-agent row.

Operator surface. memory_maintenance gains a trust section listing every writer's evidence and flagging those below TRUST_SUSPECT (0.8).

Notes

Trust is derived, never stored — nothing new is written to entries, and the number recomputes from the evidence at hand.

Low-trust entries are surfaced in the maintenance report rather than enqueued into review_queue. review_queue.kind carries a CHECK constraint that a new kind would require migrating, and a report row costs nothing; worth revisiting if the report proves too passive in practice.

The governance UI (#299) still needs to consume the new agent / source / trust fields — this PR only makes them available.

Testing

cd memory-server && node --test test/*.test.js → 138/138 pass. New coverage: provenance round-trips through store/supersede/get/search, the agent filter actually excludes other writers, REST surfaces carry both fields, agentTrust aggregation and fail-soft behaviour, NULL-agent rank invariance, cache-refresh-on-feedback, and a poisoned writer ranking below a clean one for identical text.

  • PR created by the Claude Code agent

Willem added 3 commits August 17, 2026 18:19
Aggregate helpful/harmful/invalidated evidence per writer, multiply the
cached factor into BASE_SCORE_SQL, and flag suspect agents in the
maintenance report. NULL writers stay at 1.0 so existing ranks do not
move. No new review_queue kind (CHECK constraint; a report row is enough).
Write agent+source on store/supersede, return them on every read that
already carried agent, and let memory_search filter by writer. REST
defaults source to rest; MCP defaults to mcp.
@currentbits
currentbits merged commit fd1fcac into main Aug 17, 2026
1 check failed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits deleted the coder/memory-provenance-and-per-agent-trust-sc-c75041 branch October 3, 2026 16:07
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.

Memory provenance and per-agent trust scores

1 participant