Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): prioritize original task errors on companion cards

Chris7770222ba7fd
diff --git a/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx b/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx
index 67a95714be..e237a46564 100644
--- a/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx
+++ b/apps/mobile/src/__tests__/CompanionMessageCard.test.tsx
@@ -197,6 +197,36 @@ it('keeps the original task title, live status and opening when the delegation r
expect(node.textContent).toContain('devices.companions.status.waiting');
});
+// Unit regression: a failed delegation refresh retains its old active row. An
+// authoritative task error must still win, even while an interaction is pending.
+it.each(['running', 'waiting'])('shows task errors ahead of a stale %s delegation', async (status) => {
+ remoteSessionStore.setDeviceSessions('home', 'Mac', [
+ { id: 'child', title: 'Own task', status: 'active' } as RemoteSession,
+ ]);
+ h.invoke.mockResolvedValue({ ok: true, delegations: [
+ { id: 'job', status, title: 'Report', childSessionId: 'child' },
+ ] });
+ await render();
+ h.invoke.mockRejectedValue(new Error('read failed'));
+ vi.useFakeTimers();
+ await act(async () => {
+ h.changed('home', 'maker:bot-delegation:changed', { parentSessionId: 'parent' });
+ await vi.advanceTimersByTimeAsync(400);
+ });
+ expect(node.textContent).toContain('devices.companions.stale');
+ await act(async () => {
+ if (status === 'waiting') remoteSessionStore.setPendingInteractions('child', [
+ { request: { kind: 'permission', requestId: 'permission-1' } },
+ ], { deviceId: 'home' });
+ remoteSessionStore.applyRemotePush('home', SESSION_ACTIVITY_CHANNEL, {
+ sessionId: 'child', phase: 'error', attention: true,
+ });
+ });
+ expect(node.textContent).toContain('devices.companions.status.failed');
+ expect(node.textContent).not.toContain(`devices.companions.status.${status}`);
+ expect(openEntry()?.disabled).toBe(false);
+});
+
it('opens the task from the whole card and keeps stop as a small action while it runs', async () => {
await render();
expect(openEntry()?.disabled).toBe(false);
diff --git a/apps/mobile/src/session/CompanionMessageCard.tsx b/apps/mobile/src/session/CompanionMessageCard.tsx
index fd6a558895..61404c5e92 100644
--- a/apps/mobile/src/session/CompanionMessageCard.tsx
+++ b/apps/mobile/src/session/CompanionMessageCard.tsx
@@ -200,9 +200,9 @@ export function CompanionTaskCard({
// Without either live evidence or a delegation snapshot, keep the unknown/loading state.
const resolved = value !== null || error || !online;
const status =
- task.waiting || task.activity?.phase === 'needs-interaction' || row?.status === 'waiting' ? 'waiting'
+ task.activity?.phase === 'error' ? 'failed'
+ : task.waiting || task.activity?.phase === 'needs-interaction' || row?.status === 'waiting' ? 'waiting'
: task.running || row?.status === 'running' ? 'running'
- : task.activity?.phase === 'error' ? 'failed'
: task.activity?.phase === 'completed' ? 'completed'
: row && (BOT_DELEGATION_STATUSES as readonly string[]).includes(row.status)
? row.status