Skip to content

feat: add opt-in evidence-backed knowledge memory - #183

Draft
00-Aakash-00 wants to merge 3 commits into
Merit-Systems:mainfrom
00-Aakash-00:feat/knowledge-memory
Draft

00-Aakash-00 wants to merge 3 commits into
Merit-Systems:mainfrom
00-Aakash-00:feat/knowledge-memory

Conversation

@00-Aakash-00

@00-Aakash-00 00-Aakash-00 commented Oct 21, 2026 •

Copy link
Copy Markdown

OpenInstinct’s existing profile memory is a small model-maintained document. This adds experimental knowledge memory with source evidence, revision history, immediate corrections and forgetting, background extraction, and an inspection page. A preference remembered in one chat can be corrected in another and retrieved with evidence; forgetting removes the saved versions and fences delayed jobs from restoring them.

The feature is off by default, with off, shadow, and enabled modes plus a workspace allowlist. It reuses the existing Eve, Drizzle/PostgreSQL, AI SDK, Zod, private Vercel Blob, tRPC, and UI primitives. No new dependencies or lockfile changes. Repository patterns and AGENTS.md were followed; no separate CONTRIBUTING guide or PR template was present.

Implementation

  • Scoped records, source spans, revisions, supported co-mention links, generation/replay state, durable maintenance jobs, session bindings, migration markers and artifact reservations. Two additive Drizzle migrations include the usage ledger; previously published migration 0015 is unchanged by the budget follow-up.
  • Timestamped direct-user receipts feed a durable inbox. Bounded recovery repairs missed hooks without importing pre-activation chat text. The restricted maintainer selects existing records by source relevance and proposes exact quotations; server validation enforces scope, evidence, revisions, leases and deletion state.
  • Recall replaces one bundle at turn start and compaction. Each serialized profile/context projection fits 6,000 UTF-8 bytes; the complete knowledge recall message fits 17,500 bytes, including instructions. Oversized candidates are skipped while smaller relevant candidates remain eligible. Search/read/link/history tools expose scoped evidence; explicit tools require a current user request.
  • Private immutable Markdown uses reservations before upload and validates generation, lease and revisions before publication. Corrections invalidate stale edges/snapshots. Forgetting clears derived saved content, history, sources, replay payloads and checkpoints, with retryable physical Blob cleanup.
  • /memory supports inspection, search, evidence/history, correction, forgetting and JSON/Markdown export. Requests derive scope from an authenticated owned chat. memory.status exposes scoped queue counts/timestamps and workspace-wide daily usage without saved text.
  • Legacy profile import is serialized with legacy writes and commits before clearing the old document. A persistent marker prevents re-import after forgetting or flag rollback. Personal Info and the existing workstream provider retain their ownership.

Usage budgets

KNOWLEDGE_MEMORY_DAILY_TOKENS=250000 and KNOWLEDGE_MEMORY_DAILY_CALLS=100 apply per workspace across memory scopes, using the UTC call-start day. Atomic reservations precede every extraction, including retries. Reported usage settles once; unknown/partial usage and abandoned calls retain conservative charges. The ledger records model metadata, attempts and accepted-proposal counts, including retry and empty-proposal costs, without storing prompts or output.

Exhaustion defers extraction without consuming retries. Either limit at zero pauses extraction and preserves queued input. Requests larger than an entire positive allowance fail without a model call and cannot starve later input. Explicit edits, export publication, forgetting and purge continue independently of extraction budgets. Regression coverage includes explicit saves racing budget rejection/deferral.

Reservations use serialized prompt/schema bytes plus output and framing allowances. They are not exact tokenizer counts or a dollar cap. Reported overruns are charged and prevent later admission. Non-content usage metadata survives record forgetting and is deleted with its workspace.

