perf(executor): recover approved steps on engine restart
When the engine restarts mid-step, an in-progress step may have already passed plan + code review but not yet been flipped to done by the agent's next task_update call. Previously, the next executor pass re-entered the step and replayed both reviews — measured at 5-20 min of pure waste per restart (observed in FN-2215 Step 1 and FN-2207 Step 6). recoverApprovedStepsOnResume scans the task log for any in-progress step whose most recent "code review Step N: APPROVE" entry is newer than its most recent "Step N → pending" transition, and marks those steps done before execute() runs. Safely skips steps that were reset after approval (e.g. by a workflow revision) or only received REVISE verdicts. Called from both the engine-restart path (resumeOrphaned) and the unpause path, matching the two places the task log shows as vulnerable to this race. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,26 @@ const DEFAULT_PROBE_DELAY_MS = 10_000;
|
||||
const DEFAULT_PROBE_HOST = "127.0.0.1";
|
||||
const DEFAULT_PROBE_TIMEOUT_MS = 1_000;
|
||||
|
||||
/**
|
||||
* Reject dev-server commands whose strings contain command-substitution
|
||||
* syntax. Dev-server commands are user-configured project settings (e.g.
|
||||
* `npm run dev`, `bun dev`) and are spawned with `shell: true` so users
|
||||
* can chain `&&` / `|`, but command substitution (`$(...)`, backticks,
|
||||
* process substitution) is never needed for a start command and is the
|
||||
* main payload for a settings-file compromise. Legitimate commands don't
|
||||
* need to execute a sub-command before launching the dev server.
|
||||
*/
|
||||
function assertSafeDevServerCommand(command: string): void {
|
||||
if (/\$\(|`|<\(|>\(/.test(command)) {
|
||||
throw new Error(
|
||||
"Dev-server command contains command substitution ($(...), backticks, or process substitution), which is not permitted",
|
||||
);
|
||||
}
|
||||
if (/[\0\r\n]/.test(command)) {
|
||||
throw new Error("Dev-server command contains invalid control characters");
|
||||
}
|
||||
}
|
||||
|
||||
export class DevServerProcessManager extends EventEmitter {
|
||||
private childProcess: ChildProcess | null = null;
|
||||
private portProbeTimer: NodeJS.Timeout | null = null;
|
||||
@@ -67,6 +87,7 @@ export class DevServerProcessManager extends EventEmitter {
|
||||
if (safeCommand.length === 0) {
|
||||
throw new Error("command is required");
|
||||
}
|
||||
assertSafeDevServerCommand(safeCommand);
|
||||
|
||||
const safeCwd = cwd.trim();
|
||||
if (safeCwd.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user