Skip to content

Commit 3c8b88c

Browse files
authored
Merge pull request #19 from d3cker/codex/cancel-bot-round
Cancel individual bot rounds while keeping issue tracking
2 parents 47bc55e + dd4cf13 commit 3c8b88c

23 files changed

Lines changed: 628 additions & 95 deletions

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ steps, project setup, headless operation, and removal.
2828
| [docs/architecture.md](docs/architecture.md) | Component responsibilities, a short issue-to-PR overview, configuration ownership, scheduler ownership, and shared state. | Start here to understand how the system is divided before locating implementation code. |
2929
| [docs/bot-workflow.md](docs/bot-workflow.md) | Eight Mermaid diagrams and detailed implementation notes: startup and polling; discovery and routing; task phases; sessions and questions; media helpers; verification and publication; feedback, merging, and tab closure; status, retries, and recovery. Includes links to the source for each area. | Use for exact execution order, state transitions, checkpoint behavior, failure paths, and tracing a bot task from issue to merged PR. |
3030
| [docs/configuration.md](docs/configuration.md) | The standard `.opencode/automation.json` format, defaults, setup flags, configuration tracking across Git branches, authors, triggers, checks, base branches, model capabilities, media helpers, custom prompts, signatures, and auto-merge settings. | Use when adding or changing user-facing configuration, defaults, or setup examples. |
31-
| [docs/runtime.md](docs/runtime.md) | User-visible behavior while the bot runs: GitHub questions and permission replies, branch selection, media inputs, prompt loading, follow-up comments, session tabs, runtime sidebar/status freshness, host repository inventory and discovery, local task closure, and routine management commands. | Use when changing issue conversations, session continuation, runtime tools, or TUI behavior. |
31+
| [docs/runtime.md](docs/runtime.md) | User-visible behavior while the bot runs: GitHub questions and permission replies, branch selection, media inputs, prompt loading, follow-up comments, session tabs, runtime sidebar/status freshness, host repository inventory and discovery, local task closure, cancelling rounds while retaining tracking, and routine management commands. | Use when changing issue conversations, session continuation, runtime tools, or TUI behavior. |
3232
| [docs/advanced.md](docs/advanced.md) | Separate scheduler/dispatcher setup, multiple repositories, custom RPC jobs, full options, timeouts, management and retry commands, persistence, reconciliation, locks, and known limits. | Use for low-level configuration, operational troubleshooting, recovery, or ownership/concurrency changes. |
3333
| [docs/installation.md](docs/installation.md) | Loader registration, config-directory precedence, prerequisites, source installation, project-local installation, upgrade conflicts, testing on another machine, and migration limits. | Use when working on packaging, installers, registration, upgrades, or deployment troubleshooting. |
3434
| [docs/releases.md](docs/releases.md) | Feature-to-devel and devel-to-release PR checks, automatic patch versions, manual npm version/tag releases, exact changelog notes, publication recovery, README commits on release, automatic release-to-devel synchronization, and promotion PRs into protected main. | Use for CI triggers, versioning, packaging, GitHub Release publication, branch permissions, or recovery after a failed release. |
@@ -62,7 +62,7 @@ the installation block without making remote writes. Keep its markers intact.
6262
and GitHub plugin entrypoints. `src/easy.ts` resolves standard project settings;
6363
`src/config.ts` defines the configuration schemas and route matching.
6464
- `src/dispatcher.ts` owns discovery, the durable task lifecycle, questions,
65-
feedback rounds, publication coordination, retries, durable task closure, and merge polling.
65+
feedback rounds, publication coordination, retries, durable task closure, round cancellation/resumption, and merge polling.
6666
`src/scheduler.ts` owns interval jobs; `src/state.ts` owns persistence and locks.
6767
- `src/executor.ts` owns analysis, base selection, worktrees, session execution,
6868
verification, and pushing. `src/analysis.ts` and `src/branch.ts` validate model

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ include the full version, for example `## 0.7.0-beta.1`.
2929

3030
### Added
3131

