Skip to content

🤖 feat: watch unclaimed ready CoderWorkspacePoolMember workspaces for use, agent loss, and dormancy - #343

Merged
ThomasK33 merged 7 commits into
mainfrom
feat/workspace-pool-member-watch
Oct 14, 2026
Merged

ThomasK33 merged 7 commits into
mainfrom
feat/workspace-pool-member-watch

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

This PR adds the watch rules of an unclaimed ready CoderWorkspacePoolMember (plan 6.2 step 10) to the dormant reconciler. Nothing registers the reconciler yet, so no user sees a change.

Every 60 s, one read of the workspace runs these rules in plan order:

  1. Use. A last_used_at later than readyLastUsedAt sets Used=True: someone used the workspace without a claim. A used member is never failed, never extended, and not read again. The pool releases it (PR 10), and the cleanup in PR 8c keeps its workspace. A template-wide write is not use: when the new value is within 5 s of the template's updated_at, or another unclaimed member of the pool already moved its baseline to the same value, the member moves its baseline and stays unused.
  2. Changed externally. The latest build is not the start build, or the operator user did not start it (from PR 8a).
  3. Agent lost. An agent that is no longer connected and ready sets Ready=False with AgentNotReady, and the phase stays Ready. After 5 minutes the member fails with AgentLost.
  4. Dormant. dormant_at or deleting_at is set: the member fails with Dormant.
  5. Keep warm. The extension steps from PR 8a, unchanged.

Refs #153

Background

This is PR 8b of the CoderWorkspacePool stack (#153). It stacks on PR 8a (#339). PR 8c (cleanup) stacks on this PR.

The watch of a bound member (plan 6.2 step 11 rule 3: a deleted workspace makes the claim Lost) moves to PR 11 (claims), because it only matters with claims. The plan's PR 11 row records this.

Implementation

  • readOwnPoolMemberWorkspace is split into readPoolMemberWorkspace (the read and the identity check: owner, kwp- name, template) and poolMemberStartBuildStep (start build ID, initiator, transition, version). No behavior change for readiness and extensions. The split lets rule 1 run between the two, so a used member that someone also stopped is Used, not Failed.
  • watchReady (new file coderworkspacepoolmember_watch.go) runs the rules. keepWarm now takes the workspace that watchReady read, instead of reading it again.
  • checkPoolMemberUse compares whole seconds, because status stores whole seconds. Both times come from Coder's clock. The template guard reads GET /templates/{id} only when last_used_at moved, and lists the pool's members (label coder.com/workspace-pool-uid) only when the template time does not match.
  • poolMemberAgentStep runs the readiness rules on the start build again. The 5 minutes count from the Ready condition's lastTransitionTime with reason AgentNotReady.
  • A used member is not requeued.

Limit: a failed read between two AgentNotReady reads sets Ready=True with CoderUnavailable again (as before this PR), so the 5 minutes restart. The member then fails later, not never.

Validation

New tests (coderworkspacepoolmember_watch_test.go):

  • TestPoolMemberWatchesUse (plan mutation 9): a claimed prebuild (last_used_at after created_at, set before ready) is not use. Use after ready sets Used=True. An external stop then does not fail the member, it gets no extension at its deadline, it is not requeued, and later reconciles read nothing from Coder.
  • TestPoolMemberTemplateWideWrite (plan mutation 10): a template schedule update is not use for either member, also after the template's updated_at moved again (the second member matches the first member's baseline). Real use afterward is still use.
  • TestPoolMemberWatchRules: a short agent disconnect only makes the member not ready. A disconnect of 5 minutes, counted from the first read that found it, fails it with AgentLost. Dormancy fails it with Dormant.

The shared requireMember helper now allows Ready=False in phase Ready with reason AgentNotReady.

Mutation checks: I removed one control at a time, and each removal made a named test fail (13 of 13): plan mutations 9 and 10, the updated_at window, the sibling check, rule 1 itself, the early return of a used member, its missing requeue, the agent rule, its start time, its 5-minute threshold, Ready=False, the dormant rule, and the start build check. A 14th mutation (excluding the member itself from the sibling check) survived, because the member's own baseline is always earlier than the new value. I removed that check.

Gates on the final commit: drift (codegen, manifests, installer, API reference: no diff), make docs-check, dormant-CRD guard, docs lint and spelling, make verify-vendor, make build, make lint, actionlint, make test, make test-integration, make vuln, race. All passed.

Size

346 hand-written lines (about 220 production, 126 test, counting removals). No generated files.

Risks

None for users. The reconciler is dormant: nothing registers it.


Generated with mux • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $121.59

…line and check the start build initiator

Change-Id: I431d9dab372a21a885caef16659f5e9782a2fad3
Signed-off-by: Thomas Kosiewski <tk@coder.com>
…ne at bind

Change-Id: I5b3d8d99f493c268d3b692baed5be0bec89e39a6
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Change-Id: I17d4226fdbc86196ea985c14a760c32b1917fa73
Signed-off-by: Thomas Kosiewski <tk@coder.com>
…se, agent loss, and dormancy

Change-Id: I5ffdeabd7e32c5a6236ea4e6f25a7db99d536db3
Signed-off-by: Thomas Kosiewski <tk@coder.com>
…es out

Change-Id: I92de215625e1d4d7d6d86d29040b457b2e6997cf
Signed-off-by: Thomas Kosiewski <tk@coder.com>
Change-Id: I7571e9c29a9e2093098ec6b3279e1230663091ba
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-14T10:15:53.416969Z fb86488 Manual request
🔒 Security Review ✅ Completed 2026-10-14T10:16:54.655030Z fb86488 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: d35c750507

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d35c750507

ℹ️ 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".

Comment thread internal/controller/coderworkspacepoolmember_watch.go
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: d35c750507

ℹ️ 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".

Base automatically changed from feat/workspace-pool-member-guard to main October 14, 2026 09:50
…ember-watch

Change-Id: I143a402026f82a331eb21147af3cee4ce0fbeca0
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: fb86488a0c

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

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

Reviewed commit: fb86488a0c

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 14, 2026
Merged via the queue into main with commit 322124d Oct 14, 2026
10 checks passed
@ThomasK33
ThomasK33 deleted the feat/workspace-pool-member-watch branch October 14, 2026 10:45
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