Repository navigation
fix(memory-core): mailbox SENT_TO persistence + fromIdentity filter + add_memory inbox delta (#10174) - #10178
Conversation
|
Input from Gemini 3.1 Pro (Antigravity):
|
… add_memory inbox delta (#10174)
3fc8755 to
1443401
Compare
|
Input from Claude Opus 4.7 (Claude Code):
|
…10180) (#11528) * feat(memory-core): countMessages primitive + concept provenance docs (#10180) Resolves #10180 — Mailbox polish on two adjacent surfaces. **countMessages primitive (Problem 1 — retires the 100-cap proxy):** `MailboxService.countMessages({box, status, fromIdentity?})` returns `{count}` via direct SQL prepared statements joining `Edges` and `Nodes`, patterned after `MemoryService.buildMailboxDelta` (#10178). Inbox path uses the same 3-way UNION taxonomy (SENT_TO direct DM + DELIVERED_TO per-recipient broadcast + SENT_TO AGENT:* legacy without DELIVERED_TO). Outbox path counts SENT_BY edges from the caller. Permission-checked via `CAN_READ_INBOX_OF` mirroring `listMessages`. `getHealthcheckPreview` refactored to call `countMessages({status: 'unread'})` for `unreadCount` and `listMessages({limit: 3})` for the preview surface, retiring the previous `listMessages({limit: 100})` proxy pattern that silently under-reported any inbox with > 100 unread messages. **Concept provenance docs (Problem 2 — surfaces undocumented contract):** New section in `learn/agentos/ConceptOntology.md` § Auto-Extracted Concept Provenance documenting: - Write path: `MailboxService.addMessage` → `SemanticGraphExtractor .extractMessageConcepts` (fire-and-forget post-write) - Node-side flag: `properties.auto_extracted: true` (set only on fresh-create, preserves curated node authority) - Edge-weight convention: 0.8 auto vs 1.0 curated (20% rank delta calibrated to LLM precision gap) - Read-time consumer pattern for DreamService / Librarian / future GraphRAG ranking and filtering `SemanticGraphExtractor.extractMessageConcepts` JSDoc extended with `@see` cross-references to the new ConceptOntology section + the caller in `MailboxService#addMessage`, completing the bi-directional anchor between code and substrate docs. **Substrate-shift acknowledgment:** the original #10180 ticket body cited `ai/mcp/server/memory-core/services/MailboxService.mjs` — the service moved to `ai/services/memory-core/MailboxService.mjs` via PR #11224 (memory-core flat SDK migration). Implementation here uses the current path; ticket body's file paths are stale but the premise remains valid (V-B-A: 100-cap exists at line 920-927 of the current file; ConceptOntology.md still silent on auto_extracted). **Test evidence:** 51/51 pass on MailboxService.spec.mjs (47 baseline + 4 new: AC4 countMessages-vs-listMessages parity for small inbox; AC3 150+ unread regression with explicit >100 anti-regression assertion; AC1 outbox SENT_BY counting; AC1 unbound-identity error path). **Out of scope** (per ticket Out of Scope section): - MCP tool surface for countMessages — internal service method only; add MCP exposure if external consumer surfaces - buildMailboxDelta refactoring to delegate to countMessages — keeps direct-SQL fast-path; DRY concern not correctness concern - Concurrency back-pressure on extractMessageConcepts — separate ticket * fix(memory-core): countMessages rejects unsupported box values (#10180) Cycle-1 response to @neo-gpt review on PR #11528: #11528 (review)... Required Action addressed: previously `if (box === 'outbox') ... else ...` silently aliased `box='all'` (deferred per PR body) AND any typo to the inbox query, returning a plausible but partial-result count. This commit fails fast on unsupported enum values so callers see the deferred-vs- implemented contract boundary at call-time. Changes: - `countMessages` now throws on `box !== 'inbox' && box !== 'outbox'` with a clear error message naming the unsupported value + listing the supported set + flagging `'all'` as deferred follow-up. - JSDoc extended with a Box-value contract paragraph documenting the supported enum + rationale linking back to #11528 cycle-1 review. - Regression spec test: rejects `'all'`, typos, empty string; sanity- checks `'inbox'` + `'outbox'` still work post-guard. Test results: 52/52 on MailboxService.spec.mjs (51 baseline + 1 new cycle-1 hardening). --------- Co-authored-by: tobiu <[email protected]>
Authored by Claude Opus 4.7 (Claude Code). Session d907e342-28fc-4eb6-8c51-355772dbfb44.
Resolves #10174
The mailbox A2A primitive never worked end-to-end since it shipped via #10147.
addMessagereturned optimisticstatus: 'sent', theMESSAGEnode +SENT_BYedge persisted, but theSENT_TOedge — the sole substratelistMessagesscans to populate an inbox — was silently dropped byGraphService.linkNodes's FK-style guard whenever the target was the broadcast sentinelAGENT:*OR the ambiguousAGENT:@loginprefixed form documented in the tool schema. Of the three addressing modes shipped in #10147's AC, only bare@loginever actually functioned; the AC-satisfying tests asserted on the response payload rather than reading back throughlistMessages. This PR fixes the four components that make the primitive whole + extendsadd_memorywith a per-turn inbox delta signal so agents no longer need MCP restarts to see messages written by other harness processes.Empirically surfaced during the first attempted A2A handshake between
@neo-opus-4-7and@neo-gemini-3-1-prothis session — root cause diagnosed via direct SQLite inspection after three Claude Desktop restarts failed to materialize either agent's inbox.Deltas from ticket
Pivoted Fix #3 from AuthMiddleware surgery to parameter rename. The ticket proposed removing
fromfromAuthMiddleware.IDENTITY_OVERRIDE_KEYSto unblocklistMessages({from: X}). During implementation I noticed the middleware's own scope note explicitly separates claim-of-authorship keys (blocked) from destination-address fields (allowed) — removingfromwould open a real spoof surface for any future tool that acceptsfromas a write-side authorship claim. The correct substrate for the fix is the read-path parameter itself: renamed tofromIdentityin both the tool schema andMailboxService.listMessages. Middleware stays strict; defense-in-depth preserved. Full ticket body still describes the approach; see "Evolution" section below.Implementation summary
ai/scripts/seedAgentIdentities.mjsAGENT:*as a seededBroadcastSentinelnode solinkNodes' FK guard accepts broadcast SENT_TO edgesai/mcp/server/memory-core/services/MailboxService.mjsnormalizeMailboxTarget()helper;addMessagecanonicalizes'AGENT:@login'→'@login'beforelinkNodes;listMessagesparameter renamedfrom→fromIdentity(with JSDoc explaining the AuthMiddleware rationale)ai/mcp/server/memory-core/services/MemoryService.mjsbuildMailboxDelta()helper (exported for test consumption) that bypasses the in-memory graph cache via direct SQLiteSELECTs for cross-process correctness;addMemoryresponse gains `mailbox: {unreadCount, latestPreview}ai/mcp/server/memory-core/openapi.yamllist_messagesparameter rename reflected in tool surface;MemoryResponseschema extended with themailboxblock (nullable) and nestedlatestPreviewobjecttest/playwright/unit/ai/mcp/server/memory-core/services/MailboxService.spec.mjsfilters by threadId and fromtest updated tofromIdentity; new#10174 production-convention addressingdescribe block with 6 regression tests covering bare-@login,AGENT:@loginnormalization,AGENT:*broadcast fan-out, andbuildMailboxDeltacontract (bound + unbound + broadcast-in-count)Test Evidence
Targeted:
npm run test-unit -- test/playwright/unit/ai/mcp/server/memory-core/services/MailboxService.spec.mjsResult: 16/16 passed (883ms) — 10 pre-existing tests (one updated for the param rename) + 6 net-new regression tests.
Broader memory-core suite: 78 pass, 14 pre-existing failures unrelated to this PR. Confirmed via
git diff— the failing tests touch files this PR doesn't modify (ChromaManager,FileSystemIngestor,DatabaseService.backupPath,GraphService,ChromaLifecycleService,QueryReRanker,SessionSummarization,McpServerToolLimits). The last one fails specifically onmanage_database's description being 1161 chars > 1024 cap — a pre-existing content-length violation in openapi.yaml that this PR does not touch. Worth filing as a separate chore if not already tracked.Post-Merge Validation
node ai/scripts/seedAgentIdentities.mjsagainst the shared.neo-ai-data/sqlite/memory-core-graph.sqliteto materialize theAGENT:*sentinel in the live DB (the seed is idempotent; re-runs preserve existingcreatedAt).@neo-opus-4-7broadcasts a verification message;@neo-gemini-3-1-procallslist_messages({box: 'inbox'})and sees the message + SENT_TO edge with targetAGENT:*in SQLite.add_memoryresponse contains themailboxblock; subsequentlist_messagescounts matchunreadCount.Evolution
Fix #3 pivot: anti-spoof unblock → parameter rename.
Ticket body proposed removing
fromfromAuthMiddleware.IDENTITY_OVERRIDE_KEYSas the minimal fix for thelistMessages({from: X})rejection. While reading the middleware source I caught its explicit scope note: destination-address fields are legitimate, claim-of-authorship fields are blocked. The collision isn't with the middleware's model — it's withlistMessages' parameter name, which happens to be a read-path filter semantically but shares a name with an authorship-claim key. Renaming the read-path param tofromIdentitypreserves the middleware's defense-in-depth (blocks future write-sidefromabuse) while giving the filter a non-colliding name. Zero-cost for callers since tool calls are schema-driven — the new parameter name propagates automatically.Related: sibling ticket #10176 (identity observability + Claude Desktop docs) is the non-blocking dual; parent #10139 is the mailbox A2A epic; Gemini is in parallel on #10169 (TAGGED_CONCEPT auto-emit) which is orthogonal to this SENT_TO fix and can merge in either order.