Skip to content

refactor(runners): clean up design problems in the merged runner code (task #209) - #669

Closed
aixle-com[bot] wants to merge 2 commits into
developfrom
feature/runners-design-cleanup
Closed

aixle-com[bot] wants to merge 2 commits into
developfrom
feature/runners-design-cleanup

Conversation

@aixle-com

@aixle-com aixle-com Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Board task #209: fixes the design problems that the 2026-11-07 review found in the merged runner code, as Alex decided on 2026-11-08. Items 1 and 6 were dropped. Items 2, 3, 4 and 5 are done. Item 7 was reverted in Fix CR round 1 (Alex, 2026-11-09): the tenant rule stays in TenantScope, the project's documented pattern. Behaviour is unchanged except for item 4's change, which has its own test.

2. Typed messages on the long-poll channel. runner_env_<id> now carries JSON objects with a type field: {"type":"op_enqueued","sequence":N} is an enqueue's wake-up, and {"type":"poll_waiting","poll_id":"<uuid>"} is a waiting poll's announcement. The poll: prefix is gone. A message that is not a JSON object, or has another type, makes a waiting poll read the queue again. It does not end the poll.

3. JSON Schemas for gateway requests. Three schemas are in runner/protocol/schemas/v1/: register.request.json, ops.query.json and op_result.request.json. The new helper Runners::ProtocolSchema.valid?(name, document) validates against them through json_schemer, the same way Templates::Package validates template.yaml. The error codes invalid_registration, invalid_result and invalid_request are unchanged, and PROTOCOL.md links to the schemas. The hand-written checks outcome, non_negative_integer and string_or_nil are replaced. Cases that needed care to keep behaviour unchanged:

  • os / arch: PROTOCOL §5.1 says a value that is not a string is ignored, and fixture register/boundaries.json pins that. The schema lets such a value through, and the controller then drops it (ignored_unless_string).
  • ephemeral: it is still read the way it was before, and its refusal still comes before the schema check (PROTOCOL §5.1 orders ephemeral_not_supported before invalid_registration). A non-string name reaches Registration.register! as nil, so an ephemeral body with name: 5 still gets 422 ephemeral_not_supported.
  • Query parameters: they arrive as text. A base-10 integer is read as an integer first (Integer(value, 10)), so the schema checks the type and the range, including after ≤ 2^63−1.
  • One edge does change (accepted by Alex): JSON Schema counts 1.0 as an integer, so an exit_code of 1.0 is now accepted and stored as 1. It was a 422 before. PROTOCOL §5.5 documents this.

4. Config rules move into Runners::ConfigSchema. The three rules from ManualAdapter#validate_config (home mount path, acknowledgement of writable host mounts, Docker socket) are now pure functions in ConfigSchema::TYPE_RULES. ConfigSchema.errors returns the schema's errors and, once the schema passes, the type's rules. Runner validates config only through ConfigSchema, and only when config or runner_type changes. Runners::Save is now thin and calls a plain save (no more save(validate: false)). The rule "config checks do no IO" is written in DESIGN.md §5.1 and in implementation-patterns.md.

  • Behaviour change: the config checks no longer run on revoke!, soft_delete!, disable! or enable!. A test covers a runner whose stored config fails the checks: it can still be disabled, enabled, revoked and deleted.

5. Runner policies and controllers follow the project pattern. Both runner policies authorize the action only, through dynamic_authorize!. The record.is_a?(Runner) branch and authorize_runner! are gone. The controller's lookup decides which runner a request may touch: on the project page, writes look among the project's own runners; in company settings, among the company-level runners; index and show among the runners the page lists. RunnerManagement is deleted; the actions live in the two controllers, and the shared pieces are in Runners::Form. can_manage is policy.update? && runner.project_id == current_project.id.

  • Response change (accepted by Alex): a write to a company runner from a project page answers 404 instead of the Pundit denial redirect. It is still refused.

7. Tenant rule: unchanged from develop. Per docs/architecture/implementation-patterns.md and docs/project/context.md, ownership is defined in TenantScope.owned (with TenantScope.owns_runner? for a loaded row), and Runner.visible_for_project is the picker scope, as for integrations. RunnerReference#owned_runner calls TenantScope.owns_runner?.

Related issues

Board task #209 (Simple Kanban). Runs before 8b.

Type of change

  • Refactor / chore
  • Documentation

How was this tested?

  • Runners::ProtocolSchemaTest: every schema file is named and valid; accepted and refused bodies for each schema.
  • Gateway tests: typed announcement and wake-up messages; non-announcement messages do not end a waiting poll; a null result field counts as absent; exit_code: 1.0 is stored as 1; an ephemeral registration is refused as such even when the rest of the body is invalid (including name: 5).
  • ConfigSchemaTest: the manual rules (moved from ManualAdapterTest), rule ordering and type scoping, writable_host_mounts.
  • RunnerTest: a type rule is refused by any save; config checks run only when config or type changes; a stale-config runner can still be disabled, enabled, revoked and deleted; TenantScope.owned(Runner) / owns_runner? include deleted runners and exclude other projects and companies.
  • Runners::SaveTest: capabilities, a type-rule message, an unavailable type, the name race.
  • Controller tests: every write to a company runner from a project page is a 404; another project's runner is not found; every write to a project runner from company settings is a 404; can_manage; an unacknowledged writable mount is refused with the same message as before.
  • RunnerReferenceTest: owned_runner on a deleted runner and on a stale id.

Results of the Coder runs are in the board task comments.

… config rules in ConfigSchema, action-only runner policies, one tenant rule (task #209)

- Runners::Operations: the runner_env_<id> channel carries typed JSON
  messages (op_enqueued, poll_waiting); the poll: prefix goes.
- Gateway request bodies and the long-poll query are checked against JSON
  Schemas in runner/protocol/schemas/v1/ through Runners::ProtocolSchema.
- ManualAdapter's config rules move to Runners::ConfigSchema as pure
  functions; Runner's validation calls only ConfigSchema, and only when
  config or runner_type changes. Runners::Save saves with a plain save.
- Runner policies authorize the action only; the controllers' lookup decides
  which runner a request may touch. RunnerManagement goes; Runners::Form
  holds the shared form pieces.
- Runner.of_tenant / Runner#of_tenant? hold the tenant rule; TenantScope,
  visible_for_project and RunnerReference#owned_runner call them.
  TenantScope.owns_runner? goes.

Signed-off-by: Aixle Flow <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 8, 2026
…meral registration's name (task #209, Fix CR round 1)

- RegistrationsController#create: a non-string name reaches Registration.register! as nil
  again, so an ephemeral request answers 422 ephemeral_not_supported, not 500.
- Revert item 7 to the documented pattern: TenantScope.owned(Runner) and
  TenantScope.owns_runner? hold the ownership rule, Runner.visible_for_project is the
  picker scope; Runner.of_tenant and #of_tenant? are removed.
- Docs: drop the Runner exception, reword the no-IO validation bullet.

Signed-off-by: Aixle Flow <[email protected]>
@aixle-com

aixle-com Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Reopened in Alex's name for the squash merge (task #209).

@aixle-com aixle-com Bot closed this Nov 9, 2026
@NOX73
NOX73 deleted the feature/runners-design-cleanup branch November 9, 2026 11:13
aixle-com Bot pushed a commit that referenced this pull request Nov 10, 2026
Conflicts resolved:
- Files touched on staging only by the pre-squash branches of task #209 (PR #669)
  and task #211 (PRs #667/#668) take develop's version, which carries the
  reviewed, merged form of the same work (#670, #671, #672).
- test/integration/web/company/billing_test.rb: keeps the billing redesign's
  (#646) test body with develop's 14-day trial values (#678).
- CHANGELOG.md: develop's 1.11.0 entry for the 14-day trial; the billing
  redesign entry already present above is kept once.

Signed-off-by: Alex <[email protected]>
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.

0 participants