{"record":{"id":"c49d8550eb3a8bdb","repo":"jackwener/OpenCLI","slug":"current-status-latestactivity-status-ap","errorCode":null,"errorMessage":"Current status=${latestActivity?.Status ?? ''}, approvalPending=${latestActivity?.ApprovalPending ?? ''}, approvalKind=${latestActivity?.ApprovalKind ?? ''}, approvalButton=${latestActivity?.ApprovalButton ?? ''}. Use \"opencli trae-cn targets -f json\" to find the waiting target, then run \"OPENCLI_CDP_TARGET=<target> opencli trae-cn watch --stream true --duration 300\" or \"opencli trae-cn approve\".","messagePattern":"Current status=(.+?), approvalPending=(.+?), approvalKind=(.+?), approvalButton=(.+?)\\. Use \"opencli trae-cn targets -f json\" to find the waiting target, then run \"OPENCLI_CDP_TARGET=<target> opencli trae-cn watch --stream true --duration 300\" or \"opencli trae-cn approve\"\\.","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/ask.js","lineNumber":89,"sourceCode":"        lastText = text;\n        stableSince = Date.now();\n        continue;\n      }\n      const stableFor = Date.now() - stableSince;\n      const blocked = isLikelyBlockingActivity(latestActivity);\n      const completed = isActivityComplete(latestActivity);\n      if (completed && !blocked && stableFor >= 1000) {\n        return [latest];\n      }\n      if (!blocked && stableFor >= 3000) {\n        return [latest];\n      }\n    }\n\n    if (latest?.Text) {\n      const blocked = isLikelyBlockingActivity(latestActivity);\n      if (blocked) {\n        throw new TimeoutError(\n          'trae-cn ask',\n          timeout,\n          `Current status=${latestActivity?.Status ?? ''}, approvalPending=${latestActivity?.ApprovalPending ?? ''}, approvalKind=${latestActivity?.ApprovalKind ?? ''}, approvalButton=${latestActivity?.ApprovalButton ?? ''}. Use \"opencli trae-cn targets -f json\" to find the waiting target, then run \"OPENCLI_CDP_TARGET=<target> opencli trae-cn watch --stream true --duration 300\" or \"opencli trae-cn approve\".`,\n        );\n      }\n      return [latest];\n    }\n    throw new TimeoutError('trae-cn ask', timeout, 'No Trae CN response was visible before the timeout. The agent may still be generating.');\n  },\n});\n","sourceCodeStart":71,"sourceCodeEnd":100,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/ask.js#L71-L100","documentation":"ask.js throws a TimeoutError when the Trae CN activity stream is still showing a blocking activity (an approval prompt or waiting state) when the timeout elapses. The message embeds the latest activity's Status/ApprovalPending/ApprovalKind/ApprovalButton fields and tells the operator how to find and approve the waiting target via CDP. It exists so an agent stuck on a permission dialog is distinguishable from one still generating.","triggerScenarios":"Calling `opencli trae-cn ask` when the Trae CN agent has raised an approval prompt (isLikelyBlockingActivity(latestActivity) returns true) and the user does not approve within the --timeout period. Also when a previous approval dialog is left open from an earlier run.","commonSituations":"Running the CLI unattended while Trae CN waits on a tool-approval dialog; long approval buttons with a short --timeout; leftover pending dialogs from a prior session blocking the new ask.","solutions":["Run `opencli trae-cn targets -f json` to find the waiting target, then `OPENCLI_CDP_TARGET=<target> opencli trae-cn approve` to accept the pending prompt.","Alternatively attach with `OPENCLI_CDP_TARGET=<target> opencli trae-cn watch --stream true --duration 300` to observe and interact.","Re-run ask with a larger --timeout if the approval just needs more time.","Ensure no stale approval dialogs are open before issuing ask."],"exampleFix":"// before\nopencli trae-cn ask \"do the task\" --timeout 30\n// after\nopencli trae-cn targets -f json   # find waiting target\nOPENCLI_CDP_TARGET=<target> opencli trae-cn approve\nopencli trae-cn ask \"do the task\" --timeout 120","handlingStrategy":"try-catch","validationCode":"// Before running ask, check for an already-waiting target\nconst { execSync } = require('child_process');\nconst targets = JSON.parse(execSync('opencli trae-cn targets -f json', 'utf8'));\nconst waiting = targets.filter(t => t.activity && /approve|pending|waiting/i.test(JSON.stringify(t.activity)));\nif (waiting.length) console.warn('Resolve pending approval first:', waiting.map(t => t.target));","typeGuard":"function isBlockingActivity(a) {\n  return Boolean(a && typeof a === 'object' &&\n    (a.ApprovalPending === true || a.ApprovalButton || /wait|approve/i.test(String(a.Status ?? ''))));\n}","tryCatchPattern":"try {\n  await runAsk(timeout);\n} catch (e) {\n  if (e instanceof TimeoutError && /approvalPending=true/i.test(e.message)) {\n    const target = findWaitingTarget(); // opencli trae-cn targets -f json\n    execSync(`OPENCLI_CDP_TARGET=${target} opencli trae-cn approve`);\n    return runAsk(timeout); // retry once after approving\n  }\n  throw e;\n}","preventionTips":["Clear any pending approval dialogs before launching ask.","Use a generous --timeout when running unattended.","Monitor with `opencli trae-cn watch --stream true` to spot approvals early.","Automate approve via targets -f json polling."],"tags":["timeout","approval-pending","cdp","automation"],"backgroundTag":"agent-approval-blocked-timeout","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}