Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fef6ed0
feat: add gateway Code Mode
ThomasRooney Oct 22, 2026
a730758
fix: address remaining Code Mode review findings
ThomasRooney Oct 22, 2026
55946a4
fix: harden Code Mode capacity, availability and sign-in
ThomasRooney Oct 23, 2026
26f3c8f
fix: close Code Mode review gaps in readiness, eviction and worker co…
ThomasRooney Oct 23, 2026
9fa50b7
feat: confine Code Mode workers with Landlock and test sibling isolation
ThomasRooney Oct 23, 2026
811586b
docs: describe the code runner's twelve-stream default and worker shim
ThomasRooney Oct 23, 2026
6e28a22
fix: report runner-level Code Mode refusals in the structured shape
ThomasRooney Oct 23, 2026
0321d42
fix: size Code Mode pods by runner capacity, roll busy pods, and repo…
ThomasRooney Oct 23, 2026
b871180
fix: budget Code Mode workers by CPU time instead of wall time
ThomasRooney Oct 23, 2026
618f78d
fix: keep /healthz independent of Code Mode and let busy pods finish …
ThomasRooney Oct 23, 2026
61612ce
docs: size Code Mode runner pods at a 500m CPU request
ThomasRooney Oct 23, 2026
735d84f
feat: roll Code Mode out per organization behind a staff-managed feature
ThomasRooney Oct 23, 2026
4f88c0a
feat: show Code Mode disabled in gateway settings until an organizati…
ThomasRooney Oct 23, 2026
333721f
docs: align Python Code Gateway checks with the Code Mode label and C…
ThomasRooney Oct 23, 2026
28a23a7
fix: qualify gateway overview Code Mode copy and rotate the credentia…
ThomasRooney Oct 23, 2026
aa75b30
ci: bound the code runner job and resolve relative Monty paths from t…
ThomasRooney Oct 23, 2026
0516b3c
fix: handle every Landlock filesystem right the kernel supports and h…
ThomasRooney Oct 23, 2026
61c236d
fix: refuse late start frames, allow the full suspension budget and t…
ThomasRooney Oct 23, 2026
b9882ce
fix: skip code mode members whose slug contains the path separator
ThomasRooney Oct 23, 2026
5b57873
fix: reject the latest tag for preview code runner images
ThomasRooney Oct 23, 2026
91f0936
fix: reject non-finite remote cluster client QPS
ThomasRooney Oct 23, 2026
547fbe5
fix: reject negative code runtime limits and admission waits at startup
ThomasRooney Oct 23, 2026
d8fb684
fix: count code mode admission toward wall time and report ownership …
ThomasRooney Oct 23, 2026
56bed4c
fix: report code runner callback protocol violations and keep session…
ThomasRooney Oct 23, 2026
11ab89e
fix: reject null content blocks in code mode tool results
ThomasRooney Oct 23, 2026
a932974
perf: skip tokenizing documents for empty code mode searches
ThomasRooney Oct 23, 2026
182eaca
test: assert the full callback payload reaches Python and avoid sleep…
ThomasRooney Oct 23, 2026
c965887
fix: stop the test code runner with its worker process group
ThomasRooney Oct 23, 2026
003f1f7
fix: keep the admitted represented-user policy under a Code Mode admi…
ThomasRooney Oct 23, 2026
8faf676
fix: rekey pooled Code Mode member sessions after a recheck and keep …
ThomasRooney Oct 23, 2026
5f86eb9
feat: report effective gateway discovery mode and Code Mode availability
ThomasRooney Oct 23, 2026
8849a92
fix: address Code Mode serving review findings
ThomasRooney Oct 23, 2026
c53e21d
docs: describe gateway code_mode_enabled as per gateway and requiring…
ThomasRooney Oct 23, 2026
6e4b312
fix: require the NameError in the code runtime smoke test's stateless…
ThomasRooney Oct 23, 2026
5cecf96
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney Oct 23, 2026
c5cda84
fix: address remaining Code Mode review findings
ThomasRooney Oct 23, 2026
4f9f931
fix: bound Code Mode runner admission end to end and tighten isolatio…
ThomasRooney Oct 23, 2026
e90c6b1
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney Oct 23, 2026
4cdb5cf
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney Oct 23, 2026
abb8f75
Merge remote-tracking branch 'origin/main' into land/gateway-code-mode
ThomasRooney Oct 24, 2026
e07329e
Merge remote-tracking branch 'origin/main' into land/gateway-code-mode
ThomasRooney Oct 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .agents/skills/gram-rbac/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ Dashboard code should never hand-roll scope checks — use the shared primitives

- **In the dashboard**: `const { grants } = useRBAC();` returns the raw `RoleGrant[]`. Prefer `hasScope` for gating; reach for `grants` only when you need to render them (the access page itself, diagnostics, dev overlays).
- **In Go handlers**: `authz.GrantsFromContext(ctx)` returns the grants on the request context after the engine's `PrepareContext` middleware has run.
- **Within long-lived requests**: use `Engine.RefreshContext` before a later operation that must observe grant revocation. It clears resolved grant/policy snapshots and repeats admission while retaining the original credential constraints. Continue with the returned context and fail closed on error.
- **Admitted jobs**: capture the originally prepared policies with `CaptureAdmissionBoundary`, then `Apply` that boundary to callback contexts when a job must never gain newly granted authority. The boundary retains no request context, survives later refreshes, and every policy must allow the operation.
- **Over the API**: `GET /rpc/access.listUserGrants` returns the caller's effective grants.

## Role hierarchy at a glance
Expand Down
13 changes: 13 additions & 0 deletions .changeset/gateway-code-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"server": minor
"dashboard": minor
"admin": minor
---

Add Code Mode discovery for MCP gateways. A single execute tool runs ephemeral Python with tool search, schema descriptions and live authorized calls to hosted, remote and tunneled tools. All tools (frozen) and Specific tools reuse the catalogue fixed at consent from a fast cache; All tools (live) refreshes only approved members. Adding a member requires new consent. Settings, consent and Inspect support connection overrides, execution results and nested-call outcomes.

Organization gateway connections can choose Code Mode on the consent page too, searching and calling approved tools across projects the person can reach.

Code Mode is off by default and rolled out per organization: Speakeasy staff enable it from the admin dashboard's organization Features page. New selections also require a configured code runtime.

Assistant runtime discovery skips terminating sandbox pods when selecting a running pod.
67 changes: 67 additions & 0 deletions .github/workflows/code-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Code runner
on:
pull_request:
paths:
- "agents/code-runner/**"
- "server/internal/codemode/**"
- "server/internal/sandbox/**"
- "server/cmd/gram/code_runtime*.go"
- "server/internal/mcp/serve_meta*.go"
- "server/internal/mcp/toolselection.go"
- "server/internal/mcp/metamcp/**"
- "server/internal/metamcp/**"
- "server/internal/testenv/code_runner.go"
- ".mise-tasks/test/code-mode.sh"
- ".mise-tasks/**/code-runner*.sh"
- ".mise-tasks/build/monty.sh"
- ".github/workflows/code-runner.yaml"
push:
branches: [main]
paths:
- "agents/code-runner/**"
- "server/internal/codemode/**"
- "server/internal/sandbox/**"
- "server/cmd/gram/code_runtime*.go"
- "server/internal/mcp/serve_meta*.go"
- "server/internal/mcp/toolselection.go"
- "server/internal/mcp/metamcp/**"
- "server/internal/metamcp/**"
- "server/internal/testenv/code_runner.go"
- ".mise-tasks/test/code-mode.sh"
- ".mise-tasks/**/code-runner*.sh"
- ".mise-tasks/build/monty.sh"
- ".github/workflows/code-runner.yaml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
validate:
name: validate
runs-on: ubuntu-24.04
Comment thread
ThomasRooney marked this conversation as resolved.
Resolved
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
with:
minimum_release_age: 1d
install: true
cache: true
env: false
- uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
with:
rust-src-dir: agents/code-runner
rustflags: ""
- run: mise run build:monty
- run: mise run build:code-runner
- run: mise run test:code-runner
- run: mise run lint:code-runner
- run: mise run test:code-runner-image
- run: mise run test:code-mode
125 changes: 125 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,124 @@ jobs:
tags: ${{ steps.assistantMetaGcr.outputs.tags }}
labels: ${{ steps.assistantMetaGcr.outputs.labels }}

code-runner-image:
name: code-runner-image
# The image is content-addressed by agents/code-runner (the Dockerfile pins
# Monty), so an unchanged runner is re-tagged rather than rebuilt. Every
# commit therefore gets a runner image under the same preview and sha tags
# as the server, which previews and releases resolve without a lookup.
runs-on: ubuntu-24.04
permissions:
contents: read
id-token: write # Google Cloud workload identity federation
needs: [changes]
if: github.event_name != 'merge_group' && (github.event_name != 'pull_request' || (github.event.pull_request.user.login != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork))
env:
IMAGE: gcr.io/linen-analyst-344721/${{ github.repository_owner }}/gram-code-runner
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Compute image tags
id: tags
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
REF_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
# Same value as `mise run hash:code-runner-image`.
hash=$(git rev-parse HEAD:agents/code-runner | cut -c1-12)
tags=("sha-${GITHUB_SHA}" "sha-${GITHUB_SHA::7}")
if [[ "$EVENT_NAME" == "pull_request" ]]; then
tags+=("pr-${PR_NUMBER}" "pr-${PR_NUMBER}-${HEAD_SHA::8}")
elif [[ "$REF_NAME" == "main" ]]; then
tags+=("main")
fi
{
echo "hash=$hash"
echo "aliases=${tags[*]}"
echo "push<<EOF"
echo "${IMAGE}:${hash}"
for tag in "${tags[@]}"; do echo "${IMAGE}:${tag}"; done
echo "EOF"
} >> "$GITHUB_OUTPUT"

- id: gcrAuth
name: "Authenticate to Google Cloud"
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
token_format: "access_token"
workload_identity_provider: "projects/409661704476/locations/global/workloadIdentityPools/ga-pool/providers/github-oidc-provider"
service_account: "speakeasy-registry-ga-ci@linen-analyst-344721.iam.gserviceaccount.com"

- name: Login to GCR
env:
GCR_TOKEN: ${{ steps.gcrAuth.outputs.access_token }}
run: |
max_attempts=3
for ((i=1; i<=max_attempts; i++)); do
echo "Docker login attempt $i/$max_attempts..."
if docker login -u oauth2accesstoken --password-stdin gcr.io/linen-analyst-344721 <<< "$GCR_TOKEN"; then
echo "Login successful"
exit 0
fi
if [ $i -lt $max_attempts ]; then
echo "Login failed, waiting 5s before retry..."
sleep 5
fi
done
echo "All login attempts failed"
exit 1

- name: Setup Docker builder
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4.3.0

- name: Find an existing image
id: existing
env:
HASH: ${{ steps.tags.outputs.hash }}
run: |
if docker buildx imagetools inspect "${IMAGE}:${HASH}" >/dev/null 2>&1; then
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "found=false" >> "$GITHUB_OUTPUT"
fi

- name: Tag the existing image
if: steps.existing.outputs.found == 'true'
env:
HASH: ${{ steps.tags.outputs.hash }}
ALIASES: ${{ steps.tags.outputs.aliases }}
run: |
set -euo pipefail
args=()
for tag in $ALIASES; do args+=(--tag "${IMAGE}:${tag}"); done
docker buildx imagetools create "${args[@]}" "${IMAGE}:${HASH}"

- name: Log in to Docker Hub
if: steps.existing.outputs.found != 'true'
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push code runner image
if: steps.existing.outputs.found != 'true'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: ./agents/code-runner/Dockerfile
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.push }}
cache-from: type=gha,scope=code-runner
cache-to: type=gha,mode=max,scope=code-runner

otel-collector:
name: otel-collector
runs-on: blacksmith-4vcpu-ubuntu-2404
Expand Down Expand Up @@ -2565,6 +2683,7 @@ jobs:
- functions-build-host
- functions-image
- assistant-runtime-image
- code-runner-image
- otel-collector
- ts-framework-test
- impeccable
Expand Down Expand Up @@ -2629,13 +2748,16 @@ jobs:
docker-build-client,
docker-build-pystreams,
assistant-runtime-image,
code-runner-image,
preview-image-tags,
upload-dashboard-assets,
]
permissions:
pull-requests: write # adds the preview label
# Only on PR creation, so a manually removed label stays removed. Waits
# for every preview image tag, or the preview polls for missing images.
# The code runner image is tagged for every eligible PR commit, so it is
# never skipped here and must succeed.
if: >-
!cancelled() &&
github.event_name == 'pull_request' &&
Expand All @@ -2652,6 +2774,7 @@ jobs:
needs.docker-build-pystreams.result == 'success') &&
(needs.changes.outputs.server != 'true' ||
needs.assistant-runtime-image.result == 'success') &&
needs.code-runner-image.result == 'success' &&
((needs.changes.outputs.server != 'true' && needs.changes.outputs.client != 'true') ||
needs.upload-dashboard-assets.result == 'success') &&
contains(fromJSON('["success","skipped"]'), needs.preview-image-tags.result)
Expand All @@ -2671,6 +2794,7 @@ jobs:
ci-gate,
docker-build-server,
assistant-runtime-image,
code-runner-image,
svix-sync-webhooks,
]
# ci-gate's transitive needs include path-filtered jobs, and a skipped job
Expand All @@ -2684,6 +2808,7 @@ jobs:
needs.ci-gate.result == 'success' &&
needs.docker-build-server.result == 'success' &&
needs.assistant-runtime-image.result == 'success' &&
needs.code-runner-image.result == 'success' &&
needs.svix-sync-webhooks.result == 'success' &&
github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ scratch/
/local/functions
/local/devidp
/agents/runner/target
/agents/code-runner/target
/agents/runtime-artifacts
.speakeasy/temp
/app_getgram_ai.env
Expand Down
5 changes: 5 additions & 0 deletions .mise-tasks/build/code-runner-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
#MISE description="Build the dedicated OSS Monty runtime image locally"
#MISE dir="{{ config_root }}"
set -euo pipefail
exec docker build --file agents/code-runner/Dockerfile --tag gram-code-runner:test .
7 changes: 7 additions & 0 deletions .mise-tasks/build/code-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

#MISE description="Build the ephemeral Monty code runner"
#MISE dir="{{ config_root }}/agents/code-runner"

set -euo pipefail
exec cargo build --locked "$@"
9 changes: 9 additions & 0 deletions .mise-tasks/build/monty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

#MISE description="Build the pinned OSS Monty subprocess runtime"
#MISE dir="{{ config_root }}/agents/code-runner"

set -euo pipefail
exec cargo install --locked --no-default-features --git https://github.com/pydantic/monty \
--rev 15753b35e8eee6d569f223cd19f0303dbf07f896 \
--root target/monty --bin monty monty-runtime
9 changes: 9 additions & 0 deletions .mise-tasks/hash/code-runner-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

#MISE description="Print a deterministic content hash for the code runner image sources"
#MISE dir="{{ config_root }}"
#MISE hide=true

set -euo pipefail

git rev-parse HEAD:agents/code-runner | cut -c1-12
8 changes: 8 additions & 0 deletions .mise-tasks/lint/code-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

#MISE description="Check code runner formatting and Clippy"
#MISE dir="{{ config_root }}/agents/code-runner"

set -euo pipefail
cargo fmt --check
cargo clippy --locked --all-targets -- -D warnings
5 changes: 4 additions & 1 deletion .mise-tasks/start/_default
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ pitchfork stop park
pitchfork stop --group application
pitchfork stop idle-pause
pitchfork clean
if [ "${GRAM_CODE_RUNTIME_PROVIDER:-disabled}" = local ]; then
pitchfork start code-runtime || echo "Code Mode runtime unavailable; inspect pitchfork logs code-runtime, then run mise run zero:code-mode." >&2
fi
pitchfork start --group default

gum style \
--foreground 10 --border-foreground 10 --border rounded \
--align center --width 40 --margin "0 0" --padding "0 0" \
'Local development stack is running'
'Local development stack is running'
40 changes: 40 additions & 0 deletions .mise-tasks/start/code-runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

#MISE description="Run the native local Code Mode runtime under Pitchfork"
#MISE dir="{{ config_root }}"
#MISE hide=true
#USAGE flag "--url <url>" env="GRAM_CODE_RUNTIME_URL" help="Loopback HTTP address shared with the gateway"
#USAGE flag "--monty-bin <path>" env="GRAM_CODE_RUNNER_MONTY_BIN" help="Pinned subprocess executable"

set -euo pipefail

if [ "${GRAM_ENVIRONMENT:-}" != local ] || [ "${GRAM_CODE_RUNTIME_PROVIDER:-}" != local ]; then
echo "The native code runtime requires local environment and provider settings." >&2
exit 1
fi
if [ -z "${GRAM_CODE_RUNTIME_TOKEN:-}" ]; then
echo "Run mise run zero:code-mode to configure the local runtime token." >&2
exit 1
fi

listen=$(node --input-type=module -e '
import { isIP } from "node:net";
const u = new URL(process.argv[1]);
const host = u.hostname.replace(/^\[|\]$/g, "");
if (u.protocol !== "http:" || !isIP(host) ||
!(host === "::1" || host.startsWith("127.")) ||
u.port === "0" || u.username || u.password || u.pathname !== "/" || u.search || u.hash) {
throw new Error("Code runtime URL must be a plain HTTP literal loopback address.");
}
console.log(`${u.hostname}:${u.port || "80"}`);
' "${usage_url:?GRAM_CODE_RUNTIME_URL or --url is required}")

monty_bin="${usage_monty_bin:-$MISE_PROJECT_ROOT/agents/code-runner/target/monty/bin/monty}"
if [ ! -x "$monty_bin" ]; then
echo "Run mise run zero:code-mode to build the pinned subprocess executable." >&2
exit 1
fi
mise run build:code-runner
export GRAM_CODE_RUNNER_TOKEN="$GRAM_CODE_RUNTIME_TOKEN"
exec "$MISE_PROJECT_ROOT/agents/code-runner/target/debug/gram-code-runner" \
--listen "$listen" --monty-bin "$monty_bin"
19 changes: 19 additions & 0 deletions .mise-tasks/test/code-mode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

#MISE description="Test gateway code mode through the real Rust/Monty runtime"
#MISE depends=["build:code-runner"]
#MISE dir="{{ config_root }}"

#USAGE flag "--monty-bin <path>" env="GRAM_MONTY_TEST_BIN" help="Executable built from the pinned OSS Monty revision"
#USAGE arg "[args]..." help="Additional go test arguments"

set -euo pipefail
export GRAM_CODE_RUNNER_TEST_BIN="$MISE_PROJECT_ROOT/agents/code-runner/target/debug/gram-code-runner"
export GRAM_MONTY_TEST_BIN="${usage_monty_bin:-$MISE_PROJECT_ROOT/agents/code-runner/target/monty/bin/monty}"
if [ "${1:-}" = "--monty-bin" ]; then
shift 2
elif [[ "${1:-}" == --monty-bin=* ]]; then
shift
fi
test -x "$GRAM_MONTY_TEST_BIN" || { echo "Run mise run build:monty or supply --monty-bin" >&2; exit 1; }
exec mise run test:server -tags=codemodeintegration ./internal/codemode/ ./internal/mcp/ ./cmd/gram/ -run Code "$@"
Loading
Loading