Skip to content

fix: clear the question poll when it is resolved outside the bot - #32

Merged
rubenperezrial merged 13 commits into
mainfrom
fix/question-stale-state
Oct 5, 2026
Merged

rubenperezrial merged 13 commits into
mainfrom
fix/question-stale-state

Conversation

@rubenperezrial

Copy link
Copy Markdown

Bug

With a project active, the bot stays locked behind the question flow: any command outside the allowlist replies "This command is not available until the current question flow completes" even though OpenCode has no pending question. The stale state is created when a question card is shown and is never cleared if the question is answered from another client (TUI, VS Code) or if the resolving SSE event is lost.

Cause

question.replied and question.rejected events were only logged in summary-aggregation-manager — unlike the permission flow, which clears its state on the equivalent events. There is no callback, and no interaction expires (expiresInMs is never passed), so a resolution that never reaches the bot leaves the local poll and the interaction guard stuck forever.

Fix

Two independent paths, mirroring the existing permission handling:

  1. Resolution events — summary-aggregation-manager now fires setOnQuestionResolved(sessionId, requestID) for both question.replied and question.rejected; event-subscription-service clears the poll + interaction and deletes the Telegram card when the requestID matches the active poll (no-op otherwise, so questions from background sessions are untouched).
  2. Idle safety net — at session.idle, event-subscription-service verifies the active poll against question.list({ directory }) and clears it only if the server no longer lists the request. A failed lookup or a still-pending question leaves the state untouched (no regression). The check runs as a non-blocking safeBackgroundTask so an unresponsive question.list can never stall idle finalization (finishRun, tool flush, footer, queue).

Resolved/in-flight races are covered with the same pattern as permissions: resolved requestIDs are remembered (markResolved/isResolved) so a late question.asked or an in-flight Telegram card is discarded instead of resurrecting a stale poll, and the local state is cleared before touching Telegram.

Tests

Adds 11 tests to event-subscription-service.test.ts:

  • 5 for the external-resolution path: replied, rejected, unrelated requestID, resolution while the Telegram card is still being sent, and an asked event whose request was already resolved.
  • 6 for the idle safety net: server no longer lists the question, server still lists it, no active poll, failed lookup, no current session, and a cancelled poll with a retained requestID.

Local gate: bun run check -> 2027 pass / 3 skip / 0 fail (lint + build OK).

CI

This PR is stacked on feat/session-title-fallback (PR #31); CI only runs on PRs based on main, so no checks are expected here. The local gate is the source of truth until the stack lands.

Adds a keyboard row above the agent/context grid that switches to the other project in one tap. Target: the project the last switch moved away from (settings.swapProject), falling back to the most recently active other project. The press is allowed while the session is busy: it detaches the running session instead of blocking. i18n for all locales and PRODUCT.md updated.
The project list can return entries without a name (cached session directories), which made the swap confirmation show the full worktree path.
The bottom keyboard now shows a single model button carrying the active thinking-effort variant; the separate variant button is gone. Tapping it opens the model list as before, and picking a model still opens the variant picker after the confirmation. Picking the already-active model now re-opens the variant picker with the current variant marked instead of silently resetting it to default; when the model offers no variant choice, a toast explains it. Also updated tests and PRODUCT.md.
The provider browser callback handler was defined twice with identical bodies; the second definition silently won at runtime. Keep a single copy.
- saved sessions: bottom-keyboard "Sessions" button with a menu to
  bookmark the current session (per project), open a bookmarked one, or
  drop it; bookmarks live in settings.json
- prompt queue: the per-message menu now works while the session is busy,
  a dispatch skipped by a busy re-mark is retried instead of stranding the
  queue, and abort / project switch report the prompts they discard; the
  queued-button icon becomes an hourglass
- project swap: lands on the target project's most recent session and
  releases the detached session's local busy and run state
… project swap

- adopt the session variant when present; otherwise keep the effective variant (same model) or resolve the model's configured default
- resolve the effective variant centrally (getStoredModel/getCurrentVariant share resolveVariant), also for the prompt
- drop the synthetic Default row from the variant picker; a lone real variant is still offered when it is not the active one
- tests: session adoption, resolution regressions (real config), variant menu (mocked and real-catalog chains)
- let the ⭐ button and the saved-menu callbacks through the busy guard
- bookmarking/dropping entries are local; opening another session detaches the active run (same semantics as the project swap)
- tests: busy-guard matrix with real modules and handler integration
- strip trailing commas (string-aware) before JSON.parse; warn once when the config cannot be loaded
- keeps config-based variant defaults (reasoningEffort) working with real-world opencode.jsonc files
- tests: mixed JSONC fixture, invalid-config warn-once, adversarial string/URL cases
@rubenperezrial
rubenperezrial changed the base branch from feat/session-title-fallback to main October 5, 2026 15:38
@rubenperezrial
rubenperezrial merged commit cc75afe into main Oct 5, 2026
1 check passed
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