feat(sessions): opt-in clear history and continue from plan#3462
feat(sessions): opt-in clear history and continue from plan#3462igennova wants to merge 2 commits into
Conversation
Closes PostHog#704. Lets users discard planning context and start a fresh local run seeded with the approved plan, without changing resetSession.
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
| * permission-options module (agent cannot import core). | ||
| */ | ||
| export const CLEAR_AND_CONTINUE_OPTION_ID = "clearAndContinue"; | ||
|
|
There was a problem hiding this comment.
The option id is duplicated here and in the Claude permission-options module on purpose — @posthog/agent can't import @posthog/core (import-direction rule), so there's no shared home. The doc comment above flags they must stay in sync. Open to a better spot (e.g. @posthog/shared).
| } | ||
| try { | ||
| await this.continueFromApprovedPlan( | ||
| taskId, |
There was a problem hiding this comment.
Key decision: for clear-and-continue I deliberately don't call respondToPermission. Answering "allow" makes the old planning session start streaming the implementation reply in the stale (full-planning) context, and cancelling that mid-stream is what closed the ACP connection for ~2s (Upstream fetch aborted after client disconnect). Instead I resolve the pending-permission card locally and let continueFromApprovedPlan interrupt the turn. Normal approve/reject paths are untouched — they still go through respondToPermission below.
| await this.d.trpc.agent.cancelPrompt.mutate({ sessionId: taskRunId }); | ||
| } catch { | ||
| // best-effort: the turn may already be idle | ||
| } |
There was a problem hiding this comment.
Intentionally not calling teardownSession here — it does removeSession, which leaves a window with no session for this task. The connect effect fills that window by resuming the stale run (the Resuming session race I saw in the logs). Keeping the store entry and letting createNewLocalSession → setSession swap it atomically (store auto-deletes the old taskRunId for the same taskId) means there's no dead gap and no resume race.
Summary
Why
Issue #704: after planning, clearing context before implementation avoids auto-compaction mid-implementation. This mirrors Claude’s clear-on-plan-accept flow as an explicit choice.
How it works
cancelPrompt→createNewLocalSessionwith plan seedVideo
Screen.Recording.2026-07-15.at.12.49.28.PM.mov
Test plan
resetSessionunchanged)planContinuation,sessionServicePlanContinuation,permission-options,PlanApprovalSelector