32+
- Cancel a single bot round while retaining issue/PR tracking, with durable stop
33+
recovery, preserved draft worktrees and fresh worktrees for later feedback.
34+
Resume tracking a locally closed task without replaying its abandoned round
35+
or old comments. Expose both actions in `/bot` and the CLI; show historical
36+
errors only in details after closing or cancelling.
37+
3238
- List configured repositories across the host with `opencode2-automation list`
3339
(`--json` for scripts) and `/bot` → **Repositories**. Show owner/checkout paths,
3440
base branches, timestamped dispatcher/scheduler status and concrete issue

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ installations are not removed by `npm uninstall --global`.
261261
unavailable or stale readings are marked explicitly. See
262262
[runtime panel details](docs/runtime.md#runtime-status-sidebar).
263263
- **Task management:** `/bot` lets you open a session, inspect details, close idle
264-
tabs, restart a stopped workflow, or stop sessions and end task tracking. Closing
264+
tabs, restart a stopped workflow, **Cancel current round** while keeping issue
265+
tracking, or stop sessions and end task tracking. **Resume issue tracking**
266+
restores a closed task for future comments without replaying its old round. Closing
265267
tracking preserves all local work and history, works without a surviving GitHub
266268
issue/PR, and prevents rediscovery. See [task management](docs/runtime.md#manage-tasks-from-bot).
267269
- **Progress:** use `/bot` in the TUI, or the CLI's `status`, `scan`, `pause`, and

‎docs/advanced.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,38 @@ notice; full saved text remains in task state and the session. Dispatcher check
264264
text is limited to 8,000 bytes. The complete description, including retained
265265
notes and signature, must fit within the automation limit of 60,000 bytes or
266266
publication blocks without dropping notes. Titles are not regenerated on updates.
267+
268+
269+
## Round cancellation and resuming tracking
270+
271+
Owner RPC methods `automation.github.cancelround` and
272+
`automation.github.resumetracking` accept `{ "key": "owner/repository#123" }`
273+
and return `{ "accepted": true }` when cancellation is queued. A no-op returns
274+
`false`; invalid transitions and publication/merge in flight throw an actionable
275+
error. Matching CLI commands work from the configured owner checkout. See
276+
[runtime semantics](runtime.md#cancelling-one-round-while-keeping-tracking).
277+
278+
Durable `cancellation` stores the request time and interruption error. Status
279+
`cancelling` gates worker checkpoints, session prompts, runtime hooks, discovery
280+
updates and publication; scans leave its cursor unchanged. A worker pass resumes
281+
due cancellation after restart and retries failed interruption after 30 seconds.
282+
It drains the selected worker and pending question posts before entering `watching`.
283+
The queue keeps `cancelledRounds` with prior errors, questions, feedback, worktree,
284+
session and verification/report snapshots. `controlVersion` increases on operator
285+
transitions, so stale TUI events cannot undo explicit resumption.
286+
287+
Watching continues PR-state discovery and accepts new authorized issue comments.
288+
`publishedHead` retains the successfully published SHA and approval-window time
289+
across rounds; merge checks use it while watching. No saved published head means
290+
no automatic merge until the next successful publication. Old round checkpoints
291+
are not treated as a new successful publication. Explicit resumption validates
292+
GitHub objects and advances the comment cursor to the observed backlog without
293+
queuing it; failed validation leaves tracking closed.
294+
295+
The next round allocates `localBranch` and a new managed worktree, fetching the
296+
existing remote PR head if applicable. The prior worktree and branch are never
297+
reset, cleaned, deleted or force-pushed. Checks validate the new local branch;
298+
push still targets the task's original remote `branch`. Normal publication and
299+
verification guards apply, including ancestry of the pinned base. The archived
300+
round is not replayed or published automatically. Existing queued feedback is
301+
retained by cancellation, while resuming a closed task explicitly skips backlog.

‎docs/architecture.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ loads a generic scheduler, a GitHub dispatcher, and a terminal UI component.
3737
if creating a PR without an already-saved title.
3838
6. After publication, process queued authorized issue comments as new rounds on
3939
the same worktree and branch, with a new main session and the existing open PR.
40+
After cancellation, use a fresh local branch/worktree from the published head,
41+
preserving the abandoned worktree and the remote PR branch.
4042
Keep the original PR report and update its Latest update section after pushing;
4143
preserve manual notes outside the managed description.
4244
7. Merge only after eligible approval of the published head, repository permission
@@ -87,3 +89,12 @@ Operator task closure is a durable dispatcher operation: `/bot` sends the owner
8789
hooks, feedback execution and merge monitoring exclude them. Session/worktree
8890
data is retained. See [task management](runtime.md#manage-tasks-from-bot) for
8991
in-flight operation limits and the distinction from closing a TUI tab.
92+
93+
94+
Round cancellation uses `automation.github.cancelround`: persist `cancelling`,
95+
drain execution, archive the current round, then `watching`. Discovery continues
96+
and future feedback starts a new session in an isolated worktree. Only a saved
97+
published head can authorize auto-merge while watching. Explicit
98+
`automation.github.resumetracking` restores a closed task for future comments,
99+
skipping its abandoned round and closed-period backlog after validating GitHub
100+
objects. Both operations preserve work; neither closes the GitHub PR or issue.

0 commit comments

Comments
 (0)