Skip to content

Add time-based decay, anti-patterns, and agent attribution#14

Merged
acoyfellow merged 2 commits intomainfrom
claude/confidence-decay-anti-patterns-JLus5
Mar 23, 2026
Merged

Add time-based decay, anti-patterns, and agent attribution#14
acoyfellow merged 2 commits intomainfrom
claude/confidence-decay-anti-patterns-JLus5

Conversation

@acoyfellow
Copy link
Copy Markdown
Owner

Summary

This PR adds three major features to deja-local and deja-edge memory systems:

  1. Time-based confidence decay — memories automatically lose confidence over time using an exponential half-life formula, with decay computed at recall time (read-side only)
  2. Anti-pattern tracking — memories rejected enough times auto-invert into warnings that actively surface during recall
  3. Agent attribution — optional source parameter to track which agent stored a memory

Key Changes

Time-based Confidence Decay

  • Added last_recalled_at column to track when memories were last used
  • Decay formula: decayedConfidence = storedConfidence × 0.5^(daysSince / 90)
  • A memory untouched for 90 days has its effective confidence halved
  • Recalling a memory resets its decay clock — actively used knowledge stays fresh
  • Decay is computed at recall time; stored confidence values are never mutated
  • No background jobs or cron needed — pure read-side computation

Anti-Pattern Tracking

  • Added type column ('memory' or 'anti-pattern') to track memory classification
  • When reject() drops confidence below 0.15 threshold, memory auto-inverts:
    • Type changes from 'memory' to 'anti-pattern'
    • Confidence resets to 0.5 (useful warning, not failed memory)
    • Text is prefixed with "KNOWN PITFALL: "
  • Anti-patterns appear in recall results normally, actively warning agents
  • Already-inverted anti-patterns don't double-invert on further rejections
  • Anti-patterns can be confirm()ed to boost their confidence

Agent Attribution

  • Added source column to store which agent created a memory
  • remember() now accepts optional { source?: string } parameter
  • Source is returned in Memory objects and list results
  • Backward compatible — source is undefined when not provided

Schema Migrations

  • Added migration logic to handle DBs created before these features
  • Gracefully adds missing columns: last_recalled_at, source, type
  • Existing memories default to type: 'memory' and source: undefined

Documentation Updates

  • Updated README and pattern guides with decay mechanics and anti-pattern examples
  • Added hosted service decay example in memory-hygiene.mdx
  • Documented agent attribution usage

Implementation Details

  • deja-local: Uses Bun SQLite with prepared statements; decay computed during recall
  • deja-edge: Uses Cloudflare Durable Objects SQLite; same decay logic applied
  • Hosted service: Added decay ranking in injectMemories() to sort learnings by decayed confidence
  • All changes maintain backward compatibility with existing databases
  • Comprehensive test coverage added for all three features in both packages

https://claude.ai/code/session_01MbQ14BcEn9uFntgrNidpVA

…ttern tracking

- Time-based confidence decay (all three packages): Apply exponential decay
  at recall time using half-life of 90 days. Memories not recalled or created
  recently have their effective confidence reduced, keeping recall results
  fresh. Stored confidence is never mutated by decay.

- Agent attribution (deja-local & deja-edge): Add optional `source` parameter
  to remember() for tracking which agent stored a memory. Backward-compatible.

- Anti-pattern tracking (deja-local & deja-edge): When reject() drops
  confidence below 0.15, the memory auto-inverts to an anti-pattern with
  "KNOWN PITFALL: " prefix, reset confidence of 0.5, and type "anti-pattern".
  Negative knowledge actively surfaces during recall as warnings.

All 76 tests pass (44 deja-local + 32 deja-edge).

https://claude.ai/code/session_01MbQ14BcEn9uFntgrNidpVA
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e25870fb5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…p bypass

P1: deja-edge initSchema() now calls migrateSchema() which runs ALTER TABLE
to add last_recalled_at, source, and type columns on existing Durable Objects.
Previously, upgraded DOs would fail with "no such column" errors.

P2: Strip "KNOWN PITFALL: " prefix when computing trigram similarity for
dedup/conflict detection in deja-edge. This prevents re-remembering the same
text from bypassing dedup and inserting a duplicate after anti-pattern
inversion. (deja-local uses embedding-based dedup which is unaffected since
the stored embedding remains from the original text.)

Added tests for both fixes. All 78 tests pass (44 local + 34 edge).

https://claude.ai/code/session_01MbQ14BcEn9uFntgrNidpVA
@acoyfellow acoyfellow merged commit 876791c into main Mar 23, 2026
3 checks passed
@acoyfellow acoyfellow deleted the claude/confidence-decay-anti-patterns-JLus5 branch March 23, 2026 15:29
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.

2 participants