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: recover retry actors from durable history

wytf2ee37e7d736
diff --git a/src/main/features/group_chat/index.ts b/src/main/features/group_chat/index.ts
index 6fc673c5..b4e9608b 100644
--- a/src/main/features/group_chat/index.ts
+++ b/src/main/features/group_chat/index.ts
@@ -26,7 +26,7 @@ import { fileEditLock } from '../../util/locks';
import {
COMMANDER_ID, USER_ID, readMembers, readState, seedReservedActors, purgeGroupDir,
- setCodingProjectDir, setStatus, actorSessionId,
+ setCodingProjectDir, setStatus, actorSessionId, type Actor,
} from './state';
import { isPlaceholderTitle } from './conv_title';
import {
@@ -438,7 +438,30 @@ export async function resolveFailedTurnRetry(
await seedReservedActors(userId, cid);
const members = await readMembers(userId, cid);
- const actor = members.actors.find((item) => item.id === failed.from);
+ let actor: Actor | undefined = members.actors.find((item) => item.id === failed.from);
+ let recoveredAgent: Awaited<ReturnType<typeof import('../agents')['getAgent']>> | null = null;
+ // Conversation history is the durable proof of who produced the failed
+ // reply. Older/synced conversations can retain that canonical JSONL while
+ // their derived members.json roster is missing the Agent. If the same Agent
+ // is still installed and enabled, recover its identity from the registry;
+ // enqueue() will restore membership at its normal recipient boundary before
+ // dispatch. A deleted or disabled Agent remains unavailable.
+ if (!actor && safeId(failed.from)) {
+ try {
+ const agents = await import('../agents');
+ recoveredAgent = await agents.getAgent(failed.from);
+ if (recoveredAgent && recoveredAgent.enabled !== false) {
+ actor = {
+ kind: 'agent',
+ id: recoveredAgent.agent_id,
+ name: recoveredAgent.name,
+ joined_at: failed.ts || nowIso(),
+ };
+ }
+ } catch (err) {
+ log.warn('retry Agent identity recovery failed', { error: logErrorRef(err) });
+ }
+ }
if (!actor || actor.kind === 'user' || actor.kind === 'worker') {
return { ok: false, error: 'retry actor is unavailable' };
}
@@ -446,8 +469,7 @@ export async function resolveFailedTurnRetry(
let cliRuntime: string | null = null;
if (actor.kind === 'agent') {
try {
- const agents = await import('../agents');
- const agent = await agents.getAgent(actor.id);
+ const agent = recoveredAgent || await (await import('../agents')).getAgent(actor.id);
cliRuntime = agent?.runtime?.kind === 'cli' ? agent.runtime.cli : null;
} catch (err) {
log.warn('retry CLI runtime inspection failed', { error: logErrorRef(err) });
diff --git a/test/main/features/group_chat/bus-integration.test.ts b/test/main/features/group_chat/bus-integration.test.ts
index e475ac09..78b0d4f2 100644
--- a/test/main/features/group_chat/bus-integration.test.ts
+++ b/test/main/features/group_chat/bus-integration.test.ts
@@ -2213,6 +2213,76 @@ describe('group_chat bus integration › G8d in-process dispatch (run_worker / d
expect(rows.some((row: any) => String(row.model_text || '').includes('<orchestration-resume>'))).toBe(false);
}, 15_000);
+ it('restores a missing Agent roster entry before persisting and dispatching a failed-turn retry', async () => {
+ const cid = newCid();
+ const state = await import('../../../../src/main/features/group_chat/state');
+ const groupChat = await import('../../../../src/main/features/group_chat');
+ const paths = await import('../../../../src/main/paths');
+ const agentSid = state.buildGmemberSessionId(cid, AGENT_ID);
+ const sourceId = `${cid}-source`;
+ const failedId = `${cid}-failed`;
+ const retryClientId = `retry-missing-roster-${cid}`;
+
+ // A synced/legacy task can retain its authoritative message history while
+ // the derived members.json contains only the reserved actors.
+ await state.seedReservedActors(TEST_UID, cid);
+ const messageFile = path.join(paths.userChatsDir(TEST_UID), `${cid}.jsonl`);
+ fs.writeFileSync(messageFile, [
+ JSON.stringify({
+ id: sourceId,
+ ts: '2026-08-25T09:00:00.000Z',
+ from: 'user',
+ to: [AGENT_ID],
+ text: 'Run the original task.',
+ model_text: 'Run the authoritative original task.',
+ }),
+ JSON.stringify({
+ id: failedId,
+ ts: '2026-08-25T09:01:00.000Z',
+ from: AGENT_ID,
+ to: ['user'],
+ text: 'The Agent timed out.',
+ failure_kind: 'runtime',
+ failure_code: 'cli_timeout',
+ source_message_id: sourceId,
+ turn_id: `${cid}-turn`,
+ }),
+ ].join('\n') + '\n');
+ expect((await state.readMembers(TEST_UID, cid)).actors.some((actor) => actor.id === AGENT_ID))
+ .toBe(false);
+
+ _setScript(agentSid, [
+ { type: 'final', text: 'MISSING-ROSTER-RETRY-SUCCESS: original task resumed.' },
+ ]);
+
+ const retry = await groupChat.retryFailedTurn({
+ userId: TEST_UID,
+ cid,
+ failedMessageId: failedId,
+ visibleText: 'Continue',
+ client_msg_id: retryClientId,
+ });
+ expect(retry.ok).toBe(true);
+ await waitForQuiescent(TEST_UID, cid, 5000);
+
+ const members = await state.readMembers(TEST_UID, cid);
+ expect(members.actors).toContainEqual(expect.objectContaining({
+ id: AGENT_ID,
+ kind: 'agent',
+ }));
+ const rows = fs.readFileSync(messageFile, 'utf8')
+ .split('\n').filter(Boolean).map((line) => JSON.parse(line));
+ expect(rows.find((row: any) => row.client_msg_id === retryClientId)).toMatchObject({
+ from: 'user',
+ text: 'Continue',
+ to: [AGENT_ID],
+ });
+ expect(rows.some((row: any) => (
+ row.from === AGENT_ID
+ && String(row.text || '').includes('MISSING-ROSTER-RETRY-SUCCESS')
+ ))).toBe(true);
+ }, 15_000);
+
it.each(['dispatch_to', 'hand_off_to'] as const)(
'%s relies on canonical history for an unresolved “above” reference without duplicating source snapshots',
async (sourceTool) => {
diff --git a/test/main/features/group_chat/failed-turn-retry.test.ts b/test/main/features/group_chat/failed-turn-retry.test.ts
index 4a2ac46e..852fbeb0 100644
--- a/test/main/features/group_chat/failed-turn-retry.test.ts
+++ b/test/main/features/group_chat/failed-turn-retry.test.ts
@@ -309,6 +309,34 @@ describe('group_chat failed-turn smart retry', () => {
expect(resolved.value.enqueue.failedTurnRetryMode).toBe('resume');
});
+ it('does not recover a missing roster entry for a disabled Agent', async () => {
+ const cid = 'disabled-agent-retry-cid';
+ const agentId = 'disabled-cli-agent';
+ const paths = await import('../../../../src/main/paths');
+ const dir = paths.agentDir(UID, agentId);
+ fs.mkdirSync(dir, { recursive: true });
+ fs.writeFileSync(path.join(dir, 'agent.json'), JSON.stringify({
+ agent_id: agentId,
+ name: 'Disabled CLI Agent',
+ runtime: { kind: 'cli', cli: 'codex' },
+ created_at: 't',
+ updated_at: 't',
+ }));
+ const enabled = await import('../../../../src/main/features/component_enabled');
+ enabled.setAgentEnabled(UID, agentId, false);
+ await writeAttempt(cid, { failure_kind: 'runtime', failure_code: 'cli_timeout' }, agentId);
+
+ const groupChat = await import('../../../../src/main/features/group_chat');
+ const resolved = await groupChat.resolveFailedTurnRetry({
+ userId: UID,
+ cid,
+ failedMessageId: `${cid}-failed`,
+ visibleText: 'Continue',
+ });
+
+ expect(resolved).toEqual({ ok: false, error: 'retry actor is unavailable' });
+ });
+
it('replays the authoritative request and attachments when no recoverable state exists', async () => {
const cid = 'restart-cid';
await writeAttempt(cid, { failure_kind: 'config', failure_code: 'model_not_configured' });