Repository navigation
feat(agentsapi): configure hosted network access - #161004
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
e4faad9 to
1703969
Compare
|
Validation for The environment test file passed all 23 cases: 5.24 seconds wall time for the focused command on the unchanged source before the generated-doc amendment, and 0.191 seconds summed case execution in CI. Its shared CI shard passed 114 tests across nine files in 22.00 seconds. Formatting, scoped lint, package type checking, generated configuration records, and whitespace checks also passed. The real Docker/hosted-VM network proof remains attached in the PR description. It is being reused as requested, with its public-port and SDK-version limitation stated explicitly; no additional live run was performed. |
|
Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 2:08 AM ET / 06:08 UTC. ClawSweeper reviewWhat this changesThe Agents API plugin adds hosted VM network settings, forwards them when creating sessions, and requires a session reset when a configured policy changes. Merge readiness✅ Ready for maintainer review Keep open: current main lacks hosted VM network configuration, and this PR presents a focused plugin-level implementation with credible real-VM evidence. Priority: P2 Review scores
Verification
How this fits togetherThe Agents API plugin turns OpenClaw agent requests into OpenAI-hosted sessions. It reads operator configuration and saved session bindings before creating or continuing a session through the official SDK. flowchart LR
A[Operator network setting] --> B[Agents API plugin]
B --> C{Saved session policy matches?}
C -->|Yes or new session| D[Official Agents API SDK]
C -->|No| E[Reset required]
D --> F[Hosted VM network access]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +44, Tests +97, Docs +38, Generated 0. Total +179 across 7 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep hosted egress policy in the Agents API plugin, preserve unconfigured saved sessions, and reject continuation under a changed policy until the operator resets the session. Do we have a high-confidence way to reproduce the issue? Not applicable: this adds an opt-in capability; current main has no hosted network setting to exercise as an existing-behavior bug. Is this the best way to solve the issue? Yes: the plugin already owns hosted environment selection and saved-session identity, so forwarding the native policy there is a narrow fit. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4d8c9bddda7f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
94 upstream commits, including the Telegram, Matrix and Feishu cleanup (openclaw#160970), the removal of unused Feishu send test fixtures (openclaw#160913) and hosted network access for the agentsapi plugin (openclaw#161004). Four conflicts. Two are in Feishu code. In extensions/feishu/src/send.ts, openclaw#160970 has sendMessageFeishu resolve its target from params and pass the whole target to sendReplyOrFallbackDirect. That shape is kept. The target still carries accountId from this branch's send-target.ts, so the table mode keeps following the delivering account. In extensions/feishu/src/reply-dispatcher.ts, openclaw#160970 inlined markVisibleReplySent at six call sites. This branch moved those senders into reply-senders.ts, which marks a visible reply through that callback, so the helper and the createFeishuReplySenders call are kept. The inlined assignments that merged cleanly elsewhere in the file behave the same. The other two are generated, docs/.generated/config-baseline.counts.json and docs/.generated/config-baseline.sha256. openclaw#161004 takes plugin from 4431 to 4436. This branch keeps channel at 3788 and core stays at 2475. Both files came from upstream and were regenerated. build:docker ran in a separate detached checkout of this commit outside the nested node_modules install. Regenerating there changed those two files and nothing else, giving the predicted counts, the upstream core and plugin hashes, this branch's channel hash and a new combined hash. The three generated-file checks pass there. Upstream deleted 28 test files in this range. None of them were added or changed by this branch. Feishu: 107 files and 1858 tests in the extension project, 17 files and 311 tests in the database-workers project. Each is one lower than the previous merge because openclaw#160913 removed a card edit test from send.test.ts and openclaw#160970 removed a botName test from monitor.reaction.test.ts, neither touched by this branch. The forwarder test and the routing guards pass, 431 tests. tsgo:core, tsgo:extensions, tsgo:extensions:test, tsgo:test:root, the line-cap, max-lines and assertion-safety ratchets against upstream/main, oxlint and oxfmt on the 43 changed code files all pass.
Co-authored-by: Sarah Fortune <[email protected]>
…olicies (#190036) ## Summary - **Problem:** `modelPolicy.allow` had two grammars under one name. Operator roles accepted a model-name prefix such as `openai/gpt-*`; agent policies rejected it. Role matching used a separate glob matcher, and five other callers detected wildcards by hand (`endsWith("/*")`, `slice(0, -2)`, `startsWith`). The copies agreed today but could drift, for example on padded refs like `"openai / *"`. - **Fix:** `src/config/model-policy-ref.ts` now owns one parser (`parseModelPolicyWildcardRef`: `provider/*`, `provider/namespace/*`, `provider/family-*`) and one matcher (`modelPolicyWildcardMatches`). Role policy matching, config validation, `isModelKeyAllowedBySet`, configured model entries, alias candidates, `models status` and the legacy Codex wildcard migration use them. The role-only parser, the role glob matcher and the role-only validation branch are deleted. - **User impact:** agent policies now also accept model-name prefixes such as `openai/gpt-*`. Existing agent and role configs keep their meaning; no config is invalidated. ## Evidence **Live Gateway, real operator-role identity.** Setup: - Candidate Gateway (`openclaw.mjs gateway run` from this branch) on an isolated HOME, state and loopback port. - `gateway.auth.mode: "trusted-proxy"` with a loopback proxy that sets `x-forwarded-user: [email protected]`. - `gateway.roles.default: "limited"`, with `modelPolicy: { allow: ["fixture/echo-*"], deny: ["fixture/echo-restricted*"] }`. - A loopback fake OpenAI-completions provider that logs every request. - The client is the real `GatewayClient` (webchat mode, device identity, no token), so the proxy-verified user is its only credential. ```text (1)+(2) sessions.patch fixture/echo-restricted -> FORBIDDEN "Your operator role cannot use this model…" sessions.patch fixture/echo-restricted-mini -> FORBIDDEN sessions.patch fixture/other-x -> FORBIDDEN (outside allow) sessions.patch fixture/echo-main -> ok agent run on that session -> status ok provider log: POST /v1/chat/completions model=echo-main (only request; no echo-restricted* or other-x call) (3) live reload narrows the role: deny += "fixture/echo-main*" [reload] config change detected; evaluating reload (gateway.roles.definitions.limited.modelPolicy.deny) next agent run on the pinned echo-main session -> status error "Your operator role cannot use this model…" provider requests before=2 after=2 (no new provider call) (4) upgrade cell, same state directory: published [email protected] Gateway writes and serves the role config: echo-restricted / echo-restricted-mini / other-x -> FORBIDDEN, echo-main -> ok, provider called with echo-main stop; candidate `doctor --fix` (agent DB schema 25 -> 39, role config untouched); candidate Gateway on that state: identical sessions.patch decisions (diff: IDENTICAL), provider called only with echo-main ``` **Role policy compatibility (main vs this PR, real owner code).** One script prepared role policies through `prepareOperatorModelPolicy` on an `origin/main` checkout and on this branch. It evaluated `allows()` for 12 models under 5 policies (family deny `vendor/restricted-v1*`, family allow `vendor/gpt-*`, nested `router/anthropic/*`, padded ` VENDOR / gpt-* ` with deny `vendor/gpt-5.5*`, inherited-source deny `vendor/restricted-*`). It also captured the `main` snapshots with `captureOperatorModelPolicySnapshot` and restored them on this branch with `restoreOperatorModelPolicySnapshot`. ```text prepared decisions, main vs PR: 0 differences / 60 main snapshots restored on PR vs main: 0 differences / 60 familyDeny on PR: vendor/restricted-v1 false, vendor/restricted-v1-mini false, vendor/restricted-v2 true, vendor/primary true ``` **Admission proof.** New case in `src/gateway/sessions-patch.operator-model-policy.test.ts` drives `projectSessionsPatchEntry` (the `sessions.patch` owner that admits a model before any run or provider request) with role policy `allow: ["fixture/*"]`, `deny: ["fixture/restricted-v1*"]`, once with the freshly prepared policy and once with a policy restored from its captured snapshot: ```text fixture/restricted-v1 -> FORBIDDEN "operator role cannot use this model" fixture/restricted-v1-mini -> FORBIDDEN fixture/allowed -> ok; after the operator source is revoked, its commit guard -> FORBIDDEN ``` It fails with this PR's first matcher (strict length check) and passes now. Rebased onto #190019; `pnpm check:changed` and the auth-model-policy suites pass on the rebased head. Role admission suites that consume this predicate before provider calls also pass on this branch: model fallback, CLI runner, isolated completion and image fallback operator-policy suites, plus `operator-model-policy.test.ts` (65 tests). - New regression in `model-visibility-policy.test.ts` (agent policy `openai/gpt-5.6-*` allows `gpt-5.6-sol`, not `gpt-5.5`) fails on `origin/main` and passes here. - Validation table adds `openai/gpt-*` (valid for agents) and rejects `openai/gpt *` and `*`. - Focused suites pass: model visibility, config model-ref validation, operator model policy, role mutation authority, `models status`, legacy Codex model migration, configured model entries, model selection. - Role compatibility: `modelPolicyWildcardMatches` is a plain prefix test, the same set the old role glob (`^prefix.*$`) accepted, because the parser forbids any other `*`. A new operator-policy regression (`allow: ["vendor/*"]`, `deny: ["vendor/restricted-v1*"]` must deny `vendor/restricted-v1` itself) fails on the first head of this PR and passes now. Stored role snapshots keep the same canonical wildcard keys, so restored policies match as before. - `pnpm check:changed` (dead-code step skipped) passes; config docs baseline regenerated. ## Merge danger Two-way door: no stored state or migration; a revert restores the narrower agent grammar. Blast radius: model policy matching for agents and operator roles. Role semantics are unchanged (same prefix rule, same normalized `provider/model` key). Pash/Sarah check: Sarah's commits on these files (#161609, #162335, #161048, #161004, #159363, #158307, #158703, #151176, #123875) touch Agents API, Codex and Slack config help/validation entries. This PR edits only model-policy wildcard parsing, matching and help text, so their behavior is unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
…olicies (openclaw#190036) ## Summary - **Problem:** `modelPolicy.allow` had two grammars under one name. Operator roles accepted a model-name prefix such as `openai/gpt-*`; agent policies rejected it. Role matching used a separate glob matcher, and five other callers detected wildcards by hand (`endsWith("/*")`, `slice(0, -2)`, `startsWith`). The copies agreed today but could drift, for example on padded refs like `"openai / *"`. - **Fix:** `src/config/model-policy-ref.ts` now owns one parser (`parseModelPolicyWildcardRef`: `provider/*`, `provider/namespace/*`, `provider/family-*`) and one matcher (`modelPolicyWildcardMatches`). Role policy matching, config validation, `isModelKeyAllowedBySet`, configured model entries, alias candidates, `models status` and the legacy Codex wildcard migration use them. The role-only parser, the role glob matcher and the role-only validation branch are deleted. - **User impact:** agent policies now also accept model-name prefixes such as `openai/gpt-*`. Existing agent and role configs keep their meaning; no config is invalidated. ## Evidence **Live Gateway, real operator-role identity.** Setup: - Candidate Gateway (`openclaw.mjs gateway run` from this branch) on an isolated HOME, state and loopback port. - `gateway.auth.mode: "trusted-proxy"` with a loopback proxy that sets `x-forwarded-user: [email protected]`. - `gateway.roles.default: "limited"`, with `modelPolicy: { allow: ["fixture/echo-*"], deny: ["fixture/echo-restricted*"] }`. - A loopback fake OpenAI-completions provider that logs every request. - The client is the real `GatewayClient` (webchat mode, device identity, no token), so the proxy-verified user is its only credential. ```text (1)+(2) sessions.patch fixture/echo-restricted -> FORBIDDEN "Your operator role cannot use this model…" sessions.patch fixture/echo-restricted-mini -> FORBIDDEN sessions.patch fixture/other-x -> FORBIDDEN (outside allow) sessions.patch fixture/echo-main -> ok agent run on that session -> status ok provider log: POST /v1/chat/completions model=echo-main (only request; no echo-restricted* or other-x call) (3) live reload narrows the role: deny += "fixture/echo-main*" [reload] config change detected; evaluating reload (gateway.roles.definitions.limited.modelPolicy.deny) next agent run on the pinned echo-main session -> status error "Your operator role cannot use this model…" provider requests before=2 after=2 (no new provider call) (4) upgrade cell, same state directory: published [email protected] Gateway writes and serves the role config: echo-restricted / echo-restricted-mini / other-x -> FORBIDDEN, echo-main -> ok, provider called with echo-main stop; candidate `doctor --fix` (agent DB schema 25 -> 39, role config untouched); candidate Gateway on that state: identical sessions.patch decisions (diff: IDENTICAL), provider called only with echo-main ``` **Role policy compatibility (main vs this PR, real owner code).** One script prepared role policies through `prepareOperatorModelPolicy` on an `origin/main` checkout and on this branch. It evaluated `allows()` for 12 models under 5 policies (family deny `vendor/restricted-v1*`, family allow `vendor/gpt-*`, nested `router/anthropic/*`, padded ` VENDOR / gpt-* ` with deny `vendor/gpt-5.5*`, inherited-source deny `vendor/restricted-*`). It also captured the `main` snapshots with `captureOperatorModelPolicySnapshot` and restored them on this branch with `restoreOperatorModelPolicySnapshot`. ```text prepared decisions, main vs PR: 0 differences / 60 main snapshots restored on PR vs main: 0 differences / 60 familyDeny on PR: vendor/restricted-v1 false, vendor/restricted-v1-mini false, vendor/restricted-v2 true, vendor/primary true ``` **Admission proof.** New case in `src/gateway/sessions-patch.operator-model-policy.test.ts` drives `projectSessionsPatchEntry` (the `sessions.patch` owner that admits a model before any run or provider request) with role policy `allow: ["fixture/*"]`, `deny: ["fixture/restricted-v1*"]`, once with the freshly prepared policy and once with a policy restored from its captured snapshot: ```text fixture/restricted-v1 -> FORBIDDEN "operator role cannot use this model" fixture/restricted-v1-mini -> FORBIDDEN fixture/allowed -> ok; after the operator source is revoked, its commit guard -> FORBIDDEN ``` It fails with this PR's first matcher (strict length check) and passes now. Rebased onto openclaw#190019; `pnpm check:changed` and the auth-model-policy suites pass on the rebased head. Role admission suites that consume this predicate before provider calls also pass on this branch: model fallback, CLI runner, isolated completion and image fallback operator-policy suites, plus `operator-model-policy.test.ts` (65 tests). - New regression in `model-visibility-policy.test.ts` (agent policy `openai/gpt-5.6-*` allows `gpt-5.6-sol`, not `gpt-5.5`) fails on `origin/main` and passes here. - Validation table adds `openai/gpt-*` (valid for agents) and rejects `openai/gpt *` and `*`. - Focused suites pass: model visibility, config model-ref validation, operator model policy, role mutation authority, `models status`, legacy Codex model migration, configured model entries, model selection. - Role compatibility: `modelPolicyWildcardMatches` is a plain prefix test, the same set the old role glob (`^prefix.*$`) accepted, because the parser forbids any other `*`. A new operator-policy regression (`allow: ["vendor/*"]`, `deny: ["vendor/restricted-v1*"]` must deny `vendor/restricted-v1` itself) fails on the first head of this PR and passes now. Stored role snapshots keep the same canonical wildcard keys, so restored policies match as before. - `pnpm check:changed` (dead-code step skipped) passes; config docs baseline regenerated. ## Merge danger Two-way door: no stored state or migration; a revert restores the narrower agent grammar. Blast radius: model policy matching for agents and operator roles. Role semantics are unchanged (same prefix rule, same normalized `provider/model` key). Pash/Sarah check: Sarah's commits on these files (openclaw#161609, openclaw#162335, openclaw#161048, openclaw#161004, openclaw#159363, openclaw#158307, openclaw#158703, openclaw#151176, openclaw#123875) touch Agents API, Codex and Slack config help/validation entries. This PR edits only model-policy wildcard parsing, matching and help text, so their behavior is unchanged. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Operators need to restrict which network destinations an Agents API hosted VM can reach from OpenClaw.
User Impact
Operators can configure
plugins.entries.agentsapi.config.openai_host.networkwith the API'saccessandallowed_domainsfields. Adding, changing, or removing a configured policy requires an explicit session reset. Omitted or null policy preserves existing hosted sessions and the API default; self-hosted sessions are unchanged.Why This Change Was Made
Forward the native network policy during hosted-session creation and include configured policy in saved-session identity. This prevents an existing VM from silently continuing under an old policy. Domain semantics remain validated by the API. The generated plugin configuration budget increases by five entries for this requested API-shaped configuration; core and channel configuration budgets are unchanged.
Evidence
A real ARM64 Docker Gateway run on 2026-09-28 PDT exercised the same network-policy implementation through the Gateway agent endpoint and the hosted VM. Native command records, completed turns, and released binding leases were inspected. These were real service calls, with no mocks or fakes. The existing run is reused by maintainer direction; it preceded this public port and is not an exact build of the public commit or its newer SDK dependency set. Slack transport was not tested.
Changing the policy to disabled hot-reloaded the plugin. Continuing the existing session returned the reset-required error. Native session snapshots before and after that rejected continuation were identical, with one completed turn and five items. After explicitly resetting only the test session, its replacement reported
network.access=disabledand blocked the previously reachable destination. Both probe turns completed and their binding leases cleared. The requested restricted policy was restored; final Gateway health reported no plugin errors.Captured native hosted-VM output
Restricted policy:
Disabled policy, after reset:
The prior environment suite passed 23 tests in 4.96 seconds wall time, with 0.24 seconds test execution. Formatting, scoped lint, and package type checking also passed on that implementation. On the public commit,
pnpm test extensions/agentsapi/agentsapi-environment.test.ts --maxWorkers=1passed all 23 tests in 5.24 seconds wall time. Formatting, scoped TypeScript lint, package type checking, andgit diff --checkpassed. Initial CI exposed missing generated configuration records; those records were regenerated andpnpm config:docs:checknow passes. GitHub CI is being rerun for that documentation-only correction. The existing Docker proof remains the live behavior evidence for this change; no additional live run is planned.