Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(skills): ask for a later retry when preparing a skill on the device times out (#20112)

Arvin Xuf8cb39036bef
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/skills.test.ts b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/skills.test.ts
index e95d075b287..eb94bd53c44 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/__tests__/skills.test.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/__tests__/skills.test.ts
@@ -868,6 +868,67 @@ describe('skillsRuntime', () => {
);
});
+ // A multi-MB skill on a slow link outlasts the prepare deadline while the
+ // device keeps downloading; the next call reuses that work. Telling the
+ // model the app may be outdated made it give up and blame the user's app.
+ it.each([
+ '{"error":"TIMEOUT","success":false}',
+ 'DEVICE_RESPONSE_TIMEOUT (HTTP 504)',
+ 'The operation was aborted due to timeout',
+ ])(
+ 'asks for a later retry, not an app update, when the prepare times out (%s)',
+ async (error) => {
+ mocks.prepareSkillDirectory.mockResolvedValue({ error, success: false });
+
+ const { skillsRuntime } = await import('../skills');
+ const runtime = await skillsRuntime.factory({
+ activeDeviceId: 'device-1',
+ serverDB: {} as never,
+ toolManifestMap: {},
+ topicId: 'topic-1',
+ userId: 'user-1',
+ });
+
+ const result = await runtime.execScript({
+ activatedSkills: [{ id: 'user-skill-id', name: 'user-skill' }],
+ command: 'python scripts/run.py',
+ description: 'Run skill script',
+ });
+
+ expect(result.success).toBe(false);
+ expect(result.content).toContain('did not finish in time');
+ expect(result.content).toContain('run the same execScript again');
+ expect(result.content).not.toContain('may need an update');
+ expect(mocks.executeToolCall).not.toHaveBeenCalled();
+ },
+ );
+
+ it('keeps reporting a finished download failure that merely mentions a timeout', async () => {
+ mocks.prepareSkillDirectory.mockResolvedValue({
+ error: 'Failed to download skill package: 504 Gateway Timeout',
+ success: false,
+ });
+
+ const { skillsRuntime } = await import('../skills');
+ const runtime = await skillsRuntime.factory({
+ activeDeviceId: 'device-1',
+ serverDB: {} as never,
+ toolManifestMap: {},
+ topicId: 'topic-1',
+ userId: 'user-1',
+ });
+
+ const result = await runtime.execScript({
+ activatedSkills: [{ id: 'user-skill-id', name: 'user-skill' }],
+ command: 'python scripts/run.py',
+ description: 'Run skill script',
+ });
+
+ expect(result.success).toBe(false);
+ expect(result.content).toContain('Failed to download skill package: 504 Gateway Timeout');
+ expect(result.content).not.toContain('did not finish in time');
+ });
+
it('runs without a skill dir (workingDirectory cwd) when no archive exists', async () => {
mocks.executeToolCall.mockResolvedValue({
content: 'ok',
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/skills.ts b/apps/server/src/services/toolExecution/serverRuntimes/skills.ts
index 081807144f6..aaf503e40fd 100644
--- a/apps/server/src/services/toolExecution/serverRuntimes/skills.ts
+++ b/apps/server/src/services/toolExecution/serverRuntimes/skills.ts
@@ -62,6 +62,19 @@ const log = debug('lobe-server:skills-runtime');
const withoutReplay = <T extends { error?: unknown; success: boolean }>(result: T): T =>
result.success ? result : { ...result, error: { ...toRecord(result.error), kind: 'stop' } };
+/**
+ * A prepare the gateway gave up on: its `{"error":"TIMEOUT"}` body, the
+ * transport's `DEVICE_RESPONSE_TIMEOUT` code (an empty-bodied 504), or our own
+ * HTTP deadline when the gateway never answered. Deliberately narrow: a device
+ * whose archive download itself failed (e.g. `504 Gateway Timeout` from the
+ * CDN) has finished, and must not be told the work is still continuing.
+ */
+const isPrepareTimeout = (error?: string) =>
+ !!error &&
+ (/"error"\s*:\s*"TIMEOUT"/.test(error) ||
+ error.startsWith('DEVICE_RESPONSE_TIMEOUT') ||
+ /aborted due to timeout/i.test(error));
+
interface UserSettingsWithMarketToken {
market?: {
accessToken?: string;
@@ -481,6 +494,16 @@ class SkillServerRuntimeService implements SkillRuntimeService {
return LEGACY_DEVICE_CLIENT;
}
+ // The gateway stopped waiting, not the device: it keeps downloading and
+ // unpacking (a multi-MB skill on a slow link outlasts the deadline), and
+ // the next call joins or reuses that work. "Your app may need an
+ // update" sent the model to the user instead of simply trying again.
+ if (isPrepareTimeout(prepared.error)) {
+ return fail(
+ `Preparing skill "${archive.name}" on the user's device did not finish in time. This is usually the device still downloading and unpacking the skill package (a large skill or a slow network); that continues in the background and the finished copy is reused. Wait about a minute, then run the same execScript again. If it keeps timing out, tell the user the device's network looks slow, or that the device may have gone to sleep.`,
+ );
+ }
+
return fail(
`Failed to prepare skill "${archive.name}" on the user's device: ${prepared.error ?? 'unknown error'}. ` +
'Do not retry elsewhere — report this to the user (their LobeHub app may need an update).',