{"record":{"id":"2670bd6525dd276f","repo":"can1357/oh-my-pi","slug":"acp-session-fork-is-unavailable-while-a-prompt-is","errorCode":null,"errorMessage":"ACP session fork is unavailable while a prompt is in progress: ${sessionId}","messagePattern":"ACP session fork is unavailable while a prompt is in progress: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/acp/acp-agent.ts","lineNumber":1396,"sourceCode":"\t\tif (!record) {\n\t\t\tthrow new Error(`Unsupported ACP session: ${sessionId}`);\n\t\t}\n\t\treturn record;\n\t}\n\n\t#assertMatchingCwd(session: AgentSession, cwd: string): void {\n\t\tconst expected = path.resolve(cwd);\n\t\tconst actual = path.resolve(session.sessionManager.getCwd());\n\t\tif (actual !== expected) {\n\t\t\tthrow new Error(`ACP session ${session.sessionId} is already loaded for ${actual}, not ${expected}`);\n\t\t}\n\t}\n\n\tasync #resolveForkSourceSessionPath(sessionId: string): Promise<string> {\n\t\tconst loaded = this.#sessions.get(sessionId);\n\t\tif (loaded) {\n\t\t\tif (isPromptTurnInFlight(loaded.promptTurn)) {\n\t\t\t\tthrow new Error(`ACP session fork is unavailable while a prompt is in progress: ${sessionId}`);\n\t\t\t}\n\t\t\tawait loaded.session.sessionManager.flush();\n\t\t\tconst sessionPath = loaded.session.sessionManager.getSessionFile();\n\t\t\tif (!sessionPath) {\n\t\t\t\tthrow new Error(`ACP session cannot be forked before it is persisted: ${sessionId}`);\n\t\t\t}\n\t\t\treturn sessionPath;\n\t\t}\n\n\t\tconst storedSession = await this.#findStoredSessionById(sessionId);\n\t\tif (!storedSession) {\n\t\t\tthrow new Error(`ACP session not found: ${sessionId}`);\n\t\t}\n\t\treturn storedSession.path;\n\t}\n\n\tasync #handlePromptEvent(record: ManagedSessionRecord, event: AgentSessionEvent): Promise<void> {\n\t\tconst promptTurn = record.promptTurn;","sourceCodeStart":1378,"sourceCodeEnd":1414,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/acp/acp-agent.ts#L1378-L1414","documentation":"Thrown by #resolveForkSourceSessionPath when a fork is requested for a loaded session whose prompt turn is still in flight. Forking mid-turn would copy an incoherent, partially-written conversation state, so the agent refuses while a prompt is running.","triggerScenarios":"ACP session/fork request targeting a session where a prompt has been submitted and not yet completed/aborted (record.promptTurn is in flight).","commonSituations":"Client fires fork concurrently with a long-running prompt; UI automation forks on a timer while a turn streams; a previous prompt hung and was never aborted.","solutions":["Wait for the current prompt turn to finish (await the prompt response / completion notification) before forking.","Abort the in-flight prompt (session/cancel) first, then fork.","Serialize client operations so fork requests are queued after prompt turns."],"exampleFix":"// before\nawait forkSession({ sessionId });\n// after\nawait cancelIfBusy(sessionId);\nawait waitForTurnComplete(sessionId);\nawait forkSession({ sessionId });","handlingStrategy":"validation","validationCode":"// track turn state client-side and only fork when idle\nif (turnInFlight(sessionId)) {\n  await waitForTurnCompletion(sessionId); // or await agent.cancel({ sessionId })\n}\nawait agent.fork({ sessionId });","typeGuard":null,"tryCatchPattern":"try {\n  await agent.fork({ sessionId });\n} catch (err) {\n  if (err.message.includes(\"while a prompt is in progress\")) {\n    await agent.cancel({ sessionId });\n    await agent.fork({ sessionId });\n  } else throw err;\n}","preventionTips":["Serialize fork requests after prompt completion events.","Abort hung prompts before administrative operations.","Guard UI automation so fork buttons are disabled while streaming."],"tags":["acp","session-fork","concurrency"],"backgroundTag":"operation-during-in-flight-turn","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}