# Implementation Gaps: Go NATS Server vs .NET Port

**Last updated:** 2026-02-26

## Overview

| Metric | Go Server | .NET Port | Ratio |
|--------|-----------|-----------|-------|
| Source lines | ~130K (109 files) | ~39.1K (215 files) | 3.3x |
| Test methods | 2,937 `func Test*` | 5,914 `[Fact]`/`[Theory]` (~6,532 with parameterized) | 2.0x |
| Go tests mapped | 2,646 / 2,937 (90.1%) | — | — |
| .NET tests linked to Go | — | 4,250 / 5,808 (73.2%) | — |
| Largest source file | filestore.go (12,593 lines) | NatsServer.cs (1,883 lines) | 6.7x |

The .NET port has grown significantly from the prior baseline (~27K→~39.1K lines). All 15 original gaps have seen substantial growth. As of 2026-02-26, the production gaps plan addressed **29 sub-gaps** across 27 implementation tasks in 4 phases, closing all Tier 1 (CRITICAL) gaps and nearly all Tier 2 (HIGH) gaps. The remaining gaps are primarily in Tier 3 (MEDIUM) and Tier 4 (LOW).

## Gap Severity Legend

- **CRITICAL**: Core functionality missing, blocks production use
- **HIGH**: Important feature incomplete, limits capabilities significantly
- **MEDIUM**: Feature gap exists but workarounds are possible or feature is less commonly used
- **LOW**: Nice-to-have, minor optimization or edge-case handling

---

## Gap 1: FileStore Block Management (CRITICAL)

**Go reference**: `filestore.go` — 12,593 lines
**NET implementation**: `FileStore.cs` (1,633) + `MsgBlock.cs` (630) + supporting files
**Current .NET total**: ~5,196 lines in Storage/
**Gap factor**: 2.4x (down from 20.8x)

The .NET FileStore has grown substantially with block-based storage, but the block lifecycle, encryption/compression integration, crash recovery, and integrity checking remain incomplete.

### 1.1 Block Rotation & Lifecycle — IMPLEMENTED

**Implemented in:** `MsgBlock.cs`, `FileStore.cs` (Task 3, commit phase 1)

Block rotation with size thresholds, block sealing, per-block metadata, and background flusher are now implemented. Tests: `FileStoreBlockRotationTests.cs`.

### 1.2 Encryption Integration into Block I/O — IMPLEMENTED

**Implemented in:** `FileStore.cs`, `MsgBlock.cs` (Task 1, commit phase 1)

Per-block AEAD encryption wired into the block write/read path using `AeadEncryptor`. Key generation, recovery, and cipher conversion implemented. Tests: `FileStoreEncryptionTests.cs`.

### 1.3 S2 Compression in Block Path — IMPLEMENTED

**Implemented in:** `FileStore.cs`, `MsgBlock.cs` (Task 2, commit phase 1)

S2 compression integrated into block write/read path using `S2Codec`. Message-level compression and decompression during block operations. Tests: `FileStoreCompressionTests.cs`.

### 1.4 Crash Recovery & Index Rebuilding — IMPLEMENTED

**Implemented in:** `FileStore.cs`, `MsgBlock.cs` (Task 4, commit phase 1)

Full crash recovery with block scanning, index rebuilding, TTL wheel recovery, lost-data tracking, and MaxAge enforcement on recovery. Tests: `FileStoreCrashRecoveryTests.cs`.

### 1.5 Checksum Validation (HIGH)

Go uses highway hash for per-message checksums and validates integrity on read.

**Missing:**
- `msgBlock.lchk[8]byte` — last checksum buffer
- `msgBlock.hh *highwayhash.Digest64` — highway hasher
- `msgBlock.lastChecksum()` (line 2204) — returns last computed checksum
- Message checksum validation during `msgFromBufEx()` (line ~8180)

**.NET status**: `MessageRecord` has no checksum field. No integrity checks on read.

### 1.6 Atomic File Overwrites (HIGH)

Go uses temp file + rename for crash-safe state updates.

**Missing:**
- `_writeFullState()` (line 10599) — atomic state serialization with temp file + rename
- State file write protection with mutual exclusion (`wfsmu`/`wfsrun`)

**.NET status**: Writes directly without atomic guarantees.

### 1.7 Tombstone & Deletion Tracking (HIGH)

**Missing:**
- `removeMsg()` (line 5267) — removes message with optional secure erase
- `removeMsgFromBlock()` (line 5307) — removes from specific block
- `eraseMsg()` (line 5890) — overwrites deleted message with random data (secure erase)
- Sparse `avl.SequenceSet` for deletion tracking (Go uses AVL; .NET uses `HashSet<ulong>`)
- Tombstone record persistence (deleted messages lost on crash in .NET)

### 1.8 Multi-Block Write Cache (MEDIUM)

**Missing Go functions:**
- `setupWriteCache()` (line 4443) — sets up write cache
- `finishedWithCache()` (line 4477) — marks cache complete
- `expireCache()` / `expireCacheLocked()` (line 6148+) — expires idle cache
- `resetCacheExpireTimer()` / `startCacheExpireTimer()` — manages cache timeout
- Elastic reference machinery (line 6704, `ecache.Strengthen()` / `WeakenAfter()`)
- `flushPendingMsgs()` / `flushPendingMsgsLocked()` (line 7560+) — background flush

