{"record":{"id":"8c2c84e04c74e8f2","repo":"Hmbown/CodeWhale","slug":"aa-start-failed-last","errorCode":null,"errorMessage":"aa start failed: ${last}","messagePattern":"aa start failed: (.+?)","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/harmonyos.mjs","lineNumber":196,"sourceCode":"      const out = await deviceOut([\"hidumper\", \"-s\", \"WindowManagerService\", \"-a\", \"-a\"], { timeoutMs: 25_000 }).catch(() => \"\");\n      const windows = out.split(\"\\n\").filter((l) => /Window Name|bundleName/i.test(l)).slice(0, 40).map((l) => ({ title: l.trim().slice(0, 160) }));\n      return { windows: windows.length ? windows : [{ title: \"(window list unavailable on this HarmonyOS build)\" }] };\n    },\n    open_application: async ({ bundle_id: bid, ability, name } = {}) => {\n      const bundle = bid ?? name;\n      const identifier = (value) => typeof value === \"string\" && value.length <= 256 && /^[A-Za-z_][A-Za-z0-9_]*(?:\\.[A-Za-z_][A-Za-z0-9_]*)*$/.test(value);\n      if (!identifier(bundle)) throw new ExecError(\"open_application needs a valid Harmony bundle identifier\");\n      if (ability != null && !identifier(ability)) throw new ExecError(\"open_application needs a valid Harmony ability identifier\");\n      const candidates = ability != null ? [ability] : [\"EntryAbility\", \"MainAbility\"];\n      let last = null;\n      for (const a of candidates) {\n        const r = await shell([\"aa\", \"start\", \"-b\", escDeviceText(bundle), \"-a\", escDeviceText(a)]);\n        if (r.code === 0 && !/Error|error/.test(r.stdout + r.stderr)) {\n          return { launched: true, bundle, ability: a };\n        }\n        last = (r.stderr || r.stdout).trim().slice(0, 200);\n      }\n      throw new ExecError(`aa start failed: ${last}`);\n    },\n    get_app_state: async (args = {}) => {\n      rejectAppSelectors(args);\n      const tree = await dumpLayout();\n      const els = flatten(tree);\n      return { bundle_id: tree.attributes?.bundleName ?? null, elements: els, truncated: els.length >= 600 };\n    },\n    screenshot: async (args = {}) => {\n      rejectAppSelectors(args);\n      const { path: outPath } = args;\n      const dir = process.env.CODEWHALE_CU_RECORDINGS_DIR || path.join(os.homedir(), \".codewhale-cu\", \"recordings\");\n      fs.mkdirSync(dir, { recursive: true });\n      const file = outPath || path.join(dir, `shot-${new Date().toISOString().replace(/[:.]/g, \"-\")}-${crypto.randomBytes(3).toString(\"hex\")}.jpeg`);\n      await snapshot(file);\n      const buf = fs.readFileSync(file);\n      displayPixels = jpegSize(buf) ?? displayPixels;\n      return { file, bytes: buf.length, pixels: jpegSize(buf), scale: 1, points: jpegSize(buf) };\n    },","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/harmonyos.mjs#L178-L214","documentation":"After trying each candidate ability with `aa start`, open_application throws this ExecError containing the last device-side error output (up to 200 chars) when no candidate launches successfully. It means the bundle/ability exists syntactically but the device refused to start it.","triggerScenarios":"`aa start -b <bundle> -a <ability>` exits non-zero or prints Error for every candidate ability (EntryAbility, MainAbility or the explicit one) — e.g. the app is not installed, the ability name does not exist for that bundle, or the device refuses the launch.","commonSituations":"Typo'd bundle id for an app that is not installed on the device; app's actual ability class differs from EntryAbility/MainAbility; app disabled or device policy blocking `aa start`; stale device state requiring reboot.","solutions":["Read the embedded device output for the real cause ('Ability does not exist', 'install failed', etc.).","Verify the bundle is installed via list_apps (`bm dump -a`) and use an exact bundle id.","Find the app's real ability name (module.json5) and pass it explicitly as ability.","Retry after confirming the device screen is unlocked; reboot the device or restart hdc if the error persists."],"exampleFix":"try {\n  await backend.open_application({ bundle_id: 'com.example.app' });\n} catch (e) {\n  if (String(e.message).startsWith('aa start failed')) {\n    const apps = await backend.list_apps();\n    const real = apps.apps.find(a => a.bundle_id.includes('example'));\n    if (real) await backend.open_application({ bundle_id: real.bundle_id });\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const apps = await backend.list_apps();\nif (!apps.apps.some(a => a.bundle_id === bid)) console.warn(`bundle ${bid} not installed on device`);","typeGuard":"null","tryCatchPattern":"try { await backend.open_application({ bundle_id: bid }); } catch (e) { if (String(e.message).startsWith('aa start failed')) { console.error('device said:', e.message); /* verify install + ability name, then retry */ } else throw e; }","preventionTips":["Confirm the bundle is installed via list_apps before launching.","Parse the embedded device error text for the precise cause.","Prefer default-ability launch (omit ability) unless the app needs a specific entry point.","Keep the device unlocked and hdc healthy before launch attempts."],"tags":["harmonyos","app-launch","aa-start","device"],"backgroundTag":"http-error-response","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T21:17:16.096Z"}