{"record":{"id":"1bf447fc730ba801","repo":"can1357/oh-my-pi","slug":"attach-requires-pid-or-port","errorCode":null,"errorMessage":"attach requires pid or port","messagePattern":"attach requires pid or port","errorType":"validation","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/debug.ts","lineNumber":768,"sourceCode":"\t\t\t\t\tthrow new ToolError(\n\t\t\t\t\t\t`No debugger adapter available. Installed adapters: ${getConfiguredAdapters(commandCwd)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst { adapter } = selection;\n\t\t\t\tvalidateLaunchProgram(program, commandCwd, programKind, adapter);\n\t\t\t\tconst extraLaunchArguments = resolveLaunchOverrides(adapter, program, programKind);\n\t\t\t\tconst snapshot = await dapSessionManager.launch(\n\t\t\t\t\t{ adapter, program, args: params.args, cwd: commandCwd, extraLaunchArguments },\n\t\t\t\t\tcombinedSignal,\n\t\t\t\t\ttimeoutSec * 1000,\n\t\t\t\t);\n\t\t\t\tdetails.snapshot = snapshot;\n\t\t\t\tdetails.adapter = adapter.name;\n\t\t\t\treturn result.text(formatSessionSnapshot(snapshot).join(\"\\n\")).done();\n\t\t\t}\n\t\t\tcase \"attach\": {\n\t\t\t\tif (params.pid === undefined && params.port === undefined && !params.adapter) {\n\t\t\t\t\tthrow new ToolError(\"attach requires pid or port\");\n\t\t\t\t}\n\t\t\t\tconst commandCwd = params.cwd ? resolveToCwd(params.cwd, this.session.cwd) : this.session.cwd;\n\t\t\t\tconst adapter = selectAttachAdapter(commandCwd, params.adapter, params.port);\n\t\t\t\tif (!adapter) {\n\t\t\t\t\tif (params.adapter) {\n\t\t\t\t\t\tconst command = getAdapterConfigs(commandCwd)[params.adapter]?.command ?? params.adapter;\n\t\t\t\t\t\tthrow new ToolError(formatAdapterUnavailable(params.adapter, command, commandCwd));\n\t\t\t\t\t}\n\t\t\t\t\tthrow new ToolError(\n\t\t\t\t\t\t`No debugger adapter available. Installed adapters: ${getConfiguredAdapters(commandCwd)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst snapshot = await dapSessionManager.attach(\n\t\t\t\t\t{ adapter, cwd: commandCwd, pid: params.pid, port: params.port, host: params.host },\n\t\t\t\t\tcombinedSignal,\n\t\t\t\t\ttimeoutSec * 1000,\n\t\t\t\t);\n\t\t\t\tdetails.snapshot = snapshot;","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/debug.ts#L750-L786","documentation":"The attach action needs a target: a `pid`, a `port`, or — as a permissive fallback — at least an `adapter` name (some adapters can discover targets themselves). If all three are undefined, execute throws before selecting an adapter because there is no way to identify the process or endpoint to attach to.","triggerScenarios":"Calling the debug tool with action=\"attach\" and omitting pid, port, and adapter entirely.","commonSituations":"Confusing attach with launch semantics; intending to use adapter-based auto-discovery but forgetting the adapter name; an automation script that drops optional fields when they are actually required together.","solutions":["Pass the target process id: `pid: <pid>`.","Or pass the debug adapter's listening `port` for attach-over-socket.","Or supply `adapter` if the adapter supports target discovery without an explicit pid/port."],"exampleFix":"// before\n{ \"action\": \"attach\" }\n// after\n{ \"action\": \"attach\", \"pid\": 12345 }","handlingStrategy":"validation","validationCode":"function assertAttachArgs(p: { pid?: number; port?: number; adapter?: string }): void {\n  if (p.pid === undefined && p.port === undefined && !p.adapter) {\n    throw new Error(\"attach needs pid, port, or adapter\");\n  }\n}","typeGuard":"function hasAttachTarget(p: { pid?: number; port?: number; adapter?: string }): boolean {\n  return p.pid !== undefined || p.port !== undefined || p.adapter !== undefined;\n}","tryCatchPattern":"try {\n  return await debugTool({ action: \"attach\", ...args });\n} catch (e) {\n  if (String(e).includes(\"attach requires pid or port\")) {\n    throw new Error(\"resolve a target pid or debug port before attaching\");\n  }\n  throw e;\n}","preventionTips":["Resolve the process pid (ps/proc scan) or debug listen port before invoking attach.","Model attach args as a discriminated union requiring at least one target field.","For adapter-based discovery, always name the adapter explicitly."],"tags":["debug","dap","validation","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}