Skip to content

Add Phase 4C Adaptive Memory Intelligence (classification, redaction, embeddings, retrieval, MCP & REST) - #103

Merged
besfeng23 merged 11 commits into
mainfrom
codex/add-phase-4c-adaptive-memory-features
Jun 27, 2026
Merged

Add Phase 4C Adaptive Memory Intelligence (classification, redaction, embeddings, retrieval, MCP & REST)#103
besfeng23 merged 11 commits into
mainfrom
codex/add-phase-4c-adaptive-memory-features

Conversation

@besfeng23

@besfeng23 besfeng23 commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Add a gated adaptive intelligence layer (Phase 4C / Phase 5) on top of the existing Phase 4A REST bridge and Phase 4B MCP to detect, classify, score, and surface durable memory for Joven while preserving strict safety gates and no public memory reads/writes by default.
  • Provide deterministic fallbacks and strong redaction so model calls and embeddings may be enabled later with PANDORA_ENABLE_MODEL_CALLS and PANDORA_ENABLE_EMBEDDINGS without exposing secrets or breaking existing Phase 4A/4B flows.

Description

  • Introduces secret detection/redaction and assertions (lib/services/memory-redaction-service.ts) to prevent secrets from reaching model/embedding providers.
  • Adds a deterministic memory classifier and candidate schema with a model-provider abstraction (lib/services/memory-classification-service.ts, lib/services/memory-model-provider.ts) that is gated and falls back to deterministic output when models are not enabled.
  • Adds a gated embedding abstraction with deterministic fallback and redaction (lib/services/memory-embedding-service.ts and provider shim).
  • Implements candidate queue, auto-capture rules, capture approval/capture flows, session digesting, profile upsert/versioning, open-loop tracking, and a hybrid retrieval engine scoped by user_id + namespace (lib/services/*), plus an adaptive ChatGPT context builder (lib/services/adaptive-chatgpt-context-service.ts).
  • Exposes bridge-auth REST endpoints under /api/memory/adaptive/*, /api/memory/search, and /api/memory/profiles/refresh, and extends MCP tools with adaptive tools (lib/services/pandora-mcp-tools.ts, lib/services/pandora-mcp-server.ts).
  • Adds a Supabase migration to create memory_capture_candidates, memory_profiles, memory_embeddings (pgvector), memory_session_digests, memory_open_loops, model/retrieval logs, indexes and user-scoped RLS (supabase/migrations/20260627040000_phase_4c_adaptive_memory_intelligence.sql).
  • Adds admin status pages, docs (docs/phase-4c-*.md), tests for redaction/classification/embeddings, and updates public/pandora-memory-openapi.json with adaptive endpoints.

Testing

  • Ran npm install and npm run typecheck with no type errors.
  • Ran npm run lint which passed but left three non-blocking warnings (unused symbols / anonymous default export) that are informational only.
  • Ran npm run test where the full test suite passed: 77 test files / 463 tests all green (including the new Phase 4C unit tests).
  • Ran npm run build which completed successfully; the build produced Next.js runtime warnings about Supabase usage in Edge contexts and standard lint warnings, but completed the production build.

Limitations: live external model calls are not wired yet (provider abstraction currently returns deterministic fallback until a provider is configured), and semantic vector retrieval returns no semantic matches until a vector query integration is enabled and PANDORA_ENABLE_EMBEDDINGS / PANDORA_ENABLE_SEMANTIC_RETRIEVAL are turned on.


Codex Task

Summary by CodeRabbit

  • New Features

    • Added new memory administration pages showing feature status and adaptive memory console views.
    • Introduced new memory APIs for context, analysis, session digests, search, and profile refresh.
    • Added support for adaptive context, candidate capture, open-loop tracking, and hybrid memory retrieval.
  • Bug Fixes

    • Added secret detection and redaction safeguards for sensitive content.
    • Improved memory handling with scoped access, validation, and safer defaults.
  • Documentation

    • Added guidance for memory settings, safety policy, and adaptive memory usage.
  • Tests

    • Added coverage for secret handling, classification, and embedding gating.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
memory Ready Ready Preview, Comment Jun 27, 2026 4:54am

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@besfeng23, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 51 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e9a49c38-7a81-4348-865b-54028be2ece7

📥 Commits

Reviewing files that changed from the base of the PR and between 5d7cfaa and 42232e3.

📒 Files selected for processing (10)
  • app/api/memory/adaptive/analyze/route.ts
  • app/api/memory/adaptive/context/route.ts
  • app/api/memory/adaptive/route-helper.ts
  • app/api/memory/adaptive/session-digest/route.ts
  • app/api/memory/profiles/refresh/route.ts
  • app/api/memory/search/route.ts
  • lib/services/memory-candidate-service.ts
  • lib/services/memory-model-provider.ts
  • lib/services/pandora-mcp-tools.ts
  • tests/phase4c-adaptive.test.ts
📝 Walkthrough

Walkthrough

Adds Phase 4C adaptive memory tables, service layers for redaction/classification/retrieval/persistence, new API routes and MCP tools, updated admin status pages and OpenAPI paths, plus supporting docs and tests.

Changes

Phase 4C adaptive memory intelligence

Layer / File(s) Summary
Schema and RLS migration
supabase/migrations/20260627040000_phase_4c_adaptive_memory_intelligence.sql
Creates adaptive-memory tables, indexes, vector support, and row-level security policies.
Redaction and model primitives
lib/services/memory-redaction-service.ts, lib/services/memory-classification-service.ts, lib/services/memory-embedding-service.ts, lib/services/memory-model-provider.ts
Adds secret detection/redaction, deterministic classification, embedding generation, and model-input gating.
Provider wiring, tests, and gating docs
lib/services/providers/*, tests/phase4c-adaptive.test.ts, docs/pandora-memory-env-vars.md, docs/phase-4c-adaptive-memory-intelligence.md
Adds provider re-exports, Phase 4C tests, and feature-gating documentation.
Candidate, profile, and digest persistence
lib/services/memory-candidate-service.ts, lib/services/memory-session-digest-service.ts, lib/services/memory-profile-service.ts, lib/services/memory-open-loop-service.ts, docs/pandora-chatgpt-adaptive-instructions.md, docs/pandora-memory-safety-policy.md
Adds candidate capture, session digests, profile lifecycle helpers, open-loop CRUD, and safety guidance.
Hybrid retrieval and adaptive context
lib/services/memory-hybrid-retrieval-service.ts, lib/services/adaptive-chatgpt-context-service.ts
Builds hybrid memory context and maps it into the adaptive ChatGPT context payload.
HTTP routes and admin consoles
app/api/memory/adaptive/route-helper.ts, app/api/memory/adaptive/*/route.ts, app/api/memory/search/route.ts, app/api/memory/profiles/refresh/route.ts, app/admin/memory/*/page.tsx
Adds bridge-authenticated API routes and admin pages that surface feature-flag status.
MCP tools and OpenAPI
lib/services/pandora-mcp-tools.ts, lib/services/pandora-mcp-server.ts, public/pandora-memory-openapi.json
Registers adaptive-memory MCP tools and adds matching OpenAPI operations and response schema.

Sequence Diagram(s)

sequenceDiagram
  participant NextRequest
  participant SearchRoute as "POST /api/memory/search"
  participant BridgeHelper as "withBridge(request)"
  participant RetrievalService as "getHybridMemoryContext"
  participant MemoryBridgeDbClient
  NextRequest->>SearchRoute: POST body
  SearchRoute->>BridgeHelper: withBridge(request)
  BridgeHelper-->>SearchRoute: principal, client
  SearchRoute->>RetrievalService: getHybridMemoryContext(client, input)
  RetrievalService->>MemoryBridgeDbClient: query memory tables
  MemoryBridgeDbClient-->>RetrievalService: rows
  RetrievalService-->>SearchRoute: data and warnings
  SearchRoute-->>NextRequest: JSON response
Loading
sequenceDiagram
  participant MCPClient as "MCP client"
  participant PandoraMcpServer as "createPandoraMcpServer"
  participant AdaptiveContextTool as "getAdaptiveContextTool"
  participant ContextService as "buildAdaptiveChatGptContext"
  participant RetrievalService as "getHybridMemoryContext"
  participant AuditLog as "auditPandoraMcpToolCall"
  MCPClient->>PandoraMcpServer: request get_adaptive_context
  PandoraMcpServer->>AdaptiveContextTool: dispatch rawInput
  AdaptiveContextTool->>ContextService: buildAdaptiveChatGptContext(...)
  ContextService->>RetrievalService: getHybridMemoryContext(...)
  RetrievalService-->>ContextService: context
  AdaptiveContextTool->>AuditLog: audit tool call
  AdaptiveContextTool-->>PandoraMcpServer: data and warnings
  PandoraMcpServer-->>MCPClient: JSON content
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • besfeng23/Memory#101: Extends the MCP server/tooling foundation that this PR now wires into additional adaptive-memory tools and routes.

Poem

I hopped through tables, neat and wide,
With secrets redacted, tucked inside.
Adaptive context, crisp and bright,
MCP tools blink in rabbit-light.
🐇 Phase 4C carrots, ready to bite.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the PR’s main addition: Phase 4C adaptive memory intelligence across classification, redaction, embeddings, retrieval, MCP, and REST.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/add-phase-4c-adaptive-memory-features

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Copy link
Copy Markdown

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: 5d7cfaa5be

ℹ️ 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".

Comment thread app/api/memory/adaptive/route-helper.ts Outdated
Comment thread lib/services/pandora-mcp-tools.ts Outdated
Comment thread lib/services/memory-model-provider.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant