Skip to content

fix(cloud-task): resume terminal cloud runs with the selected question answer#3215

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/resume-cloud-run-on-question-answer
Jul 7, 2026
Merged

fix(cloud-task): resume terminal cloud runs with the selected question answer#3215
tatoalo merged 1 commit into
mainfrom
posthog-code/resume-cloud-run-on-question-answer

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Answering a question on a completed cloud run went nowhere. When a cloud run terminalizes with an unanswered AskUserQuestion, its log carries a _posthog/permission_request with no resolution, so the desktop recovers and renders the question card.
Follow-up to #3199, which made questions on cloud runs relay and park instead of auto-resolving — this completes the loop so the user's late answer actually reaches the agent.

image

Changes

  • respondToPermission in sessionService now branches on terminal cloud runs: instead of proxying a permission_response, it formats the selected answer and routes it through sendCloudPrompt
  • New pure helper formatPermissionAnswerPrompt builds the resume prompt: each question quoted above its answer, with fallbacks for free-text input and bare option picks. Plain approvals return null — approving a tool call that no longer exists shouldn't spin a run — so those responses are dropped with a log line.
  • cancelPermission on a terminal cloud run resolves the card locally without proxying a command that can't succeed.

@trunk-io

trunk-io Bot commented Jul 7, 2026

Copy link
Copy Markdown

😎 Merged manually by @tatoalo - details.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit d882085.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(cloud-task): resume a terminal cloud..." | Re-trigger Greptile

Comment thread packages/core/src/sessions/permissionResponse.test.ts Outdated
Comment thread packages/core/src/sessions/permissionResponse.ts Outdated
@tatoalo tatoalo force-pushed the posthog-code/resume-cloud-run-on-question-answer branch from b15cdd4 to 8f04d50 Compare July 7, 2026 11:16
…on answer

When a terminal cloud run has a pending AskUserQuestion request, clicking the recovered card cannot proxy a permission_response to the dead sandbox. Route selected question answers through the terminal resume path as the next user message, refresh stale run status before responding, and recover pending question cards from persisted session logs after app restart.

Keep resumed single-answer prompts user-facing by sending only the selected answer, while still dropping plain approvals on dead runs instead of spinning a pointless resume.

Generated-By: PostHog Code
@tatoalo tatoalo force-pushed the posthog-code/resume-cloud-run-on-question-answer branch from 8f04d50 to d882085 Compare July 7, 2026 11:24
@tatoalo tatoalo self-assigned this Jul 7, 2026
@tatoalo tatoalo marked this pull request as ready for review July 7, 2026 11:25
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 7, 2026
@tatoalo tatoalo requested a review from a team July 7, 2026 11:26

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR exceeds the size gate ceiling (712 lines vs 500L limit), requiring human review. The logic itself looks sound — focused fix for terminal cloud run permission handling with good test coverage — but this threshold requires a human sign-off before auto-approval can proceed.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 7, 2026
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "fix(cloud-task): resume a terminal cloud..." | Re-trigger Greptile

@tatoalo tatoalo merged commit 7ece0f0 into main Jul 7, 2026
31 checks passed
@tatoalo tatoalo deleted the posthog-code/resume-cloud-run-on-question-answer branch July 7, 2026 11:52
tatoalo added a commit that referenced this pull request Jul 7, 2026
…tches and restarts

Since questions relay over the durable event stream (#3199, #3215), users
report that switching chats resets answered questions. Two gaps cause it:

1. The question card held its in-progress step answers in component state.
   Switching chats unmounts the card, so every answer selected so far was
   wiped and the card restarted at question 1 on return. The answers now
   live in a view store keyed by toolCallId, and the card restores them
   (including free-text input, via a new ActionSelector initialCustomInput
   seed) on remount. Submit and cancel clear the draft.

2. A question answered after its run terminalized (the resume-as-prompt
   path) never got a `_posthog/permission_resolved` record: the sandbox
   that would write one is gone, so the request stays pending in the
   persisted log forever and any log derivation that escapes the in-memory
   guards (app restart, another device, a session rebuild) re-surfaces the
   answered question as a fresh card. The client now appends the resolved
   marker to the owning run's log itself, tracks responded requestIds so
   stale snapshots (a marker not yet flushed to storage) cannot re-add
   them, and the watcher dedups replayed permission_request frames by
   stream id — they previously bypassed the seenEventIds guard entirely.

Generated-By: PostHog Code
Task-Id: 9c723d92-b8ef-4c9f-9317-2f53b4644f33
tatoalo added a commit that referenced this pull request Jul 7, 2026
…tches and restarts

Since questions relay over the durable event stream (#3199, #3215), users
report that switching chats resets answered questions. Two gaps cause it:

1. The question card held its in-progress step answers in component state.
   Switching chats unmounts the card, so every answer selected so far was
   wiped and the card restarted at question 1 on return. The answers now
   live in a view store keyed by toolCallId, and the card restores them
   (including free-text input, via a new ActionSelector initialCustomInput
   seed) on remount. Submit and cancel clear the draft.

2. A question answered after its run terminalized (the resume-as-prompt
   path) never got a `_posthog/permission_resolved` record: the sandbox
   that would write one is gone, so the request stays pending in the
   persisted log forever and any log derivation that escapes the in-memory
   guards (app restart, another device, a session rebuild) re-surfaces the
   answered question as a fresh card. The client now appends the resolved
   marker to the owning run's log itself, tracks responded requestIds so
   stale snapshots (a marker not yet flushed to storage) cannot re-add
   them, and the watcher dedups replayed permission_request frames by
   stream id — they previously bypassed the seenEventIds guard entirely.

Generated-By: PostHog Code
Task-Id: 9c723d92-b8ef-4c9f-9317-2f53b4644f33
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.

2 participants