{"record":{"id":"fb0966ce38344b6f","repo":"Hmbown/CodeWhale","slug":"no-running-application-with-pid-pid-call-list-apps-for-the","errorCode":null,"errorMessage":"no running application with pid ${pid}; call list_apps for the current processes","messagePattern":"no running application with pid (.+?); call list_apps for the current processes","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/darwin.mjs","lineNumber":564,"sourceCode":"    // Failed selection must not leave an earlier app armed for shared input.\n    state.foregroundInput = false;\n    state.inputApp = null;\n    // pid is the most specific identity and the only one that separates two\n    // processes of the same bundle (e.g. a second Chrome on its own profile),\n    // so it wins when given.\n    const find = {};\n    if (pid) find.pid = pid; else if (bid) find.bundle_id = bid; else find.name = String(name).replace(/\\.app$/, \"\");\n    let p;\n    // Binding an already-running app must not ask LaunchServices to reopen\n    // it: reopen can raise windows even with open -g on some applications.\n    if (!urlArg) {\n      try { p = await native(\"app_info\", { app_ref: find, activate }); }\n      catch (error) {\n        if (!error.message.includes(\"application not found\")) throw error;\n      }\n    }\n    if (!p?.found) {\n      if (!name && !bid) throw new ExecError(`no running application with pid ${pid}; call list_apps for the current processes`);\n      const args = [];\n      if (urlArg) args.push(urlArg);\n      if (bid) args.unshift(\"-b\", bid); else args.unshift(\"-a\", name);\n      if (!activate) args.unshift(\"-g\");\n      const r = await runL(\"open\", args, { timeoutMs: 25_000 });\n      if (r.code !== 0) throw new ExecError(`open failed: ${r.stderr.trim().slice(0, 200)}`, r);\n      await new Promise((res) => setTimeout(res, 600));\n      p = await native(\"app_info\", { app_ref: find, activate });\n    }\n    if (activate && p?.frontmost === false) throw Object.assign(new ExecError(\"The selected application did not become frontmost; no input mode was enabled. Continue with background control or wait for the user.\"), { code: \"activation_not_confirmed\" });\n    if (p?.bundle_id === \"net.codewhale.computer-use\") throw Object.assign(new ExecError(\"The Computer Use setup and safety controls belong to the user and cannot be operated by this plugin.\"), { code: \"protected_application\" });\n    // A bare executable has no bundle id; carrying an empty one would make the\n    // identity unmatchable.\n    state.inputApp = { pid: p.pid, ...(p.bundle_id ? { bundle_id: p.bundle_id } : {}) };\n    state.foregroundInput = !!activate;\n    return { launched: true, activate, keyboard_delivery: activate ? \"foreground-guarded\" : \"process\", input_scope: activate ? \"shared-desktop\" : \"application\", shared_pointer: !!activate, isolated_desktop: false, url: urlArg ?? null, resolved: p?.found ? { name: p.name, pid: p.pid, bundle_id: p.bundle_id, frontmost: p.frontmost } : null };\n  }\n","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/plugins/computer-use/src/backends/darwin.mjs#L546-L582","documentation":"After trying to resolve the pid through the native helper (app_info), the backend found no running application with that pid and there is no name or bundle_id fallback to launch. It tells you to call list_apps for the current process list. Note this throw dereferences pid in the message, so it is only reachable when pid was provided (pid-only lookups that fail).","triggerScenarios":"open_application({ pid: N }) where no process with pid N is running (it exited, or the pid came from a stale list_apps result), and neither name nor bundle_id was supplied as a fallback.","commonSituations":"Agent caches a pid from an earlier list_apps call, the app crashes or is relaunched with a new pid, then a later open_application by pid fails; using a pid captured on a different machine/session.","solutions":["Call list_apps and use a currently valid pid or app name.","Supply name or bundle_id alongside pid so the backend can fall back to launching via `open`.","Refresh the pid after the app restarts instead of reusing a cached value."],"exampleFix":"// before\nawait backend.open_application({ pid: stalePid });\n// after\nconst apps = await backend.list_apps();\nconst app = apps.find(a => a.name === \"Safari\");\nawait backend.open_application({ pid: app.pid });","handlingStrategy":"validation","validationCode":"const apps = await backend.list_apps();\nif (!apps.some(a => a.pid === pid)) {\n  throw new Error(`pid ${pid} is not running; refresh from list_apps`);\n}\nawait backend.open_application({ pid });","typeGuard":"function pidIsLive(apps, pid) {\n  return apps.some(a => a.pid === pid);\n}","tryCatchPattern":"try {\n  await backend.open_application({ pid });\n} catch (e) {\n  if (String(e.message).startsWith('no running application with pid')) {\n    const apps = await backend.list_apps();\n    // re-resolve and retry with a live pid or name\n  } else throw e;\n}","preventionTips":["Never cache pids across app restarts; re-resolve from list_apps.","Always include a name or bundle_id fallback alongside pid."],"tags":["process-not-found","stale-pid","computer-use"],"backgroundTag":"entity-not-found","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}