Purpose: Convert the feature/improvement ideas already captured in this repository into a concrete, execution-ready plan tied to the current codebase.
Date: 2026-02-13 Last Review: 2026-02-13 (Phase 0 + Phase 1 deep review)
Overall Assessment: The implementation is solid and production-ready with a few polish items identified during deep review. The committer demonstrated good security practices (timing-safe comparisons, proper CORS handling, signature verification) and addressed the core performance bottlenecks effectively.
Strengths:
- ✅ Security implementations use correct cryptographic primitives (
crypto.timingSafeEqual) - ✅ Regex optimisations properly hoisted to class-level constants
- ✅ N+1 fix correctly removes async/await from synchronous operations
- ✅ Error responses consistently sanitised across all route files
- ✅ Connection pool configuration is comprehensive with sensible defaults
- ✅ Backward compatibility maintained throughout
Areas for Improvement:
⚠️ Minor code duplication (duplicate index creation statements)⚠️ Noisy logging pattern (warnings repeat per-request instead of once at startup)⚠️ Rate-limit eviction uses O(n) scan (acceptable but could be optimised)⚠️ Missing input validation on pool configuration env vars
- Node/TS engine + API:
packages/openmemory-js/src/- Routes:
server/routes/*.ts - Memory core:
memory/hsg.ts - DB schema/init:
core/db.ts - Auth/rate limiting:
server/middleware/auth.ts - Ingestion + extraction + compression:
ops/*.ts - Temporal graph:
temporal_graph/*.ts
- Routes:
- Python SDK + server:
packages/openmemory-py/src/openmemory/- Mirror memory implementation (
memory/,ops/,core/,server/routes/)
- Mirror memory implementation (
- Dashboard (Next.js):
dashboard/
- HSG sectors currently configured in TS/Python (episodic, semantic, procedural, emotional, reflective)
- Memory CRUD + query already available under
/memory/* - Temporal fact graph exists (
temporal_facts,temporal_edgesin Node DB init) - Source ingestion + GitHub webhook route exists (
server/routes/sources.ts) - Version field already exists on memory rows (
version integer default 1)
packages/openmemory-js:npm run buildcurrently fails in this environment due to missing module/type resolutionpackages/openmemory-py:pytestunavailable in current environment (No module named pytest)dashboard:npm run lintfails in this environment (eslint: not found)
These are environment/dependency setup issues, not changes introduced by this improvement planning update.
- Small, vertical slices over broad rewrites.
- Schema-safe migrations (additive first, no destructive migration in first pass).
- Feature parity discipline between Node and Python APIs where feasible.
- Security and observability gates before broad rollout.
- Document-heavy features must remain optional/configurable to avoid changing baseline memory behavior for existing users.
- Current touchpoint:
packages/openmemory-js/src/server/middleware/auth.ts - Plan:
- Add explicit
OM_REQUIRE_AUTH=true|falsegate. - Default to backward-compatible behavior; enable strict mode for production.
- Add explicit
- Deliverables:
- Config parsing update
- Auth middleware branch for strict mode
- README +
.env.exampledocumentation
- Acceptance criteria:
- Strict mode returns 503/401 when key missing.
- Non-strict mode preserves current behavior with warning logs.
- Current touchpoint:
packages/openmemory-js/src/server/index.ts(Access-Control-Allow-Origin: *) - Plan:
- Add
OM_CORS_ALLOWED_ORIGINSenv-based allowlist. - Keep wildcard fallback only when allowlist not configured.
- Add
- Acceptance criteria:
- Requests with disallowed origin do not receive permissive CORS headers.
- Current touchpoint:
server/middleware/auth.tsin-memoryMap - Plan:
- Introduce max-entry cap + oldest-entry eviction (minimal change).
- Add optional Redis/Valkey-backed limiter as later enhancement.
- Acceptance criteria:
- Store size remains bounded under high-IP churn simulation.
- Current touchpoints: route handlers under
server/routes/*.ts - Plan:
- Standardize generic client error codes; keep detailed logs server-side.
- Sweep source/webhook routes for remaining internal leakage.
- Acceptance criteria:
- No raw stack or provider internals returned in 500 responses.
- Current touchpoints:
- TS:
packages/openmemory-js/src/memory/hsg.ts(compute_tag_match_score) - PY:
packages/openmemory-py/src/openmemory/memory/hsg.py
- TS:
- Plan:
- Batch fetch memory/tag rows per query cycle.
- Cache decoded tags per request.
- Acceptance criteria:
- Query path issues O(1) tag-fetch batches rather than per-candidate fetches.
- Current touchpoint:
packages/openmemory-js/src/core/db.ts - Plan:
- Validate indexes against query predicates (
user_id,primary_sector,segment, temporal filters, waypoints). - Add missing additive indexes with migration guard checks.
- Validate indexes against query predicates (
- Acceptance criteria:
- Query plans for top endpoints avoid full scans for common filtered reads.
- Current touchpoint:
packages/openmemory-js/src/ops/compress.ts,memory/hsg.ts - Plan:
- Hoist regex constants out of function hot paths.
- Avoid repeated parse/normalize in loops.
- Acceptance criteria:
- No behavior change; measurable CPU reduction in benchmark script.
- Current touchpoint:
packages/openmemory-js/src/core/db.ts - Plan:
- Validate pool settings via env (
max, idle timeout) and document production defaults.
- Validate pool settings via env (
- Acceptance criteria:
- Stable operation under concurrent add/query load without connection starvation.
- Touchpoints: embedding call sites in TS/PY memory add pipeline
- Plan:
- Add bounded exponential backoff for retriable provider failures.
- Acceptance criteria:
- Intermittent provider failures no longer fail the entire request on first attempt.
- Touchpoints:
- TS:
packages/openmemory-js/src/memory/hsg.ts - PY:
packages/openmemory-py/src/openmemory/core/constants.pyandmemory/hsg.py
- TS:
- Plan:
- Move sector defaults into a shared config artifact (or generated constants) loaded by both stacks.
- Acceptance criteria:
- Sector definitions and weights are consistent across runtimes.
- Touchpoints: async fire-and-forget branches (
update_user_summary, reflections, decay/prune) - Plan:
- Add lightweight structured logs and counters for background failures.
- Acceptance criteria:
- Operators can identify failing background jobs without deep tracing.
All features below are already identified in the improvement scope; this section turns them into implementation slices with dependencies and testable exits.
- Extend metadata conventions for document-centric fields (
doc_type,parties,effective_dates,source_refs). - Add migration pattern for additive tables/columns and rollback instructions.
- Define route versioning strategy for new document endpoints.
- Touchpoints:
server/routes/memory.ts,memory/hsg.ts, DB schema incore/db.ts - Schema plan:
- Reuse existing
versionfield, addprevious_version_id,change_summary,diff_blob(JSON/text).
- Reuse existing
- API plan:
POST /memory/:id/version✅GET /memory/:id/versions✅GET /memory/:id/diff/:other_id✅
- Acceptance criteria:
- Version chain is queryable and diff output is deterministic. ✅
Implementation:
- Created
core/versioning.tswith version storage, diff computation, and history retrieval - Added
version_historytable to both Postgres and SQLite - Created versioning routes:
/memory/:id/versions,/memory/:id/version,/memory/:id/diff/*,/memory/:id/restore/:version - Auto-versioning on content updates via
update_memory()function - Line-based diff with change classification (minor/moderate/major)
- Touchpoints:
ops/extract.ts,memory/hsg.ts,server/routes/memory.tsor newroutes/citations.ts - Plan:
- Add citation extraction pass (regex + normalization) during ingest/update.
- Store citations as linked memories/metadata edges.
- Acceptance criteria:
- Can retrieve citations for a document and reverse-lookup documents by citation.
- Touchpoints:
ops/extract.ts(TS),ops/extract.py(PY) - Plan:
- Introduce schema-driven extraction per doc type.
- Validate extracted payload with zod/pydantic before persistence.
- Acceptance criteria:
- Extraction output is typed, validated, and stored without breaking existing metadata users.
- Touchpoints: versioning APIs + diff utility module
- Plan:
- Generate word/line diffs and classify substantive changes (financial/date/party/general).
- Acceptance criteria:
- API returns summary + categorized change set.
- Touchpoints: middleware layer, DB schema, route wrappers
- Plan:
- Add append-only audit table and middleware hook for mutating document actions.
- Add read endpoint with filters + pagination.
- Acceptance criteria:
- Create/update/delete/version actions are traceable by actor/time/resource.
- Touchpoints: new route module + storage table + render utility
- Plan:
- CRUD templates, typed variable schema, instantiate to memory entry.
- Acceptance criteria:
- Template instantiation validates required variables and produces stored output.
- Touchpoints: new validation service + route + optional temporal facts integration
- Plan:
- Start with deterministic rule checks (required clause/prohibited term/field present).
- Keep LLM-based checks explicitly optional.
- Acceptance criteria:
- Rule run produces reproducible violation report with severity levels.
- Touchpoints: extraction pipeline + similarity query endpoint
- Plan:
- Segment documents into clauses, store clause-level vectors/metadata, expose nearest-neighbor search.
- Acceptance criteria:
- Returns similar clauses above configurable threshold excluding same clause ID.
- Document type detection
- Party extraction
- Date extraction + normalization
Each quick win should land behind ingestion metadata enrichment, without API breaking changes.
- Lane 1 — API/Schema: route updates, migrations, storage/index changes
- Lane 2 — Extraction/Memory Logic: parsing, classification, ranking, retry logic
- Lane 3 — SDK/Parity: Python parity updates and compatibility checks
- Lane 4 — Validation/Docs: tests, benchmarks, security checks, and docs updates
When a phase starts, schedule independent items across these lanes concurrently (for example: A2 + B2 + C3 can run in parallel by separate owners, then merge after validation).
- A1, A2, A4
- D0 foundation
- Baseline metrics and benchmark scripts
- B1, B2, B3
- C3
- D5 audit trail
- D1 versioning
- D4 redline detection
- D9 quick wins
- D2 citation tracking
- D3 structured extraction
- D8 clause similarity
- D6 template management
- D7 compliance rules engine
- C1 reliability retries
- C2 TS/PY config parity
- Route handlers for new document endpoints
- Extraction/parsing normalization utilities
- Diff classification and citation regex normalization
- Auth/CORS/rate-limit behavior branches
- End-to-end: ingest → version → diff → audit entries
- End-to-end: ingest legal text → citation extraction → citation search
- End-to-end: template instantiate → memory add → query recall
- Before/after query latency for tagged multi-candidate queries
- DB query plan snapshot checks for indexed predicates
- Auth required mode behavior
- CORS allowlist behavior
- Webhook signature verification regression
- Error response leakage regression
- Risk: Divergence between Node and Python behavior.
- Mitigation: parity matrix + shared config artifacts + conformance tests.
- Risk: Schema bloat from document-specific features.
- Mitigation: additive schema + clear migration gates + metadata namespacing.
- Risk: False positives in citation/compliance extraction.
- Mitigation: deterministic first-pass rules + confidence scoring + review tooling.
- Risk: Throughput regressions from added processing.
- Mitigation: async/background extraction path with configurable toggles.
The program is complete when:
- Security hardening items in Workstream A are implemented and documented.
- Performance items in Workstream B show measurable improvements.
- Reliability/code quality items in Workstream C are merged with tests.
- Document/legal features in Workstream D are delivered per phase with acceptance criteria met.
- Node + Python user-facing behavior is documented where parity differs.
- Phase 0 complete (2026-02-13) — see Review Findings below
- Phase 1 complete (2026-02-13) — see Review Findings below
- Phase 0/1 Remediation items (new)
- Phase 2 complete
- Phase 3 complete
- Phase 4 complete
- Final parity/security/perf sign-off complete
Implementation Quality: Good
Review Findings:
- ✅ Uses
crypto.timingSafeEqualfor constant-time API key comparison — correct security practice - ✅ Strict mode (
OM_REQUIRE_AUTH=true) returns 503 when key not configured - ✅ Non-strict mode preserves backward compatibility with warnings
⚠️ REMEDIATION NEEDED: Warning logs fire on every request when auth is disabled, causing log noise
Remediation Item A1.1:
- Issue: Lines 121-125 in
auth.tslog warnings per-request - Fix: Move warnings to a startup-only log (use a
has_warnedflag or log incfg.ts) - Priority: Low (cosmetic, not functional)
Implementation Quality: Good
Review Findings:
- ✅ Allowlist-based CORS with
OM_CORS_ALLOWED_ORIGINSenv var - ✅ Backward-compatible wildcard fallback when not configured
- ✅ Correctly omits CORS headers for non-allowlisted origins
No remediation needed.
Implementation Quality: Acceptable
Review Findings:
- ✅
MAX_RATE_LIMIT_ENTRIES = 10,000cap prevents unbounded memory growth - ✅ Oldest-entry eviction logic is correct
⚠️ MINOR: O(n) linear scan to find oldest entry (acceptable for 10k entries)
Remediation Item A3.1 (Optional):
- Issue: Linear scan at line 61-73 could be slow under extreme load
- Fix: Use a min-heap or maintain an insertion-order linked list
- Priority: Very Low (only matters if rate-limit store churns at >1000 req/s)
Implementation Quality: Excellent
Review Findings:
- ✅ All 500 responses across
sources.ts,compression.ts,dashboard.ts,users.tsnow return generic error codes - ✅ Server-side logging preserved with
console.error() - ✅ No stack traces or provider internals leaked
No remediation needed.
Implementation Quality: Excellent
Review Findings:
- ✅
compute_tag_match_score()now accepts memory object directly (no DB call) - ✅ Function is no longer async — correctly reflects synchronous operation
- ✅ Applied to both TypeScript (
hsg.ts) and Python (hsg.py) - ✅
parse_json_field()helper added to avoid repeated JSON parsing
No remediation needed.
Implementation Quality: Good with minor issue
Review Findings:
- ✅ Indexes added:
salience,created_at,last_seen_at, composite(user_id, created_at) - ✅ Both Postgres and SQLite implementations updated
⚠️ BUG: Duplicate index creation statements
Remediation Item B2.1:
- Issue: Line 263 in
db.tscreatesopenmemory_stats_type_idxtwice (Postgres) - Issue: Lines 594-598 in
db.tscreateidx_edges_validitytwice (SQLite) - Fix: Remove duplicate
CREATE INDEXstatements - Priority: Low (no functional impact, just wasted cycles on startup)
Implementation Quality: Excellent
Review Findings:
- ✅ 46+ regex patterns hoisted to class-level constants in
compress.ts - ✅ Clean organisation:
SEM_FILTERS,SEM_REPLACEMENTS,SYN_CONTRACTIONS,AGG_ABBREVIATIONS - ✅ Patterns compiled once at class instantiation
- ✅
parse_json_field()helper inhsg.tsreduces redundant parsing
No remediation needed.
Implementation Quality: Good
Review Findings:
- ✅ 4 env vars:
OM_PG_POOL_MAX,OM_PG_POOL_MIN,OM_PG_POOL_IDLE_TIMEOUT,OM_PG_POOL_CONNECTION_TIMEOUT - ✅ Sensible defaults (max=20, min=0, idle=30s, conn=10s)
- ✅ Pool config logged on startup
⚠️ MINOR: No validation that pool values are positive integers
Remediation Item B4.1 (Optional):
- Issue: Negative or zero pool values would cause undefined behaviour
- Fix: Add validation in
cfg.tswithMath.max(1, num(...))for pool max - Priority: Very Low (unlikely misconfiguration)
Status: Implemented in Phase 0/1 Remediation workstream.
Implementation:
- Created
core/observability.tsmodule with structured logging and metrics - Updated
server/index.tsto wrap decay and prune tasks with observability - Updated
memory/reflect.tsto use observability for reflection tasks - Updated
memory/user_summary.tsto use observability for user summary tasks - Added
/dashboard/tasksendpoint exposing task metrics (run count, success/failure rates, last errors) - All background tasks now log structured output with duration and result data
Status: Implemented in Phase 0/1 Remediation workstream.
Implementation:
- Created
core/audit.tsmodule with audit_log(), query_audit_logs(), count_audit_logs(), get_resource_history() functions - Added audit_logs table to both Postgres and SQLite database initialization
- Created
/audit/logs,/audit/resource/:type/:id,/audit/statsAPI endpoints - Hooked audit logging into memory routes: create, update, delete, reinforce, ingest actions
- All audit entries include: resource_type, resource_id, action, actor_id, actor_type, timestamp, changes, metadata
Implementation Quality: Excellent
- ✅ Uses
crypto.timingSafeEqualfor constant-time comparison - ✅ Properly checks signature length before comparison (prevents timing leak)
- ✅ Requires raw body for HMAC verification
- ✅ Clear error messages without leaking internals
Status: Partial
- ✅
hsg.pyupdated with N+1 fix ⚠️ Need to verify: Python compression engine regex hoisting not confirmed⚠️ Need to verify: Python auth middleware parity with TS changes
| Item | Priority | Effort | Impact |
|---|---|---|---|
| A1.1 Startup-only auth warnings | Low | 15 min | Log cleanliness |
| B2.1 Remove duplicate indexes | Low | 5 min | Startup performance |
| C3 Background observability | Medium | 2-4 hrs | Operability |
| Python parity verification | Medium | 1-2 hrs | Consistency |
| B4.1 Pool value validation | Very Low | 10 min | Edge case safety |
| A3.1 Rate-limit LRU optimisation | Very Low | 1-2 hrs | Extreme scale only |
- B2.1 — Quick fix, removes code smell ✅ DONE
- A1.1 — Quick fix, improves log hygiene ✅ DONE
- C3 — Should have been in Phase 1, important for operations ✅ DONE
- Python parity — Verify or implement missing changes