Skip to content

Feat support chat abort method#318

Merged
everettjf merged 4 commits intomicroclaw:mainfrom
flyflypeng:feat-support-chat-abort-method
Apr 1, 2026
Merged

Feat support chat abort method#318
everettjf merged 4 commits intomicroclaw:mainfrom
flyflypeng:feat-support-chat-abort-method

Conversation

@flyflypeng
Copy link
Copy Markdown
Contributor

fix #317

Add ability to abort ongoing streaming chat runs via WebSocket RPC to give users control over long-running or unwanted agent responses.

- Add `chat_abort` module with global registry of active abort controllers
  keyed by run_id, using Arc<AtomicBool> for lock-free abort signaling
- Add `AgentEvent::Cancelled` variant to explicitly signal cancellation
  instead of reusing FinalResponse with magic string
- Wire chat.abort in ws.rs to call both chat_abort::abort_chat_run_by_id
  (sets AtomicBool) and run_control::abort_runs (notifies agent loop)
- stream.rs registers runs at start, buffers text deltas for partial
  recovery, detects abort via STOPPED_TEXT return, publishes "aborted"
  event with partial text
- RunHub tracks aborted flag; forward_run_event maps "aborted" to
  ChatEventPayload with state:"aborted"
- Ignore spec/ directory
Log key checkpoints in the chat.abort handling path:
- ws.rs: log completed abort with session_key, run_id, chat_id, aborted_count
- run_control.rs: log abort_runs firing with run_count and source_ids
- agent_engine.rs: log agent loop cancellation via notify
- stream.rs: log when stream detects abort response
- chat_abort.rs: debug-level logging for edge cases (not found, mismatch)
@flyflypeng flyflypeng requested a review from everettjf as a code owner April 1, 2026 08:55
everettjf and others added 2 commits April 1, 2026 09:57
When MICROCLAW_SKIP_WEB_BUILD is set (e.g. in Docker builds), only
verify that the required web assets exist — skip the mtime-based
staleness check that can produce false positives due to Docker layer
caching timestamp behavior.

Fixes Docker Build CI failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Remove unused fields (started_at_ms, expires_at_ms, owner_conn_id)
  from ChatAbortControllerEntry. started_at_ms had a bug
  (Instant::now().elapsed() always ≈ 0) and expires_at_ms was never
  checked — both were dead code.
- Simplify register_chat_run signature (drop unused owner_conn_id param).
- Fix flaky tests: use unique keys per test instead of clear_all_runs()
  to avoid interference when tests run in parallel on the shared global
  registry.
- Remove unrelated spec/ entry from .gitignore.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@everettjf everettjf merged commit dd47ebe into microclaw:main Apr 1, 2026
10 checks passed
@everettjf
Copy link
Copy Markdown
Contributor

Thank you

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.

Feat:Implement chat.abort WebSocket RPC for Streaming Run Interruption

2 participants