Validation

  • pnpm check --concurrency=1: all six tasks passed, including 1,134 tests across 112 files, TypeScript, lint, formatting and unused-code checks. No test timeouts or assertions were relaxed.
  • pnpm build: passed with memory enabled and synthetic local configuration.
  • pnpm db:check and all 17 migrations into fresh PostgreSQL 17: passed.
  • pnpm test:runtime: 3 evaluations / 17 gates passed, proving memory binding and timestamped receipts precede first-turn tool execution.
  • Live-evaluation cleanup: supervisor and real-database tests cover ownership, the five-minute grace, failed deletion, bounded cleanup, interruption and exit-code preservation. No real Blob request was made.

The deterministic suites include the full remember → correct → recall → forget flow across fresh provider contexts, ownership, replay/compaction, revision conflicts, stale workers, source recovery, upload failure, account deletion and migration races. Earlier independent browser QA passed 39 tested branches after fixing five UI issues; this follow-up does not change that UI.

Executable benchmarks:

  • pnpm bench:memory:scenarios: 40 frozen scenarios × 3 repetitions = 120 passing evidence gates against real services/migrations in PGlite. Model extraction, Blob and recovery HTTP use fixtures. The JSON report separates unsupported legacy APIs, shared behavior not run against the baseline, and semantic quality not measured.
  • pnpm bench:memory:scale: three independent 1,000-record runs, 30 warm samples per operation per run. Older-target search p95 10.315–10.602 ms; full fresh recall p95 27.709–28.712 ms. Multilingual recall is 17,227 UTF-8 bytes, reduced from 24,560 bytes after the benchmark exposed the old character-based limit. Escaping/multilingual regression tests preserve whole lines and records.
  • The scale runner exercises the installed Eve file-memory provider: its default cap admitted 30 fixture entries; its actual parser rejected the 184,484-byte 1,000-entry document above its 65,536-byte limit. This is a capacity observation. Small in-process legacy recall is not a like-for-like latency or quality comparison with database-backed 1,000-record recall.
  • Real PostgreSQL 17 concurrency smoke: 25/25 assertions, with eight distinct backend connections observed waiting on the workspace admission lock. Call cap admitted 3/12 requests; token cap admitted 1/12; after settlement, exactly one additional request fit. Unknown/crashed charges, settlement idempotency and workspace isolation passed without deadlocks.

Local scale results measure PGlite/WASM, not hosted PostgreSQL, network latency, production queue freshness or model answer quality. Byte bounds do not establish the proposed 4,500-token recall target.

Rollout limits

This remains a draft pending live model and deployed private Blob validation. Two opt-in live flows now cover explicit controls and ordinary input → scheduled maintenance → fresh recall, each repeated three times. They are implemented but not executed here because AI Gateway/OIDC and target storage credentials are unavailable. Runtime smoke uses the existing deterministic model fixture. The live-eval supervisor cleans synthetic artifacts before deleting its disposable database, retaining cleanup state if deletion fails.

Upstream Checks and Vercel preview deployment require maintainer authorization for this contributor PR. Passing local validation is not a completed upstream CI or preview deployment.

The extractor is conservative: English first-person statements, exact quotes and supported co-mentions. It does not infer personality, merge entities, interpret relative dates, ingest arbitrary browser content or mirror personal data into Git. Richer entities, knowledge-to-workstream links and synthesized active context remain separate follow-ups. The 40 deterministic cases and two live flows do not claim completion of the broader 40-scenario live semantic comparison.

Authorization/input-request events stop capture for that chat while preserving earlier independent memories. Exhausted or permanently oversized inputs discard unsupported text while retaining non-content replay fences. Forgotten saved content is unavailable immediately; physical artifact purge is retryable. Original conversations, downloaded exports and provider backups are outside saved-memory deletion. See configuration, migration, benchmark and operational details.

Inspiration

Inspired by Dhravya Shah’s article about Instinct’s memory. The article is an outside-in reconstruction of a closed product. This is an independent implementation for OpenInstinct, with no claim to reproduce Instinct’s source or measured behavior.

This branch has not been deployed

No deployments
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.

1 participant