#21115: fix(agent): immediately abort active run on stop/abort message during…
size: XS
Cluster:
Subagent Enhancements and Features
Summary
Problem: Stop/abort messages sent via Telegram (or any channel) while the agent is mid-generation were silently enqueued as normal followup runs and only processed after the current run finished — making them useless as interrupts.
Why it matters: Users had no way to halt a runaway or misdirected agent from the chat interface; they had to switch to the dashboard to manually abort, which is slow and breaks the UX flow.
What changed: In agent-runner.ts, before enqueuing a followup run, we now check if the incoming prompt is an abort trigger. If it is, we immediately call abortEmbeddedPiRun, clear all session queues, stop any running subagents, and return an acknowledgement reply instead of queuing.
What did NOT change: Normal (non-abort) followup runs continue to enqueue exactly as before. No changes to gateway routing, channel adapters, or any other part of the system.
Change Type
Bug fix
Scope
Gateway / orchestration
Linked Issue/PR
Closes #20600
User-visible / Behavior Changes
Users who send "stop", "abort", or a recognized interrupt keyword via Telegram (or any supported channel) while the agent is actively generating will now receive an immediate acknowledgement and the agent will halt. Previously the agent would continue and only process the stop message after completing its run.
Security Impact
New permissions/capabilities? No
Secrets/tokens handling changed? No
New/changed network calls? No
Command/tool execution surface changed? No
Data access scope changed? No
Repro + Verification
Environment
OS: Windows 11 (WSL2 / Ubuntu)
Runtime/container: Node.js
Model/provider: claude-opus-4-5
Integration/channel: Telegram
Relevant config: Default session/queue settings
Steps
Start a conversation with an agent via Telegram
Send a message that triggers a long-running response (e.g., multiple tool calls or a research task)
While the agent is generating, send "Stop" or "STOP" via Telegram
Observe the agent behaviour
Expected
Agent halts immediately upon receiving the stop message
User receives an abort acknowledgement reply
No further queued responses are processed
Actual (before fix)
Agent continues generating and completes its run
Stop message is processed as a new turn after generation finishes
User must use the dashboard to abort manually
Evidence
Failing test/log before + passing after
Trace/log snippets — Gateway logs confirmed long-running sessions (569s) with no evidence of stop messages being processed mid-run
Screenshot/recording
Perf numbers
Human Verification
Verified scenarios: Abort keyword sent mid-generation correctly halts the run, clears queues, stops subagents, and returns acknowledgement reply
Edge cases checked: Non-abort followup messages still enqueue normally; sessionId null case handled with ?? ""
What I did not verify: Behaviour across all supported channels beyond Telegram; edge cases where multiple stop messages are sent in rapid succession
Compatibility / Migration
Backward compatible? Yes
Config/env changes? No
Migration needed? No
Failure Recovery
How to disable/revert: Revert the changes to src/auto-reply/reply/agent-runner.ts — specifically remove the isAbortRequestText check block added before enqueueFollowupRun
Files/config to restore: src/auto-reply/reply/agent-runner.ts only
Known bad symptoms to watch for: If abort messages start incorrectly halting legitimate runs, check the isAbortRequestText matching logic in abort.ts
Risks and Mitigations
Risk: isAbortRequestText may match legitimate messages that happen to contain stop-like keywords in certain languages or contexts
Mitigation: The matching logic lives in abort.ts and can be tightened independently without touching this fix. Scope is limited to the enqueue decision point only.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds immediate abort logic for stop/abort commands during active agent generation. Before the incoming abort message is enqueued as a followup run, the code now checks `isAbortRequestText`, and if true, immediately calls `abortEmbeddedPiRun`, clears session queues, stops any subagents, and returns an acknowledgment reply.
**Changes:**
- Added imports for `abortEmbeddedPiRun`, `formatAbortReplyText`, `isAbortRequestText`, `stopSubagentsForRequester`, and `clearSessionQueues`
- Inserted abort-check block before `enqueueFollowupRun` at line 237-252 to intercept abort requests during active runs
- Used existing abort infrastructure (`abort.ts`) to detect and format abort messages
**Behavior:**
- Stop/abort messages sent while agent is generating now halt immediately instead of queuing
- Users receive acknowledgment reply with subagent count if applicable
- Normal (non-abort) messages continue to enqueue as before
<h3>Confidence Score: 5/5</h3>
- Safe to merge - focused bug fix with well-tested abort infrastructure
- The change is a clean, minimal fix that intercepts abort messages before they're enqueued. It reuses existing, well-tested abort functions (`isAbortRequestText`, `abortEmbeddedPiRun`, `clearSessionQueues`, `stopSubagentsForRequester`) and only modifies the enqueue decision point. The logic is properly guarded (runs only when `isActive && (shouldFollowup || resolvedQueue.mode === "steer")`), and tests exist for the abort detection logic. No new functionality is introduced - just moving the abort check earlier in the flow.
- No files require special attention
<sub>Last reviewed commit: d58b946</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#17721: fix: abort child run on subagent timeout + retry with backoff + sta...
by IrriVisionTechnologies · 2026-02-16
81.1%
#6143: fix(agents): handle AbortError from activeSession.abort() on timeout
by Glucksberg · 2026-02-01
80.4%
#19256: feat: add 'stop all' command and fix subagent cascade on word-trigg...
by lancejames221b · 2026-02-17
79.8%
#10509: fix(telegram): bare abort words bypass debounce + clear buffered me...
by romancircus · 2026-02-06
78.4%
#5467: Fix: make embedded compaction wait abortable
by yoyooyooo · 2026-01-31
78.4%
#14136: feat: add agent collapse safeguards and fix TUI display on abort
by liangweigain-create · 2026-02-11
77.1%
#18432: fix(agents): clear active run state immediately on embedded timeout
by BinHPdev · 2026-02-16
76.9%
#2541: fix(agents): add error handling to orphaned message cleanup
by Episkey-G · 2026-01-27
76.6%
#19452: fix: skip stale responses in interrupt queue mode via generationId
by kisjovan · 2026-02-17
76.0%
#18468: fix(agents): prevent infinite retry loops in sub-agent completion a...
by BinHPdev · 2026-02-16
75.9%