Repository navigation
feat(runners): RunnerRuntime and the op path, session_id in the op envelope, the dev local adapter (task 8a) - #665
Merged
Conversation
added 12 commits
November 7, 2026 10:28
…velope, the dev local adapter (task 8a) Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
…fake engine an http url Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
…he machine, and the scanners cap a runner op Signed-off-by: Aixle Flow <[email protected]>
Signed-off-by: Aixle Flow <[email protected]>
… through a volume Signed-off-by: Aixle Flow <[email protected]>
…he web container's output Signed-off-by: Aixle Flow <[email protected]>
…ig, whose keys arrive as symbols Signed-off-by: Aixle Flow <[email protected]>
added 3 commits
November 7, 2026 16:23
…d container.start and container.stop refuse another session's container
image.ensure, container.start and env.scrub take {image}: the reference as the
user gave it, a tag or a digest. The runner always pulls it and reports whether
the pull brought a new image; no digest is sent or returned.
container.stop without this session's container answers session_mismatch when
the environment's session container is another session's, and
no_session_container when there is none. container.start over another
session's container answers session_mismatch; over its own or an unlabelled
leftover, container_exists as before.
PROTOCOL.md §6, §6.1, §6.2 and §6.4 and the fixtures are updated.
Signed-off-by: Aixle Flow <[email protected]>
… a session's ops reach its machine only while it holds it - Runners::ImagePin is deleted: RunnerRuntime sends the image reference as it was given, container.image_override included, and the platform never contacts a registry. - AdmittedPhaseActivity persists RunnerRuntime's identity before pull_image, so a pull that fails, or a stop before the create, still runs cleanup_session and frees the machine. - A failed or unanswered env.reset moves the machine to failed and clears current_session_id; deleting the session frees nothing. A runner whose every machine failed fails the launch at once, naming them and how to bring one back (Runners::Machines, Runners::Resolver). - RunnerRuntime sends an op only while the session holds its machine, and stops waiting at the op's deadline, which is the activity's end less 5 s; the sweep's grace is for the ops nobody waits for. - AuthPause#heal! lets each holder be written through its own runtime. - CleanupStaleActivity sends a runner nothing, and moves a machine a stale session still holds to failed. - DESIGN.md, docs/project/context.md and bin/runner-local follow. Signed-off-by: Aixle Flow <[email protected]>
…aced Signed-off-by: Aixle Flow <[email protected]>
NOX73
reviewed
Nov 7, 2026
NOX73
reviewed
Nov 7, 2026
added 3 commits
November 8, 2026 07:45
…ner.start stops at its deadline, and the pull sends the registry's Docker credentials Fix CR round 4 (Alex, comments 68781 and 68791), the runner side: - Session ops get their own handler type, SessionHandler, with the envelope's session_id as a parameter. sessionOp reads it once and refuses a missing or non-positive one; WithOpSession and OpSession are removed. - container.start runs the pull, the volumes, the create and the start under context.WithDeadline(op.DeadlineAt): past it, it creates nothing and the ops loop moves on. - The pull resolves the credentials of the image's registry as the Docker CLI does (LoadDefaultConfigFile, GetAuthConfig, credential helpers included) and passes them as ImagePullOptions.RegistryAuth; with none, the pull stays anonymous. - PROTOCOL.md and the fixtures README say so. Signed-off-by: Aixle Flow <[email protected]>
…ine, and the cleanup waits for an unfinished start
Fix CR round 4 (Alex, comments 68781 and 68791), the platform side:
- Runners::Operations.enqueue! takes the session of every op,
environment ops included, and creates the op only while that session
holds the environment, under the row lock it already takes. It
replaces RunnerOperation#session_is_on_the_environment.
- The op sequence is a counter on runner_environments (op_sequence), so
the prune and a session's deletion remove any finished op.
- Machines.acquire! no longer touches the caller's session and answers
the winner's hold when two attempts of one session race;
Machines.fail!(..., holder:) is a compare-and-set; unregistering a
machine ends its hold; Machines.availability answers a symbol and one
method words the refusal.
- The company keys of the session references, with a unique index on
terminal_sessions (id, company_id).
- The cleanup sends nothing while an op of the session is unfinished on
its machine (BaseRuntime#cleanup_ready?).
- An answered container.start refusal is a
ContainerRuntime::CreateRefusedError and pins no reservation;
RunnerRuntime::PullFailed is removed.
- The SessionContextService tests inject the runtime.
- The local runner's Dockerfile moves to docker/runner/local, and its
image is ${RUNNER_IMAGE:-runner}.
- DESIGN.md is updated.
Signed-off-by: Aixle Flow <[email protected]>
…lete key, and the enqueue leaves its transaction with next Fixes the Coder run of db88af2 found: the dumped schema orders the runner_environments keys the other way, the company-key test of runner_operations saved without the op's runner and company, and enqueue! returned from inside its transaction block. Signed-off-by: Aixle Flow <[email protected]>
added 2 commits
November 8, 2026 12:02
…ores them, and a runner stop during ContainerCreate answers a result - registryAuth maps docker.io and index.docker.io to https://index.docker.io/v1/, as the Docker CLI's getAuthConfigKey does. - container.start handles context.Canceled during ContainerCreate apart from the deadline: it removes what the daemon may have created and answers container_start_failed, with no nil dereference. - PROTOCOL.md §6: finished ops are kept 7 days, and sequence comes from the per-machine counter; §6.1 names the Docker Hub key. Signed-off-by: Aixle Flow <[email protected]>
… for any unfinished op, and the container name is the platform's - BaseRuntime: a runtime call is external I/O and is never made inside a database transaction; test/support/runtime_transaction_guard.rb fails a test that makes one inside an application transaction. - Sessions::SecretRegistry#publish! writes the list outside any transaction, serialized with a connection-level advisory lock. - RunnerRuntime#cleanup_ready? is false while any op is pending or delivered on the machine the session holds, env.reset included. - RunnerRuntime#create_container returns container_name(session); an answer naming another container is an error. - DESIGN.md §2.4/§5.3 and row 8a. Signed-off-by: Aixle Flow <[email protected]>
… NoMachine is never dispatched, and the transaction guard checks the whole runtime interface Signed-off-by: Aixle Flow <[email protected]>
…he round 7 docs and comments The host runner cuts a positive exec timeout to the seconds left until the op's deadline_at, as it already bounds an exec without one, so an exec never holds the serial ops loop past its op's deadline. DESIGN.md: row 8c says how a terminal log over 1 MiB is stored until 8c, row 11 notes the bounded removal of the scrub helper container. The transaction guard's and NEVER_DISPATCHED's comments say exactly what holds. Signed-off-by: Aixle Flow <[email protected]>
Contributor
Author
Fix CR round 7 (Alex, 2026-11-08)Commit:
No change, as Alex decided: the serial scanner budget, the Tests (Coder workspace
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix CR round 6 (Alex, 2026-11-08)
Commit:
d54eb55f(runner, platform, tests and docs). No schema change.container.start. EveryContainerRemoveincontainer.start's failure paths runs under a fresh context with its own timeout (Environment.RemoveTimeout, 30 s by default), derived withcontext.WithoutCancelso it keeps the context's values only. A stalled daemon can no longer hold up the serial host loop. A removal that fails (not-found counts as removed) is logged through the environment's logger and named in the answer's message. The answer stayscontainer_start_failed; the session still holds its machine, and the cleanup'senv.resetremoves what is left. Go tests: a remove that blocks returns within the timeout, and a remove that errors is logged; both answercontainer_start_failed.NoMachineis never dispatched.Runners::Machines::NoMachineis inAdmittedPhaseActivity::NEVER_DISPATCHED:acquire!raises it before any op exists, so the create operation isretryable, notuncertain. Test (RunnerSessionLaunchTest): the machine fails after the launch and beforecreate_container; the create fails with the runner-named message and the cleanup releases the admission at once, with nothing sent to the runner.mock("runtime")is not aBaseRuntime, and astubs(...)on a runtime sits on the singleton class in front of the check. This is stated in the guard's header. Mocha is not hooked. New guarded tests: a wholeSessionContextServiceassembly with a credential onFakeRuntime;Agents::CredentialDeliveryto a runner holder (RunnerRuntime+FakeHostRunner) and a hosted holder (FakeRuntime);Sessions::AuthPause#heal!with a renewal onFakeRuntime.CALLSisBaseRuntime.public_instance_methods(false)minusEXEMPT, which listscontainer_identifierandsession_identitywith their reasons (no I/O).image_digestandresolve_containerare now checked.session_identity,cleanup_sessionandsession_absent?, which every runtime already implemented andAdmittedPhaseActivitycalls on every runtime, are declared onBaseRuntime, so they stay checked.RuntimeTransactionGuardTestcompares the guard's list with the interface and checksimage_digestandresolve_containerinside a transaction.409 busy) and DESIGN.md §5.3: a machine unregistered during a session leaves that session's container running; the operator removes it by hand until scrub and return to service (tasks 11 and 13).No change:
SecretRegistry's blocking advisory lock (thread atsecret_registry.rb:72), as Alex decided.Tests (Coder workspace
aixle-prod-2c822a0f, checkoutd54eb55f, job0f88dc20cdc2, logs in/var/lib/aixle-jobs/runner-8a-fixcr6-d54eb55/)gofmt -l .(clean),go vet ./...,go test -race ./...,go mod tidy -diff: pass (01-go.log).rubocop --force-exclusionon the 8 changed.rbfiles: no offenses (20-rubocop.log).bin/vite build, then the whole Rails unit suite: 9897 runs, 0 failures, 0 errors with the guard active for every test (30-rails.log).Fix CR round 5 (Alex, 2026-11-08)
Commits:
585780cd(runner) and24df2bd3(platform and docs).registryAuthmapsdocker.ioandindex.docker.iotohttps://index.docker.io/v1/before the lookup, as the Docker CLI'sgetAuthConfigKeydoes. Go test: with{"auths": {"https://index.docker.io/v1/": …}}, a Hub reference (myorg/agent:1,docker.io/…,index.docker.io/…) sends those credentials toImagePull.ContainerCreate. Acontext.Canceledcreate removes whatever the daemon may have created and answerscontainer_start_failed("cut short");pastDeadline's nil is never dereferenced. Go test: the fake engine cancels the context once it has made the container and never answers;container.startreturns a result and nothing is left.sequencecomes from a per-machine counter. The prune bullet below is corrected, and this description now has Fix CR round 4 and 5 sections.BaseRuntimestates the contract for every runtime, hosted included: a runtime call is external I/O and is never made inside a transaction.Runners::Operations.enqueue!may still join a caller's transaction; waiting for the op's result inside it is what deadlocks.test/support/runtime_transaction_guard.rbprepends a check to everyBaseRuntimesubclass,FakeRuntimeincluded. A runtime call made while a joinable transaction is open is recorded, and the test fails at teardown. The test's own wrapping transaction is opened non-joinable, so it does not count. It is recorded rather than raised because the code under test may rescue what the call raises (SecretRegistrydoes).Sessions::SecretRegistry#publish!writes the list outside any transaction. A session's publications stay in order throughpg_advisory_lockbefore andpg_advisory_unlockinensure, on the same key.RuntimeTransactionGuardTest, andSecretRegistryRunnerTest, which publishes through a realRunnerRuntimeanswered byFakeHostRunner: thewrite_fileop completes before its deadline and the list holds the secret.SecretRegistryConcurrencyTeststill passes with the connection-level lock.RunnerRuntime#cleanup_ready?is false while anypendingordeliveredop exists on the machine the session holds, not only ops with itsterminal_session_id. Test: with anenv.resetpending, the cleanup is not ready until that reset expires or finishes, and nothing else is queued.create_containerreturnscontainer_name(session)(aixle-<key>-<session_id>). Acontainer.startanswer naming another container raises a plainRuntimeError, so the create stays uncertain and the cleanup still resets the machine. No new index and no new migration. Test: two sessions on two runners, and acontainer.startanswer naming the other session's container. The create fails, the session's later status and cleanup reach only its own machine, and the other session's container is untouched.Docs: PROTOCOL.md §6 and §6.1; DESIGN.md §5.3 (
create_container,cleanup) and row 8a.Run on Coder workspace
aixle-prod-2c822a0fat24df2bd3, logs in/var/lib/aixle-jobs/runner-8a-fixcr5-24df2bd/:gofmt -l .,go vet ./...,go test -race ./...,go mod tidy -diff, golang:1.27.3): pass (01-go.log).20-rubocop.log).bin/vite build, thenrails test): 9891 runs, 0 failures, 0 errors, with the transaction guard active for every test (31-rails-with-assets.log). A first run without the Vite build (30-rails.log) had 0 failures and 673 errors, all "Vite Ruby can't find … in the manifests".24df2bd3: all 17 checks pass.Fix CR round 4 (Alex, 2026-11-08)
Commits:
099eedf0(runner and the Dockerfile move),db88af2b(platform, migration and docs),945c5f43(fixes the first test run found).container.startruns the pull, the volumes,ContainerCreateandContainerStartundercontext.WithDeadline(op.DeadlineAt)and creates nothing past it. On the platform,BaseRuntime#cleanup_ready?letsRunnerRuntimeanswer false while an op is unfinished on the session's machine, so the cleanup returnscleanup_pendingand is retried.docker/cli'sLoadDefaultConfigFileandGetAuthConfig, credential helpers included, and passes them asImagePullOptions.RegistryAuth. With none, the pull is anonymous.ContainerRuntime::CreateRefusedErroris resolved inrecord_failed_operation;RunnerRuntime::PullFailedis removed. An expired create staysuncertain.runner_environments.op_sequence(migration20261108100000, backfilled), and the prune deletes every old finished op.ON DELETE CASCADEstays.enqueue!(…, session:)creates an op only while that session holds the machine, under the environment lock. This replaced the model validation, andacquire!no longer touches the caller's session.Machines.fail!(env, reason, holder:)is a compare-and-set;unregister!clears the hold;acquire!is idempotent for one session;Machines.availabilityanswers:available,:none_registeredor:all_failed.runner_operationsandrunner_environmentstoterminal_sessions (id, company_id).SessionHandler(ctx, sessionID, payload);WithOpSessionis removed.image: ${RUNNER_IMAGE:-runner}, and the Dockerfile isdocker/runner/local/Dockerfile.aixle-prod-2c822a0fat945c5f43(logs in/var/lib/aixle-jobs/runner-8a-fixcr4-945c5f4/): Go pass, migration with no schema diff, rubocop clean, 1307 Rails runs with 0 failures.Fix CR round 3 (Alex, 2026-11-07): the image is pulled as on Kubernetes, and
RunnerRuntimeis not bound to a sessionCommits:
f924a28f(runner),7aa55e31(platform and docs),80ea0c70and0dd88495(fixes found by the test run).RunnerRuntime#pull_imagedoes nothing, likeKubernetesRuntime#pull_image. The machine is taken increate_container.container.startalways pulls the reference, then creates and starts the container (Docker's create API does not pull). The pull runs after the cheap refusals (session_mismatch,container_exists), so a refused start pulls nothing. A failed pull isimage_pull_failed, with nothing created;image_not_foundis gone.image.ensureis removed everywhere:RunnerOperation::OPS,RunnerRuntime,FakeHostRunner,PROTOCOL.md(§6.1 is now "The agent image", which says howcontainer.startpulls),ops/image_ensure.json, the Go handler and its tests. The pull helpers moved torunner/internal/docker/image.go, andcontainer_start.jsongained animage_pull_failedcase.identity_before_pull?andpersist_identity_before_pullare removed.AdmittedPhaseActivityalready persisted the identity beforecreate_containerfor every runtime.RunnerRuntime::PullFailed(anImagePullError). The runner answers it only when nothing was created, sorecord_failed_operationtreats it as resolved and the cleanup releases the admission. Without this the create operation stayed pinned (unresolved_operation).create_containerbudget is 600 s (AgentSessionStrategy#phase_config). DESIGN.md §12.3 records this as a deliberate change to hosted: a larger timeout only.RunnerRuntimeis not bound to a session.RunnerRuntime.new(op_timeout:); one object serves any session.create_container(spec)takes the session from the spec'saixle.session_idlabel. A spec without it is refused before anything is sent.runtime_idits id is (runtime_kind = RunnerRuntime), whether that id is the cleanup identityrunner-session-<id>or the container's name. An id that no runner admission has answersno_session_containerand sends nothing.index_session_admissions_on_runner_runtime_id(runtime_id, runner admissions only), keeps that lookup off a table scan.op_timeoutstays a setting of the object.ContainerRuntime.for_sessionstill decides between a runner and hosted.cancellation.check!on every look, asToolStrategy#wait_with_heartbeatdoes. The op itself is left to its deadline.Runners::Operations.awaithas a comment: polling the database is to be revisited with P1 (DESIGN.md §16), for example with a wake-up on the pub/sub the long-poll uses.ContainerRuntime.for_sessionusessession&.runner_id.failed.Runners::Credentials.rotate!callsRunners::Machines.fail!(environment, "credential reuse detected"):failed, the reason instate_reason, held by no session. The DESIGN.md §2.2 note is updated. A new test shows that such a machine is not given a session.Docs: DESIGN.md §2.2, §2.4, §5.3 (both phase tables, the
for_sessionsnippet, the wait), the §6.4 op table, §6.8, §8, §12.3, and rows 6a and 8a.PROTOCOL.md§6, §6.1, §6.2 and §6.4.Tests (adapted):
runner_runtime_test.rbdrives one runtime across sessions through their admissions (FakeHostRunner.identify!). It adds a test of one runtime serving two sessions on two machines, a test of an unknown id, a test that the cleanup identity finds the session, and a cancellation test.runner_session_launch_test.rbnow has the pull failing incontainer.start, the capacity wait increate_container, and a stop before the create that takes no machine. There are also the contract test,AuthPause,ContainerRuntimeTest,AgentSessionStrategyTest(600 s) andCredentialsTest. In Go:container.startalways pulls (tag, digest, untagged as:latest), a failed pull creates nothing, and a refused start pulls nothing.Run on Coder workspace
aixle-prod-2c822a0f:80ea0c70, logs in/var/lib/aixle-jobs/runner-8a-fixcr3-80ea0c7/:gofmt -l,go vet ./...,go test -race ./...): pass.0994730dschema loaded,db:migrate, and the dumpeddb/schema.rbequals the committed one.test/docs,test/config): 1561 runs, 0 failures, 0 errors.0dd88495, logs in/var/lib/aixle-jobs/runner-8a-fixcr3-0dd8849/:test/services/container_runtime,container_runtime_test.rb,test/services/runners, the runner models, every Temporal activity, the runner launch, failed-machine, gateway, gateway-ops, conformance and container-workflow integration tests,HostedRuntimeUnchangedTest(§12.3),AgentSessionStrategyTestandAuthPauseTest): 794 runs, 0 failures, 0 errors.The open review threads of rounds 2 and 3 are untouched, as Alex asked.
Fix CR round 2 (Alex, 2026-11-07): the runtime is picked in one place and passed explicitly
This round is a refactor with no behaviour change. Commits:
db8d6534(the refactor) and0994730d(a test).The rule.
ContainerRuntime.for_sessionis the only place that picks a runtime. No runtime lives inThread.current, a global or class-level state. A runtime reaches the code that uses it as an argument or a constructor dependency.Places changed:
SessionContextServiceis one object per assembly,SessionContextService.new(container_id, session, runtime:). It holds the container, the session, its runtime and the context log.SessionContextService.assemble_session_contextis the thin entry point. It callsContainerRuntime.for_session(session)once and builds the object.Thread.current[:session_context_runner_runtime],Thread.current[:session_context_runtime],assemble_on_runnerandrunner_session?.container_idandsessionarguments, andinject_oauth_token!loses itssession.nil?guard, because the session is always there.Sessions::SecretRegistry.publish!in the MCP config step now gets the assembly's runtime instead of building its own.runtimeto each helper, because every helper that touches the container would otherwise take one more argument.AgentCredential#write_to_container(container_id, workflow_config = {}, runtime:):runtime:is required, and the method callsAgentCredentialsService.for(agent_type, runtime: runtime)with no conditional.ScanDeadContainersActivity,ScanNoOutputSessionsActivityandScanQuotaErrorsActivity:runtime_foris deleted. Each callsContainerRuntime.for_session(session, op_timeout: Settings.runners.scan_op_timeout)once per session and passes the result to the methods that use it.CleanupStaleActivity: the hosted-onlyruntimeis deleted, and the hosted path callsfor_sessionthe same way. Therunner_idbranch that moves a held machine tofailedstays (round 1, item 8).Agents::CredentialDeliverytakes each holder's runtime fromfor_session. Itsruntime:constructor parameter, unused since round 1, is removed.AdmittedPhaseActivity#persist_identity_before_pull: onlyidentity_before_pull?decides, and therunner_idcheck is gone. A hosted session's runtime is now built atpull_image. It answers false, so nothing is persisted there.RunnerRuntimerequirestemporalio/activity(the [Note] from verification round 1).session_context_service.rbline references indocs/project/context.mdanddocs/architecture/implementation-patterns.mdfollow the move.Reusing one hosted runtime: not measured on a cluster, chosen from the code.
DockerRuntimeholds no state, because it uses docker-api's process-wide connection. A runtime per session costs one allocation.KubernetesRuntimebuilds its Kubeclient clients lazily per instance, and a client's first call adds one discovery request (GET /api/v1). A runtime per session therefore costs the three per-minute scanners one extra small GET per hosted session per sweep, on top of the reads they already make.ContainerRuntimewould need process-level mutable state, which the rule excludes. So I chose one runtime per session per sweep. If the extra GETs matter, a cache belongs inKubernetesRuntime's clients, which is a hosted change outside this task.Tests.
Thread.currentnow build the assembly with its runtime.AgentSessionStrategyTest'sinject_credentialexpectations were dead, because that method is no longer on the class. They now expect a singleassemble_session_context.for_sessiongives.Run on Coder workspace
aixle-prod-2c822a0fat0994730d, with logs in/var/lib/aixle-jobs/runner-8a-fixcr2/:Runners::*, every Temporal activity, the runner launch, failed-machine, conformance and gateway tests,HostedRuntimeUnchangedTest(§12.3) andContainerWorkflowIntegrationTest: 675 runs, 0 failures, 0 errors.test/docsandtest/config: 1420 runs, 0 failures, 0 errors.The four review-round-2 threads stay open for Alex's decision.
Fix CR round 1 (Alex's decisions, 2026-11-07)
No digest (Alex's decision, replacing the platform-side pin):
Runners::ImagePinand its tests are deleted. The platform never contacts a registry, which also resolves the SSRF thread.image.ensure,container.startand the helper container ofenv.scrubtake{"image": <reference>}: the reference as the user gave it, a tag or a digest,container.image_overrideincluded (now forimage.ensuretoo, so the image pulled is the image started).pulledsays whether the pull brought a new image: the daemon did not have it, or the reference now names another image ID. A failed pull isimage_pull_failed, even with an older copy on the daemon. No op returns a digest. A reference with neither tag nor digest is read as:latest.PROTOCOL.md§6.1, §6.2 and §6.4, the fixtures, and DESIGN.md (§5.3, the §6.4 op table, §6.8, §7.2, rows 6a, 6b and 8a) are updated.bin/runner-localkeeps the note that the agent images must come from a registry.The fixes:
pull_image.AdmittedPhaseActivitypersistsRunnerRuntime's identity (runner-session-<id>,runtime_kind) beforepull_image(BaseRuntime#identity_before_pull?, true only forRunnerRuntime; a hosted session's runtime is not built there). Tests:image.ensurefails, and a stop betweenpull_imageandcreate_container. In both, the cleanup runscontainer.stopandenv.resetand the machine is free.ImagePin. Resolved by the deletion above.Runners::Operations.awaitstops at the op'sdeadline_atand expires the op.EXPIRY_GRACE(10 s) is only inexpire_overdue!, the sweep for ops nobody waits for. An op's deadline is at most the activity's end lessRunnerRuntime::ACTIVITY_MARGIN(5 s), so the activity acts on the expired outcome before Temporal times it out. A scanner pays exactlyscan_op_timeoutper unanswered op. Test:cleanup_sessionin an activity context with an unansweredenv.resetleaves the machinefailedwith the reason.AuthPause#heal!no longer passes its runtime. Each holder is written through its own runtime. Test: a hosted paused session and a runner holder of the same credential.docs/project/context.mdnow describes Docker'sexec!. DESIGN.md §12.3 records this deliberate change to hosted.batchinRunnerRuntime, and the session's identity is only in the envelope.RunnerEnvironment.stategetsfailed. A failed or unansweredenv.resetmoves the machine tofailed, clearscurrent_session_idand keeps the reason instate_reason, as text for people.Machines::RESET_FAILEDandreset_failed?are removed. A free machine isregisteredwith no session, so deleting the session frees nothing.session_absent?is true once the session holds no machine. A runner whose every machine isfailedfails the launch at once (Runners::ResolverandRunners::Machines). The message names the machines and their reasons and says how to bring one back:aixle-runner unregister, thenconfigure. Thecapacity_waitmessage counts onlyregisteredmachines. The gateway still accepts afailedmachine's credentials (test). Regression test:test/integration/runner_failed_machine_test.rbfailsenv.reset, releases the admission, deletes the session throughDELETE /api/v1/terminal_sessions/:id, and shows that no other session can take the machine.CleanupStaleActivitysends a runner nothing. If a stale runner session still holds a machine, the machine moves tofailedwith "held by stale session " and the move is logged. Tests cover a session with a machine and one without.session_mismatchfrom the lifecycle ops.RunnerRuntimesends an op only while the session holds its machine (runner_environments.current_session_id). Otherwise it answersno_session_containeritself and enqueues nothing. On the Go side,container.stopwithout this session's container answerssession_mismatch(another session's container) orno_session_container(none).container.startover another session's container answerssession_mismatch, and over its own container or an unlabelled leftover it answerscontainer_exists.cleanup_sessionlogs a failedcontainer.stopand goes on toenv.reset.RunnerRuntime#stop_containertreatsno_session_containeras already stopped, as Docker does.PROTOCOL.md§6 and §6.2, the fixtures and the Go tests are updated, includingTestASessionOpOfAnotherSessionIsRefused.Fix CR round 1 tests: on Coder workspace
aixle-prod-2c822a0f, logs in/var/lib/aixle-jobs/runner-8a-fixcr1/:go:gofmt -l .,go vet ./...andgo test -race ./...pass.test/services/container_runtime,test/services/runners, the runner launch, failed-machine, gateway, conformance and selection integration tests,HostedRuntimeUnchangedTest,AuthPause,CleanupStaleActivity, the sweep, the runner models): 451 runs, 0 failures.ContainerWorkflowV2with history replay, admission,test/config,test/docs, the terminal-sessions API): 1503 runs. 1498 passed. The other 5 were image-name assertions inAgentAuthStrategyTest, which failed because a previous run had leftAGENT_IMAGE_PREFIXin the workspace's.env. With that line removed, the file passes on its own: 56 runs, 0 failures.Summary
Board task #207, Runners 8a:
RunnerRuntimeand the op path,session_idin the op envelope, and the devlocaladapter. Design:docs/design/agent-runtimes/DESIGN.md§15 row 8a.What changed
ContainerRuntime.for_sessionandRunnerRuntime(§5.3)ContainerRuntime.for_session(session)gives a session with a runnerContainerRuntime::RunnerRuntime. Every other session getsContainerRuntime.build, unchanged.BaseStrategy#runtime(and#resolve_container) andAdmittedPhaseActivity(create and cleanup);SessionContextService, and the credential write it makes, which passes the runtime toAgentCredentialsService;Sessions::LiveLogReader,Sessions::AuthPause,Sessions::SecretRegistry,Trackers::WorkspaceandAgents::CredentialDelivery;ScanDeadContainersActivity,ScanQuotaErrorsActivity,ScanNoOutputSessionsActivityandCleanupStaleActivity.ContainerSweepOrphanedResourcesActivitysweeps the hosted runtime's own objects, so it is unchanged.RunnerRuntimeenqueues the op withRunners::Operations.enqueue!and waits for its result withRunners::Operations.await, which heartbeats the activity. It then answers whatDockerRuntimeanswers.errororexpiredgives the strategy what a hosted failure gives:ContainerUnreachableErrorfromexec!without the session's container, exit code 1 fromexec,falsefromwrite_file,nilfromread_file,:missingfromcontainer_status.batchgrouping (decision 5).deadline_atis at most the end of the activity that sends it, less 5 s. The wait stops at the deadline and expires the op. Inside that, each op has its own budget:exec: itstimeout+ 30 s;Settings.runners.op_timeout, 60 s, which is whatDockerRuntime#execwaits by default;lifecycle_op_timeout, 600 s.scan_op_timeout(15 s). A machine that does not answer reads as unknown, never as dead or idle, and cannot hold up the hosted sessions' sweep.pull_imagedoes nothing (Fix CR round 3).create_containertakes a free machine and sendscontainer.start, which always pulls the image reference as given, a tag or a digest (Fix CR round 1: no digest).create_containersendscontainer.start. See "Decisions to review" for why it is here.start_containerandwait_for_readywait forstatusrunning.cleanupcollects the logs and outputs through the same strategy code, then sendscontainer.stopandenv.reset, then frees the machine.config.container(§2.7). Its resources are the hosted container's limits unlesscontainer.resourcessets them.Runners::Resolverno longer refuses withrunner_execution_not_enabled. A runner with no registered machine is refused at launch withrunner_unreachableand a message that names the runner.DockerRuntime#exec!raisesContainerUnreachableErrorfor a container the daemon does not know. Before, it raisedNoMethodErroronnil. The contract test's "exec!with no container" scenario needs this.Which machine takes the session (decision 2):
Runners::Machinesregisteredmachine of its runner, one session per machine. The machine is taken under its row lock (FOR UPDATE SKIP LOCKED).terminal_sessions.runner_environment_idand inrunner_environments.current_session_id(unique). The second one is the hold.ContainerRuntime::CapacityError, so the session waits incapacity_wait.env.resetand is free again.failed, held by no session, with the reason instate_reason, so it takes no other session (Fix CR round 1). The session's reservation is still released.session_idin the op envelope (requirement 1)runner_operations.terminal_session_id.session_idonly for session ops.session_idleft the payloads ofcontainer.startandcontainer.stop.session_idfrom the envelope:session_required;aixle.com/sessionlabel is refused withsession_mismatch, and the container is not touched;container.startnames and labels the container from the envelope.PROTOCOL.md§5.4 and §6 are updated, and the §8 item is removed. The fixtures have the newsession_on_machinesetup step, implemented by both harnesses.The queue's housekeeping
deadline_at;RunnerOperationsSweepWorkflow, every 5 minutes, for ops nobody waits for, 10 s past theirdeadline_at,pendingordelivered.enqueue!takes the next sequence fromrunner_environments.op_sequence, on the row it already locks.Runners::Operations.prune!deletes everycompleted,failedandexpiredop older than 7 days, the newest included, and a session's deletion takes its ops with it (ON DELETE CASCADE). The counter never goes back, sosequencekeeps growing after a prune.The dev
localadapter (§12.2)runner-localCompose service, under therunnersprofile, buildsaixle-runnerfromrunner/(docker/runner-local/Dockerfile).127.0.0.1:4003, the only addressaixle-runneraccepts plain http on. It uses this machine's Docker socket.bin/runner-local register <runner id>mints a registration token, runsconfigureand starts the service.bin/runner-local unregisterandbin/runner-local logsalso exist.Docs:
PROTOCOL.md,fixtures/README.mdandDESIGN.md:session_idin the envelope;Decisions to review
container.startis sent increate_container, not instart_container. The container's environment holds the session's secrets: session keys, the VS Code token, credential-sync keys. It exists only in the create phase, becauseContainerService::CREATE_ONLY_KEYSdrops it from the phase state, which Temporal history and the admission record persist. So the runner creates and starts the container in that one op, the way a Kubernetes pod is created running.start_containerthen waits for nothing more than the container running. A retried create that finds its own container running adopts it.create_container(Fix CR round 3), the first phase that needs it, sincecontainer.startpulls the image there.The image is pinned on the platform.Fix CR round 1 replaced this with Alex's decision: no digest, and the runner always pulls the reference it is given. For the devlocaladapter, point the agent images at a registry, for exampleAGENT_IMAGE_PREFIX=ghcr.io/aixlehq/flow-.409 busyonDELETE /registrationis not built. It is not in 8a's scope list. A machine unregistered during a session leaves the session's next ops unanswered until they expire.PROTOCOL.md§8 says so.What answers
RunnerRuntime's ops in the tests, and whyContainerRuntime::FakeHostRunner(test/support/fakes/fake_host_runner.rb) subscribes toenqueued.runner_operations. It answers each op on the machine's real queue the moment the op is enqueued, throughRunners::Operations.record_result!, with the resultPROTOCOL.md§6 specifies. It answers from an in-memory machine (FakeMachine).RunnerRuntimetalks to: the queue and the op results. The gateway's HTTP is covered byRunnerGatewayOperationsTestand the conformance fixtures. The Go runner's Docker calls are covered by its own tests.test/services/container_runtime/runner_runtime_contract_test.rb),DockerRuntimeruns unchanged, through docker-api, against the Docker Engine API.FakeDockerEngineserves that API over WebMock from the same machine. Each scenario runs on both runtimes, and the strategy must get the same result:execwith a non-zero code;exec!with no container;Sessions::LiveLogReaderreading a live and a gone container.How was this tested?
bin/rails test test/services/container_runtime test/services/container_runtime_test.rb test/services/runners test/integration/runner_session_launch_test.rb test/integration/hosted_runtime_unchanged_test.rb test/integration/runner_protocol_conformance_test.rb test/integration/runner_gateway_operations_test.rb test/temporal/activities/runner_operations.cd runner && gofmt -l . && go vet ./... && go test -race ./....manualrunner in a company withexternal_runnerson.AGENT_IMAGE_PREFIX=ghcr.io/aixlehq/flow- make up, thenbin/runner-local register <runner id>.Run on a Coder workspace (
aixle-prod-2c822a0f, earlieraixle-prod-ee0c28d5), in thewebimage of this branch:go:gofmt -l .,go vet ./...,go test -race ./...inrunner/(golang:1.27.3). All passed.bin/rails db:migrateon the develop schema. The dumpeddb/schema.rbmatches the committed one.bundle exec rubocop --force-exclusion <changed .rb files>. No offenses.SessionContextService, the sessions services, the internal tools, the trackers, every Temporal activity,ContainerWorkflowV2and the history replay, the container runtimes,Runners::*, the runner gateway and conformance,HostedRuntimeUnchangedTest, the runner selection and launch tests, the admission services,test/configandtest/docs. 1904 runs, 0 failures, 0 errors. CI runs the full suite.Related issues
Board task #207 (Runners 8a). The next parts are 8b (the callback proxy) and 8c (the live log and parity with hosted).
Type of change
Checklist
git commit -s).[Unreleased]in CHANGELOG.md. There is none: runner execution is behindexternal_runners, which only the test company has, as for the earlier runner tasks.