Commit graph

39038 commits

Author SHA1 Message Date
Ishaan Jaffer
76b56b18e5
Merge branch 'litellm_lit-2891-settings-ui-cloud-agents' into litellm_lit-2890-b2-warm-pool 2026-05-06 15:41:16 -07:00
Ishaan Jaffer
2dfaca5bdc
Merge branch 'litellm_lit-2878-epic-b-vm-provisioning' into litellm_lit-2890-b2-warm-pool 2026-05-06 15:41:04 -07:00
Ishaan Jaffer
662f96a152
test(agent-vm): add cold-boot P50 ≤ 30s gate (validation #14) 2026-05-06 15:40:07 -07:00
Ishaan Jaff
b13deccdac
fix: ASCII-only AMI description (AWS rejects em-dash)
EC2 `ModifyImageAttribute` rejects "Character sets beyond ASCII are not
supported" when registering the AMI description. The whole AMI rolls back
on this error. Replace em-dash with hyphen.

LIT-2878
2026-05-06 15:36:29 -07:00
ishaan-berri
aba131d3cf
fix: Vertex Anthropic streaming status error hangs (#27310)
* Fix streaming HTTP status error hangs

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* Fix sync streaming HTTP status error hangs

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* Cap sync streaming error read workers

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

---------

Co-authored-by: oss-agent-shin <279349115+oss-agent-shin@users.noreply.github.com>
Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
2026-05-06 15:32:55 -07:00
Ishaan Jaff
5847e7bf32
docs: bake real AMI id (ami-074a518157fe137b4) into example config
Built by `packer build` against the BYOC PoC account (us-west-2). Customers
running their own BYOC account should re-run the Packer build and replace
this value.

LIT-2878
2026-05-06 15:32:46 -07:00
Ishaan Jaff
6746626717
fix(cloud-agents): mirror worker_jwt_hash index in litellm-proxy-extras schema.prisma 2026-05-06 15:32:04 -07:00
Ishaan Jaff
07e373f9f7
fix(cloud-agents): mirror worker_jwt_hash index in proxy schema.prisma 2026-05-06 15:32:00 -07:00
Ishaan Jaff
26de269add
fix: rename env_creds in get_team_vm_config to satisfy mypy
`creds` was reassigned from `AwsCreds` to `Optional[AwsCreds]` in the
fallback branch — rename the second binding so mypy can narrow the type.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
b25dd8b716
fix: type-narrow session_id in _terminate_and_mark (mypy)
Defensive: if both `session_id` and `id` are missing, return early. The
str-cast keeps mypy happy when the row uses a UUID-typed column.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
2dc9b255f2
test: register pytest 'slow' marker for real-cloud agent_session tests
Avoids the PytestUnknownMarkWarning when collecting
`tests/test_litellm/proxy/agent_session_endpoints/vm_providers/test_ec2_provider_real.py`
without `-m slow`.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
88a6d0e242
fix: AMI build — disable apt cnf-update-db post-invoke hook + don't remap python3
The cnf-update-db post-invoke hook fails (exit 100) when we install a
non-default python3 alongside, because cnf-update-db imports apt_pkg which
is bound to /usr/bin/python3 -> python3.12. Disabling the hook makes apt
update + install idempotent for AMI builds.

Also stop remapping /usr/bin/python3 via update-alternatives — it breaks
Ubuntu's python-coupled apt tooling. Tools that need 3.13 invoke it
explicitly; the systemd unit already uses /usr/bin/python3.13.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
48c8ba1fe7
test: real-cloud EC2Provider tests — slow-marked, gated by BYOC env vars
Validations #3 (real boot), #11 (real BYOC fail-fast), and the real-cloud
piece of #8. Skipped by default; enable with `pytest -m slow` when the
`LITELLM_AGENT_AWS_*` + `LITELLM_TEST_*` env vars are set.

Each test wraps RunInstances in try/finally with TerminateInstances and
installs a 60-min process watchdog (per the AWS safety boundary) so a
hung test cannot leak an instance.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
0b3cb3040d
test: sweepers — bootstrap-timeout, heartbeat-loss, max-session-minutes (Validation #7, #9, #10)
Mocked Prisma client driving each sweeper through its happy path plus the
optimistic-lock branch (sweeper skips a session whose status changed
underneath it).

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
35f174b392
test: BYOC creds resolver — encrypt/decrypt round trip, cross-team isolation, env fallback
Covers validation #11 (no creds = fail-fast, no instance launched), #12
(two teams resolve to two distinct creds objects), and the env-var fallback
path used in local dev before the LiteLLM_AgentVMConfig table is populated.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
d519852165
test: EC2Provider unit tests — spot fallback, invalid-creds, creds-no-leak
Mocked tests using a fake boto3 client. Covers validations #5 (spot →
on-demand fallback), #8 (terminate idempotent on already-gone), #11
(invalid creds raise InvalidCredentialsError without launching anything),
and #13 (AWS keys never appear in log records, repr, or exception messages).

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
a149bd6bb7
test: NoopProvider lifecycle + idempotent terminate
LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
0b6be2ac1d
test: factory tests — provider swap is config-only, unknown values rejected (Validation #1, #6)
LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
10a5d25e95
test: scaffold test packages for agent_session_endpoints (LIT-2878) 2026-05-06 15:31:57 -07:00
Ishaan Jaff
ba2edee79d
docs: AMI build + boot-mode + cleanup playbook (infra/ami/README.md)
Covers: prerequisites (Packer + AWS profile), `packer init` + `packer
build` invocation, sharing the AMI cross-account via `ami_users`, the
`LITELLM_AGENT_MODE` boot-mode contract, the Epic C migration path, and
the leak-cleanup one-liner that targets `LitellmManagedBy=agent-vm-provider`.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
2535a437c6
feat: daemon stub — placeholder until Epic C (LIT-2879) ships the real daemon
Behaviour:
- reads runtime config from systemd's EnvironmentFile
- session mode: bootstrap → heartbeat every 30s, exit cleanly on HTTP 410
- warm mode: idle (real warm-pool hydrate lands in B2)
- redacts JWT in log output

Zero non-system deps (only `requests`, installed by the AMI builder).
Replaced wholesale by Epic C.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
03de8f56a6
feat: systemd unit for litellm-agent-runtime daemon
Reads runtime config from /etc/litellm-agent/runtime.env (written by
EC2 user-data, mode 600). Restart=on-failure with a 5s backoff so transient
network blips during bootstrap don't permanently kill the session.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
29667d22cd
feat: AMI runtime install script (node24, python3.13, git, gh, uv, bun)
Provisioner script driven by `litellm-agent-runtime.pkr.hcl`. Each tool is
pinned to a specific version and verified against a SHA-256 sidecar where
upstream provides one (uv) — see CLAUDE.md "CI Supply-Chain Safety".
The bun installer has no checksum sidecar, so we pin a version and pull the
artifact directly (not the install script).

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
0ea60840f6
feat: Packer config for litellm-agent-runtime AMI
Builds an Ubuntu 24.04 AMI with node 24, python 3.13, git, gh, uv, bun, and
the agent-runtime systemd unit autostarted on boot. The daemon honours
`LITELLM_AGENT_MODE` from EC2 user-data: `session` for cold-boot,
`warm` for warm-pool prewarming (B2).

Uses IMDSv2 only. Tags every resource Packer creates for easy cleanup.
`ami_users` lets us share the AMI cross-account without rebuilding.

Validation #2 (`packer build`) covers this file.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
82c302453d
docs: example config.yaml for agent_settings.vm_provider=ec2
Documents the agent_settings YAML shape consumed by `get_vm_provider`.
B0's AWS resource IDs are referenced via `default_ami_id: ami-CHANGEME`;
the user fills in the real AMI after running `packer build`.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
e06f7b2d56
feat: bootstrap_timeout / heartbeat / max-session sweepers for agent sessions
Three sweepers run on the same 30s tick:
- bootstrap_timeout — sessions stuck in `provisioning` past the timeout
- heartbeat_timeout — `ready` sessions whose daemon stopped checking in
- max_session_minutes — sessions older than the configured ceiling

Each sweeper:
- bounds its batch to 100 rows so a backlog doesn't stall the loop
- re-fetches the row (optimistic lock) before terminating so multiple
  proxy replicas don't double-terminate
- treats terminate failures as non-fatal (retry next tick)

Uses Prisma model methods (`find_many` / `find_unique` / `update`); no
raw SQL per project rules.

Validations covered: #7 (max_session_minutes), #9 (bootstrap_timeout), #10
(heartbeat_loss).

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
1bf4e6d385
feat: EC2Provider — boto3-backed VM provisioner with BYOC + spot fallback
One EC2 per session, launched in the team's AWS account using the team's
BYOC creds (decrypted at use, never logged). Spot first, on-demand fallback
when capacity unavailable. Per-session tags (litellm-session-id,
litellm-team-id, litellm-agent-id) for cleanup.

Safety:
- `set_stream_logger('botocore', WARNING)` so SigV4 payloads can't leak the
  access key into proxy logs (regression-tested in #13)
- creds enter via ProvisionContext, never leave this module
- `_safe_aws_error` formats ClientError without echoing the request payload
- `InvalidClientTokenId` / `SignatureDoesNotMatch` → fail-fast InvalidCredentialsError
- terminate is idempotent on already-gone instances

Validations covered: #5 (spot fallback), #8 (terminate idempotent), #11
(invalid creds fail-fast), #13 (creds never logged).

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
0203e72358
feat: BYOC AWS creds resolver — get_team_vm_config() + encrypt/decrypt helpers
Reads the team's BYOC AWS creds from `LiteLLM_AgentVMConfig` (decrypts
each field individually) and falls back to `LITELLM_AGENT_AWS_*` env vars
for local dev. Raises `InvalidCredentialsError` if neither path yields
creds (validation #11 fail-fast).

Falls back gracefully when the table doesn't exist yet (Epic G hasn't
shipped its migration), so this code can land before LIT-2891.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
6832c176f5
feat: get_vm_provider() factory keyed off agent_settings.vm_provider
Reads `agent_settings.vm_provider` and `agent_settings.<provider>` from
the loaded proxy config and builds the matching provider. Defaults to
`noop`. Unknown values raise `ValueError` listing the supported
providers so config typos surface fast.

Validation #1 (test_factory) covers this path. Validation #6 (provider
swap is config-only) is also exercised here.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
bdcda518a7
feat: NoopProvider for tests + agent_settings.vm_provider=noop config
In-memory `AgentVMProvider` used by the unit tests and as the default when
`agent_settings.vm_provider` is unset. The factory returns `NoopProvider`
when no AWS-backed provider is configured so the proxy boots cleanly without
AWS credentials.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
380cf11298
feat: AgentVMProvider abstraction + ProvisionContext / VMHandle / VMStatus
The pluggable VM-provider ABC for agent sessions. Per-session VMs are
provisioned via this interface; v1 implementation is EC2 (BYOC AWS).

Key types: `ProvisionContext` carries the team's AWS creds + EC2 overrides
through to the provider. `AwsCreds.__repr__` redacts secrets so we cannot
accidentally print them. `InvalidCredentialsError` (400) and
`ProvisionError` (500) are the user-facing error types.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
b3a6dd0f4c
feat: vm_providers package public re-exports (LIT-2878) 2026-05-06 15:31:57 -07:00
Ishaan Jaff
a6c10b75c4
feat: scaffold litellm/proxy/agent_session_endpoints package (LIT-2878) 2026-05-06 15:31:57 -07:00
Ishaan Jaff
2f6aac4d86
feat: migration for LiteLLM_AgentVMConfig BYOC AWS settings table
Picked up by `prisma migrate deploy` on proxy startup (the
`litellm-proxy-extras` package bundles its own migration directory).
LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
b65ebb586b
feat: add LiteLLM_AgentVMConfig table for BYOC AWS settings (proxy-extras schema)
Mirrors the schema in the published `litellm-proxy-extras` package so the
bundled migrations match what Prisma actually applies on proxy startup.
LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
f6ce16e281
feat: add LiteLLM_AgentVMConfig table for BYOC AWS settings (proxy schema)
Mirrors the root-level schema.prisma change so the bundled proxy schema
stays in sync. LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
530211c558
feat: add LiteLLM_AgentVMConfig table for BYOC AWS settings (root schema)
Per-team BYOC AWS config consumed by the agent-session EC2 VM provider.
`aws_creds_enc` is a JSON blob with each field individually encrypted via
`encrypt_value_helper` so a partial DB leak doesn't expose the secret.
Owned by Epic G's Settings UI (LIT-2891); consumed by Epic B's EC2 provider.

LIT-2878
2026-05-06 15:31:57 -07:00
Ishaan Jaff
b96e13a9d3
fix(cloud-agents): mirror worker_jwt_hash index in root schema.prisma 2026-05-06 15:31:56 -07:00
Ishaan Jaff
4479944d35
fix(cloud-agents): index worker_jwt_hash to avoid full scans (Greptile P2)
LIT-2890 / B2's long-poll heartbeat calls find_worker_by_jwt on every
request, which filters by worker_jwt_hash. Without an index that's a
full table scan per heartbeat once the worker pool grows past a handful
of rows. Adding the index now so it lands with the table create rather
than as a follow-up migration during B2 ramp-up.
2026-05-06 15:31:50 -07:00
Ishaan Jaff
efcdbee010
test(cloud-agents): _resolve_proxy_url honors trust boundaries
Covers all four resolution paths and the security-critical default:

  * LITELLM_CLOUD_AGENT_PROXY_BASE_URL wins regardless of forwarded
    headers (and trailing slashes get stripped).
  * X-Forwarded-Host is IGNORED unless LITELLM_TRUST_PROXY_HEADERS=1.
    A forged header pointing at attacker.example must not show up.
  * Trust-flag opt-in honors X-Forwarded-Host + X-Forwarded-Proto,
    but x-forwarded-proto alone (no host) doesn't poison the response.
  * Last-resort fallback to localhost:4000 when no Host header.
2026-05-06 15:31:42 -07:00
Ishaan Jaff
6a0f04c8f3
fix(cloud-agents): stop trusting X-Forwarded-Host in install URL (Greptile P1)
Resolution order for the URL embedded in the install one-liner is now:

  1. LITELLM_CLOUD_AGENT_PROXY_BASE_URL env var (operator-configured,
     fully trusted) — recommended for production.
  2. X-Forwarded-Host / X-Forwarded-Proto, ONLY when the operator
     opts in via LITELLM_TRUST_PROXY_HEADERS=1.
  3. The request's direct Host header — safe by default because it
     reflects the actual TCP destination, not an attacker-supplied hop.

Previously any authenticated caller could forge X-Forwarded-Host to
embed an attacker-controlled URL in the install command. If a second
operator ran that command, the worker would send its raw pair token to
the attacker's host, who could then call POST /v2/agent-workers/register
and gain a long-lived worker JWT.

Also adds structured logging on /register failures (invalid / replayed
/ expired tokens) so operators running the proxy behind a WAF / fail2ban
can detect abuse at the network layer (the proxy itself doesn't ship a
built-in per-IP limiter).
2026-05-06 15:31:35 -07:00
Ishaan Jaff
0a942c2ed8
test(cloud-agents): _aws_mock_enabled defaults off and only "1" enables it
Locks the production-safe default for LITELLM_CLOUD_AGENT_MOCK_AWS so a
future revert to the unsafe "1" default trips CI. Also covers the
strict-string parsing — typos like "true" / "yes" must NOT silently
flip on the mock.
2026-05-06 15:31:22 -07:00
Ishaan Jaff
a9cd1fc764
fix(cloud-agents): default LITELLM_CLOUD_AGENT_MOCK_AWS to off (Greptile P1)
Previously the test-connection endpoint defaulted to mock-on, so a fresh
production proxy would silently return a synthetic success for any
non-empty AWS access key. Operators saving incorrect credentials would
only discover the failure later when VMs failed to launch.

Default is now "0" — operators must set LITELLM_CLOUD_AGENT_MOCK_AWS=1
explicitly to opt into the mock path during local development.

Also adds an inline comment on _build_update_payload's `is not None`
guard so a future contributor doesn't silently drop `False` / `0`
updates by switching to truthy comparison.
2026-05-06 15:31:17 -07:00
Ishaan Jaff
793e769bd5
test(cloud-agents): pin shell-quoting behavior for install command
Adds three regression cases that fail if a future change drops the
shlex.quote() pass on proxy_url, raw_token, or install_script_url. The
existing simple-input cases still pass unchanged because shlex.quote
returns alnum/colon/slash/dot strings verbatim.
2026-05-06 15:31:08 -07:00
Ishaan Jaff
e4cce78b6e
fix(cloud-agents): shell-quote install command interpolations (Greptile P1)
shlex.quote() the install_script_url, proxy_url, and raw_token before
interpolating into the curl-pipe-sh one-liner. Without quoting, a
proxy_url containing spaces or shell metacharacters (e.g. via a misconfig
or the X-Forwarded-Host issue Greptile also flagged) could produce a
malformed or exploitable command on the worker box.
2026-05-06 15:31:02 -07:00
ishaan-berri
c15718f9d1
Fix Anthropic streaming reasoning token usage (#27319)
* fix anthropic streaming reasoning token usage

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* test anthropic streaming reasoning usage end to end

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* address anthropic reasoning token text split

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* harden anthropic reasoning usage for mocked tokens

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

---------

Co-authored-by: oss-agent-shin <279349115+oss-agent-shin@users.noreply.github.com>
Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
2026-05-06 15:28:22 -07:00
ishaan-berri
bd1a05aed9
Fix MCP DB reload partial failures (#27314)
* Fix MCP database reload partial failures

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* Avoid staged MCP registry exposure

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

---------

Co-authored-by: oss-agent-shin <279349115+oss-agent-shin@users.noreply.github.com>
Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
2026-05-06 15:18:18 -07:00
ishaan-berri
924c141843
Add new chat model metadata (#27313)
* add new model metadata

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

* address review feedback

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>

---------

Co-authored-by: oss-agent-shin <279349115+oss-agent-shin@users.noreply.github.com>
Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
2026-05-06 15:15:21 -07:00
Ishaan Jaffer
45b1336115
test(cloud-agents): write-only secret invariants (LIT-2891 validation #2) 2026-05-06 15:14:22 -07:00
Ishaan Jaffer
d384bb757f
test(cloud-agents): pair token + worker JWT helper tests (LIT-2891 validation #5) 2026-05-06 15:14:22 -07:00