agentos icon indicating copy to clipboard operation
agentos copied to clipboard

A GMI turn stopped after its last step still files its exchange in cognitive memory

Open jddunn opened this issue 1 week ago • 0 comments

What happened

A GMI turn that is stopped after its last model step still files its exchange in the agent's cognitive memory. This holds for a turn stopped by the caller's abortSignal or by session.close() while an onAfterGeneration hook runs. After the main loop, GMI.processTurnStream calls memoryBridge.syncForTurn() without reading the turn's stop (GMI.ts). On a session that is not a souled agent's, syncForTurn() encodes both sides (CognitiveMemoryBridge.ts). The session's own check rejects the turn only after the generator ends. So the turn rejects as stopped while its exchange is in memory, and a slow embedding provider makes close() wait for that encoding.

A souled agent's turn is not affected: its mind files through the session's view, which reads the stop.

Expected: a turn stopped after its last step files nothing in cognitive memory, as a turn stopped during a request files nothing. The finished steps stay marked partial, and their usage stays counted.

Steps to reproduce

const stop = new AbortController();
const a = gmi({
  provider: 'openai',
  model: 'gpt-4o',
  memory: { embedding: { provider: 'openai' } },
  // stops the turn after its last model step
  onAfterGeneration: async () => {
    stop.abort();
  },
});
await a.session('s1', { userId: 'u1' }).send('My canary is LARK-7.', { abortSignal: stop.signal }); // rejects
// the agent's cognitive memory now holds both sides of the stopped turn

Package and version

@framers/agentos 0.20.0 (master d85502981a22018e2125a535aea7d945ecdbcb8c). Found in the review of #900.

Environment

Any.

Logs

None.

jddunn avatar Nov 23 '26 20:11 jddunn