Skip to content

bug(desktop): AskUserQuestion prompt is lost when the session is not the active view when the request arrives #2072

Closed

Description

@Astro-Han

What happened

In the Desktop app, when an agent calls AskUserQuestion while the user is viewing another session (or another section), the question prompt bar is never shown — even after switching back to that session. The transcript shows the tool call, but the interactive prompt (UserQuestionPrompt) is missing. The session stays parked waiting for an answer that the UI can never provide, so the run stalls indefinitely.

The same defect does not exist for sandbox-boundary requests: switching away and back re-hydrates them.

Root cause

Session events are delivered only to the renderer's subscription for the currently active session:

  • apps/desktop/src/renderer/app-shell-effects.ts — useActiveSessionEvents subscribes window.maka.sessions.subscribeEvents(activeId, ...) and unsubscribes when activeId changes.
  • apps/desktop/src/main/session-stream.ts — main sends sessions:event:<sessionId> to the renderer unconditionally; Electron drops IPC messages with no listener.

So a user_question_request event that arrives while the session is not the active view is dropped. The prompt state lives only in the renderer's in-memory interactionBySession queue (app-shell-session-events.ts), fed exclusively by live events; there is no query, no replay, and no re-derivation from persisted messages when the session is re-focused.

The invariant violated:

The event stream is a notification, not state. Any pending interaction must be re-queryable from an authoritative source, not dependent on the recipient being present when the event fires.

Maka already upholds this invariant for sandbox-boundary requests: the kernel keeps a sandboxBoundaryRequestOwners registry (packages/runtime/src/runtime-kernel.ts:422), registers/clears via the event observation hook (observeSandboxBoundaryEvent, :2593), exposes listActiveSandboxBoundaryRequests (:2346), and the renderer reconciles the queue on activeId change (apps/desktop/src/renderer/app-shell.tsx:1045-1067). AskUserQuestion is the single exception to this invariant.

How to reproduce

  1. Start a session with a real backend and trigger an AskUserQuestion while the session is active — prompt appears (baseline works).
  2. Send a new request that will call AskUserQuestion, then switch to another session (or another section such as 扩展/设置) before it fires.
  3. Switch back to the first session.
  4. Expected: the question prompt bar is visible and answerable.
  5. Actual: the transcript shows the tool call, but .maka-user-question-prompt is absent; the run is parked waiting on respondToUserQuestion forever.

A deterministic reproduction is available with the fake backend (FAKE_ASK_USER_QUESTION_PROMPT): trigger the prompt, switch away, switch back — the prompt does not re-appear. The existing E2E apps/desktop/e2e/ask-user-question.spec.ts only covers the active-view case.

Environment

  • Maka commit: fab124577
  • OS: macOS
  • Surface: Desktop

Proposed fix (root-cause, category-level)

Make pending interactions a queryable resource instead of a one-shot event, mirroring the sandbox-boundary path and absorbing it as one mechanism:

  1. Runtime kernel (packages/runtime/src/runtime-kernel.ts): generalize observeSandboxBoundaryEvent → observeInteractionEvent so sandbox_boundary_request / user_question_request register, and sandbox_boundary_decision_ack / the tool_result answering a question unregister; clearSandboxBoundaryRequestOwners(sessionId, turnId) already clears per turn and covers both. Add listActiveInteractions(sessionId).
  2. SessionManager + IPC + preload: replace sessions:listActiveSandboxBoundaryRequests with sessions:listActiveInteractions (keep the old channel as an alias or remove it).
  3. UI (packages/ui/src/interaction-queue.ts): generalize reconcileSandboxBoundaryInteractions → reconcileInteractions (the current implementation already passes through non-boundary entries; the ComposerInteraction type is already the union of both event types).
  4. Renderer (apps/desktop/src/renderer/app-shell.tsx:1045-1067): the existing boundary hydration effect becomes one fetch + one reconcile for both interaction types, keeping the epoch guard.
  5. Tests: kernel registry unit tests (register/unregister/query/conflict), IPC contract, UI reconcile tests, and an E2E (fake backend → prompt → switch away → switch back → .maka-user-question-prompt visible).

This fixes the whole category (switch away/back, prompt pending at startup, renderer reload, background/child-session questions), not just the reported scenario. The event stream then remains purely incremental.

Alternative (minimal) path

If a small diff is preferred first: subscribe to all session events (add a sessions:event broadcast alongside the per-session channels in session-stream.ts, plus a subscribeAllSessionEvents in preload), feeding the existing per-session handleEvent — ~40 lines, no state-model change. It fixes the reported scenario but not the whole category (renderer not present at event time, e.g. startup/reload).

Non-goals

  • No disk persistence of pending interactions: their lifecycle belongs to the in-process parked continuation; after a main-process restart the continuation itself no longer exists, so persisting the request body has nothing to answer it. Peer implementations (Paseo, opencode) use in-memory registries + query endpoints.

Evidence

  • Subscription scope: apps/desktop/src/renderer/app-shell-effects.ts (useActiveSessionEvents, subscribeEvents(activeId, ...))
  • Drop without listener: apps/desktop/src/main/session-stream.ts:420/556/586 (safeSendToRenderer('sessions:event:<id>', ...))
  • Renderer-only prompt state: apps/desktop/src/renderer/app-shell-session-events.ts:128-131 (enqueue on live event), apps/desktop/src/renderer/app-shell.tsx:602 (activeQuestion)
  • Existing boundary hydration (the pattern to mirror): apps/desktop/src/renderer/app-shell.tsx:1045-1067 + packages/runtime/src/runtime-kernel.ts:2593/2346/422
  • Related peer analysis (hermes-agent documents the identical bug for its clarify.request one-shot events; OpenHands/lobehub/opencode/paseo all model pending interactions as re-queryable snapshots or persisted message fields)

Activity

  1. added
    bug
    on Aug 4, 2026
  2. added a commit that references this issue on Aug 4, 2026
    eae7832
  3. added a commit that references this issue on Aug 4, 2026
    eae1976
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions