Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions apps/desktop/src/main/__tests__/interrupted-resume.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { materializeTurns } from '@maka/ui';
import { latestInterruptedResumeTurnId } from '../../renderer/interrupted-resume.js';

describe('latest interrupted resume candidate', () => {
it('recognizes a timeout after a completed tool result', () => {
assert.equal(
latestInterruptedResumeTurnId([
{
turnId: 'turn-1',
status: 'failed',
errorClass: 'timeout',
tools: [{ status: 'completed' }],
},
]),
'turn-1',
);
});

it('does not offer continuation for an incomplete or errored tool', () => {
assert.equal(
latestInterruptedResumeTurnId([
{
turnId: 'turn-1',
status: 'failed',
errorClass: 'timeout',
tools: [{ status: 'running' }],
},
]),
undefined,
);
assert.equal(
latestInterruptedResumeTurnId([
{
turnId: 'turn-1',
status: 'failed',
errorClass: 'timeout',
tools: [{ status: 'completed' }, { status: 'interrupted' }],
},
]),
undefined,
);
assert.equal(
latestInterruptedResumeTurnId([
{
turnId: 'turn-1',
status: 'failed',
errorClass: 'timeout',
tools: [{ status: 'errored' }],
},
]),
undefined,
);
});

it('rejects the mixed shape produced by materializeTurns', () => {
const [turn] = materializeTurns([
{ type: 'user', id: 'user-1', turnId: 'turn-1', ts: 1, text: 'inspect' },
{
type: 'turn_state',
id: 'state-1',
turnId: 'turn-1',
ts: 2,
status: 'failed',
errorClass: 'timeout',
partialOutputRetained: false,
},
{ type: 'tool_call', id: 'call-1', turnId: 'turn-1', ts: 3, toolName: 'Read', args: {} },
{
type: 'tool_result',
id: 'result-1',
turnId: 'turn-1',
ts: 4,
toolUseId: 'call-1',
isError: false,
content: { kind: 'text', text: 'ok' },
},
{ type: 'tool_call', id: 'call-2', turnId: 'turn-1', ts: 5, toolName: 'Read', args: {} },
]);

assert.deepEqual(turn?.tools.map((tool) => tool.status), ['completed', 'interrupted']);
assert.equal(latestInterruptedResumeTurnId(turn ? [turn] : []), undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ describe('failed turn execution state', () => {
/部分回答/,
);
});

});
18 changes: 14 additions & 4 deletions apps/desktop/src/renderer/interrupted-resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ export interface InterruptedResumeTurn {
turnId: string;
status: string;
errorClass?: string;
/** Tool activity already has a durable result in the rendered Turn. */
tools?: readonly { status: string }[];
}

export function latestInterruptedResumeTurnId(
turns: readonly InterruptedResumeTurn[],
): string | undefined {
const latestTurn = turns.at(-1);
return latestTurn?.status === 'failed'
&& latestTurn.errorClass?.toLowerCase() === 'app_restarted'
? latestTurn.turnId
: undefined;
if (latestTurn?.status !== 'failed') return undefined;
const errorClass = latestTurn.errorClass?.toLowerCase();
if (errorClass === 'app_restarted') return latestTurn.turnId;
if (
errorClass?.includes('timeout') &&

@Astro-Han Astro-Han Aug 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not offer timeout recovery when Safe Resume is disabled

Safe-boundary resume is off by default unless MAKA_RUNTIME_SAFE_BOUNDARY_RESUME=1 is set. I could not find a production Desktop startup path that enables it, but this branch now exposes the action for its normal target case: a timeout after completed tools. Clicking it in the default configuration always parks with resume_feature_disabled.

Runtime still fails closed, so this is not a safety problem. It is a UX problem: the button promises a recovery action that cannot run. Could we either hide it when the Runtime capability is disabled, or make enabling the capability part of this rollout?

简体中文

Safe Resume 默认关闭,只有设置 MAKA_RUNTIME_SAFE_BOUNDARY_RESUME=1 才能使用,但这里会在默认 Desktop 中为“工具已完成后超时”的情况显示恢复按钮。用户点击后只会得到 resume_feature_disabled

Runtime 仍会安全地拒绝执行,所以这不是安全问题,但按钮在默认配置下无法完成它承诺的操作。可以在能力未开启时隐藏按钮,或者把开启该能力纳入这次发布。

latestTurn.tools !== undefined &&
latestTurn.tools.length > 0 &&
latestTurn.tools.every((tool) => tool.status === 'completed')
) {
return latestTurn.turnId;
}
return undefined;
}