Skip to content

feat(runners): the callback proxy — the proxy sidecar, the host runner relay and the gateway proxy route (task #216, 8b) - #677

Merged
NOX73 merged 34 commits into
developfrom
feature/runners-8b-callback-proxy
Nov 11, 2026
Merged

NOX73 merged 34 commits into
developfrom
feature/runners-8b-callback-proxy

Conversation

@NOX73

@NOX73 NOX73 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Task #216, row 8b of the external runners design (docs/design/agent-runtimes/DESIGN.md §6.6, §6.9.3, §15): the callback proxy. An agent on a manual runner can now reach MCP (finish_session included), the agent credential sync and refresh, git credentials (GitHub, GitLab, Bitbucket, Azure DevOps), cloud credentials and stored files through a proxy on 127.0.0.1 next to it. Before this, a runner session started but could not call the platform.

Go (runner/)

  • aixle-runner --mode proxy is the sidecar (internal/proxy.RunSidecar). It is a reverse proxy on 127.0.0.1:7690 that relays to the host runner's Unix socket and holds no credential.
  • The relay (proxy.Relay, served by proxy.Host) has a socket per session in <state dir>/proxy/<session>/, mounted read-only into that session's sidecar only. It serves /runner/v1/proxy/* and nothing else (404 not_proxied). It drops the agent's Authorization and X-Aixle-Runner-* headers, adds the machine's access token, refreshes once on invalid_token, and streams the answer back chunk by chunk.
  • container.start opens the relay, then creates the sidecar from the agent image, with the host runner's own binary bind-mounted read-only as its entrypoint. The sidecar runs as 65534:65534 with every capability dropped, no-new-privileges and a read-only root filesystem. The agent container then joins the sidecar's network namespace (NetworkMode: container:<sidecar>).
    • With network: host no sidecar is created. The host runner listens on the payload's proxy_port on the machine's 127.0.0.1 instead.
  • container.stop removes the agent's container, then the sidecar, and closes the relay. env.scrub and env.reset remove sidecars along with the environment's other containers and close every relay. A restarted host runner serves the running sidecars again (Environment.Resume).
  • Decision 10: when a sidecar exits and the host runner did not remove it, the host runner stops the agent's container, so the session fails through the existing dead-container path. It also logs the sidecar's exit code and the last 50 lines of its log.
  • Decision 4: when the daemon refuses the sidecar's bind mount ("bind source path does not exist"), container.start fails with docker_files_not_visible. The message names the paths and the cause (a remote DOCKER_HOST, or a daemon that runs elsewhere).
  • Conformance: the Go test now fails for a fixture that drives no exchange, unless the fixture is on gatewayOnly with a reason. No fixture is on that list.

Platform

  • The gateway route ANY /runner/v1/proxy/:route/* (RunnerGateway::V1::ProxiesController) checks, in order:
    1. the environment credential;
    2. the allow-list (Runners::Proxy::ROUTES, decision 7; there is no OTLP route yet);
    3. that the session key belongs to the session that holds this environment (Runners::Proxy.holder).
  • The forward (decision 8): the request goes to the internal endpoint over HTTP, unchanged, with X-Aixle-Runner-Environment added. The answer is streamed back with ActionController::Live.
  • No body schema (decision 9). Every refusal on this route carries X-Aixle-Runner-Refusal, so the runner can tell the gateway's own refusals from the endpoint's answers.
  • The callback URL seam (decision 6): runtime.callback_url(name, session) (ContainerRuntime::CallbackUrls). Hosted runtimes return the Settings value unchanged. RunnerRuntime returns http://127.0.0.1:<port>/<route>.
    • Every caller listed in the task reads through it: the env vars, the MCP config, the asset URLs (ContainerAssetUrl now supports a host with a path), read_tool_result, and the OTLP endpoint of the agent configs.
    • RunnerRuntime does no string replacement.
  • No OTLP for runner sessions (decision 7): Claude and Gemini telemetry is off, Codex gets no [otel] block, and Kiro gets KIRO_DISABLE_TELEMETRY, because without an endpoint its export falls back to the vendor's collector.

Docs

  • runner/protocol/PROTOCOL.md §5.6 describes the proxy: route, port, socket, headers, refusals, and no body schema. §6.2 and §6.4 describe the changed container.start, container.stop and scrub. The fixtures are in fixtures/v1/proxy/, with the new setup steps session_holds_machine and upstream_answers.
  • DESIGN.md: row 8b is marked done, §6.6, §6.9.3 and §12.3 now match the code, and the OTLP route is listed as deferred.

For review

  • The network: host port is per session, not per environment. It is 20000 + session id mod 10000, sent as proxy_port. The strategy builds the container's environment before the session takes a machine, so the address cannot depend on the machine. If two network: host sessions on one machine collide on the port, the second fails with proxy_port_in_use.
  • The dev local adapter now keeps its binary and state in RUNNER_LOCAL_DIR (default /tmp/aixle-runner-local), a host directory mounted at the same path, so the daemon can resolve the sidecar's bind mounts. A machine registered before this change must run bin/runner-local register again.
    • With network: host, the local adapter's listener runs in web's network namespace, not the machine's, so that case needs a real machine.

Related issues

Board task #216 (Runners 8b).

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / chore
  • Breaking change

How was this tested?

  • Go: gofmt -l ., go vet ./..., go test -race -count=1 ./... and the linux/amd64 and arm64 builds all passed. New tests are in internal/proxy/proxy_test.go and internal/docker/proxy_test.go; the conformance test was extended.
  • Rails: the new tests are test/integration/runner_gateway_proxy_test.rb, test/services/runners/proxy_test.rb and test/services/container_runtime/callback_urls_test.rb. The §12.3 hosted-unchanged test, the strategy, adapter, ContainerAssetUrl and conformance tests were extended.
  • A manual check on real Docker: a sidecar ran as 65534:65534 with a read-only root filesystem and every capability dropped, with the socket directory mounted read-only. A container that joined its network namespace reached the relay through 127.0.0.1:7690, and the path, query, escaping, headers and body arrived unchanged.

Checklist

  • I read CONTRIBUTING.md.
  • All my commits are signed off for the DCO (git commit -s).
  • I have signed (or will sign) the CLA when the bot prompts me — or my
    organization has executed the Corporate CLA.
  • make check_all passes locally (tests, rubocop, brakeman, eslint, typescript).
  • I added/updated tests where it makes sense.
  • I updated documentation where it makes sense.
  • User-visible changes have an entry under [Unreleased] in CHANGELOG.md. (No entry: external runners are behind the external_runners flag, and the earlier runner tasks added none either.)
  • My commits use clear, descriptive messages.

Comment thread runner/internal/proxy/host.go Resolved
Comment thread runner/internal/proxy/proxy.go Resolved
Comment thread app/services/runners/proxy.rb Resolved
Comment thread app/services/runners/proxy.rb Resolved

@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.

Changes requested, with 2 [Must] items, both inline:

  • runner/internal/proxy/host.go:69: OpenSocket deletes the bind-mounted socket directory, so a host-runner restart cuts the running sidecars off from their relay.
  • runner/internal/proxy/proxy.go:90: the relay's prefix check lets dot segments through, with the machine's bearer token attached.

The rest is in line with the task's decisions and the project's conventions. That covers the callback URL seam at every call site, the allow-list, the key-to-holder check, no body schema, the docs and the fixtures. There are also 1 [Recommendation] and 2 [Note] comments inline.

Comment thread runner/internal/docker/proxy.go Resolved
Comment thread runner/internal/docker/proxy.go Resolved
Comment thread runner/internal/proxy/host.go Resolved
…bound body reads (task #216)

- OpenSocket keeps the session's socket directory across a restart and
  replaces only relay.sock, so a running sidecar's bind mount reaches it.
- The relay refuses empty, . and .. segments after decoding, and an
  encoded / or a backslash, as not_proxied.
- Resume stops the agent's container when a relay or a network: host
  listener cannot be served again, so the session fails.
- The relay and the sidecar read a request body within 30 s
  (408 body_timeout); the answer stays unbounded.

Signed-off-by: Alex <[email protected]>
…s in the gateway proxy (task #216)

- Drop the headers a Connection header nominates, on requests and answers.
- Release the Active Record connection before the forward.
- Rescue ClientDisconnected, close the stream and log at info.
- One MCP key lookup (MCP::SessionKey.lookup) for MCPController and
  Runners::Proxy, and each key's header as its SessionKey module's HEADER.
- Say why the assets route is safe only on dev-only filesystem storage,
  and how proxied calls take gateway threads.

Signed-off-by: Alex <[email protected]>
…time (task #216)

callbacks: and otel_endpoint: are required, and the adapters no longer fall
back to the hosted values. Callers that mean hosted pass them explicitly.

Signed-off-by: Alex <[email protected]>
…ll (task #216)

After a failed body read the read deadline stays, so the server's drain of
the unread body fails at once and the 408 goes out. The sidecar opens a
connection to the relay socket per call, so a replaced relay is reached on
the next call.

Signed-off-by: Alex <[email protected]>
Comment thread app/services/runners/proxy.rb Resolved
Comment thread runner/internal/proxy/proxy.go Resolved
Comment thread app/services/agents/base_adapter.rb Resolved
…-callback-proxy

Resolved per Alex's decisions (task #216, comment 72539):
- PROTOCOL.md: develop keeps §5.6 (releases) and §5.7 (checksums); the
  callback proxy becomes §5.8, and every reference to it is updated.
- HostOptions.Binary has one meaning: the runner's own executable, symlinks
  resolved, which a self-update replaces and the proxy sidecar runs. One
  resolver (update.BinaryPath); ownBinary is dropped.
- main.go: the host/proxy mode switch, with host still passing NoSelfUpdate.
- client.go: develop's do/newRequest and the branch's Proxy with its own
  non-redirecting client.
- conformance_test.go: both harness changes; the protocol-header presence
  checks apply to the proxy fixtures too.
- routes, process-mode route test, fixtures README and DESIGN.md: both sides.

Signed-off-by: Alex <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 10, 2026
aixle-com[bot]
aixle-com Bot previously approved these changes Nov 10, 2026

@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 round 4 at 70ee7094: approved. I reviewed the Fix CR round 3 commits (27963f57, bd4aad58, 50e10e3c, a8f193b6) and the conflict resolutions of the develop merge against Alex's decisions in task #216 (comments 72129 and 72539). I found nothing that needs a review comment. CI passes all 17 checks.

Comment thread runner/internal/docker/proxy.go Resolved
@aixle-com
aixle-com Bot dismissed their stale review November 10, 2026 18:48

Approval withdrawn

RunHost returned to polling after a failed Environment.Resume, and nothing
called Resume again. It now returns the error, a plain failure rather than
ExitStop, so systemd (Restart=always) restarts the runner until Docker
answers.

Signed-off-by: Alex <[email protected]>
sidecarExited read the log tail first, with no deadline of its own, so a
stalled logs endpoint could keep the agent running. The agent is stopped
first, and the tail is read under SidecarLogTimeout. Resume logs the real
exit code of a stopped sidecar that is still there.

Signed-off-by: Alex <[email protected]>
A malformed percent escape, or octets that are not UTF-8, in a proxy path
are refused as route_not_allowed instead of raising. The controller skips
Rails' path parameter encoding check so such a path reaches the allow-list.

Signed-off-by: Alex <[email protected]>
An API controller has no ParameterEncoding table of its own, so
skip_parameter_encoding needs setup_param_encode first. The gateway test
sends malformed triplets through PATH_INFO, since the test client refuses
them in a URL. gofmt the Environment struct.

Signed-off-by: Alex <[email protected]>
The restart retry through the service manager, the sidecar-exit order and
log deadline, and the strict decoding of proxy paths.

Signed-off-by: Alex <[email protected]>
Comment thread app/services/runners/proxy.rb Resolved
aixle-com[bot]
aixle-com Bot previously approved these changes Nov 10, 2026

@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.

Round 5 (head 81da93f): the three round 4 findings are fixed as Alex decided, and tests cover them. I left one non-blocking [Recommendation] (a raw non-ASCII path segment still gets a 500, and a code comment's claim about the Go relay is inaccurate). No [Must] findings.

Comment thread runner/internal/protocol/client.go Resolved
Comment thread runner/internal/proxy/proxy.go Resolved
Comment thread runner/internal/docker/proxy.go Resolved
Comment thread runner/internal/proxy/host.go Resolved
@aixle-com
aixle-com Bot dismissed their stale review November 10, 2026 21:22

Approval withdrawn

- watchSidecar: a wait result with an error is a failed wait; inspect and wait again
- the host runner narrows its state directory to 0700 at start, or needs an operator
- the relay logs the route without the query, and a transport failure without its URL
- settings_problems refuses a host port range that includes an image port
- Route#allows? refuses a raw octet outside ASCII as route_not_allowed

Signed-off-by: Alex <[email protected]>
aixle-com[bot]
aixle-com Bot previously approved these changes Nov 11, 2026

@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 round 6 (head 9a806e8f): each of the six round 5 decisions is done as decided, with tests. This round adds no PR comments. The details are in the board comment on task #216.

@aixle-com
aixle-com Bot dismissed their stale review November 11, 2026 07:54

Approval withdrawn

@NOX73
NOX73 merged commit 08f5663 into develop Nov 11, 2026
17 checks passed
NOX73 added a commit that referenced this pull request Nov 11, 2026
…s-0-1-0

* origin/develop:
  feat(coder): clone GitLab, Bitbucket and Azure DevOps repos in coder_prepare_repo (#703)
  fix(agents): show each runtime's own logo everywhere (#704)
  feat(teams): assign cards to a team and run triggers as a team (#701)
  feat(agents): collect the Copilot CLI transcript as a session log (#700)
  fix(agents): keep Grok and Antigravity conversations in the terminal scrollback (#698)
  feat(billing): redesign the Billing tab around active and previous subscriptions (#646)
  feat(web): switch the UI, admin, public pages and emails to Inter (#699)
  chore(deps): weekly dependency batch — aws-sdk-core 3.267 retry fix, prism 2, Mantine 9.7.5, runner Go 1.27.4 (#697)
  fix(board): leave archived tasks out of agent board listings (#690)
  feat(agents): add GitHub Copilot CLI as an agent runtime (#684)
  feat(runners): the callback proxy — the proxy sidecar, the host runner relay and the gateway proxy route (task #216, 8b) (#677)

Signed-off-by: Rozhnov Alexandr <[email protected]>
aixle-com Bot pushed a commit that referenced this pull request Nov 11, 2026
Conflicts were between staging's feature-branch merges of #677, #684 and an
earlier head of #689 and develop's squash-merges of #677/#684 (plus #700,
#704). Each hunk takes develop's side (the final, reviewed version), except
config/settings.yml, which keeps the runners.release block of #689, and
CHANGELOG.md, which keeps both sides' entries. Staging-only content (#494)
merged without conflict and is kept.
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