Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix(chat): ignore ended-turn events before restoring busy UI

CloudTianTianc0ecd4956cea
diff --git a/src/renderer/modules/conversation.js b/src/renderer/modules/conversation.js
index 0e6390d1..810cf398 100644
--- a/src/renderer/modules/conversation.js
+++ b/src/renderer/modules/conversation.js
@@ -15212,17 +15212,6 @@ function _handleGroupBusEvent(cid, streamingMsg, evData, { archive = false } = {
// event is delivered once. A re-delivered one could no longer recreate a
// consumed Commander bubble anyway — rows are addressed by render key, and
// a settled row is never reopened as a streaming target.
- // A renderer can attach after the actor's initial `state_changed(running)`
- // event has already passed (refresh, tab switch, scheduled/remote run).
- // Process events are proof that work is still active, so recover the
- // composer state here instead of leaving the button in blue "send" mode
- // while a live placeholder is visibly thinking.
- if (!isGroupConversationBusy(cid)) {
- setGroupConversationBusy(cid, true);
- _updateConvSidebarBadge(cid, true);
- startPolling(cid);
- if (cid === currentCid) _updateConvSendUI(cid);
- }
// Once Commander has flushed a segment it is inside a dispatch loop, and
// its remaining tool progress is orchestration bookkeeping while a delegated
// agent works. Opening a row for that would put an empty "thinking"
@@ -15234,11 +15223,14 @@ function _handleGroupBusEvent(cid, streamingMsg, evData, { archive = false } = {
&& data.type !== 'delta'
&& !visiblePlanEvent
&& !_findRenderNode(cid, _segmentRenderKey(turnId, evData.seg));
- if (orchestrationIdle) return;
- const target = _ensureActorPlaceholder(
+ const target = orchestrationIdle ? null : _ensureActorPlaceholder(
cid, actor, streamingMsg, turnId, undefined, undefined, evData.seg,
);
- if (!target) {
+ // A settled turn can receive events for another (or missing) segment.
+ // Reject those before recovering the busy UI. Live targets were already
+ // checked by _ensureActorPlaceholder; avoid another scan on every token.
+ if (!target && turnId && _turnHasEndedRow(cid, turnId)) return;
+ if (!target && !orchestrationIdle) {
// Terminal content is authoritative. A process event buffered by a
// redundant stream can arrive after that row is finalized; dropping it
// preserves the final text and makes terminal-late delivery idempotent.
@@ -15252,6 +15244,18 @@ function _handleGroupBusEvent(cid, streamingMsg, evData, { archive = false } = {
});
return;
}
+ // A renderer can attach after the actor's initial `state_changed(running)`
+ // event has already passed (refresh, tab switch, scheduled/remote run).
+ // Process events are proof that work is still active, so recover the
+ // composer state here instead of leaving the button in blue "send" mode
+ // while a live placeholder is visibly thinking.
+ if (!isGroupConversationBusy(cid)) {
+ setGroupConversationBusy(cid, true);
+ _updateConvSidebarBadge(cid, true);
+ startPolling(cid);
+ if (cid === currentCid) _updateConvSendUI(cid);
+ }
+ if (orchestrationIdle) return;
// Diagnostic — count how many deltas reach the renderer per actor.
// If this number is much smaller than the bus emit count from the
// turn-end log, the bottleneck is upstream (IPC batching). If it's
diff --git a/test/renderer/conversation-keyed-rendering.test.ts b/test/renderer/conversation-keyed-rendering.test.ts
index 26f7c16e..f16a0450 100644
--- a/test/renderer/conversation-keyed-rendering.test.ts
+++ b/test/renderer/conversation-keyed-rendering.test.ts
@@ -747,6 +747,77 @@ describe('keyed rendering › terminal hand-off with an end-of-turn record', ()
expect(container.rows.filter((row) => row.dataset.fromActor === 'agent-a')).toHaveLength(1);
});
+ it.each([
+ ['earlier delta', 0, { type: 'delta', text: 'Late text' }],
+ ['same-segment delta', 1, { type: 'delta', text: 'Late text' }],
+ ['missing-segment tool event', undefined, { type: 'event', event: { stream: 'tool', data: { phase: 'end', id: 't1', name: 'hand_off_to' } } }],
+ ['later orchestration event', 2, { type: 'event', event: { stream: 'tool', data: { phase: 'end', id: 't1', name: 'hand_off_to' } } }],
+ ])('ignores %s after the turn ends without restarting idle UI', (_label, seg, data) => {
+ const { context, container } = loadRenderer(CID);
+ handoffPrelude(context);
+ context.setGroupConversationBusy(CID, false);
+ context.__warnings = [];
+ context.__pollStarts = 0;
+ context.__busyBadges = 0;
+ vm.runInContext(`
+ _convLog.warn = (...args) => __warnings.push(args);
+ startPolling = () => { __pollStarts += 1; };
+ _updateConvSidebarBadge = () => { __busyBadges += 1; };
+ `, context);
+ const rowsBefore = container.rows.slice();
+ const savedBefore = JSON.stringify(rowsBefore.map(row => ({ dataset: row.dataset, bodies: row.bodies })));
+
+ context._handleGroupBusEvent(CID, null, {
+ type: 'process', cid: CID, actor: 'commander', turn_id: TURN, seg, data,
+ });
+
+ expect(context.__warnings).toEqual([]);
+ expect(context.isGroupConversationBusy(CID)).toBe(false);
+ expect(context.__pollStarts).toBe(0);
+ expect(context.__busyBadges).toBe(0);
+ expect(container.rows).toEqual(rowsBefore);
+ expect(JSON.stringify(container.rows.map(row => ({ dataset: row.dataset, bodies: row.bodies })))).toBe(savedBefore);
+
+ // The ended Commander must not block a distinct turn's real output.
+ context._handleGroupBusEvent(CID, null, {
+ type: 'process', cid: CID, actor: 'commander', turn_id: 'next-turn', seg: 0,
+ data: { type: 'delta', text: 'New answer' },
+ });
+ expect(context.isGroupConversationBusy(CID)).toBe(true);
+ expect(context.__pollStarts).toBe(1);
+ expect(container.rows.at(-1)?.bodies.final.textContent).toBe('New answer');
+ expect(context.__warnings).toEqual([]);
+ });
+
+ it('keeps a delegate live while dropping late Commander output', () => {
+ const { context, container } = loadRenderer(CID);
+ handoffPrelude(context);
+ context._handleGroupBusEvent(CID, null, {
+ ...delta(0, 'Delegate answer', 'agent-a'), turn_id: 'delegate-turn',
+ });
+ context.__warnings = [];
+ vm.runInContext('_convLog.warn = (...args) => __warnings.push(args);', context);
+ context._handleGroupBusEvent(CID, null, delta(0, 'Late Commander text'));
+ expect(context.__warnings).toEqual([]);
+ expect(context.isGroupConversationBusy(CID)).toBe(true);
+ expect(container.rows.filter(row => row.dataset.fromActor === 'agent-a'))
+ .toHaveLength(1);
+ expect(container.rows.at(-1)?.bodies.final.textContent).toBe('Delegate answer');
+ expect(commanderRows(container).map(row => row.dataset.msgId)).toEqual(['msg-end']);
+ });
+
+ it('still reports a genuinely missing live target', () => {
+ const { context } = loadRenderer(CID);
+ context.__warnings = [];
+ vm.runInContext(`
+ _ensureActorPlaceholder = () => null;
+ _convLog.warn = (...args) => __warnings.push(args);
+ `, context);
+ context._handleGroupBusEvent(CID, null, delta(0, 'Live answer'));
+ expect(context.__warnings.map((args: any[]) => args[0]))
+ .toEqual(['group process target missing']);
+ });
+
it('still lets a later segment stream after a mid-turn segment record (negative control)', () => {
const { context, container } = loadRenderer(CID);
context._handleGroupBusEvent(CID, null, delta(0, 'Handing this over.'));