**.NET status**: Synchronous flush on rotation; no background flusher, no cache expiration.

### 1.9 Missing IStreamStore Interface Methods — IMPLEMENTED

**Implemented in:** `IStreamStore.cs`, `FileStore.cs`, `MemStore.cs` (Tasks 5-6, commit phase 1)

All missing interface methods added to `IStreamStore` and implemented in both `FileStore` and `MemStore`: `StoreRawMsg`, `LoadNextMsgMulti`, `LoadPrevMsg`, `LoadPrevMsgMulti`, `NumPendingMulti`, `SyncDeleted`, `EncodedStreamState`, `Utilization`, `FlushAllPending`, `RegisterStorageUpdates`, `RegisterStorageRemoveMsg`, `RegisterProcessJetStreamMsg`, `ResetState`, `UpdateConfig`, `Delete(bool)`, `Stop()`. Tests: `StreamStoreInterfaceTests.cs`.

### 1.10 Query/Filter Operations (MEDIUM)

Go uses trie-based subject indexing (`SubjectTree[T]`) for O(log n) lookups. .NET uses linear LINQ scans.

**Missing:**
- `FilteredState()` (line 3191) — optimized filtered state with caching
- `checkSkipFirstBlock()` family (lines 3241–3287)
- `numFiltered*()` family (lines 3308–3413)
- `LoadMsg()` (line 8308) — block-aware message loading

---

## Gap 2: JetStream Cluster Coordination (CRITICAL)

**Go reference**: `jetstream_cluster.go` — 10,887 lines
**NET implementation**: `JetStreamMetaGroup.cs` (454) + `StreamReplicaGroup.cs` (300) + supporting files
**Current .NET total**: ~2,787 lines in Cluster/ + Raft/
**Gap factor**: ~3.9x
**Missing functions**: ~84

The .NET implementation provides a skeleton suitable for unit testing but lacks the real cluster coordination machinery. The Go implementation is deeply integrated with RAFT, NATS subscriptions for inter-node communication, and background monitoring goroutines.

### 2.1 Cluster Monitoring Loop — IMPLEMENTED

**Implemented in:** `JetStreamMetaGroup.cs` (Task 10, commit phase 2)

Cluster monitoring loop with RAFT ApplyQ processing, orphan detection, cluster size checking, stream/consumer health checks, and subject overlap prevention. Tests: `ClusterMonitoringTests.cs`.

### 2.2 Stream & Consumer Assignment Processing — IMPLEMENTED

**Implemented in:** `JetStreamMetaGroup.cs`, `StreamReplicaGroup.cs` (Task 11, commit phase 2)

Stream and consumer assignment processing including create, update, delete, and removal operations. Tests: `AssignmentProcessingTests.cs`.

### 2.3 Inflight Request Deduplication — IMPLEMENTED

**Implemented in:** `JetStreamMetaGroup.cs` (Task 12, commit phase 2)

Inflight stream and consumer proposal tracking with ops count, deleted flag, and assignment capture. Tests: `InflightDedupTests.cs`.

### 2.4 Peer Management & Stream Moves (HIGH)

**Missing:**
- `processAddPeer()` (lines 2290–2340)
- `processRemovePeer()` (lines 2342–2393)
- `removePeerFromStream()` / `removePeerFromStreamLocked()` (lines 2396–2439)
- `remapStreamAssignment()` (lines 7077–7111)
- Stream move operations in `jsClusteredStreamUpdateRequest()` (lines 7757+)

### 2.5 Leadership Transition — IMPLEMENTED

**Implemented in:** `JetStreamMetaGroup.cs`, `StreamReplicaGroup.cs` (Task 13, commit phase 2)

Meta-level, stream-level, and consumer-level leader change processing with step-down mechanisms. Tests: `LeadershipTransitionTests.cs`.

### 2.6 Snapshot & State Recovery — IMPLEMENTED

**Implemented in:** `JetStreamMetaGroup.cs` (Task 9, commit phase 2)

Meta snapshot encode/decode with S2 compression, apply snapshot with delta computation, and stream/consumer change collection. Tests: `SnapshotRecoveryTests.cs`.

### 2.7 Entry Application Pipeline (HIGH)

**Missing:**
- `applyMetaEntries()` (lines 2474–2609, 136 lines) — handles all entry types
- `applyStreamEntries()` (lines 3645–4067, 423 lines) — per-stream entries
- `applyStreamMsgOp()` (lines 4068–4261, 194 lines) — per-message ops
- `applyConsumerEntries()` (lines 6351–6621, 271 lines) — per-consumer entries

### 2.8 Topology-Aware Placement (MEDIUM)

