Skip to content

refactor(coderd/x/chatd): delete the runner's unreachable task index - #30936

Draft
ibetitsmike wants to merge 3 commits into
mainfrom
mike/chatd-runner-task-index
Draft

ibetitsmike wants to merge 3 commits into
mainfrom
mike/chatd-runner-task-index

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Deletes the runner's secondary task index. spawnTaskIfNeeded skipped a spawn when the active task had the same kind, history version, and status, but that guard cannot fire. The PR removes the guard, the tasksByIndex map that only it read, the taskIndexKey type, the taskRecord fields that fed the index, and a redundant check before cancelActiveTask. It renames spawnTaskIfNeeded to spawnTask and deletes TestRunner_CleansUpOnOwnershipTakeover, whose steps all repeat in TestWorker_CleanupStopsRoutingAndCancelsTasks.

Why it is safe

  • Only spawnTaskIfNeeded sets activeTaskSet, and processState calls acceptState (which sets hasAcceptedState) right after every spawn. On each later event, processState cancels the active task, which clears activeTaskSet, before it spawns. So the guard's first operand is always false.
  • For the same reason, activeTaskSet implies hasAcceptedState, so processState drops the r.hasAcceptedState && r.activeTaskSet check and calls cancelActiveTask, which already returns when no task is active.
  • With the guard replaced by if r.activeTaskSet { panic(...) }, go test ./coderd/x/chatd/ and go test ./coderd/ -run Chat pass.
  • localLocks still serializes a canceled task with its same-key replacement (TestRunner_SerializesReplacementTasksForSameHistoryAndStatus), and the task-ID map stays.
  • git grep finds no other use of taskIndexKey, tasksByIndex, or spawnTaskIfNeeded.

Each deleted check, its copy in the remaining test, and a mutant that fails both tests on main and the remaining test here:

Deleted check Remaining check Mutant
first generation task starts same waitCall running spawns an interrupt task
takeover cancels the task same requireTaskCanceled no ownership check; no requestCleanup
no task starts after takeover assertNoCall after one more publish takeover cancels the task and spawns an abandon task

Review focus

The dead-guard argument depends on the order in processState: cancel the active task, spawn, then acceptState. The newRunner and taskRecord hunks otherwise only realign fields after gofmt.

Validation

  • go test ./coderd/x/chatd/ -race -count=1 -run '^(TestRunner_|TestWorker)': 67 tests pass on main, 66 on this branch.
  • go test ./coderd/x/chatd/ -count=1: pass.
  • Mutants (go test -overlay): each fails as listed. A copy with a syntax error fails to build, so the overlay applies.
  • The pre-commit hook (make pre-commit) passed.

Xum, an AI agent, opened this PR for @ibetitsmike and wrote this description.

spawnTaskIfNeeded skipped a spawn when the active task already had the
same kind, history version, and status. That guard cannot fire:
processState cancels the active task, which clears activeTaskSet, before
every spawn after the first. Delete the guard, the tasksByIndex map that
only it read, the taskIndexKey type, and the taskRecord fields that only
fed the index. Rename spawnTaskIfNeeded to spawnTask.

Delete TestRunner_CleansUpOnOwnershipTakeover. Every step of it is also
in TestWorker_CleanupStopsRoutingAndCancelsTasks, which then publishes
the new state again and checks that no task starts.
…eTask

activeTaskSet implies hasAcceptedState: acceptState runs right after
every spawn and nothing resets hasAcceptedState. cancelActiveTask
already returns when no task is active, so processState calls it
unconditionally.
@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T17:05:39.549202Z 8b0a74c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 08e9607488

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike

Copy link
Copy Markdown
Collaborator Author

@codex review

Xum, an AI agent, requested this review for @ibetitsmike.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 8b0a74c1bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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.

1 participant