---
id: 12543
title: Remove MailboxService B3 AiConfig defensive read
state: CLOSED
labels:
  - enhancement
  - ai
  - refactoring
  - architecture
assignees:
  - neo-gpt
createdAt: '2026-06-04T20:50:53Z'
updatedAt: '2026-06-05T01:50:27Z'
githubUrl: 'https://github.com/neomjs/neo/issues/12543'
author: neo-gpt
commentsCount: 0
parentIssue: 12461
subIssues: []
subIssuesCompleted: 0
subIssuesTotal: 0
blockedBy: []
blocking: []
closedAt: '2026-06-05T01:50:27Z'
---
# Remove MailboxService B3 AiConfig defensive read

## Context

This is a narrow B3 cleanup child under #12461 / #12456 for the Memory Core mailbox reply-policy read.

Current verified source on `origin/dev`:

```js
const strictReplyPolicy = aiConfig.mailbox?.defaultReplyPolicy === 'blocked';
```

V-B-A collision sweep run before filing:
- `git grep -n -E "(aiConfig|AiConfig)(\.[A-Za-z0-9_]+)*\?\." origin/dev -- ai/services/memory-core/MailboxService.mjs` found only the MailboxService reply-policy read for this scope.
- `gh issue list --state open --search "MailboxService defaultReplyPolicy AiConfig B3"` returned no open issues.
- `gh pr list --state open --search "MailboxService defaultReplyPolicy AiConfig"` returned no open PRs.
- Existing B3 lanes are disjoint: maintenance scripts (#12541/#12542), GitLab HealthService (#12526/#12528), and ConceptDiscoveryService (#12538/#12539).

## Problem

`MailboxService.addMessage()` gates strict reply behavior using an optional-chain read of `aiConfig.mailbox.defaultReplyPolicy`. Under ADR 0019, resolved AiConfig leaves are the use-site source of truth and B3 defensive reads should fail loudly instead of silently degrading when a required config subtree is absent.

The current `?.` masks missing `mailbox` configuration by treating the strict policy as false, which can weaken the configured reply-policy contract without surfacing the configuration drift.

## Architectural Reality

`ai/mcp/server/memory-core/config.mjs` defines the `mailbox` subtree and `defaultReplyPolicy` leaf. `MailboxService` is a consumer of that resolved config, not an owner or fallback surface.

B3 cleanup means removing defensive optional chaining on config reads while preserving the existing policy behavior:
- `'blocked'` enables strict reply-policy enforcement.
- `'open'` keeps reply behavior permissive.
- Missing config should fail at the read site rather than becoming an implicit open policy.

## Fix

Replace the defensive read in `ai/services/memory-core/MailboxService.mjs` with a direct resolved-leaf read:

```js
const strictReplyPolicy = aiConfig.mailbox.defaultReplyPolicy === 'blocked';
```

Do not introduce a local fallback, alias, re-export, or default in `MailboxService`.

## Contract Ledger

| Consumed Surface | Required Contract | Why it matters |
| --- | --- | --- |
| `MailboxService.addMessage()` reply-policy gate | Reads `aiConfig.mailbox.defaultReplyPolicy` directly | A missing mailbox config subtree must fail loudly instead of silently bypassing strict reply enforcement |
| `ai/mcp/server/memory-core/config.mjs` mailbox subtree | Owns `mailbox.defaultReplyPolicy` as the resolved config leaf | Keeps AiConfig as the single source of truth per ADR 0019 |
| Existing MailboxService policy tests | Continue proving both blocked and open policy behavior | Confirms this is a B3 read-shape cleanup, not a policy semantic change |

## Decision Record Impact

Aligned with ADR 0019: the reactive Provider-backed AiConfig singleton remains the SSOT. This ticket removes a consumer-side defensive read and does not create new config ownership.

## Acceptance Criteria

- `MailboxService.addMessage()` no longer uses `aiConfig.mailbox?.defaultReplyPolicy`.
- The replacement is a direct resolved-leaf read with no fallback.
- Focused MailboxService unit coverage still passes for blocked and open reply-policy behavior.
- The change does not alter mailbox policy semantics, A2A message delivery, or permission behavior.

## Out of Scope

- B4 cleanup of test-level singleton mutation patterns.
- Changing the default reply policy.
- Other #12461 B3 clusters in TransportService, MemoryService, SummaryService, SessionService, CollectionProxy, Orchestrator, BaseServer, or Logger.

## Related

- Parent: #12461
- Epic: #12456
- ADR: `learn/agentos/decisions/0019-aiconfig-reactive-provider-ssot.md`

## Origin Session

`dcdaac0b-9ae0-45b5-b4da-da39541af497`

## Retrieval Hint

`MailboxService defaultReplyPolicy AiConfig B3 ADR 0019`

## Timeline

- 2026-06-04T20:50:54Z @neo-gpt assigned to @neo-gpt
- 2026-06-04T20:50:55Z @neo-gpt added the `enhancement` label
- 2026-06-04T20:50:55Z @neo-gpt added the `ai` label
- 2026-06-04T20:50:55Z @neo-gpt added the `refactoring` label
- 2026-06-04T20:50:55Z @neo-gpt added the `architecture` label
- 2026-06-04T20:51:02Z @neo-gpt added parent issue #12461
- 2026-06-04T20:54:55Z @neo-gpt cross-referenced by PR #12544
- 2026-06-05T01:50:27Z @tobiu referenced in commit `6f6665e` - "fix(ai): remove mailbox B3 config defense (#12543) (#12544)

Co-authored-by: tobiu <tobiasuhlig78@gmail.com>"
- 2026-06-05T01:50:27Z @tobiu closed this issue

