Skip to content

feat(sessions): opt-in clear history and continue from plan#3462

Open
igennova wants to merge 2 commits into
PostHog:mainfrom
igennova:fix/704
Open

feat(sessions): opt-in clear history and continue from plan#3462
igennova wants to merge 2 commits into
PostHog:mainfrom
igennova:fix/704

Conversation

@igennova

@igennova igennova commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an opt-in plan-approval option: Approve, clear history, and continue from plan (alongside normal approve + reject).
  • Normal Approve and proceed keeps planning history unchanged.

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

  1. User is in plan mode → agent proposes a plan
  2. Plan card offers:
    • Approve and proceed (keep context)
    • Approve, clear history, and continue from plan (fresh context)
    • Reject with feedback
  3. Clear path: resolve permission UI locally → cancelPromptcreateNewLocalSession with plan seed
  4. Same task / title; new task run (chat thread resets by design)

Video

Screen.Recording.2026-07-15.at.12.49.28.PM.mov

Test plan

  • Enter plan mode → create a plan → confirm new clear option appears
  • Approve and proceed → planning history remains; agent continues in-place
  • Clear history and continue → chat resets; agent starts from plan only; no ACP/error toast
  • [x]Mode selector still applies on clear path (e.g. auto / acceptEdits)
  • Reject with feedback still works
  • Error-state New Session still reconnects in place (resetSession unchanged)
  • Unit tests: planContinuation, sessionServicePlanContinuation, permission-options, PlanApprovalSelector

Closes PostHog#704. Lets users discard planning context and start a fresh local
run seeded with the approved plan, without changing resetSession.
@trunk-io

trunk-io Bot commented Jul 15, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

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";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@igennova igennova changed the title feat(sessions): opt-in clear history and continue from plan (#704) feat(sessions): opt-in clear history and continue from plan Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant