fix(btw): record an aborted work run as cancelled - #169
Merged
YUZHEthefool merged 1 commit intoSep 14, 2026
Merged
Conversation
10 tasks
run_agent reports an abort by setting agent_user_aborted and clearing agent_stop_requested, because an aborted run must not look like a stop request that is still pending. WorkLoop only read the cleared flag, so a work task the user stopped through /task stop ended as completed and /work status reported an aborted task as finished. Treat either marker as a cancellation. The regression test drives the real run_agent with only the model runner replaced, so it exercises the same control flow that produces the markers. Fixes #153 AI-Generated: true Generated-At: 2026-09-11T13:29:48Z
git fetch origin fix/btw-dual-loop-history-152
git rebase origin/fix/btw-dual-loop-history-152
# after resolving the conflicts
git push --force-with-leaseThe |
YUZHEthefool
added this pull request to stack #174
September 11, 2026 15:57
YUZHEthefool
force-pushed
the
fix/btw-work-cancel-on-abort-153
branch
from
September 11, 2026 16:00
799394b to
03cbbc3
Compare
|
✅ Conflicts resolved; removing the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A work task the user stopped reported
completed. Expected/work statustoreport
cancelled; actual it reportedcompletedafter the executor reportedits abort.
Related issue
Fixes #153
Root cause
run_agentreports an abort by settingagent_user_abortedand clearingagent_stop_requested, because an aborted run must not look like a stop requestthat is still pending.
WorkLoop._executeread only the cleared flag, so theabort fell through to
completed.Reproduction
Enable BTW and the work loop with a local Agent, start
/work <task>, send/task stopwhile it runs, wait for the executor to reportaborted, then read/work status. The regression test drives that same control flow: the realrun_agentis the work loop's executor and only the model runner is a doubleconfigured to emit
aborted.Implementation notes
Treat either marker as a cancellation. The test asserts
agent_user_aborted is Trueandagent_stop_requested is Falsebefore asserting the status, so itfails again if the loop ever goes back to depending on the stop flag alone.
Validation
The new test was also run against the unmodified tree, where it fails with
WorkSessionStatus.COMPLETED, so it is a real regression test.make check,make quality, and the coverage-gated--test-profile allrunwere not run locally on this Windows checkout; this PR relies on CI for those,
as #168 did.
After #168 was rebased onto the updated
masterhead, this branch was rebased ontothe new head as well and the whole stack was re-validated at its tip:
pytest tests/unit -q5233 passed / 6 skipped andpytest --test-profile blocking -q5354 passed / 6 skipped / 1 deselected.The count above was taken on this branch before that rebase.
Compatibility and risk
None. BTW stays off by default; no route, schema, configuration, or dependency
change.
Checklist
docs/zh/anddocs/en/when needed. (No user-visible text changed.)docs/public/openapi.json, and tests change together when routes or schemas change. (No route or schema change.)pyproject.toml,requirements.txt, anduv.locktogether. (No dependency change.)!and aBREAKING CHANGE:footer. (None.)Agent note
Goal: resolve #153 so an aborted work run is recorded as
cancelled, keeping BTW off by default and preserving authorization and request
identity.
Paths touched:
astrbot/core/agent/btw/work_loop.py,tests/unit/test_btw_work_loop.py.Checks run: the commands under Validation. The new test was first run against the
unmodified tree and failed on the reported status, then passed with the fix.
Residual risk: the loop now treats two markers as cancellation. A run that both
reports a stop and a failure still resolves to
failed, unchanged from before.Tools used: Claude Code (Opus 5) with the repository's AGENTS.md and AI_POLICY.md.
This PR is stacked on #168 (
fix/btw-dual-loop-history-152); merge that first.