Repository navigation
feat: add gateway Code Mode #6978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
fef6ed0
feat: add gateway Code Mode
ThomasRooney a730758
fix: address remaining Code Mode review findings
ThomasRooney 55946a4
fix: harden Code Mode capacity, availability and sign-in
ThomasRooney 26f3c8f
fix: close Code Mode review gaps in readiness, eviction and worker co…
ThomasRooney 9fa50b7
feat: confine Code Mode workers with Landlock and test sibling isolation
ThomasRooney 811586b
docs: describe the code runner's twelve-stream default and worker shim
ThomasRooney 6e28a22
fix: report runner-level Code Mode refusals in the structured shape
ThomasRooney 0321d42
fix: size Code Mode pods by runner capacity, roll busy pods, and repo…
ThomasRooney b871180
fix: budget Code Mode workers by CPU time instead of wall time
ThomasRooney 618f78d
fix: keep /healthz independent of Code Mode and let busy pods finish …
ThomasRooney 61612ce
docs: size Code Mode runner pods at a 500m CPU request
ThomasRooney 735d84f
feat: roll Code Mode out per organization behind a staff-managed feature
ThomasRooney 4f88c0a
feat: show Code Mode disabled in gateway settings until an organizati…
ThomasRooney 333721f
docs: align Python Code Gateway checks with the Code Mode label and C…
ThomasRooney 28a23a7
fix: qualify gateway overview Code Mode copy and rotate the credentia…
ThomasRooney aa75b30
ci: bound the code runner job and resolve relative Monty paths from t…
ThomasRooney 0516b3c
fix: handle every Landlock filesystem right the kernel supports and h…
ThomasRooney 61c236d
fix: refuse late start frames, allow the full suspension budget and t…
ThomasRooney b9882ce
fix: skip code mode members whose slug contains the path separator
ThomasRooney 5b57873
fix: reject the latest tag for preview code runner images
ThomasRooney 91f0936
fix: reject non-finite remote cluster client QPS
ThomasRooney 547fbe5
fix: reject negative code runtime limits and admission waits at startup
ThomasRooney d8fb684
fix: count code mode admission toward wall time and report ownership …
ThomasRooney 56bed4c
fix: report code runner callback protocol violations and keep session…
ThomasRooney 11ab89e
fix: reject null content blocks in code mode tool results
ThomasRooney a932974
perf: skip tokenizing documents for empty code mode searches
ThomasRooney 182eaca
test: assert the full callback payload reaches Python and avoid sleep…
ThomasRooney c965887
fix: stop the test code runner with its worker process group
ThomasRooney 003f1f7
fix: keep the admitted represented-user policy under a Code Mode admi…
ThomasRooney 8faf676
fix: rekey pooled Code Mode member sessions after a recheck and keep …
ThomasRooney 5f86eb9
feat: report effective gateway discovery mode and Code Mode availability
ThomasRooney 8849a92
fix: address Code Mode serving review findings
ThomasRooney c53e21d
docs: describe gateway code_mode_enabled as per gateway and requiring…
ThomasRooney 6e4b312
fix: require the NameError in the code runtime smoke test's stateless…
ThomasRooney 5cecf96
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney c5cda84
fix: address remaining Code Mode review findings
ThomasRooney 4f9f931
fix: bound Code Mode runner admission end to end and tighten isolatio…
ThomasRooney e90c6b1
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney 4cdb5cf
Merge remote-tracking branch 'origin/main' into e2e/pr-6978
ThomasRooney abb8f75
Merge remote-tracking branch 'origin/main' into land/gateway-code-mode
ThomasRooney e07329e
Merge remote-tracking branch 'origin/main' into land/gateway-code-mode
ThomasRooney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| 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. |
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
| 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 | ||
|
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 | ||
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
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
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
| 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 . |
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
| 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 "$@" |
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
| 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 |
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
| 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 |
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
| 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 |
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
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
| 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" |
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
| 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 "$@" |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.