Skip to content

fix(gateway): emit error when turn cancels before agent ready - #66545

Open
deniqlab wants to merge 1 commit into
NousResearch:mainfrom
deniqlab:fix/63078-turn-cancel-error-event
Open

fix(gateway): emit error when turn cancels before agent ready#66545
deniqlab wants to merge 1 commit into
NousResearch:mainfrom
deniqlab:fix/63078-turn-cancel-error-event

Conversation

@deniqlab

@deniqlab deniqlab commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

When a turn is cancelled during lazy agent startup, run_after_agent_ready() used to clear the inflight turn and return silently. That made the Desktop look like the first send vanished: prompt.submit returned streaming, but the user never received an error event or a turn start.

This patch emits an explicit error event before returning in the cancelled / not-running path so the client can surface the failure instead of hanging silently.

Changes

  • tui_gateway/server.py: emit an error event when the deferred turn is cancelled before agent readiness or the session is no longer running.
  • tests/test_tui_gateway_server.py: add regression coverage for both the user-cancelled and not-running cases.

Verification

  • /Users/debuggerson/.hermes/hermes-agent/venv/bin/python -m pytest tests/test_tui_gateway_server.py -k 'interrupt_before_agent_ready_prevents_late_turn_start or prompt_submit_emits_error_when_stopped_before_agent_ready'
  • /Users/debuggerson/.hermes/hermes-agent/venv/bin/python -m pytest tests/test_tui_gateway_server.py
  • git diff --check

Closes #63078

@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Jul 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of open #65567: both live diffs add the same deferred-turn error event for cancellation or stopped sessions before agent readiness. #65567 is the earlier focused PR.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for isolating the deferred-start cancellation path. Current main still has the silent return at tui_gateway/server.py:9398-9401, while session.interrupt sets the observed flag at tui_gateway/server.py:9005. The proposed error event matches existing Ink handling at ui-tui/src/app/createGatewayEventHandler.ts:973-991 and Desktop handling at apps/desktop/src/app/session/hooks/use-message-stream/gateway-event.ts:695-744.

This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 18, 2026
@GottZ

GottZ commented Aug 3, 2026

Copy link
Copy Markdown

This was generated by AI during triage.

Summary

Three PRs address or reference #63078: #65567 and #66545 add error emission for the pre-ready cancellation/not-running branch, while merged #71140 records a broader fix for the reported first-message loss by extending the agent-build wait and surfacing initialization failures. The two open PRs cover the silent-return symptom but do not resolve the underlying long-build timeout described by the issue.

Related pull requests

Duplicates

#66545 is substantively a duplicate of #65567; #65567's server-side change was subsequently incorporated into the broader merged #71140, yielding the explicit chain #66545#65567#71140.

Suggested consolidation

Close #66545 as duplicate of #65567, then close #65567 as duplicate of merged #71140. This departs from the keep_open reviews on #66545 and #65567 because the later merged #71140 records incorporation of #65567's server-side path and adds the broader build-wait fix; additionally, the blocking contributor review on #65567 requires intentional Stop not to emit a generic error, so neither open diff should be merged unchanged.

Complex graph

flowchart LR
    classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
    classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
    classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
    classDef best stroke-width:3px,stroke:#b45309
    classDef target stroke-width:3px,stroke:#4338ca
    I63078(["issue #63078 (closed)"])
    subgraph Dup65567 ["PRs duplicating each other"]
        P65567["PR #65567 (open)"]
        P66545["PR #66545 (open)"]
    end
    P66545 -.->|partial| I63078
    class I63078 closed
    class P65567 open
    class P66545 open
    class P65567 best
    class P66545 target
    click I63078 "https://github.com/NousResearch/hermes-agent/issues/63078"
    click P65567 "https://github.com/NousResearch/hermes-agent/pull/65567"
    click P66545 "https://github.com/NousResearch/hermes-agent/pull/66545"
Loading

Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).

Cross-PR triage: Reviewed 3 pull requests and 1 issue in this complex. Diffs were read for 2 of 3 PRs (rest unavailable); Assessment working set: 11 kB of PR diffs, 13 kB of issue/PR text, 13 kB of discussion (15 comments), 5 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(desktop): first message in a new session leaves a blank session — no messages, no error, no response

4 participants