Skip to content

feat(runners): the runner core without Coder, in the layers of runner-layers.md (17c, #305) - #920

Merged
aixle-com[bot] merged 25 commits into
developfrom
feature/runner-core-without-coder
Nov 30, 2026
Merged

aixle-com[bot] merged 25 commits into
developfrom
feature/runner-core-without-coder

Conversation

@NOX73

@NOX73 NOX73 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Row 17c of docs/design/agent-runtimes/runner-coder.md §14 (task #305), reworked to the layer design of task #308: docs/design/agent-runtimes/runner-layers.md on feature/runners-layers-design at ee5a255e (PR #931, not merged). For names, layout, the adapter interface, locks, state changes, transactions and IO that design wins; the behaviour of row 17c and "What must not change" still hold. Nothing here creates a coder runner: coder stays out of Adapter::REGISTRY, and the Coder services, the Coder adapter, the reconciler and the UI are 17b, 17d and 17e.

What changed in the rework

app/services/runners/ is now four layers (runner-layers.md §3, §4):

adapter.rb  capabilities.rb  reasons.rb  errors.rb
core/            allocation.rb  registration.rb  selection.rb  management.rb
adapters/        manual.rb  manual/availability.rb  provisioned.rb
infrastructure/  store/{environments,locks,runner_status,transactions}.rb
                 credentials/{tokens,rotation,revocation,refused}.rb
                 operations/{queue,run,outcome}.rb
                 gateway/{protocol_schema,version,release,result_uploads,install_script,proxy,liveness}.rb
                 relay/{signals,route,checks,tunnel,tunnel_ticket}.rb
                 config_schema.rb
  • Runners::Reasons and Runners::Errors (§8): NoMachine is Errors::NoEnvironment, the wait and refusal reasons are one set of constants, Pending, ProvisionError, UnsupportedOperation, Refused, plus the new InTransaction and InvalidTransition. AdmittedPhaseActivity, SessionAdmission, SessionService, WorkflowService read them.
  • One owner of an environment's state (§6): Infrastructure::Store::Environments (locked, locked_under_runner, strict apply!, create!, take_free!, free!, let_go!) is the only code that fires RunnerEnvironmentStateMachine events. apply! raises InvalidTransition for an event the state does not allow and rolls a multi-event call back; the tolerant callers check may_<event>? inside locked. Store::Locks is the only code that locks a runner row.
  • The adapter interface, complete (§5): every method declared on Adapter and raising NotImplementedError; Adapters::Manual (was ManualAdapter) and Adapters::Provisioned (was Runners::Provisioning, now the base class whose advance! is the step machine). ReleaseContext replaces runtime:; Operations::Run and Operations::Outcome moved down from RunnerRuntime. fail! and end_registration! are state-only, teardown! is the IO step. The registration trio (issue_registration!, lock_registration_target!, register_machine!) and check_in! replace the branch on a bound token and the type checks.
  • Token minting with no type check and no mode parameter (§5.3): Credentials::Tokens.mint_unbound_registration! and .mint_bound_registration!. Credentials.rotate! split into Credentials::Rotation.rotate_pair! and Core::Registration.refresh!, which fails the environment through its adapter in the same transaction.
  • No hidden hooks (§7): Operations::Queue.enqueue! no longer wakes (the caller runs Queue.wake), Relay::Signals publishes at once and each method that changes a hold publishes, the RunnerEnvironment after_save is gone, and Store::Transactions.none_open! guards every method that does IO.
  • Runner Revoke and Delete as entry points (§9.2): Core::Registration.revoke_runner! and .delete_runner! replace the Runner after_save callbacks and RunnerStateMachine#soft_delete!; the controllers call them. finish_pending_retirements! (D16) is called by SettleAbandonedActivity.
  • Core::Management (runner_types, form_attributes, save, check_health!, list_environments, machine_counts) and Infrastructure::ConfigSchema.record_rules, which moves the Runner validations by type into data (§10).
  • Tests: the runner suites moved to the layout (core/, adapters/, infrastructure/<area>/); machines_test.rb and machines_concurrency_test.rb keep their paths. New: layering_test.rb, adapter_contract_test.rb, state_machines/runner_environment_ownership_test.rb, state_machines/runner_ownership_test.rb, infrastructure/store/environments_test.rb, core/registration_retirement_test.rb, and a reused refresh token on a provisioned environment.
  • Docs: docs/architecture/runtime-layers.md as §12.4 says (the layers, where differences live, a new "Transactions and IO" section, the guarantees with the new names, adding a runner type); the names in implementation-patterns.md, docs/architecture/index.md and the PROTOCOL.md note.

The behaviour of the first round of this PR (17c) is unchanged: the allocator's steps, the provisioned arm, the migration (version kept, staging applied it), the two §17 checks, and the five fixes of triage batch 1.

Review round 3 (Alex's six threads and the board review)

  • Runners::Interface, the one module code outside app/services/runners calls (controllers, activities, RunnerRuntime, SessionService, WorkflowService, Sessions::Lifecycle, the initializers, models). Each method is one delegation to a core module or to read-only infrastructure; layering_test.rb fails on an interface method that is more than that. Name: I kept Alex's Interface. Gateway is taken (Infrastructure::Gateway, the runner gateway controllers), Api reads as HTTP, and Facade names the pattern, not what a caller programs against; Runners::Interface.revoke!(machine) reads well at the call site.
  • What may still be referenced from outside (OUTSIDE_ALLOWLIST in layering_test.rb, each with its reason; the test fails on any other Runners:: constant outside the directory, and on an allowlist entry nobody uses): Runners::Errors, Runners::Reasons (public by the test's PUBLIC_MODULES), Runners::Adapter::ReleaseContext (data the runtime builds), Infrastructure::Credentials::Refused (the error the gateway and the page map), Infrastructure::Gateway::ResultUploads::Unreadable (the error the runtime maps), Infrastructure::ConfigSchema (Runner's validations).
  • scan_contact!(session) reads the environment from the session. TerminalSession#on_runner_environment? and #runner_environment_being_built? replace the two conditions in ScanDeadContainersActivity. Runner#environment_limit replaces max_environments || max_concurrency.
  • Core::Registration.revoke!(machine) and .unregister!(machine) (the machine's own aixle-runner unregister) replace the public end_registration!, which is private now. The gateway, the runner pages and RunnerMachineReturn call them through the interface.
  • One leaving step: Adapter#finish_leaving!(environment, held_before) (the teardown of a tearing_down environment, then the relay's signal if the hold changed) and Adapter#let_go!(session) (let go, then the signal) are on the Adapter base. Allocation.release!, .sweep_abandoned!, .scan_contact! and Registration.check_in!, .refresh!, end_one! and the retirement's session step call them; the sequence is written once.
  • Infrastructure::Gateway::Platform takes Binary, binaries_for, config and gateway_url out of Core::Registration.
  • Allocation.take! has no savepoint: acquire! refuses an open transaction, so no caller's transaction exists. The concurrency suites pass without it.
  • Authors: the rework commits are rewritten as Alex, signed off, with the file contents unchanged (a git diff of the old and the new head was empty before the force push), as decided.

Costs (§14 of runner-coder.md)

  1. Core::Allocation.acquire! takes the runner row FOR UPDATE for every type, where Machines took FOR SHARE for a manual runner. MachinesConcurrencyTest (two sessions racing for one manual machine, two attempts of one session, revoke against acquire in both orders) passes.
  2. A runner Revoke ends each manual machine through end_registration! (§6.1, D50): every machine becomes gone with state_reason revoked.
  3. The manual-specific code is in Adapters::Manual (and Adapters::Manual::Availability).

The first run of finish_pending_retirements!, and other behaviour changes

  • Rows from before this code. On develop, a runner's Revoke revoked its credentials and ended its sessions but left its manual machines registered (or failed). The first run of finish_pending_retirements! (one minute after deploy, on the abandoned-session schedule) finds every environment that is not gone (and not tearing_down) under a revoked or deleted runner and runs the second step of the retirement for that runner: the relay is told machine_revoked for each of its machines, any session of it that is still not ended fails with the revoked message (and lets its machine go), and each machine becomes gone with state_reason revoked, its credentials revoked again (they already are). What a person sees: the machines of an already-revoked runner show as gone instead of offline or failed. No live runner is touched. Cost: one pass over those runners, once; afterwards the query finds nothing. Covered by RegistrationRetirementTest ("on its first run it ends the machines a runner revoked before this code left registered or failed").
  • IO inside a transaction now raises. acquire!, release!, sweep_abandoned!, check_in!, refresh!, end_registration!, revoke_runner!, delete_runner!, Operations::Run.call and the outside adapter methods raise Errors::InTransaction when a transaction is open. Before, Operations.await only said so in a comment. The full Rails suite passes with it; a caller found later would fail loudly instead of holding a lock across an op.
  • Signals. A relay signal or an op wake is published when the step runs, not after the outermost commit. Each publisher now runs after its own transaction, so the order is the same (commit, then publish).

Design deviations

Where the design did not fit the code, the closest reading, for the design to be updated from:

  1. Store::Transactions.none_open! is in infrastructure/store/transactions.rb (gap 1 of the decision; missing from the §4 tree).
  2. ReleaseContext#deadline_at is a callable, not a value. The scrub and the reset that follows it each get the lifecycle budget from the moment they are sent, as RunnerRuntime#lifecycle_op gave them; a value computed once would shorten the reset's deadline.
  3. Adapter#end_registration! answers the id of the session the environment held, so the core knows whether to tell the relay the hold went. The adapter still fails that session itself (after the row's own transaction), as §5.2 says.
  4. Resolver is gone, with no alias. Core::Selection.resolve! (the name keeps the bang: it raises) and Errors::Refused; SessionService, WorkflowService and LaunchStepSessionActivity call them directly. §8 kept Resolver::Refused as an alias; nothing else referenced it.
  5. Core::Management names: runner_types and form_attributes (the two halves of form), save (answers true or false, as Runners::Save.call did; save! would say it raises), check_runner! and apply_health (one runner, used by the tests), machine_counts (the runner list's busy/total, which RunnerResource reads).
  6. Core::Allocation.cleanup_ready?(session, environment) and .stop_first?(environment) take the records RunnerRuntime already read.
  7. Relay::Signals.hold_changed(environment_id, before): one helper that publishes machine_session only when the hold differs from what it was before the step. Store::Environments.held_by, .holder_id and .take_free!, and RunnerEnvironment.held_by (the read L1 uses, §3 rule 4), are small additions.
  8. mint_bound_registration! checks the state only. With no runner parameter, "another runner's environment" cannot be passed; the row's own runner is locked first. The test of an origin: registered row in provisioning was dropped, as §5.3 says the state is the whole condition.
  9. finish_pending_retirements! takes no now: (nothing in it depends on the time) and leaves tearing_down rows to the type's reconciler (17d).
  10. The concurrency suites (machines_concurrency_test, allocation_concurrency_test, revocation_concurrency_test, first_use_concurrency_test) hold a transaction open around a core method to force the order of a race. They stub Store::Transactions.none_open!; nothing else in them changed.
  11. machines_test.rb and machines_concurrency_test.rb keep their paths, as §4 says for the suites of §1 (§12.5 suggests splitting machines_test; not done).
  12. Runner.retired (scope) is added for finish_pending_retirements!; retired? was the record's form.
  13. Commit order of §12.1 not followed (see "Not done" below).
  14. Runners::Interface is the one public module (Alex's decision on the review of this PR); it is not in runner-layers.md, which lets entry points call Core::* directly (§3 rule 4). OUTSIDE_ALLOWLIST is the list of §3's exceptions.
  15. end_registration! runs as an outside method of Core::Registration: its own transaction (the adapter's), then the session's failure, then finish_leaving! and the relay's machine_revoked. It is private; the callers use revoke! and unregister!.
  16. The leaving step is on the Adapter base (finish_leaving!, let_go!; Adapter::SHARED_METHODS lists them, so the contract tests do not ask a type to implement them), not in each core module. A core method calls it on the adapter it already holds. finish_leaving! tears down only an environment that is tearing_down (a manual machine's teardown! does nothing, so the change is for a type that is gone at once).
  17. Infrastructure::Gateway::Platform (gateway URL, binaries, the config the runner is told) is a new module; the design did not place them.

Not done in this round

  • The commit order of §12.1 (commits 1 to 10, each green). The rework stays as working commits on top of the merge: the PR is reviewed as a whole and develop squash-merges (Alex's decision). The branch was force-pushed once, to rewrite the authors of the Aixle Flow commit, so cla passes.
  • Staging and QA wait for the code review, as decided.

Tests

On a Coder workspace, logs under /var/lib/aixle-jobs/run1/ on it:

  • Full Rails suite (bin/rails test, no coverage) at 0fde84e1: 11995 runs, 1 failure (RunnerProxySettingsTest, which reads required_env.rb for the old constant; fixed in 0c025fc4), 0 errors (full-r2.log).
  • At 0c025fc4: test/services/runners, the two model tests, test/config, test/docs and test/temporal/activities: 830 runs, 0 failures, 0 errors (run7.log).
  • rubocop on the changed Ruby files: no offenses (rubocop-r4.log). zeitwerk:check: all good.
  • New tests: Runner#environment_limit, the two TerminalSession predicates, Adapter#finish_leaving! and #let_go!, Gateway::Platform, end_registration! private, and in layering_test.rb the outside-references rule, its allowlist and "the interface only delegates".

Runners::Allocator replaces Machines on the start path for every runner type;
the environment state machine gains its provisioned arm; every difference
between types on the start path becomes an Adapter method.

Signed-off-by: Alex <[email protected]>

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of head 70373c8. One [Must] (model predicate rule), one [Recommendation].

Comment thread app/services/runners/registration.rb Resolved
Comment thread docs/architecture/runtime-layers.md Resolved
Comment thread app/services/runners/registration.rb Resolved
Comment thread app/services/runners/allocator.rb Resolved
Comment thread app/services/runners/allocator.rb Resolved
…dempotent acquire

- RunnerEnvironment#being_built? and .being_built replace provisioning?||booting? in the dead-container scan and Registration.
- Bound registration locks its environment before the token (runner, environment, credentials).
- Allocator.take! re-checks the session's hold under the runner lock and saves the hold through the session's validations.
- implementation-patterns.md lists all RunnerEnvironment states.

Signed-off-by: Alex <[email protected]>
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA. Thank you!
Posted by the CLA Assistant Lite bot.

@aixle-com aixle-com Bot changed the title feat(runners): the runner core without Coder (17c, #305) feat(runners): the runner core without Coder, in the layers of runner-layers.md (17c, #305) Nov 30, 2026
Comment thread app/services/runners/core/allocation.rb Resolved
@aixle-com
aixle-com Bot force-pushed the feature/runner-core-without-coder branch from 9e68af2 to 561857e Compare November 30, 2026 13:01
…nt limit

- Runners::Interface is the one module code outside app/services/runners calls;
  the layering test fails on any other layer reference outside it.
- Adapter#finish_leaving! and #let_go! write the teardown-then-signal and
  let-go-then-signal sequences once.
- Core::Registration.revoke! and .unregister! replace the public end_registration!.
- Gateway::Platform takes the gateway URL, binaries and config out of Registration.
- scan_contact! takes the session only; TerminalSession and Runner name the
  predicates and the environment limit.
- Allocation.take! drops its savepoint.

Signed-off-by: Alex <[email protected]>

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review of head 0c025fc. No blocking findings; two non-blocking comments inline.

@aixle-com
aixle-com Bot merged commit a811de9 into develop Nov 30, 2026
18 checks passed
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