---
id: 10222
title: Remove Memory Core Band-Aids and Polish Cache Coherence
state: CLOSED
labels:
  - enhancement
  - ai
  - refactoring
  - architecture
  - core
assignees:
  - neo-gemini-pro
createdAt: '2026-04-23T09:16:59Z'
updatedAt: '2026-04-23T09:46:56Z'
githubUrl: 'https://github.com/neomjs/neo/issues/10222'
author: neo-gemini-pro
commentsCount: 0
parentIssue: 10186
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-04-23T09:46:56Z'
---
# Remove Memory Core Band-Aids and Polish Cache Coherence

### Context
With the successful merge of PR #10221 (resolving #10190) and empirical validation via full swarm restart cycles, the underlying `Database` cache coherence vulnerabilities have been resolved. The temporary band-aids put in place prior to the substrate fix (#10185 and #10182) are now obsolete and need to be removed to reduce operational complexity and avoid masking future regressions. Additionally, peer review on PR #10221 identified missing architectural documentation for future telemetry.

### The Problem
During the cache coherence diagnostic phase, two temporary mitigations were introduced into `Server.mjs`:
1. **#10185 Retry Loop**: Added to `bindAgentIdentity` to poll for graph nodes, attempting to mask the symptom of fresh-boot cache divergence.
2. **#10182 Self-Heal**: Added to the `CallToolHandler` to late-bind identities if they were missed during boot.

Since #10190 natively fixed the cache coherence issue by stripping the `lastSyncId` guard, `GraphService.getNode` is now guaranteed to return accurate results without needing artificial delays or retries. Keeping these band-aids introduces technical debt and makes the code harder to reason about.

### The Architectural Reality
- `ai/mcp/server/memory-core/Server.mjs`: `bindAgentIdentity` contains an obsolete 3-retry polling loop with a 200ms sleep and vicinity tracker resets. The tool call handler contains the `#10182` late-binding fallback.
- `ai/graph/Database.mjs`: Lines 78 and 281 lack the "Anchor & Echo" rationale for the #10190 changes (removing the `lastSyncId` guard and the empty-vicinity mark), leaving a knowledge gap for future debugging. The `syncCache` JSDoc also omits the new invariant that fresh-boots are legitimate triggers that invalidate the cache.

### The Fix
1. **Remove Retry Loop**: Strip the 3-attempt polling logic from `Server.mjs:bindAgentIdentity`. A single `GraphService.getNode({id: graphNodeId})` call is now sufficient since `await GraphService.ready()` ensures the cache is coherent.
2. **Remove Self-Heal**: Strip the `!this.stdioIdentity.agentIdentityNodeId` fallback block from the `CallToolRequestSchema` handler in `Server.mjs`.
3. **Anchor & Echo**: Add inline comments citing #10190 / ADR 0001 Bug A (at `Database.mjs:78`) and Bug B (at `Database.mjs:281-283`).
4. **JSDoc Extension**: Update the `syncCache` JSDoc to explicitly state that `lastSyncId=0` triggers a legitimate catch-up rather than a skip, and clarify that it *invalidates* stale entries rather than upserting new ones.

### Acceptance Criteria
- [ ] `bindAgentIdentity` in `Server.mjs` no longer contains a polling loop or vicinity cache deletion.
- [ ] Tool dispatch in `Server.mjs` no longer contains the `#10182` self-heal logic.
- [ ] `ai/graph/Database.mjs` contains explicit inline comments detailing the "WHY" for both Bug A and Bug B resolutions.
- [ ] `syncCache` JSDoc explicitly documents its invariant behavior regarding fresh boots and invalidation vs upserts.

### Out of Scope
- Modifying the underlying `GraphLog` or `Database.mjs` execution logic (this is strictly a cleanup and documentation pass).
- Any modifications to the `MailboxService` or A2A handshakes.

### Avoided Traps
- **Trap**: Leaving the band-aids as "defense in depth." **Why avoided**: It masks potential future regressions in the `Database` coherence layer. If the cache is incoherent, we *want* the identity binding to fail so the substrate issue is surfaced immediately, rather than silently retrying.

### Related
- Resolves #10190 post-merge polish suggestions
- Removes band-aids from #10182, #10185
- Epic: #10186

Origin Session ID: e068b094-fcae-436a-a9ab-c513246f7f71

## Timeline

- 2026-04-23T09:17:00Z @neo-gemini-pro added the `enhancement` label
- 2026-04-23T09:17:00Z @neo-gemini-pro added the `ai` label
- 2026-04-23T09:17:00Z @neo-gemini-pro added the `refactoring` label
- 2026-04-23T09:17:00Z @neo-gemini-pro added the `architecture` label
- 2026-04-23T09:17:01Z @neo-gemini-pro added the `core` label
- 2026-04-23T09:20:33Z @neo-gemini-pro assigned to @neo-gemini-pro
- 2026-04-23T09:20:37Z @neo-gemini-pro added parent issue #10186
- 2026-04-23T09:26:36Z @neo-gemini-pro cross-referenced by PR #10223
- 2026-04-23T09:32:57Z @neo-gemini-pro referenced in commit `3ee73f2` - "fix(ai): remove memory core band-aids and polish cache coherence (#10222)"
- 2026-04-23T09:46:56Z @tobiu referenced in commit `e5ad843` - "fix(ai): remove memory core band-aids and polish cache coherence (#10222) (#10223)

Co-authored-by: tobiu <tobiasuhlig78@gmail.com>"
- 2026-04-23T09:46:56Z @tobiu closed this issue
- 2026-04-23T10:27:34Z @neo-gemini-pro cross-referenced by #10226
- 2026-05-03T14:33:42Z @neo-gpt cross-referenced by #10645
- 2026-05-03T16:43:35Z @neo-opus-ada cross-referenced by PR #10656

