neoagent 3.3.1-beta.4 → 3.3.1-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,15 @@ function createBehaviorPipeline(deps = {}) {
29
29
  }
30
30
 
31
31
  function noteInbound({ userId, agentId, msg }) {
32
+ // Snapshot the current epoch without claiming a new speak-turn.
33
+ // Speak turns are claimed only when the gate decides to engage, so
34
+ // silent room traffic cannot invalidate an in-flight reply.
35
+ const state = getThreadState(userId, agentId, msg.platform, msg.chatId);
36
+ msg.behaviorTurnEpoch = state.turnEpoch;
37
+ return state.turnEpoch;
38
+ }
39
+
40
+ function claimSpeakTurn({ userId, agentId, msg }) {
32
41
  const state = bumpTurnEpoch(userId, agentId, msg.platform, msg.chatId);
33
42
  msg.behaviorTurnEpoch = state.turnEpoch;
34
43
  return state.turnEpoch;
@@ -83,6 +92,7 @@ function createBehaviorPipeline(deps = {}) {
83
92
  };
84
93
  }
85
94
  if (config.enabled === false) {
95
+ const speakTurnEpoch = claimSpeakTurn({ userId, agentId, msg });
86
96
  return {
87
97
  engage: true,
88
98
  decision: {
@@ -94,7 +104,7 @@ function createBehaviorPipeline(deps = {}) {
94
104
  rationale: 'Behavior modules are disabled; using the standard response path.',
95
105
  tokenPath: 'gate_skip',
96
106
  latencyMs: 0,
97
- turnEpoch,
107
+ turnEpoch: speakTurnEpoch,
98
108
  },
99
109
  config,
100
110
  promptBlocks: [],
@@ -173,7 +183,14 @@ function createBehaviorPipeline(deps = {}) {
173
183
  };
174
184
  }
175
185
 
176
- const promptBlocks = await registry.composeContext(baseCtx);
186
+ // Claim the speak turn only after engagement is confirmed.
187
+ const speakTurnEpoch = claimSpeakTurn({ userId, agentId, msg });
188
+ decision.turnEpoch = speakTurnEpoch;
189
+
190
+ const promptBlocks = await registry.composeContext({
191
+ ...baseCtx,
192
+ turnEpoch: speakTurnEpoch,
193
+ });
177
194
 
178
195
  return {
179
196
  engage: true,
@@ -314,18 +314,16 @@ async function executeQueuedMessage({
314
314
  };
315
315
  }
316
316
 
317
- const stopTypingKeepalive = msg.isGroup
318
- ? async () => {}
319
- : startTypingKeepalive({
320
- messagingManager,
321
- userId,
322
- agentId,
323
- runId,
324
- platform: msg.platform,
325
- chatId: msg.chatId,
326
- signal,
327
- onError: reportSideEffectError
328
- });
317
+ const stopTypingKeepalive = startTypingKeepalive({
318
+ messagingManager,
319
+ userId,
320
+ agentId,
321
+ runId,
322
+ platform: msg.platform,
323
+ chatId: msg.chatId,
324
+ signal,
325
+ onError: reportSideEffectError,
326
+ });
329
327
 
330
328
  try {
331
329
  const socialConfig = behaviorResult?.config || resolveBehaviorConfig(userId, agentId, {