Skip to content

docs(agent-relay-cursor, agent-relay-claude-code): order the module after setup - #1239

Merged
BobbyHo merged 7 commits into
mainfrom
bobby/relay-67-c-order-module-after-setup
Nov 10, 2026
Merged

BobbyHo merged 7 commits into
mainfrom
bobby/relay-67-c-order-module-after-setup

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

Both Agent Relay modules start the worker as soon as the workspace agent runs its start scripts, which can be before the template has cloned a repository or installed tools. The fix is a coder_script_order rule beside the module call, but neither README said so, and the module cannot declare the rule itself. This PR adds a "Start the worker after your setup" section to both READMEs, with the rule, its requirements and what happens when setup fails, and bumps both modules to 1.0.1. No Terraform changes.

Refs https://linear.app/codercom/issue/RELAY-67/start-the-cursor-worker-only-after-the-workspace-agent-is-ready

How to navigate this PR
  • Docs only. Two READMEs change and nothing else.
  • Reading order:
    1. registry/coder/modules/agent-relay-cursor/README.md: the new section after Requirements, the extra sentence on the repo-scoped pools bullet, and the version pins.
    2. registry/coder/modules/agent-relay-claude-code/README.md: the same section with the runner's names, and the version pins.
  • Check that the rule in each section is the one the Coder docs show, with the module's own name in run.
Implementation
  • Both READMEs gain a "Start the worker after your setup" (Cursor) or "Start the runner after your setup" (Claude Code) section after Requirements. It explains why the start step cannot wait on its own, shows a coder_script plus a coder_script_order rule, and lists six notes: the Coder and provider versions, that startup_script cannot be ordered, what requires = "success" and "completion" do with a failed setup, the time budget (the pool's dispatch_deadline for Claude Code, reapStartupGrace for Cursor), what happens when a prebuild is claimed, and that a cli_binary wrapper is not needed.
  • The Cursor section's wrapper note also says why a wrapper is a trap: the status script recognises the worker by the binary's basename, so a wrapper not named agent reads as orphaned. The Claude Code status script checks liveness by pid only, so its note stops at "not needed".
  • The Cursor "Repo-scoped pools" bullet now ends with a link to the new section.
  • Both sections end with a link to the public docs page, "Start the worker after workspace setup". The Claude Code README adds that the page's 15-minute limit is the Cursor startup grace and that Claude Code pools are bounded by dispatch_deadline, until docs: say what Agent Relay does with agent readiness coder#31896 gives both budgets on that page.
  • Version pins in every example block move from 1.0.0 to 1.0.1 in both READMEs. main.tf is untouched, so 1.0.1 behaves exactly like 1.0.0.
  • The "three ordered startup steps" sentence under Scripts and logs is unchanged. That ordering is between the module's own steps and is not what the new section is about.
Expected Output
  • A template author who copies the section's block gets a worker that starts only after coder_script.setup finishes.
  • With the default requires, a failed setup skips the module's scripts and the worker never starts. Agent Relay newer than 0.15.0 fails the session about a minute after the agent reports the failure (coder/agent-relay#155). On 0.15.0 and older, a Cursor workspace waits out the startup grace and is deleted; a Claude Code work order is redelivered at dispatch_deadline and the workspace is rebuilt on every delivery.
  • With requires = "completion", the worker starts even when setup fails.
  • On Coder older than 2.39.0, the rule is ignored without an error and the worker starts right away. A provider older than 2.20.0 has no coder_script_order data source, so the template fails to import.
  • For Claude Code, build plus setup plus runner start must fit in the pool's dispatch_deadline (default 5 minutes from the work order's issue), or Anthropic redelivers and Agent Relay rebuilds the workspace. For Cursor, build plus setup must finish within reapStartupGrace (default 15 minutes from the build's creation), or Agent Relay deletes the workspace.
  • A claimed prebuild reruns setup and shows idle until it finishes; a setup that fails on a claim leaves it at idle until the work order is redelivered and Agent Relay rebuilds the workspace.
  • registry.coder.com shows the new section on both module pages after the 1.0.1 release.
Testing
  • bun x prettier --check on both READMEs passes.
  • go build ./cmd/readmevalidation && ./readmevalidation passes.
  • .github/scripts/version-bump.sh --ci patch origin/main passes, so the pins match a patch bump.
  • No Terraform or test changes, so main.tftest.hcl and main.test.ts are unchanged and were not rerun.

…fter setup

Both modules start the worker as soon as the agent runs its start
scripts, before a template's own setup has finished, and the module
cannot declare an ordering rule for scripts outside itself. Add a
section to each README that shows the coder_script_order rule a
template needs, its version requirements and what a failed setup does.
Bump both modules to 1.0.1; main.tf is unchanged.
@BobbyHo BobbyHo added the version:patch Add to PRs requiring a patch version upgrade label Nov 7, 2026
@linear-code

linear-code Bot commented Nov 7, 2026

Copy link
Copy Markdown

RELAY-67

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Module Scorecard Check

coder/agent-relay-claude-code: 63 → 64

✅ Score improvement: 63 → 64 (+1).

Theme Before After
Presentation & Onboarding 6 / 17 12 / 17
Integration 10 / 25 5 / 25
Credential Hygiene 20 / 20 20 / 20
Restricted-Environment 12 / 20 12 / 20
Engineering Quality 10 / 10 10 / 10
Overall 63 / 100 64 / 100
Full scorecard for this PR
Presentation & Onboarding Agent Integration Credential Hygiene Restricted-Environment Readiness Engineering Quality Overall
12 / 17 5 / 25 20 / 20 12 / 20 10 / 10 64 / 100
Drilldown

Presentation & Onboarding — 12 / 17

Criterion Max Score Notes
Configuration-mode examples 12 12 README shows worked examples for every major mode: base usage with install_cli, additional_args ordering/quoting, release_idle_session_min override, health_port override, and the coder_script_order rule for setup-before-runner sequencing. Each comes with a code block and sensible-default commentary.
Visual preview 5 0 No image, GIF, or video anywhere in the README.

Credential Hygiene — 20 / 20

Criterion Max Score Notes
Secrets marked sensitive 16 16 The module takes no secret-bearing variables at all by design — the work-order JWT is explicitly kept out of Terraform ("it is never a build parameter... never reaches the provisioner, Terraform state, or the build's parameters"). README examples contain no inline keys or placeholder secrets.
Non-hardcoded auth path 4 4 Documents the ephemeral-workspace-secret delivery path (SELF_HOSTED_RUNNER_ENVIRONMENT_SECRET injected by the agent) as the explicit alternative to pasting a credential into the template, in both "Requirements" and "Parameters" sections.

Restricted-Environment Readiness — 12 / 20

Criterion Max Score Notes
Mirrorable artifact source 5 0 install.sh.tftpl hardcodes curl https://claude.ai/install.sh -fsSL | bash; no module variable overrides this download URL. cli_binary only overrides the binary path/name on disk, not the fetch source.
Bring-your-own binary 10 10 install_cli = false fully skips the download and is thoroughly documented ("Bake it into the image and set this to false for faster workspaces"; install.sh.tftpl falls back to expecting the binary already on PATH).
Egress transparency 3 0 No dedicated network/offline section, and no README text names the claude.ai install endpoint or any Anthropic API endpoint contacted at runtime — only the tftpl source comments mention the URL, not the README itself.
Runs without sudo 2 2 install.sh, start.sh, and cleanup.sh never invoke sudo; the CLI installs to ~/.local/bin and all state lives under $HOME/.coder-modules.

Engineering Quality — 10 / 10

Criterion Max Score Notes
Input quality 6 6 Every variable has a clear description and sensible default; several carry validation blocks (cli_binary command-word regex, exit_if_unused_min/release_idle_session_min/health_port numeric bounds, additional_args reserved-flag and newline checks).
Test coverage 4 4 main.tftest.hcl extensively covers parameter contract/business logic via plan-mode assertions; main.test.ts runs real container-based end-to-end lifecycle tests (install, start, cleanup races, idle release, wrapper permission behavior).

Agent Integration — 5 / 25

Criterion Max Score Notes
AI governance 10 0 No mention of Coder AI Gateway or Agent Firewall anywhere in the README.
Dashboard entry point 5 0 No coder_app resource or documented dashboard launch surface; the module is headless, status surfaces only through agent metadata.
Session continuity 5 5 "Idle session release" section explicitly documents resuming: "the runner parks the session server-side and exits... The user's next message resumes the session on a fresh runner."
Managed configuration 5 0 base_dir (workdir) exists as a variable but is never mentioned in the README body; no documented MCP/settings/policy config either.

Overall — 64 / 100

Raw 59 / 92 → round(59 / 92 × 100) = 64

coder/agent-relay-cursor: 59 → 63

✅ Score improvement: 59 → 63 (+4).

Theme Before After
Presentation & Onboarding 6 / 17 6 / 17
Integration 5 / 25 10 / 25
Credential Hygiene 20 / 20 20 / 20
Restricted-Environment 13.5 / 20 12 / 20
Engineering Quality 10 / 10 10 / 10
Overall 59 / 100 63 / 100
Full scorecard for this PR
Presentation & Onboarding Agent Integration Credential Hygiene Restricted-Environment Readiness Engineering Quality Overall
6 / 17 10 / 25 20 / 20 12 / 20 10 / 10 63 / 100
Drilldown

Presentation & Onboarding — 6 / 17

Criterion Max Score Notes
Configuration-mode examples 12 6 README shows real tf examples for the default install_cli path, additional_args, management_addr override, and the coder_script_order setup pattern. However computer_use/share_desktop — a major mode requiring extra image packages — is only described in prose under Requirements with no code example, so coverage is partial.
Visual preview 5 0 No image, GIF, or video anywhere in README.

Credential Hygiene — 20 / 20

Criterion Max Score Notes
Secrets marked sensitive 16 16 No Terraform variable ever holds the worker token by design — it arrives as an ephemeral workspace secret (AGENT_RELAY_CURSOR_TOKEN) injected by the agent, documented explicitly ("never reaches the provisioner, Terraform state, or the build's parameters"). No example inlines a secret value.
Non-hardcoded auth path 4 4 README's "Worker credential" section documents the ephemeral-secret/session-token flow in detail as the sole auth path, analogous to a managed credential pattern.

Restricted-Environment Readiness — 12 / 20

Criterion Max Score Notes
Mirrorable artifact source 5 0 install.sh.tftpl hardcodes curl https://cursor.com/install -fsSL | bash; no module variable overrides this download URL.
Bring-your-own binary 10 10 install_cli = false fully disables download and cli_binary overrides the binary path; documented in the main example and Requirements section ("Bake it into the image and set this to false for faster workspaces").
Egress transparency 3 0 No dedicated network/egress/air-gapped section; cursor.com and Cursor API endpoints are mentioned only incidentally inside install/worker descriptions, not enumerated anywhere.
Runs without sudo 2 2 All scripts (cleanup.sh.tftpl, install.sh.tftpl, start.sh.tftpl, status.sh.tftpl, session_attached.sh.tftpl) run as the workspace user with no sudo invocation anywhere.

Engineering Quality — 10 / 10

Criterion Max Score Notes
Input quality 6 6 Every variable has a detailed description and sensible default; several carry validation blocks (cli_binary command-safety regex, management_addr host:port + port-range checks, share_desktop requires computer_use, additional_args rejects reserved flags/newlines, serving_log_pattern non-empty).
Test coverage 4 4 Extensive main.tftest.hcl covering parameter contract and rendered-script business logic, plus a thorough main.test.ts exercising install/start/cleanup lifecycle end-to-end in containers.

Agent Integration — 10 / 25

Criterion Max Score Notes
AI governance 10 0 No mention anywhere of Coder AI Gateway or Agent Firewall; the module integrates with "Agent Relay" (a different Coder product) but does not document AI Gateway/Agent Firewall auth, routing, or policy enforcement.
Dashboard entry point 5 5 coder_app resources cursor_web and cursor_desktop are implemented and documented in the README ("Open in Cursor Web"/"Open in Cursor Desktop"), conditionally created when a session id is present.
Session continuity 5 5 README explicitly documents native session continuity: agent_relay_cursor_idle_release_timeout keeps the worker connected after a session ends "waiting for a follow-up" before releasing, and agent_relay_session_id ties a workspace to a specific cloud-agent session for reconnect.
Managed configuration 5 0 No documented MCP, settings, policy, or workdir configuration management; additional_args only passes raw CLI flags, and repo cloning/config is explicitly stated as the template's responsibility, not the module's.

Overall — 63 / 100

Raw 58 / 92 → round(58 / 92 × 100) = 63

Tip

You can run this locally by telling your agent: "review this module against .github/scorecard/SCORECARD.md".


Scored against SCORECARD.md with solstice-1. Language-model scores are advisory.

@BobbyHo

BobbyHo commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@BobbyHo

BobbyHo commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review coder-agents-review 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.

This PR adds a section to both Agent Relay module READMEs that orders the module after template setup with coder_script_order, and bumps both to 1.0.1. Per the request on this PR, only P0 to P2 findings are posted: 1 P1 and 6 P2.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coder/coder docs/agent-relay/setup.md:251: the shared Agent Relay docs give the same 15-minute setup limit for both providers, which does not hold for Claude Code pools, where the spawn hint's dispatch_deadline (default 5m) bounds runner start.

🤖 This review was automatically generated with Coder Agents.

…time budget and prebuild notes

The start-after-setup section gave both modules a 15-minute setup
budget. For Claude Code the limit is the pool's dispatch_deadline,
default 5 minutes from the work order's issue, and a miss rebuilds
the workspace on every redelivery. For Cursor the limit is
reapStartupGrace, measured from the build's creation, so it includes
build time. Setup also runs again when a prebuild is claimed, and the
early session failure needs Agent Relay newer than 0.15.0.
@BobbyHo

BobbyHo commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@BobbyHo
BobbyHo requested a review from Emyrk November 9, 2026 21:22
@BobbyHo
BobbyHo marked this pull request as ready for review November 9, 2026 21:23
@BobbyHo
BobbyHo requested a review from nickvigilante November 9, 2026 21:23

@coder-agents-review coder-agents-review 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.

581379c fixes all seven round 1 findings, including the P1 on the Claude Code setup budget, verified against agent-relay main (3a1a1c4). This round has 2 new P2 findings, both in the Claude Code README, where two bullets copied from the Cursor README describe Cursor behavior. Claude Code work orders are redelivered and Cursor sessions are not, so the outcomes differ.

Out of scope (needs a ticket or explicit acceptance by a human):

  • registry/coder/modules/agent-relay-cursor/status.sh.tftpl:36 (and agent-relay-claude-code/status.sh.tftpl:30): the state file survives an agent reinit and only the module's own cleanup deletes it, so while the rule holds the module's scripts the status shows the previous start's idle.
  • coder/agent-relay internal/workspacereaper/lifecycle.go:138: the reaper keeps every idle workspace, including a claimed Cursor prebuild whose setup failed, so that workspace is never reaped and its session is never failed.

🤖 This review was automatically generated with Coder Agents.

…er a failed setup

Both failed-setup notes said the relay fails or ignores the session.
In fact Anthropic redelivers the work order and the dispatcher rebuilds
any workspace whose runner is not up. Newer releases retry a failed
setup once on a pending status before the attempt rule makes the second
failure final; 0.15.0 and older rebuild at every dispatch_deadline. A
claimed prebuild keeps the idle status through every lap, so the retry
rule never applies to it.
@BobbyHo

BobbyHo commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review coder-agents-review 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.

95cb6bd fixes both round 2 findings: the failed-setup bullet now gives the Claude Code behavior for each Agent Relay version, and the claimed-prebuild bullet describes the redelivery and rebuild. This round has 1 new P2, in the sentence 95cb6bd added about what happens after that rebuild.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coder/agent-relay internal/workspacedispatcher/dispatcher.go:732 (kick): the start build it issues gives the agent a new token, so a prebuild-derived workspace whose template ignores env changes (as Coder's prebuild docs recommend) keeps a container whose agent token coderd no longer accepts, and the rebuilt workspace's agent never connects. Inferred from the provider and coderd code, not run.

🤖 This review was automatically generated with Coder Agents.

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed 95cb6bd separately from the two Coder Agents rounds.
The snippets match the provider v2.20.0 coder_script_order schema and the selector rules in Order startup and shutdown scripts.
The status-script, retry, and reaper claims match the module scripts and agent-relay main.
The comments below include one P1, one P2, and a few P3 items.

P1: Both "full example" links point into coder/agent-relay, which is an internal repository, so every registry.coder.com reader gets a 404 even after coder/agent-relay#157 merges.

P2: The Claude Code README now documents a per-pool dispatch_deadline, which Agent Relay added in 0.15.0, while Requirements still support v0.14.0, where the budget is a fixed 300 seconds.

P3 items not attached to a line:

  • The new text writes Agent Relay versions as 0.15.0, while Requirements in the same files use v0.14.0. Pick one form.
  • The PR description's Expected Output says that a provider older than 2.20.0 ignores the rule without an error. Only an older Coder does that. Provider 2.19.0 has no coder_script_order data source, so template import fails. The README wording is correct.

Questions:

  • The same guidance now lives in both READMEs and in coder/coder docs/agent-relay/setup.md, and the three already disagree on the setup budget. The Agent Relay version-specific failure behavior changes with relay releases, not module releases. Could the READMEs keep the snippet and the module-specific notes, and link to the Coder docs for the rest?
  • The Claude Code failure bullets (lines 110 to 136) branch on the Agent Relay version inside long sentences. Would a small table of relay version, setup outcome, and result be easier to scan?

Out of scope, for coder/coder docs follow-ups:

  • docs/agent-relay/setup.md:251 gives a 15-minute setup limit for both providers, which does not hold for Claude Code pools. The round 1 review noted this too.
  • docs/agent-relay/configuration.md does not document --reap-startup-grace.

Generated with Coder Agents on behalf of @nickvigilante.

…med-prebuild bullet

A kick is a plain start build, so the provider gives the agent a new
token on refresh, the container that carries it in env is replaced and
the state file goes with it. The status then reads pending and the
one-retry rule applies, so the bullet no longer says the status stays
idle on every delivery.
…stions

The "full example" links pointed into coder/agent-relay, which is
private, so public readers got a 404. Both READMEs now link to the
Agent Relay setup docs instead.

Also from the review: a setup that times out skips the module too, the
startup grace is named by its flag, Agent Relay 0.14.0 has a fixed
300s budget for Claude Code pools, versions drop the v prefix, and the
Claude Code failure bullets become a table of relay version, setup
outcome and result.
@BobbyHo

BobbyHo commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks Nick. fc7562e takes every inline suggestion; replies are on each thread. On the rest:

  • Version form: both Requirements lines now write 0.14.0 without the v, matching the new text and the Coder version in the same sentence.
  • PR description: the Expected Output bullet now says that only older Coder ignores the rule silently, and that a provider older than 2.20.0 has no coder_script_order data source, so import fails.
  • Consolidation: agreed. The relay-version failure behaviour belongs in the Coder docs, which docs: say what Agent Relay does with agent readiness coder#31896 already carries per provider. Once that merges I will trim both READMEs to the snippet, the module-specific notes and one short failure line per provider with a link, so registry.coder.com has no gap in between.
  • Table: done for the Claude Code README in fc7562e. The two long failure bullets are now one short bullet each plus a three-column table of relay version, setup outcome and result.
  • Out of scope: the 15-minute line in setup.md and the missing --reap-startup-grace entry in configuration.md both go on the docs: say what Agent Relay does with agent readiness coder#31896 list.

@BobbyHo

BobbyHo commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review coder-agents-review 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.

e4845d2 fixes the round 3 finding: the claimed-prebuild bullet now stops at the rebuild. fc7562e also replaces the private agent-relay links that round 1 recorded below the P2 limit. This round has 1 new P2, on the link that replaced them in the Claude Code README.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coder/coder docs/agent-relay/setup.md:251, recorded in round 1: the 15-minute setup limit is still there for both providers on main, and also on bobby/relay-67-e-agent-readiness-docs, so trimming the READMEs to a link after coder/coder#31896 merges would remove the only correct Claude Code budget unless that branch fixes this line.

🤖 This review was automatically generated with Coder Agents.

…describes

The setup page's 15-minute limit is the Cursor startup grace. A Claude
Code pool is bounded by dispatch_deadline, so a reader who sized setup
from that page would hit the rebuild loop described in the table.

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working through all of these.
I checked 8040c84 against my review, and every inline fix and summary item is in.
Approving, with two small follow-ups that don't block the merge:

  • PR description: the Implementation section still says both sections link the example templates in coder/agent-relay and that this PR should land after coder/agent-relay#157. The links now point to the public setup docs, so that bullet can go.
  • Claude Code README, lines 140 and 141: the note that the docs page's 15-minute limit applies only to Cursor pools goes stale once coder/coder#31896 updates that page to give both budgets. Please remove it as part of the README trim you planned after #31896 merges.

Generated with Coder Agents on behalf of @nickvigilante.

@BobbyHo

BobbyHo commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review coder-agents-review 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.

8040c84 fixes the round 4 finding: the Claude Code README now says the linked page's 15-minute limit is not the Claude Code budget and points to dispatch_deadline. All findings posted in rounds 1 to 4 are resolved, and this round has no P0 to P2 findings.

🤖 This review was automatically generated with Coder Agents.

@BobbyHo

BobbyHo commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks Nick. The stale Implementation bullet about the example-template links is replaced; the body now describes the docs link and the Claude Code budget note. I also fixed the Expected Output line that said 0.15.0 and older "wait out the startup grace", since that is the Cursor path; it now gives the Claude Code redelivery path too. The lines 140-141 note is on the list for the README trim after coder/coder#31896 merges.

@BobbyHo
BobbyHo merged commit 06d13d8 into main Nov 10, 2026
5 checks passed
@BobbyHo
BobbyHo deleted the bobby/relay-67-c-order-module-after-setup branch November 10, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

version:patch Add to PRs requiring a patch version upgrade

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants