Skip to content

feat(roadmap): a loopback gateway broker in the job process #3820

Closed

Description

@dan-petty

Problem

The implement step shell cannot call devops ai rag-query or devops review, because the shell has no gateway key. A key in the shell would undo #2667: the job process holds the key and is not dumpable, so the shell cannot read it. #3563 proposed a Caddy broker, which cannot work: execve sets the dumpable flag to 1 again, and the shell has the same user as the broker, so it could read /proc/<pid>/environ.

Expected

A loopback proxy that runs inside the job process (already non-dumpable, already holds the key) forwards only an exact allowlist of method and path pairs to the gateway. A per-step token dies with the step. The shell receives the proxy address and the token, never the gateway key.

Acceptance criteria

  • A test: a request with the step token to an allowed method and path reaches the recorded gateway.
  • A test: a request to any other path or method, or with another token, is refused.
  • A test: the token stops working when the step ends.
  • A test: the environment and arguments of the shell hold no gateway key.
  • The change names the allowed paths and says how a shell call counts against the step budget and tier accounting. /chat/completions and /embeddings are the same endpoints as the model of the agent, so the decision is part of this item.

Existing tool considered

The project already depends on fastapi, uvicorn and httpx2 (pyproject.toml). Use them for the proxy. No new binary, no Caddy in the runner image.

Related

Split from #3563 (comment of 2026-11-06). Related: #3041, #2667. Items B and C of the same split give rag-query and devops review their other needs.

Proposed design

Problem statement

The implement step shell cannot call devops ai rag-query or devops review because it has no gateway key. A key in the shell would expose it, and a Caddy broker cannot protect it. The item adds a loopback broker inside the job process. The broker holds the key, forwards only two exact gateway endpoints, and gives each step a token that dies with the step.

Acceptance criteria

Requirement: Loopback-only broker

The broker MUST bind only to the loopback interface.

Scenario: Non-loopback address is refused

  • WHEN The job process configures the broker with an address that is not a loopback address.
  • THEN The broker refuses to start and reports the invalid address.

Requirement: Allowed request reaches gateway

The broker SHALL forward an allowed request from a step to the recorded gateway.

Scenario: Allowed request

  • WHEN A step sends POST /chat/completions with its step token to the broker address.
  • THEN The broker sends the request to the recorded gateway with the gateway key and returns the gateway response to the step.

Requirement: Exact method and path allowlist

The broker MUST forward only the exact method and path pairs POST /chat/completions and POST /embeddings.

Scenario: Other path or method

  • WHEN A step sends a request to another path, or sends a method other than POST to an allowed path, with a valid step token.
  • THEN The broker returns a refusal and sends no request to the gateway.

Requirement: Step token required

The broker MUST refuse a request that does not carry the current step token.

Scenario: Wrong token

  • WHEN A step sends a request to an allowed path with a token other than the current step token.
  • THEN The broker returns a refusal and sends no request to the gateway.

Requirement: Token dies with the step

The broker MUST reject the step token after the step ends.

Scenario: Token after step end

  • WHEN The step has ended and a request uses the token that the step held.
  • THEN The broker returns a refusal and sends no request to the gateway.

Requirement: No gateway key in shell

The job process MUST NOT put the gateway key in the environment or arguments of the step shell.

Scenario: Shell environment and arguments

  • WHEN The job process starts a step shell.
  • THEN The environment and arguments of the shell hold the broker address and the step token, and hold no gateway key.

Requirement: Shell call accounting

A shell request through the broker SHALL count against the step budget and tier accounting as a model call of the agent.

Scenario: Budget and tier record

  • WHEN A shell call through the broker returns a gateway response with usage.
  • THEN The step budget and the tier accounting record the call with the same usage and tier as a model call of the agent.

Existing Tool Considered

No alternatives check has run. The project already depends on fastapi==0.142.2, uvicorn==0.53.0 and httpx2==2.13.1 (pyproject.toml). These open, maintained libraries cover the loopback server and the upstream client. They lack a per-step token and an exact method and path allowlist. The change adds a small broker module of about 150 lines and 7 tests. Its estimated build cost is 8,000 tokens and 2 hours. Keep cost is low because the libraries carry the HTTP work. No new binary and no Caddy.

Key questions

  • Which exact method and path pairs does the broker allow?: Allow only POST /chat/completions and POST /embeddings. These are the gateway endpoints that devops ai rag-query and devops review need. (best practice) [sources: tests/ai/client/test_ai_client_providers_and_embeddings.py, tests/ai/rag/test_embedding_providers.py]
    • Chosen: POST /chat/completions and POST /embeddings. The item names these two endpoints, and they are the model endpoints of the agent.
    • Rejected: A prefix such as /v1/*. A prefix lets the shell reach unrelated gateway routes.
    • Rejected: Only POST /chat/completions. devops ai rag-query needs embeddings.
  • How does a shell call count against the step budget and tier accounting?: Count it as a model call of the agent. Use the gateway response usage and the same tier as the agent's model call. (best practice) [sources: CONTEXT.md, tests/ai/client/test_ai_client_telemetry.py]
    • Chosen: Same as an agent model call. The endpoints are the same, so one budget and one tier record avoid double counting or hidden spend.
    • Rejected: A separate tool budget. It splits one cost across two records and hides spend from the step budget.
    • Rejected: No accounting. It lets shell calls spend without a budget or tier record.
  • How does the shell receive the broker address and the step token?: Set the broker URL and the per-step token as environment variables for the step shell. Keep the gateway key in job-process memory only. (best practice) [sources: CONTEXT.md, src/devops_cli/roadmap/implement/implement_shell_policy.py]
    • Chosen: Environment variables. The shell can read them, and they die with the step process.
    • Rejected: Command-line arguments. Arguments are visible in process listings and can leak the token.
    • Rejected: A file in the worktree. The file can persist after the step and can be read by later steps.
  • How does the broker revoke the step token?: Create a random token per step, keep it in job-process memory, and delete it when the step ends. The broker accepts only the live token. (best practice) [sources: src/devops_cli/roadmap/implement/implement_shell_policy.py, CONTEXT.md]
    • Chosen: In-memory per-step token deleted at teardown. It dies with the step and leaves no file or process to read later.
    • Rejected: A token in a file deleted at teardown. A crash can leave the file behind.
    • Rejected: A long-lived token. It outlives the step and breaks the per-step limit.
  • Which libraries run the loopback server and send the upstream request?: Use FastAPI and uvicorn for the loopback server and httpx2 for the upstream request. The project already depends on them. (best practice) [sources: pyproject.toml, src/devops_cli/server/app.py, src/devops_cli/ai/mcp/remote.py]
    • Chosen: FastAPI, uvicorn and httpx2. The project already depends on them, and they cover the server and client.
    • Rejected: A Caddy sidecar. execve sets the dumpable flag, and the shell shares the user, so it can read /proc/<pid>/environ.
    • Rejected: A new socket server. It adds code and tests that the existing libraries already cover.
  • Where does the broker listen?: Bind 127.0.0.1 on an ephemeral port in the job process. Reject any bind on a non-loopback address. (best practice) [sources: CONTEXT.md, src/devops_cli/server/app.py]
    • Chosen: Loopback ephemeral port. Only the step on the same pod can reach it, and the port needs no fixed allocation.
    • Rejected: A Unix domain socket. The item asks for a loopback proxy, and HTTP clients expect a URL.
    • Rejected: A fixed port on the pod IP. Other pods can reach it, and the port can conflict.
  • How does the broker authenticate to the gateway without exposing the key?: The job process reads the gateway key into memory. The broker adds it to the upstream request and never writes it to the shell. (best practice) [sources: CONTEXT.md, src/devops_cli/roadmap/implement/implement_shell_policy.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-08: in-use.
The item already names this tool.
Tool: fastapi/fastapi (https://github.com/fastapi/fastapi), MIT, last activity 2026-11-08, maintained.

Activity

  1. added
    source/agent
    type/feature
    scope/roadmap
    status/new
    value/high
    effort/medium
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. It is a planned feature that maintains a security property but is not a regression or active exploit.
    • Value: High. Without it the implement shell cannot call rag-query or devops review at all.
    • Effort: Medium. It needs a proxy, an allowlist, a per-step token, and four tests, but reuses fastapi, uvicorn, and httpx already in the project.
    • Related: feat(roadmap): allow scoped review and RAG calls from the implement shell #3563, which asks for a different change. Both target the implement shell's gateway access; #3563 is the umbrella, and the candidate is the specific loopback-proxy part of that split.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 7, 2026
  5. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 8436734 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: No search turned up a ready-made broker with per-step tokens: the proxy projects found (mitmproxy, proxy.py, LiteLLM proxy) run out of process and bring no step-scoped token, key isolation or budget accounting. The libraries the issue already depends on do cover the generic half of the need — FastAPI/uvicorn serve the loopback endpoint and enforce exact method/path routing, and httpx2 sends the upstream request — so they cover part of it, while the per-step token, its revocation at step end, the gateway-key handling and the budget/tier accounting stay project code.

    The item already names this tool.

    Tool: fastapi/fastapi (https://github.com/fastapi/fastapi)

    • License: MIT
    • Last activity: 2026-11-08
    • Maintained: yes

    Covers:

    • Serves the broker over HTTP on 127.0.0.1 with an ephemeral port in the job process (uvicorn)
    • Exact method and path matching by route declaration: only POST /chat/completions and POST /embeddings exist, other paths and methods are refused before the handler runs
    • A request dependency can check the step token header and refuse the request before it is forwarded
    • httpx2 (already a dependency) sends the allowed request to the recorded gateway with the key held in job-process memory

    Lacks:

    • No per-step token: issuing a random token per step, keeping it in memory and revoking it at step teardown is project code
    • No gateway-key isolation or shell environment/argument handling; the broker must add the key to the upstream request itself
    • No budget or tier accounting that records a shell call as a model call of the agent
    • No loopback-only bind guard that refuses a non-loopback address
    • Not a complete broker: the broker module and its seven tests still have to be written

    Tools considered:

    Searches run:

    • in-process loopback HTTP proxy per-request token allowlist python library, results: 5
    • LiteLLM proxy virtual key per-key budget model allowlist, results: 5
    • mitmproxy addon restrict requests by method and path, results: 5
    • proxy.py python proxy server plugin github, results: 5
    • litellm proxy server virtual keys documentation, results: 5
    • mitmproxy github project, results: 5
    • litellm, results: 5
    • fastapi, results: 5
    • mitmproxy, results: 5
    • proxy.py, results: 5

    Sources:

    Checked on 2026-11-08. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    owner/service
    and removed
    owner/service
    on Nov 16, 2026
  8. 45 remaining items

  9. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    The runner Job devops-cli-implement-devops-cli-3820-6bd3f1 ended: succeeded.
    Image digest: sha256:47b191971ac0f40357ab821d8b13fa5ae022b11beccd42ea859f629c94751c51

    The last lines of its log:

    # Implement plan for dan-petty/devops-cli
    
    ## To implement
    - #3820 feat(roadmap): a loopback gateway broker in the job process: branch `feat/3820-a-loopback-gateway-broker-in-the`, pull request #6157
    Disk use of the home volume at the end of step rebase: 285.1 MB. Largest folders: .data 170.1 MB, worktree/openspec 59.6 MB, worktree/tests 31.5 MB, worktree/src 15.7 MB, worktree/docs 2.6 MB, worktree/k8s 2.3 MB, worktree/.github 272.0 KB, worktree/.ast-grep 208.0 KB.
    Failure class conflict. Action left: wait.
    ✓ Took 0 item(s) to a ready pull request, stopped 1.
    
  10. removed
    owner/service
    on Nov 17, 2026
  11. added
    status/in-review
    and removed
    status/blocked
    on Nov 17, 2026
  12. removed
    status/in-review
    on Nov 18, 2026
  13. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-18 06:26 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/roadmapsource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions