Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
packages/contracts or packages/shared (packages/client-runtime, used by web, desktop and mobile)
Steps to reproduce
isWorkflowScriptMessage in packages/client-runtime/src/state/subagentRuntime.ts tests the first user message of a provider-native subagent thread against WORKFLOW_SCRIPT_START whenever the server did not set workflowScript on that message. Only the Claude adapter sets it, so other providers' subagent threads and older threads take this path.
The regex backtracks exponentially on a prompt that opens with slash-only comment dividers, and on runs of block comments. On main at 7b44788, Node 26.13.1:
const WORKFLOW_SCRIPT_START = /^\s*(?:(?:\/\/[^\n]*|\/\*[\s\S]*?\*\/)\s*)*export\s+const\s+meta\b/;
WORKFLOW_SCRIPT_START.test("////////////\n".repeat(3) + "const x = 1;"); // 11 ms
WORKFLOW_SCRIPT_START.test("////////////\n".repeat(4) + "const x = 1;"); // 242 ms
WORKFLOW_SCRIPT_START.test("/".repeat(40) + "\nconst x = 1;"); // 1066 ms
WORKFLOW_SCRIPT_START.test("/**/".repeat(30) + "const x = 1;"); // 5307 msEach extra divider line multiplies the time by about 20, so six lines of twelve slashes take more than a minute.
In the app: open a subagent thread from a provider other than Claude whose prompt starts with a few lines like ////////////////////////////////////////, for example a prompt that quotes a source file with divider comments at the top.
Expected behavior
The thread opens. A prompt that does not start with export const meta after its leading comments is rejected in linear time.
Actual behavior
The client blocks on the regex while it renders the thread. With a handful of divider lines it does not come back.
The same backtracking also lets a commented-out export match: // export const meta = {} is treated as a workflow script, because [^\n]* can stop before the end of the line.
Impact
Minor bug or occasional failure. The trigger is narrow, but when it is hit the thread cannot be opened.
Version or commit
main at 7b44788; the regex was added in #20857.
Environment
Found by reading the code while reviewing static-analysis findings, then confirmed by timing the regex in Node 26.13.1 on Linux x64. I have not hit it in daily use.
Activity