Skip to content

The agent that grows with you

fix(desktop): retire stale generation mutations

KoNit-K2b9825587d3a
diff --git a/apps/desktop/src/api/canonical-protocol.ts b/apps/desktop/src/api/canonical-protocol.ts
index 1190e7cff36..b7380778868 100644
--- a/apps/desktop/src/api/canonical-protocol.ts
+++ b/apps/desktop/src/api/canonical-protocol.ts
@@ -221,9 +221,9 @@ export class CanonicalDesktopProtocol {
if (typeof reason === 'string') { this.settleModelConfirmation(params) }
// A typed busy refusal of a rewind or a move wrote nothing either; the retry is a new request at the new revision.
- if (reason !== 'revision_conflict' && !(reason === 'session_busy' && ['rewind', 'workspace'].includes(params.operation as string))) { return }
+ if (reason !== 'revision_conflict' && reason !== 'stale_generation' && !(reason === 'session_busy' && ['rewind', 'workspace'].includes(params.operation as string))) { return }
- // A confirmed CAS refusal did not mutate. Ambiguous transport failures keep
+ // A confirmed fence refusal did not mutate. Ambiguous transport failures keep
// the original revision/id so a retry cannot overwrite another user's edit.
for (const [key, mutation] of this.mutations) { if (mutation.request_id === params.request_id) { this.mutations.delete(key) } }
}
diff --git a/apps/desktop/src/api/canonical-retained-mutation-stale.test.ts b/apps/desktop/src/api/canonical-retained-mutation-stale.test.ts
index 4ebb081d189..02d2c31958f 100644
--- a/apps/desktop/src/api/canonical-retained-mutation-stale.test.ts
+++ b/apps/desktop/src/api/canonical-retained-mutation-stale.test.ts
@@ -26,3 +26,16 @@ test('an acknowledged later edit retires an older retained mutation; its stale r
protocol.result('session.title', lostA, { session_id: 's', revision: 8, title: 'A' })
expect(protocol.prepare('session.archive', { session_id: 's', archived: true }).expected_revision).toBe(9)
})
+
+test('a stale generation refusal retires a retained reasoning mutation', () => {
+ const protocol = new CanonicalDesktopProtocol()
+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 7, execution_generation: 3 })
+
+ const first = protocol.prepare('config.set', { key: 'reasoning', session_id: 's', value: 'high' })
+ protocol.failure(first, { data: { reason: 'stale_generation' } })
+
+ protocol.result('session.resume', { session_id: 's' }, { session_id: 's', revision: 8, execution_generation: 4 })
+ const retry = protocol.prepare('config.set', { key: 'reasoning', session_id: 's', value: 'high' })
+ expect(retry).toMatchObject({ expected_revision: 8, expected_generation: 4 })
+ expect(retry.request_id).not.toBe(first.request_id)
+})