**Missing from PlacementEngine (currently 80 lines vs Go's 312 lines for `selectPeerGroup()`):**
- Unique tag enforcement (`JetStreamUniqueTag`)
- HA asset limits per peer
- Dynamic available storage calculation
- Tag inclusion/exclusion with prefix handling
- Weighted node selection based on availability
- Mixed-mode detection
- `tieredStreamAndReservationCount()` (lines 7524–7546)
- `createGroupForConsumer()` (lines 8783–8923, 141 lines)
- `jsClusteredStreamLimitsCheck()` (lines 7599–7618)

### 2.9 RAFT Group Creation & Lifecycle (MEDIUM)

**Missing:**
- `createRaftGroup()` (lines 2659–2789, 131 lines)
- `raftGroup.isMember()` (lines 2611–2621)
- `raftGroup.setPreferred()` (lines 2623–2656)

### 2.10 Assignment Encoding/Decoding (MEDIUM)

**Missing (no serialization for RAFT persistence):**
- `encodeAddStreamAssignment()`, `encodeUpdateStreamAssignment()`, `encodeDeleteStreamAssignment()`
- `decodeStreamAssignment()`, `decodeStreamAssignmentConfig()`
- `encodeAddConsumerAssignment()`, `encodeDeleteConsumerAssignment()`
- `encodeAddConsumerAssignmentCompressed()`, `decodeConsumerAssignment()`
- `decodeConsumerAssignmentCompressed()`, `decodeConsumerAssignmentConfig()`

### 2.11 Unsupported Asset Handling (LOW)

**Missing:**
- `unsupportedStreamAssignment` type (lines 186–247) — graceful handling of version-incompatible streams
- `unsupportedConsumerAssignment` type (lines 268–330)

### 2.12 Clustered API Handlers (MEDIUM)

**Missing:**
- `jsClusteredStreamRequest()` (lines 7620–7701, 82 lines)
- `jsClusteredStreamUpdateRequest()` (lines 7757–8265, 509 lines)
- System-level subscriptions for result processing, peer removal, leadership step-down

---

## Gap 3: Consumer Delivery Engines (HIGH)

**Go reference**: `consumer.go` — 6,715 lines, 209 functions
**NET implementation**: `PushConsumerEngine.cs` (264) + `PullConsumerEngine.cs` (411) + `AckProcessor.cs` (225) + `PriorityGroupManager.cs` (102) + `RedeliveryTracker.cs` (92) + `ConsumerManager.cs` (198)
**Current .NET total**: ~1,292 lines
**Gap factor**: 5.2x

### 3.1 Core Message Delivery Loop (CRITICAL)

**Missing**: `loopAndGatherMsgs()` (Go lines ~1400–1700) — the main consumer dispatch loop that:
- Polls stream store for new messages matching filter
- Applies redelivery logic
- Handles num_pending calculations
- Manages delivery interest tracking
- Responds to stream updates

### 3.2 Pull Request Pipeline — IMPLEMENTED

**Implemented in:** `PullConsumerEngine.cs` (Task 16, commit phase 3)

Full pull request handler with waiting request queue, max bytes accumulation, flow control, request expiry, batch size enforcement, and priority group pin ID assignment. Tests: `PullPipelineTests.cs`.

### 3.3 Inbound Ack/NAK Processing Loop — IMPLEMENTED

**Implemented in:** `AckProcessor.cs` (Task 15, commit phase 3)

Background ack processing with `+ACK`, `-NAK`, `+TERM`, `+WPI` frame parsing, handler dispatch, ack deadline management, and redelivery scheduling. Tests: `AckNakProcessingTests.cs`.

### 3.4 Redelivery Scheduler — IMPLEMENTED

**Implemented in:** `RedeliveryTracker.cs` (Task 14, commit phase 3)

Min-heap/priority queue redelivery with deadline ordering, batch dispatch, per-sequence redelivery state, and rate limiting. Tests: `RedeliverySchedulerTests.cs`.

### 3.5 Idle Heartbeat & Flow Control (HIGH)

**Missing**:
- `sendIdleHeartbeat()` (Go line ~5222) — heartbeat with pending counts and stall headers
- `sendFlowControl()` (Go line ~5495) — dedicated flow control handler
- Flow control reply generation with pending counts

### 3.6 Priority Group Pinning — IMPLEMENTED

**Implemented in:** `PriorityGroupManager.cs` (Task 18, commit phase 3)

Pin ID generation and assignment, pin timeout timers, `Nats-Pin-Id` header response, advisory messages on pin/unpin events, and priority group state persistence. Tests: `PriorityPinningTests.cs`.

### 3.7 Pause/Resume State Management — IMPLEMENTED

**Implemented in:** `ConsumerManager.cs` (Task 17, commit phase 3)

PauseUntil deadline tracking, pause expiry timer, pause/resume advisory generation, and pause state in consumer info response. Tests: `PauseResumeTests.cs`.

### 3.8 Delivery Interest Tracking (HIGH)

**Missing**: Dynamic delivery interest monitoring:
- Subject interest change tracking
- Gateway interest checks
- Subscribe/unsubscribe tracking for delivery subject
- Interest-driven consumer cleanup (`deleteNotActive`)

### 3.9 Max Deliveries Enforcement (MEDIUM)

`AckProcessor` checks basic threshold but missing:
- Advisory event generation on exceeding max delivers
- Per-delivery-count policy selection
- `NotifyDeliveryExceeded` advisory

### 3.10 Filter Subject Skip Tracking (MEDIUM)

**Missing**: Efficient filter matching with compiled regex, skip list tracking, `UpdateSkipped` state updates.

### 3.11 Sample/Observe Mode (MEDIUM)

**Missing**: Sample frequency parsing (`"1%"`), stochastic sampling, latency measurement, latency advisory generation.

### 3.12 Reset to Sequence (MEDIUM)

**Missing**: `processResetReq()` (Go line ~4241) — consumer state reset to specific sequence.

### 3.13 Rate Limiting (MEDIUM)

`PushConsumerEngine` has basic rate limiting but missing accurate token bucket, dynamic updates, per-message delay calculation.

### 3.14 Cluster-Aware Pending Requests (LOW)

**Missing**: Pull request proposals to RAFT, cluster-wide pending request tracking.

---

## Gap 4: Stream Mirrors, Sources & Lifecycle (HIGH)

**Go reference**: `stream.go` — 8,072 lines, 193 functions
**NET implementation**: `StreamManager.cs` (644) + `MirrorCoordinator.cs` (364) + `SourceCoordinator.cs` (470)
**Current .NET total**: ~1,478 lines
**Gap factor**: 5.5x

### 4.1 Mirror Consumer Setup & Retry — IMPLEMENTED

**Implemented in:** `MirrorCoordinator.cs` (Task 21, commit phase 4)

Mirror error state tracking (`SetError`/`ClearError`/`HasError`), exponential backoff retry (`RecordFailure`/`RecordSuccess`/`GetRetryDelay`), and gap detection (`RecordSourceSeq` with `HasGap`/`GapStart`/`GapEnd`). Tests: `MirrorSourceRetryTests.cs`.

### 4.2 Mirror Message Processing — IMPLEMENTED

**Implemented in:** `MirrorCoordinator.cs` (Task 21, commit phase 4)

Gap detection in mirror stream, sequence alignment tracking, and mirror error state management. Tests: `MirrorSourceRetryTests.cs`.

### 4.3 Source Consumer Setup (HIGH)

`SourceCoordinator` (470 lines) exists but missing:
- Complete source consumer API request generation
- Subject filter configuration
- Subject transform setup
- Account isolation verification
- Flow control configuration
- Starting sequence selection logic

### 4.4 Deduplication Window Management — IMPLEMENTED

**Implemented in:** `SourceCoordinator.cs` (Task 21, commit phase 4)

Public `IsDuplicate`, `RecordMsgId`, and `PruneDedupWindow(DateTimeOffset cutoff)` for time-based window pruning. Tests: `MirrorSourceRetryTests.cs`.

### 4.5 Purge with Subject Filtering — IMPLEMENTED

**Implemented in:** `StreamManager.cs` (Task 19, commit phase 3)

Subject-specific purge, sequence range purge, keep-N functionality, and consumer purge cascading. Tests: `PurgeFilterTests.cs`.

### 4.6 Interest Retention Enforcement — IMPLEMENTED

**Implemented in:** `StreamManager.cs` (Task 20, commit phase 3)

Interest-based message cleanup, per-consumer interest tracking, filtered consumer subject matching, and orphan message cleanup. Tests: `InterestRetentionTests.cs`.

### 4.7 Stream Snapshot & Restore (MEDIUM)

`StreamSnapshotService` is a 10-line stub. Missing:
- Snapshot deadline enforcement
- Consumer inclusion/exclusion
- TAR + S2 compression/decompression
- Snapshot validation
- Partial restore recovery

### 4.8 Stream Config Update Validation (MEDIUM)

**Missing**:
- Subjects overlap checking
- Mirror/source config validation
- Subjects modification handling
- Template update propagation
- Discard policy enforcement

### 4.9 Source Retry & Health — IMPLEMENTED

**Implemented in:** `SourceCoordinator.cs`, `MirrorCoordinator.cs` (Task 21, commit phase 4)

Exponential backoff retry via shared `RecordFailure`/`RecordSuccess`/`GetRetryDelay` pattern. Tests: `MirrorSourceRetryTests.cs`.

### 4.10 Source/Mirror Info Reporting (LOW)

**Missing**: Source/mirror lag, error state, consumer info for monitoring responses.

---

## Gap 5: Client Protocol Handling (HIGH)

**Go reference**: `client.go` — 6,716 lines, 162+ functions
**NET implementation**: `NatsClient.cs` (924 lines)
**Gap factor**: 7.3x

### 5.1 Flush Coalescing — IMPLEMENTED

**Implemented in:** `NatsClient.cs` (Task 22, commit phase 4)

`MaxFlushPending=10` constant, `SignalFlushPending()`/`ResetFlushPending()` methods, `FlushSignalsPending` and `ShouldCoalesceFlush` properties, integrated into `QueueOutbound` and `RunWriteLoopAsync`. Tests: `FlushCoalescingTests.cs`.

### 5.2 Stall Gate Backpressure — IMPLEMENTED

**Implemented in:** `NatsClient.cs` (nested `StallGate` class) (Task 23, commit phase 4)

SemaphoreSlim-based stall gate that blocks producers at 75% buffer threshold. `UpdatePending`, `WaitAsync`, `Release`, `IsStalled` API. Tests: `StallGateTests.cs`.

### 5.3 Write Timeout with Partial Flush Recovery — IMPLEMENTED

**Implemented in:** `NatsClient.cs` (Task 24, commit phase 4)

`WriteTimeoutPolicy` enum (Close, TcpFlush), `GetWriteTimeoutPolicy(ClientKind)` per-kind mapping (routes/gateways/leaves can recover, clients close), `FlushResult` readonly record struct with `IsPartial`/`BytesRemaining`. Tests: `WriteTimeoutTests.cs`.

### 5.4 Per-Account Subscription Result Cache (HIGH)

**Missing**: `readCache` struct with per-account results cache, route targets, statistical counters. Go caches Sublist match results per account on route/gateway inbound path (maxPerAccountCacheSize=8192).

### 5.5 Slow Consumer Stall Gate (MEDIUM)

**Missing**: Full stall gate mechanics — Go creates a channel blocking producers at 75% threshold, per-kind slow consumer statistics (route, gateway, leaf), account-level slow consumer tracking.

### 5.6 Dynamic Write Buffer Pooling (MEDIUM)

`OutboundBufferPool` exists but missing flush coalescing integration, `pcd` broadcast optimization.

### 5.7 Per-Client Trace Level (MEDIUM)

`SetTraceMode()` exists but missing message delivery tracing (`traceMsgDelivery`) for routed messages, per-client echo support.

### 5.8 Subscribe Permission Caching (MEDIUM)

`PermissionLruCache` caches PUB permissions but NOT SUB. Go caches per-account results with genid-based invalidation.

### 5.9 Internal Client Kinds (LOW)

`ClientKind` enum supports CLIENT, ROUTER, GATEWAY, LEAF but missing SYSTEM, JETSTREAM, ACCOUNT kinds and `isInternalClient()` predicate.

### 5.10 Adaptive Read Buffer Short-Read Counter (LOW)

`AdaptiveReadBuffer` implements 2x grow/shrink but missing Go's `srs` (short reads) counter for more precise shrink decisions.

---

## Gap 6: MQTT Protocol (HIGH)

**Go reference**: `mqtt.go` — 5,882 lines
**NET implementation**: `Mqtt/` — 1,238 lines (8 files)
**Gap factor**: 4.7x

### 6.1 JetStream-Backed Session Persistence — IMPLEMENTED

**Implemented in:** `MqttSessionStore.cs`, `MqttRetainedStore.cs` (Task 25, commit phase 4)

IStreamStore-backed session persistence (`ConnectAsync`, `AddSubscription`, `SaveSessionAsync`, `GetSubscriptions`) and retained message persistence (`SetRetainedAsync`, `GetRetainedAsync` with tombstone tracking). Tests: `MqttPersistenceTests.cs`.

### 6.2 Will Message Delivery (HIGH)

`MqttSessionStore` stores will metadata (`WillTopic`, `WillPayload`, `WillQoS`, `WillRetain`) but does NOT publish the will message on abnormal client disconnection.

### 6.3 QoS 1/2 Tracking (HIGH)

`MqttQoS2StateMachine` exists for QoS 2 state transitions but missing:
- JetStream-backed QoS 1 acknowledgment tracking
- Durable redelivery of unacked QoS 1/2 messages
- PUBREL delivery stream for QoS 2 phase 2

### 6.4 MaxAckPending Enforcement (HIGH)

**Missing**: No backpressure mechanism for QoS 1 accumulation, no per-subscription limits, no config reload hook.

### 6.5 Retained Message Delivery on Subscribe (MEDIUM)

`MqttRetainedStore` exists but not JetStream-backed and not integrated with subscription handling — retained messages aren't delivered on SUBSCRIBE.

### 6.6 Session Flapper Detection (LOW)

Partially implemented in `MqttSessionStore` (basic structure present) but integration unclear.

---

## Gap 7: JetStream API Layer (MEDIUM)

**Go reference**: `jetstream_api.go` (5,165) + `jetstream.go` (2,866) = 8,031 lines
**NET implementation**: ~1,374 lines across 11 handler files
**Gap factor**: 5.8x

### 7.1 Leader Forwarding (HIGH)

API requests arriving at non-leader nodes must be forwarded to the current leader. Not implemented.

### 7.2 Clustered API Handlers (HIGH)

**Missing**:
- `jsClusteredStreamRequest()` — stream create in clustered mode
- `jsClusteredStreamUpdateRequest()` — update/delete/move/scale (509 lines in Go)
- Cluster-aware consumer create/delete handlers

### 7.3 API Rate Limiting & Deduplication (MEDIUM)

No request deduplication or rate limiting.

### 7.4 Snapshot & Restore API (MEDIUM)

No snapshot/restore API endpoints.

### 7.5 Consumer Pause/Resume API (MEDIUM)

No consumer pause/resume API endpoint.

### 7.6 Advisory Event Publication (LOW)

No advisory events for API operations.

---

## Gap 8: RAFT Consensus (CRITICAL for clustering)

**Go reference**: `raft.go` — 5,037 lines
**NET implementation**: `Raft/` — 1,838 lines (17 files)
**Gap factor**: 2.7x

### 8.1 Persistent Log Storage — IMPLEMENTED

**Implemented in:** `RaftWal.cs` (Task 7, commit phase 2)

Binary WAL with header, CRC32 integrity, append/sync/compact/load operations. Crash-tolerant recovery with truncated/corrupt record handling. Tests: `RaftWalTests.cs`.

### 8.2 Joint Consensus for Membership Changes — IMPLEMENTED

**Implemented in:** `RaftNode.cs` (Task 8, commit phase 2)

Two-phase joint consensus per RAFT paper Section 4: `BeginJointConsensus`, `CommitJointConsensus`, `CalculateJointQuorum` requiring majority from both Cold and Cnew. Tests: `RaftJointConsensusTests.cs`.

### 8.3 InstallSnapshot Streaming (HIGH)

`RaftSnapshot` is fully loaded into memory. Go streams snapshots in chunks with progress tracking.

### 8.4 Leadership Transfer (MEDIUM)

No graceful leader step-down mechanism for maintenance operations.

### 8.5 Log Compaction (MEDIUM)

Basic compaction exists but no configurable retention policies.

### 8.6 Quorum Check Before Proposing (MEDIUM)

May propose entries when quorum is unreachable.

### 8.7 Read-Only Query Optimization (LOW)

All queries append log entries; no ReadIndex optimization for read-only commands.

### 8.8 Election Timeout Jitter (LOW)

May not have sufficient randomized jitter to prevent split votes.

---

## Gap 9: Account Management & Multi-Tenancy (MEDIUM)

**Go reference**: `accounts.go` — 4,774 lines, 172+ functions
**NET implementation**: `Account.cs` (280) + auth files
**Current .NET total**: ~1,266 lines
**Gap factor**: 3.8x

### 9.1 Service Export Latency Tracking (MEDIUM)

**Missing**: `TrackServiceExport()`, `UnTrackServiceExport()`, latency sampling, p50/p90/p99 tracking, `sendLatencyResult()`, `sendBadRequestTrackingLatency()`, `sendReplyInterestLostTrackLatency()`.

### 9.2 Service Export Response Threshold (MEDIUM)

**Missing**: `ServiceExportResponseThreshold()`, `SetServiceExportResponseThreshold()` for SLA limits.

### 9.3 Stream Import Cycle Detection (MEDIUM)

Only service import cycles detected. **Missing**: `streamImportFormsCycle()`, `checkStreamImportsForCycles()`.

### 9.4 Wildcard Service Exports (MEDIUM)

**Missing**: `getWildcardServiceExport()` — cannot define wildcard exports like `svc.*`.

### 9.5 Account Expiration & TTL (MEDIUM)

**Missing**: `IsExpired()`, `expiredTimeout()`, `setExpirationTimer()` — expired accounts won't auto-cleanup.

### 9.6 Account Claim Hot-Reload (MEDIUM)

**Missing**: `UpdateAccountClaims()`, `updateAccountClaimsWithRefresh()` — account changes may require restart.

### 9.7 Service/Stream Activation Expiration (LOW)

**Missing**: JWT activation claim expiry enforcement.

### 9.8 User NKey Revocation (LOW)

**Missing**: `checkUserRevoked()` — cannot revoke individual users without re-deploying.

### 9.9 Response Service Import (LOW)

**Missing**: Reverse response mapping for cross-account request-reply (`addReverseRespMapEntry`, `checkForReverseEntries`).

### 9.10 Service Import Shadowing Detection (LOW)

**Missing**: `serviceImportShadowed()`.

---

## Gap 10: Monitoring & Events (MEDIUM)

**Go reference**: `monitor.go` (4,240) + `events.go` (3,334) + `msgtrace.go` (799) = 8,373 lines
**NET implementation**: `Monitoring/` (1,698) + `Events/` (960) + `MessageTraceContext.cs` = ~2,658 lines
**Gap factor**: 3.1x

### 10.1 Closed Connections Ring Buffer (HIGH)

**Missing**: Ring buffer for recently closed connections with disconnect reasons. `/connz?state=closed` returns empty.

### 10.2 Account-Scoped Filtering (MEDIUM)

**Missing**: `/connz?acc=ACCOUNT` filtering.

### 10.3 Sort Options (MEDIUM)

**Missing**: `ConnzOptions.SortBy` (by bytes, msgs, uptime, etc.).

### 10.4 Message Trace Propagation (MEDIUM)

`MessageTraceContext` exists but trace data not propagated across servers in events.

### 10.5 Auth Error Events (MEDIUM)

**Missing**: `sendAuthErrorEvent()`, `sendAccountAuthErrorEvent()` — cannot monitor auth failures.

### 10.6 Full System Event Payloads (MEDIUM)

Event types defined but payloads may be incomplete (server info, client info fields).

### 10.7 Closed Connection Reason Tracking (MEDIUM)

`ClosedClient.Reason` exists but not populated consistently.

### 10.8 Remote Server Events (LOW)

**Missing**: `remoteServerShutdown()`, `remoteServerUpdate()`, `leafNodeConnected()` — limited cluster member visibility.

### 10.9 Event Compression (LOW)

**Missing**: `getAcceptEncoding()` — system events consume more bandwidth.

### 10.10 OCSP Peer Events (LOW)

**Missing**: `sendOCSPPeerRejectEvent()`, `sendOCSPPeerChainlinkInvalidEvent()`.

---

## Gap 11: Gateway Bridging (MEDIUM)

**Go reference**: `gateway.go` — 3,426 lines
**NET implementation**: `GatewayManager.cs` (225) + `GatewayConnection.cs` (259) + `GatewayInterestTracker.cs` (190) + `ReplyMapper.cs` (174)
**Current .NET total**: ~848 lines
**Gap factor**: 4.0x

### 11.1 Implicit Gateway Discovery — IMPLEMENTED

**Implemented in:** `GatewayManager.cs`, `GatewayInfo.cs` (Task 27, commit phase 4)

`ProcessImplicitGateway(GatewayInfo)` with URL deduplication, `DiscoveredGateways` property. New `GatewayInfo` record type. Tests: `ImplicitDiscoveryTests.cs`.

### 11.2 Gateway Reconnection with Backoff (MEDIUM)

**Missing**: `solicitGateways()`, `reconnectGateway()`, `solicitGateway()` with structured delay/jitter.

### 11.3 Account-Specific Gateway Routes (MEDIUM)

**Missing**: `sendAccountSubsToGateway()` — routes all subscriptions without per-account isolation.

### 11.4 Queue Group Propagation (MEDIUM)

**Missing**: `sendQueueSubsToGateway()` — queue-based load balancing may not work across gateways.

### 11.5 Reply Subject Mapping Cache (MEDIUM)

**Missing**: `trackGWReply()`, `startGWReplyMapExpiration()` — dynamic reply tracking with TTL. Basic `_GR_` prefix exists but no caching.

### 11.6 Gateway Command Protocol (LOW)

**Missing**: `gatewayCmdGossip`, `gatewayCmdAllSubsStart`, `gatewayCmdAllSubsComplete` — no bulk subscription synchronization.

### 11.7 Connection Registration (LOW)

**Missing**: `registerInboundGatewayConnection()`, `registerOutboundGatewayConnection()`, `getRemoteGateway()` — minimal gateway registry.

---

## Gap 12: Leaf Node Connections (MEDIUM)

**Go reference**: `leafnode.go` — 3,470 lines
**NET implementation**: `LeafNodeManager.cs` (328) + `LeafConnection.cs` (284) + `LeafHubSpokeMapper.cs` (121) + `LeafLoopDetector.cs` (35)
**Current .NET total**: ~768 lines
**Gap factor**: 4.5x

### 12.1 TLS Certificate Hot-Reload (MEDIUM)

**Missing**: `updateRemoteLeafNodesTLSConfig()` — TLS cert changes require server restart.

### 12.2 Permission & Account Syncing (MEDIUM)

**Missing**: `sendPermsAndAccountInfo()`, `initLeafNodeSmapAndSendSubs()` — permission changes on hub may not propagate.

### 12.3 Leaf Connection State Validation (MEDIUM)

**Missing**: `remoteLeafNodeStillValid()` — no validation of remote config on reconnect.

### 12.4 JetStream Migration Checks (LOW)

**Missing**: `checkJetStreamMigrate()` — cannot safely migrate leaf JetStream domains.

### 12.5 Leaf Node WebSocket Support (LOW)

**Missing**: Go accepts WebSocket connections for leaf nodes.

### 12.6 Leaf Cluster Registration (LOW)

**Missing**: `registerLeafNodeCluster()`, `hasLeafNodeCluster()` — cannot query leaf topology.

### 12.7 Connection Disable Flag (LOW)

**Missing**: `isLeafConnectDisabled()` — cannot selectively disable leaf solicitation.

---

## Gap 13: Route Clustering (MEDIUM)

**Go reference**: `route.go` — 3,314 lines
**NET implementation**: `RouteManager.cs` (324) + `RouteConnection.cs` (296) + `RouteCompressionCodec.cs` (135)
**Current .NET total**: ~755 lines
**Gap factor**: 4.4x

### 13.1 Implicit Route Discovery — IMPLEMENTED

**Implemented in:** `RouteManager.cs`, `NatsProtocol.cs` (Task 27, commit phase 4)

`ProcessImplicitRoute(ServerInfo)`, `ForwardNewRouteInfoToKnownServers`, `AddKnownRoute`, `DiscoveredRoutes`, `OnForwardInfo` event. Added `ConnectUrls` to `ServerInfo`. Tests: `ImplicitDiscoveryTests.cs`.

### 13.2 Account-Specific Dedicated Routes (MEDIUM)

**Missing**: Per-account route pinning for traffic isolation.

### 13.3 Route Pool Size Negotiation (MEDIUM)

**Missing**: Handling heterogeneous clusters with different pool sizes.

### 13.4 Route Hash Storage (LOW)

**Missing**: `storeRouteByHash()`, `getRouteByHash()` for efficient route lookup.

### 13.5 Cluster Split Handling (LOW)

**Missing**: `removeAllRoutesExcept()`, `removeRoute()` — no partition handling.

### 13.6 No-Pool Route Fallback (LOW)

**Missing**: Interoperability with older servers without pool support.

---

## Gap 14: Configuration & Hot Reload (MEDIUM)

**Go reference**: `opts.go` (6,435) + `reload.go` (2,653) = 9,088 lines
**NET implementation**: `ConfigProcessor.cs` (1,438) + `NatsConfLexer.cs` (1,503) + `NatsConfParser.cs` (421) + `ConfigReloader.cs` (526)
**Current .NET total**: ~3,888 lines
**Gap factor**: 2.3x

### 14.1 SIGHUP Signal Handling — IMPLEMENTED

**Implemented in:** `SignalHandler.cs`, `ConfigReloader.cs` (Task 26, commit phase 4)

`SignalHandler` static class with `PosixSignalRegistration` for SIGHUP. `ConfigReloader.ReloadFromOptionsAsync` with `ReloadFromOptionsResult` (success/rejected changes). Tests: `SignalHandlerTests.cs`.

### 14.2 Auth Change Propagation (MEDIUM)

**Missing**: When users/nkeys change, propagate to existing connections.

### 14.3 TLS Certificate Reload (MEDIUM)

**Missing**: Reload certificates for new connections without restart.

### 14.4 Cluster Config Hot Reload (MEDIUM)

**Missing**: Add/remove route URLs, gateway URLs, leaf node URLs at runtime.

### 14.5 Logging Level Changes (LOW)

**Missing**: Debug/trace/logtime changes at runtime.

### 14.6 JetStream Config Changes (LOW)

**Missing**: JetStream option reload.

---

## Gap 15: WebSocket Support (LOW)

**Go reference**: `websocket.go` — 1,550 lines
**NET implementation**: `WebSocket/` — 1,453 lines (7 files)
**Gap factor**: 1.1x

WebSocket support is the most complete subsystem. Compression negotiation (permessage-deflate), JWT auth through WebSocket, and origin checking are all implemented.

### 15.1 WebSocket-Specific TLS (LOW)

Minor TLS configuration differences.

---

## Priority Summary

### Tier 1: Production Blockers (CRITICAL) — ALL IMPLEMENTED

1. ~~**FileStore encryption/compression/recovery** (Gaps 1.1–1.4)~~ — IMPLEMENTED (Tasks 1–4)
2. ~~**FileStore missing interface methods** (Gap 1.9)~~ — IMPLEMENTED (Tasks 5–6)
3. ~~**RAFT persistent log** (Gap 8.1)~~ — IMPLEMENTED (Task 7)
4. ~~**RAFT joint consensus** (Gap 8.2)~~ — IMPLEMENTED (Task 8)
5. ~~**JetStream cluster monitoring loop** (Gap 2.1)~~ — IMPLEMENTED (Task 10)

### Tier 2: Capability Limiters (HIGH) — ALL IMPLEMENTED

6. **Consumer delivery loop** (Gap 3.1) — remaining (core message dispatch loop)
7. ~~**Consumer pull request pipeline** (Gap 3.2)~~ — IMPLEMENTED (Task 16)
8. ~~**Consumer ack/redelivery** (Gaps 3.3–3.4)~~ — IMPLEMENTED (Tasks 14–15)
9. ~~**Stream mirror/source retry** (Gaps 4.1–4.2, 4.9)~~ — IMPLEMENTED (Task 21)
10. ~~**Stream purge with filtering** (Gap 4.5)~~ — IMPLEMENTED (Task 19)
11. ~~**Client flush coalescing** (Gap 5.1)~~ — IMPLEMENTED (Task 22)
12. ~~**Client stall gate** (Gap 5.2)~~ — IMPLEMENTED (Task 23)
13. ~~**MQTT JetStream persistence** (Gap 6.1)~~ — IMPLEMENTED (Task 25)
14. ~~**SIGHUP config reload** (Gap 14.1)~~ — IMPLEMENTED (Task 26)
15. ~~**Implicit route/gateway discovery** (Gaps 11.1, 13.1)~~ — IMPLEMENTED (Task 27)

Additional Tier 2 items implemented:
- ~~**Client write timeout recovery** (Gap 5.3)~~ — IMPLEMENTED (Task 24)
- ~~**Stream interest retention** (Gap 4.6)~~ — IMPLEMENTED (Task 20)
- ~~**Stream dedup window** (Gap 4.4)~~ — IMPLEMENTED (Task 21)
- ~~**Consumer priority pinning** (Gap 3.6)~~ — IMPLEMENTED (Task 18)
- ~~**Consumer pause/resume** (Gap 3.7)~~ — IMPLEMENTED (Task 17)
- ~~**Cluster assignment processing** (Gap 2.2)~~ — IMPLEMENTED (Task 11)
- ~~**Cluster inflight dedup** (Gap 2.3)~~ — IMPLEMENTED (Task 12)
- ~~**Cluster leadership transition** (Gap 2.5)~~ — IMPLEMENTED (Task 13)
- ~~**Cluster snapshot recovery** (Gap 2.6)~~ — IMPLEMENTED (Task 9)

### Tier 3: Important Features (MEDIUM)

16–40: Account management, monitoring, gateway details, leaf node features, consumer advanced features, etc.

### Tier 4: Nice-to-Have (LOW)

41+: Internal client kinds, election jitter, event compression, etc.

---

## Test Coverage Gap Summary

All 2,937 Go tests have been categorized:
- **2,646 mapped** (90.1%) — have corresponding .NET tests
- **272 not_applicable** (9.3%) — platform-specific or irrelevant
- **19 skipped** (0.6%) — intentionally deferred
- **0 unmapped** — none remaining

The .NET test suite has **5,914 test methods** (expanding to ~6,532 with parameterized `[Theory]` test cases). Of these, **4,250** (73.2%) are linked back to Go test counterparts via the `test_mappings` table. The remaining tests are .NET-specific — covering implementations (SubjectTree, ConfigProcessor, NatsConfLexer, RAFT WAL, joint consensus, etc.) that don't have 1:1 Go counterparts.

The production gaps implementation (2026-02-25/26) added **106 new test methods** across 10 new test files covering FileStore block management, RAFT persistence, cluster coordination, consumer delivery, stream lifecycle, client protocol, MQTT persistence, config reload, and route/gateway discovery.

Many tests validate API contracts against stubs/mocks rather than testing actual distributed behavior. The gap is in test *depth*, not test *count*.
