fix(agent): stop auto-answering questions before desktop connects#2677
Draft
adamleithp wants to merge 1 commit into
Draft
fix(agent): stop auto-answering questions before desktop connects#2677adamleithp wants to merge 1 commit into
adamleithp wants to merge 1 commit into
Conversation
AskUserQuestion tool calls were intermittently being auto-answered (surfacing as "Question answered"/"Answer received") without any user interaction. In createCloudClient.requestPermission, questions only relayed to the desktop when session.hasDesktopConnected was already true. That flag starts false for cloud-initialized sessions and only flips true once the desktop's SSE stream attaches. If the agent fired a question during that startup window, it fell through to the auto-approve path and silently selected the first option — the race that made it intermittent. Treat questions like plan approvals: always relay and wait. The permission_request is buffered by broadcastEvent and replayed when the desktop connects (and persisted to the log), so an early question is no longer auto-answered. Generated-By: PostHog Code Task-Id: 4c98167b-4c73-424e-9f2c-0e1200d41041
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Contributor
|
Reviews (1): Last reviewed commit: "fix(agent): stop auto-answering question..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users reported that the agent's question prompts (
AskUserQuestion) were sometimes auto-dismissed or auto-answered without any interaction — the agent would continue as if the question had been answered. It was intermittent, which pointed at a race.Closes #2550
Changes
In
createCloudClient.requestPermission, questions only relayed to the desktop whensession.hasDesktopConnectedwas alreadytrue. That flag startsfalsefor cloud-initialized sessions and only flipstrueonce the desktop's SSE stream attaches. A question fired during that startup window fell through to the auto-approve path and silently picked the first option — surfacing as "Question answered"/"Answer received".Now questions always relay and wait, exactly like plan approvals. The
permission_requestis buffered and replayed when the desktop connects (and persisted to the log), so an early question is no longer auto-answered.How did you test this?
question-relay.test.ts: the test that previously asserted questions auto-approve without a desktop now asserts they relay and stay pending until answered (regression test).pnpm --filter @posthog/agent test question-relay— all 43 tests pass.pnpm --filter @posthog/agent typecheckandbiome linton the changed files — clean.Automatic notifications
Created with PostHog Code from a Slack thread