Skip to content

🤖 refactor: share workspace provenance, readiness, delete, and 429 backoff steps - #255

Merged
ThomasK33 merged 1 commit into
mainfrom
refactor/shared-workspace-steps
Oct 13, 2026
Merged

ThomasK33 merged 1 commit into
mainfrom
refactor/shared-workspace-steps

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

This refactor changes no behavior. The workspace steps of the CoderTemplateTest controller move into internal/controller/coder_workspace_steps.go, so the upcoming CoderWorkspacePool controllers can call the same code. These steps are provenance after an uncertain create, the readiness rules for one build, the delete step, and the HTTP 429 backoff. The CoderTemplateTest reconciler now calls them through thin wrappers. No test file changed.

Refs #153

Background

This is PR 3 of the CoderWorkspacePool stack (#153), after #250 (shared owner and template lookups). A pool member creates, confirms, waits for, and deletes one workspace. It needs the crash-safety rules that CoderTemplateTest already proves in envtest and Kind:

  • provenance, including claimed Coder prebuilds;
  • the readiness rules;
  • counting each failed delete build once;
  • cancel-before-delete;
  • the jittered 429 backoff.

Before, these rules read and wrote CoderTemplateTest status fields directly. Now they take the pinned IDs, one build, or a small state struct.

Implementation

coder_workspace_steps.go:

Function Moved from Change
workspaceProvenance(ctx, sdk, workspace, operatorID, organizationID, templateID, templateVersionID) provenance Takes the pinned IDs instead of the test.
workspaceBuildReadiness(build, name) *coderStep the core of checkReadiness Covers the build job status and the agent rules. Nil means ready. The 410 check, the start-build identity check, and the pass record stay in CoderTemplateTest.
deleteCoderWorkspace(ctx, sdk, *workspaceDeleteState, now, countEveryFailure) the body of deleteStep Works on workspaceDeleteState (workspace ID and name, delete build ID, attempts). countEveryFailure is the old afterPass rule.
coderDeleteRetryAt, coderDeleteBackoff templateTestDeleteRetryAt, templateTestDeleteBackoff Renamed only.
coderBackoff{next, forget} the 429 part of retryAfter and the reconciler's sync.Map The same 2 s to 2 min doubling with 20 % jitter, keyed per object.
coderBuildPoll (5 s) templateTestRunningPoll templateTestRunningPoll is now defined as coderBuildPoll.

Also:

  • coderAnswerFor, isCoderNotFound, coderStatus, and coderErrorSummary move from codertemplatetest_controller.go to coder_access.go. Another controller already calls them (🤖 feat: add the CoderAIProvider reconciler skeleton #245). I did not merge controlPlaneWait into coderStep, because that would edit the CoderAIProvider controller of the parallel stack.
  • deleteStep keeps its assertion and copies the state back into status. Every write happens where it did before.
  • The e2e paths filter now lists coder_workspace_steps.go, so this shared code also gets the full Kind E2E on pull requests.

Validation

  • Every existing CoderTemplateTest envtest passes unchanged, with and without -race. No test file changed.
  • Mutation checks against the unchanged tests: 22 mutants of the moved code. 20 made a named test fail:
    • provenance: initiator, version, build 1 required, and the prebuild rule;
    • readiness: no agents, sub-agents, start error, connection timeout, waiting, cancel, and the error code in the message;
    • delete: count once, the after-pass rule, the backoff wait, cancel-before-delete, storing the delete build ID, and the backoff doubling;
    • 429 backoff: the doubling and the count.
  • Two mutants survived. Both are gaps in the existing CoderTemplateTest tests, unchanged by this PR:
    1. The organization and template check in provenance. In Coder a version belongs to exactly one template, so the pinned-version check already rejects the same workspaces. The check stays as defense in depth.
    2. The message variant of BuildFailed for a failed build without an error code. The reason stays BuildFailed, so only the message text changes.

Risks

Low. The moved code drives CoderTemplateTest confirm, readiness, and cleanup. A mistake would show as a wrong reason, a leaked test workspace, or a wrong retry time. The unchanged envtests, the mutation checks, and the full Kind E2E cover these paths.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $47.06

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T16:25:13.867196Z 44f4758 PR opened
🔒 Security Review ✅ Completed 2026-10-13T16:27:21.965678Z 44f4758 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.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 44f475812d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit f791e34 Oct 13, 2026
10 checks passed
@ThomasK33
ThomasK33 deleted the refactor/shared-workspace-steps branch October 13, 2026 16:52
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