Skip to content

Commit a3f495e

Browse files
committed
docs: document gateway node helpers
1 parent 1e43873 commit a3f495e

5 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/gateway/node-connect-reconcile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Gateway node connect reconciliation.
2+
// Computes approved runtime surfaces and pending pairing upgrades on reconnect.
13
import type { ConnectParams } from "../../packages/gateway-protocol/src/index.js";
24
import type { OpenClawConfig } from "../config/types.openclaw.js";
35
import {

src/gateway/node-pending-work.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Gateway pending node-work queue.
2+
// Stores short-lived per-node prompts until connected nodes drain/ack them.
13
import { randomUUID } from "node:crypto";
24
import {
35
asDateTimestampMs,
@@ -69,6 +71,8 @@ function getOrCreateState(nodeId: string): NodePendingWorkState {
6971
}
7072

7173
function pruneExpired(state: NodePendingWorkState, nowMs: number): boolean {
74+
// Expiry pruning bumps revision so polling nodes can observe that work changed
75+
// even when no explicit acknowledge call happened.
7276
const validNowMs = asDateTimestampMs(nowMs);
7377
if (validNowMs === undefined) {
7478
return false;

src/gateway/server-node-events.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Gateway node event dispatcher.
2+
// Handles device/node-originated events and routes them to sessions/channels.
13
import { randomUUID } from "node:crypto";
24
import {
35
normalizeLowercaseStringOrEmpty,
@@ -117,6 +119,8 @@ function shouldDropDuplicateVoiceTranscript(params: {
117119
fingerprint: string;
118120
now: number;
119121
}): boolean {
122+
// Voice providers can replay identical transcript fragments during reconnect.
123+
// Keep only a bounded last fingerprint per session to avoid duplicate sends.
120124
const previous = recentVoiceTranscripts.get(params.sessionKey);
121125
if (
122126
previous &&

src/gateway/server-node-session-runtime.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Gateway node session runtime factory.
2+
// Creates node registry, subscription, and voice-wake fanout state.
13
import { NodeRegistry, type SerializedEventPayload } from "./node-registry.js";
24
import {
35
createSessionEventSubscriberRegistry,

src/gateway/server-node-subscriptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Gateway node subscription manager.
2+
// Maintains bidirectional node/session fanout indexes.
13
import { serializeEventPayload, type SerializedEventPayload } from "./node-registry.js";
24

35
// Node subscription manager keeps bidirectional node/session indexes so gateway
@@ -92,6 +94,8 @@ export function createNodeSubscriptionManager(): NodeSubscriptionManager {
9294
if (!nodeSet) {
9395
return;
9496
}
97+
// Remove reverse session indexes before deleting the node index so session
98+
// fanout cannot retain disconnected node ids.
9599
for (const sessionKey of nodeSet) {
96100
const sessionSet = sessionSubscribers.get(sessionKey);
97101
sessionSet?.delete(normalizedNodeId);

0 commit comments

Comments
 (0)