{"record":{"id":"0861437851d2f3fb","repo":"Hmbown/CodeWhale","slug":"windows-get-app-state-does-not-support-window-id","errorCode":null,"errorMessage":"Windows get_app_state does not support window_id","messagePattern":"Windows get_app_state does not support window_id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/backends/win32.mjs","lineNumber":358,"sourceCode":"      let argumentsScript = \"\";\n      if (urlArg != null) {\n        if (typeof urlArg !== \"string\" || !URL.canParse(urlArg) || /[\\0\\r\\n]/.test(urlArg)) throw new ExecError(\"open_application url must be an absolute URL\");\n        // Start-Process joins ArgumentList into a Windows command line. Quote\n        // one argument there, and transport that string as data into PowerShell.\n        const quoted = '\"' + urlArg.replace(/(\\\\*)\"/g, '$1$1\\\\\"').replace(/(\\\\+)$/g, '$1$1') + '\"';\n        const encoded = Buffer.from(quoted, \"utf16le\").toString(\"base64\");\n        argumentsScript = `$launchArg = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${encoded}')); `;\n      }\n      // activate defaults to background on every platform: a minimized\n      // launch leaves the user's foreground window alone. Windows input is\n      // still shared-surface — this only controls the launch, not input.\n      const windowStyle = activate === true ? \"\" : \" -WindowStyle Minimized\";\n      const r = await psOk(`${argumentsScript}Start-Process -FilePath \"${target}\"${windowStyle}${urlArg != null ? \" -ArgumentList $launchArg\" : \"\"}; Write-Output '{\"launched\": true}'`, { timeoutMs: 20_000 });\n      if (r.code !== 0) throw new ExecError(`Start-Process failed: ${r.stderr.trim().slice(0, 200)}`, r);\n      return { launched: true, name: target, url: urlArg ?? null, activate: activate === true };\n    },\n    get_app_state: async (args = {}) => {\n      if (Object.hasOwn(args, \"window_id\")) throw unsupportedSelector(\"Windows get_app_state does not support window_id\");\n      const { app_ref, detail } = args;\n      if (Object.hasOwn(args, \"app_ref\") && (!app_ref || typeof app_ref !== \"object\" || Array.isArray(app_ref)\n        || Object.keys(app_ref).length !== 1 || !Object.hasOwn(app_ref, \"name\") || typeof app_ref.name !== \"string\" || !app_ref.name.trim())) {\n        throw unsupportedSelector(\"Windows get_app_state supports only app_ref: { name: exact window title }; PID, bundle_id and other references are unsupported\");\n      }\n      const filter = Buffer.from(app_ref?.name ?? \"\", \"utf16le\").toString(\"base64\");\n      const maxEls = detail === \"full\" ? 800 : 400;\n      const j = await psJson(`${UIA_PRELUDE}\n$max = ${maxEls};\n$filter = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${filter}'));\n$root = [System.Windows.Automation.AutomationElement]::RootElement;\n$els = New-Object System.Collections.ArrayList;\n$found = $false; $truncated = $false; $appName = $null;\n$targets = @($root.FindAll([System.Windows.Automation.TreeScope]::Children, [System.Windows.Automation.Condition]::TrueCondition));\nif ($filter) {\n  $targets = @($targets | Where-Object { [string]::Equals($_.Current.Name, $filter, [StringComparison]::OrdinalIgnoreCase) });\n  if ($targets.Count -gt 1) { throw 'More than one application window has this exact name' }\n}","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/backends/win32.mjs#L340-L376","documentation":"On Windows, get_app_state inspects one application's UIA tree but cannot address a specific window by id; it throws unsupportedSelector when window_id is present. The backend supports selecting the app only by exact window title via app_ref.name.","triggerScenarios":"Calling get_app_state with window_id set (e.g. an id previously returned by list_windows on another platform).","commonSituations":"Cross-platform scripts carrying macOS window ids into the Windows backend; agents caching window ids across calls; treating list_windows output ids as stable handles on Windows.","solutions":["Remove window_id and pass app_ref: { name: <exact window title> } instead.","Get the exact title from list_windows or list_apps.title first.","If the app has multiple windows, note that the backend matches by title filter only; disambiguate by title text.","On macOS, window_id remains supported — gate the call on process.platform or backend name."],"exampleFix":"// before\nawait computerUse({ action: \"get_app_state\", app_ref: { name: \"Notepad\" }, window_id: 42 });\n// after\nawait computerUse({ action: \"get_app_state\", app_ref: { name: \"Notepad\" } });","handlingStrategy":"validation","validationCode":"if (args.window_id != null) throw new Error(\"win32 get_app_state: drop window_id, use app_ref.name\");","typeGuard":"const winSafeAppStateArgs = (a) => a != null && a.window_id === undefined && typeof a.app_ref?.name === \"string\" && a.app_ref.name.trim().length > 0;","tryCatchPattern":"try { await getAppState(args) } catch (e) { if (String(e.message).includes(\"does not support window_id\")) { delete args.window_id; await getAppState(args); } else throw e; }","preventionTips":["Never persist window ids across platforms; resolve titles instead","Look up the exact window title with list_windows/list_apps before get_app_state","Gate selector usage on the active backend"],"tags":["windows","computer-use","unsupported-selector","uia"],"backgroundTag":"unsupported-operation","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}