Skip to content

fix(gateway): select openai-completions owner from session key - #138329

Open
teddytennant wants to merge 1 commit into
openclaw:mainfrom
teddytennant:fix/openai-completions-agent-owner
Open

teddytennant wants to merge 1 commit into
openclaw:mainfrom
teddytennant:fix/openai-completions-agent-owner

Conversation

@teddytennant

@teddytennant teddytennant commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Generic openclaw / openclaw/default aliases forced a default agent before x-openclaw-session-key could name the owner. In an explicit multi-agent fleet with no default, a completion with model: openclaw and x-openclaw-session-key: agent:scripts:foobar still got AgentSelectionRequiredError from resolveDefaultAgentId after #137913.

Why This Change Was Made

resolveAgentIdForRequest in src/gateway/http-utils.ts now resolves the owner in this order: agent header, agent-specific model, configured default for a generic model, then the agent-prefixed session key, then the required default. The generic alias asks tryResolveDefaultAgentId instead of throwing, so a fleet with no default falls through to the session key. The parsed agent goes through parseAgentSessionKey plus assertKnownAgentId, so the session-key grammar stays in one place and an unknown agent is still rejected. x-openclaw-agent-id still wins. Two agents with no session key and no agent header still return AgentSelectionRequiredError.

The Chat Completions and Responses references only described x-openclaw-session-key as session routing, so docs/gateway/openai-http-api.md now lists the selector precedence and the case where an agent-scoped key supplies the owner, and docs/gateway/openresponses-http-api.md points at it. pnpm format:docs:check, docs:check-mdx and codespell on the two pages are clean.

User Impact

Operators running an explicit multi-agent fleet without a default agent can send model: "openclaw" plus the agent's own session key to the Chat Completions, Responses and embeddings endpoints and reach that agent, instead of a 400. Fleets with a default agent behave as before.

Evidence

Current head d1c134a6926febaf6cec329cb4e37a5233d9762d. Selector behavior is unchanged from ebf037423f4c37db14f74ab2a024e43a2a04c3ac (src/gateway/http-utils.ts blob 36a7f65dd24bad89b0fea397d32a5258d2b0839c). d1c134a6926 adds the embeddings operator-role ceiling. The Gateway command is node --import ./scripts/tsx.mjs src/entry.ts gateway run --bind loopback --force. The provider is scripts/e2e/mock-openai-server.mjs on loopback. The client is curl. State dirs are throwaway. The September chat-only before/after trace (main returned 400, an earlier head returned 200) predates conflict rejection and did not cover Responses, embeddings, or an upgrade. The Chat Completions, conflict, Responses, and embeddings traces below were captured on 0d69691; the selector file is the same blob, so they still describe this head. The v2026.10.2 upgrade trace is from ebf03742, with the older-binary guard left enabled. The operator-role traces are from this head's parent process on ebf03742 for chat, and from a restart on d1c134a6926 for the embeddings ceiling.

Chat Completions, session key owns the agent

Two agents, agents.ownership: "explicit", no default. Alpha's model is openai/alpha-model, beta's is openai/beta-model. Token auth. Chat Completions and Responses enabled.

POST /v1/chat/completions
Authorization: Bearer trace-token-138329
x-openclaw-session-key: agent:beta:trace-owner
{"model":"openclaw","messages":[{"role":"user","content":"Reply with OPENCLAW_E2E_TRACE_OK"}]}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 300

{"id":"chatcmpl_fc460813-5110-413d-b14b-d76119356a89","object":"chat.completion","created":1791826561,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_TRACE_OK"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

The mock request for that turn is POST /v1/chat/completions with model=beta-model. The user text contains Runtime: agent=beta | session=agent:beta:trace-owner. The gateway session write is agentId=beta. A later activity-recap call uses gpt-5.6-luna and is not the agent turn.

Contradictory selectors

Same gateway. model: "openclaw/alpha" with x-openclaw-session-key: agent:beta:trace-conflict-model:

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Content-Length: 140

{"error":{"message":"Selected agent 'alpha' does not match the agent in `x-openclaw-session-key` ('beta').","type":"invalid_request_error"}}

x-openclaw-agent-id: alpha with x-openclaw-session-key: agent:beta:trace-conflict-header and model: "openclaw" returns the same 400 and message. Neither request reached the mock.

Responses and embeddings

POST /v1/responses, model: "openclaw", stream: false, x-openclaw-session-key: agent:beta:trace-responses, input Reply with OPENCLAW_E2E_RESPONSES_OK:

HTTP/1.1 200 OK
{"id":"resp_3794a6d6-1d4a-434b-9446-a1df6fad114c","object":"response","created_at":1791826585,"status":"completed","model":"openclaw","output":[{"type":"message","id":"msg_10c65ddb-c929-4464-868a-d12c32b6576e","role":"assistant","content":[{"type":"output_text","text":"OPENCLAW_E2E_RESPONSES_OK"}],"phase":"final_answer","status":"completed"}]}

The mock agent turn is model=beta-model and Runtime: agent=beta | session=agent:beta:trace-responses.

POST /v1/embeddings, model: "openclaw", input: "OPENCLAW_E2E_EMBED_OK", x-openclaw-session-key: agent:beta:trace-embed. Beta's memory-search model is beta-embed; alpha's is alpha-embed.

HTTP/1.1 200 OK
Content-Length: 145

{"object":"list","data":[{"object":"embedding","index":0,"embedding":[1,0,0,0]}],"model":"openclaw","usage":{"prompt_tokens":0,"total_tokens":0}}

The mock embeddings request for that call is model=beta-embed with input OPENCLAW_E2E_EMBED_OK.

Operator role, grant, and revocation

Trusted-proxy identity, not the shared-secret owner token. gateway.auth.mode is trusted-proxy (x-forwarded-user, required x-forwarded-proto, loopback allowed). Roles are the real gateway.roles.definitions entries. beta-operator has agents: ["beta"], scopes: ["operator.write"], sessions.others: "none". alpha-only has agents: ["alpha"] and the same scope ceiling. Each caller is a user profile assigned that role. The fleet is still explicit alpha/beta with no default. model is openclaw. The session header is x-openclaw-session-key: agent:beta:.... The provider is the same loopback mock. Forwarded client addresses, provider keys, host, repo path, OS, and node lines are omitted.

Allowed restricted operator

[email protected], POST /v1/chat/completions, session agent:beta:trace-allowed, content Reply with OPENCLAW_E2E_ALLOWED_OK.

HTTP/1.1 200 OK
{"id":"chatcmpl_a5fdbf55-ada1-42f2-934a-be8539dd987e","object":"chat.completion","created":1791899130,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_ALLOWED_OK"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

The mock went from 0 requests to 1: POST /v1/chat/completions, model=beta-model. The provider user text includes Runtime: agent=beta | session=agent:beta:trace-allowed | model=openai/beta-model | default_model=openai/beta-model | channel=webchat. It does not contain alpha-model.

Role forbidden from beta

[email protected], same endpoint, session agent:beta:trace-forbidden, content Reply with OPENCLAW_E2E_FORBIDDEN_OK.

HTTP/1.1 403 Forbidden
{"error":{"message":"Your operator role cannot create sessions for agent \"beta\"; choose an allowed agent or ask a gateway administrator to update your role.","type":"forbidden"}}

The mock stayed at 1. No new provider request.

Revoked grant before further provider I/O

After that allowed turn, gateway.roles.definitions.beta-operator.agents changed from ["beta"] to []. The running gateway logged:

2026-10-13T13:47:17.020+00:00 [reload] config change detected; evaluating reload (gateway.roles.definitions.beta-operator.agents)
2026-10-13T13:47:17.111+00:00 [reload] config hot reload applied (gateway.roles.definitions.beta-operator.agents)

Same profile, same session agent:beta:trace-allowed, content Reply with OPENCLAW_E2E_REVOKED_OK:

HTTP/1.1 403 Forbidden
{"error":{"message":"Your operator role cannot create sessions for agent \"beta\"; choose an allowed agent or ask a gateway administrator to update your role.","type":"forbidden"}}

The mock stayed at 1.

Embeddings ceiling

Chat and Responses already call authorizeGatewaySessionCreation after the shared selector. Embeddings did not, so a session-key owner reached the embedding provider when the role disallowed that agent.

Before d1c134a6926, [email protected], POST /v1/embeddings, model openclaw, session agent:beta:trace-embed-forbidden, input OPENCLAW_E2E_EMBED_FORBIDDEN:

HTTP/1.1 200 OK
{"object":"list","data":[{"object":"embedding","index":0,"embedding":[1,0,0,0]}],"model":"openclaw","usage":{"prompt_tokens":1,"total_tokens":1}}

The mock logged POST /v1/embeddings with model=beta-embed.

d1c134a6926 applies the same ceiling before embedding provider I/O. The gateway was restarted on that commit, and beta-operator.agents was restored to ["beta"].

[email protected], session agent:beta:trace-embed-forbidden-fixed, input OPENCLAW_E2E_EMBED_FORBIDDEN_FIXED:

HTTP/1.1 403 Forbidden
{"error":{"message":"Your operator role cannot create sessions for agent \"beta\"; choose an allowed agent or ask a gateway administrator to update your role.","type":"forbidden"}}

The mock request count did not change.

[email protected], session agent:beta:trace-embed-allowed-fixed, input OPENCLAW_E2E_EMBED_ALLOWED_FIXED:

HTTP/1.1 200 OK
{"object":"list","data":[{"object":"embedding","index":0,"embedding":[1,0,0,0]}],"model":"openclaw","usage":{"prompt_tokens":1,"total_tokens":1}}

The new mock line is POST /v1/embeddings, model=beta-embed. pnpm test -- src/gateway/embeddings-http.role-ceiling.test.ts passed in the gateway-server Vitest project (1 test).

Base vs head regression tests

pnpm test -- src/gateway/http-utils.request-context.test.ts -t "agent-prefixed session key|session key owner|explicit owner when a multi-agent"

Head d1c134a6926: 6 passed. Those cases are the session-key owner in an explicit fleet, the session key beating a default agent, header conflict, model conflict, an agreeing selector, and an ownerless fleet still requiring an owner.

Merge-base 5d5407ae973addb2174301fb17808382ef0a97a1: the same tests ran against that commit's resolveAgentIdForRequest. The new conflict-error export was stubbed so this tree's module graph could load. The resolver body is the merge-base function and does not read the session key. 4 failed, 2 passed:

  • infers the owner from an agent-prefixed session key: AgentSelectionRequiredError (explicit fleet, no default)
  • keeps the session key owner over a default agent: expected main to be scripts
  • rejects an agent header that conflicts with the session key: did not throw
  • rejects an agent-specific model that conflicts with the session key: did not throw
  • agreeing selector: passed (the header already wins)
  • ownerless fleet still requires an owner: passed

Upgrade from published v2026.9.9

[email protected] (bcfc888) from npm. openclaw setup --non-interactive wrote the state dir with agent main (meta.lastTouchedVersion 2026.9.9, no agents.ownership). That CLI enabled chat completions. The mock provider (openai/main-model on loopback, allowPrivateNetwork) was then in the config, and openclaw config validate on 2026.9.9 accepted it. No x-openclaw-session-key.

POST /v1/chat/completions
{"model":"openclaw","user":"upgrade-thread","messages":[{"role":"user","content":"Reply with OPENCLAW_E2E_TURN1"}]}

HTTP/1.1 200 OK
{"id":"chatcmpl_248c0bc0-ad1f-4241-b122-5ac51681a16e","object":"chat.completion","created":1791826663,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_TURN1"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

Mock: model=main-model, Runtime: agent=main | session=agent:main:openai-user:upgrade-thread.

Stopped that Gateway and started this head on the same state dir and config. Same shape, user: "upgrade-thread", content Reply with OPENCLAW_E2E_TURN2, still no session-key header:

HTTP/1.1 200 OK
{"id":"chatcmpl_f1cae9c8-ad63-4e36-8fd1-4c676b35245c","object":"chat.completion","created":1791826814,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_TURN2"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

Mock: model=main-model, same session agent:main:openai-user:upgrade-thread. The provider transcript is the turn-1 user text, assistant OPENCLAW_E2E_TURN1, then the turn-2 user text. lastTouchedVersion stayed 2026.9.9.

Upgrade from published v2026.10.2

[email protected] (b8952d4) from npm. openclaw setup --non-interactive --accept-risk --auth-choice skip --no-install-daemon wrote an isolated state dir with default agent main (meta.lastTouchedVersion 2026.10.2, no agents.ownership). Chat completions were then enabled. The mock provider is this tree's scripts/e2e/mock-openai-server.mjs on loopback (openai/main-model, api: openai-completions, allowPrivateNetwork, context window 200000). openclaw config validate on 2026.10.2 accepted it. Token auth. No x-openclaw-session-key. OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS was unset for every command.

Non-default agent settings on that state, read back with openclaw config get before either Gateway start: agents.defaults.thinkingDefault low, agents.defaults.timeoutSeconds 900, agents.entries.main.identity.name Upgrade Trace, agents.entries.main.identity.theme harbor, agents.defaults.model.primary openai/main-model.

2026.10.2 Gateway startup:

[gateway] agent model: openai/main-model (thinking=low, fast=off)
[gateway] ready
POST /v1/chat/completions
Authorization: Bearer <trace-token>
{"model":"openclaw","stream":false,"user":"upgrade-thread","messages":[{"role":"user","content":"Reply with OPENCLAW_E2E_TURN1"}]}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 297

{"id":"chatcmpl_67a7f6db-57fd-45f5-a17e-0cd746ad1081","object":"chat.completion","created":1791840659,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_TURN1"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

Mock agent turn: POST /v1/chat/completions, model=main-model. The user text contains Reply with OPENCLAW_E2E_TURN1 and Runtime: name=Upgrade Trace | agent=main | session=agent:main:openai-user:upgrade-thread | model=openai/main-model | default_model=openai/main-model (host, repo path, and OS fields omitted). A later activity-recap call uses gpt-5.6-luna and is not the agent turn.

Stopped that Gateway. This head is package 2026.10.2 (ebf0374), the same version as lastTouchedVersion, so the older-binary guard does not treat it as a downgrade. A plain gateway run on the same state dir, with the guard left enabled, did not print the older-binary refusal. It stopped before listening because the published release's agent database is schema 24 and this tree expects schema 26:

OpenClaw agent database uses schema version 24; stop active agents and run openclaw doctor --fix to migrate session identities before using it.
Sessions remain unavailable. Stop the Gateway, run "openclaw doctor --fix" to inspect and repair this agent database, and restart.

That is current main's schema gate, not the version guard. openclaw doctor --fix --non-interactive --yes from this head, still with the override unset, migrated the agent database to schema 26 and finished with Doctor complete. It also disabled skills that are not installed in this environment. The authored agent settings above were unchanged, and lastTouchedVersion stayed 2026.10.2.

The following plain gateway run logged agent model: openai/main-model (thinking=low, fast=off) and [gateway] ready. A chat attempt while startup inspection was still running returned 500 (Agent main has not completed startup inspection and preparation). The log then said agent database recovered after background inspection and preparation. The same request after that recovery:

POST /v1/chat/completions
Authorization: Bearer <trace-token>
{"model":"openclaw","stream":false,"user":"upgrade-thread","messages":[{"role":"user","content":"Reply with OPENCLAW_E2E_TURN2"}]}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 297

{"id":"chatcmpl_d384a7cc-d7e4-4d14-b785-0a02585315b7","object":"chat.completion","created":1791841266,"model":"openclaw","choices":[{"index":0,"message":{"role":"assistant","content":"OPENCLAW_E2E_TURN2"},"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

Mock: model=main-model. The provider transcript includes the turn-1 user text (still carrying name=Upgrade Trace | agent=main | session=agent:main:openai-user:upgrade-thread), assistant OPENCLAW_E2E_TURN1, then the turn-2 user text. After that turn, the config file still had thinkingDefault low, timeoutSeconds 900, identity name Upgrade Trace, theme harbor, primary openai/main-model, chat completions true, and lastTouchedVersion 2026.10.2. agents.ownership stayed unset. The running Gateway process did not have OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS set.

This replaces the earlier v2026.10.2 trace that only continued after OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS=1.

AI-assisted. Fully tested.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR lets agent-scoped session keys select the executing agent, rejects contradictory selectors, and applies the operator agent allowlist to embeddings.

Example: An explicit alpha/beta fleet receives POST /v1/chat/completions with model "openclaw" and x-openclaw-session-key "agent:beta:trace-owner".

  • Before: Default-agent resolution fails because the fleet has no default.
  • After: The request returns HTTP 200 and executes beta using beta-model.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused shared-owner repair with shipped HTTP traces, authorization negative controls, supporting regression coverage, and no actionable correctness finding; pending workflow gates do not reduce the rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied terminal and provider traces exercise the real loopback Gateway through curl for Chat Completions, Responses, and embeddings, show beta’s actual provider selection, reject conflicting selectors and forbidden operators before provider requests, and reject a revoked chat grant; comparison with the previous head confirms the routing and embeddings repairs survive main’s asynchronous session-access integration.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scripts targeting an agent through its session key fail in a multi-agent Gateway without a default, or routing and execution can disagree about the owner.
Reason: The patch restores the explicit session-owner contract across the shared HTTP surface and keeps ambiguous requests and unauthorized agent use rejected.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it fixes a current multi-agent routing failure, and no introduced correctness defect was found. The previous conflict is resolved; enforced maintainer security approval and unfinished CI remain landing gates.

Priority: P2
Reviewed head: 39e12b93d8fa54fe819dc7b93f9294dcd33ef6ed

Before merge

  • Complete next step - A maintainer must complete the enforced security-sensitive review and approve the current revision.

Findings

None.

Agent review details

How this fits together

The Gateway’s OpenAI-compatible HTTP adapters translate authenticated requests into agent turns or embedding-provider calls, sharing agent selection and existing authorization owners.

flowchart TD
  A[HTTP client] --> B[Gateway authentication]
  B --> C[Shared agent selector]
  C --> D[Operator agent policy]
  D --> E[Chat and Responses execution]
  D --> F[Embedding provider]
  E --> G[HTTP response]
  F --> G
Loading

Technical review

Best possible solution:

Land the shared ownership repair after the existing exact-head CI and maintainer security gates pass.

Do we have a high-confidence way to reproduce the issue?

Current main’s resolver demonstrably ignores the session-key owner before default resolution; supplied Gateway traces and base-versus-head assertions support the reported failure, although no target code was executed during this review.

Is this the best way to solve the issue?

The repair belongs in the existing shared selector and command owner, and reuses the existing role policy rather than adding a parallel routing or authorization mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against cbc95bc981bd.

Provenance checked

  • Generic model aliases and default-agent precedence changes intended behavior with a stated reason (d106696: Make the OpenAI-compatible surface agent-first, with generic aliases targeting the default; local history confirms the change, while the commit-to-PR lookup returned no associated PR.)
  • Shared Chat Completions and Responses execution keeps the original intent (refactor(gateway): share OpenAI-compatible agent run handling #151044: Centralize ingress command setup and terminal handling; this patch carries the already-resolved agent through that same owner.)
  • Unknown-agent rejection keeps the original intent (fix(gateway): reject unknown OpenAI agent selectors #92510: Reject explicit selectors outside the configured roster instead of creating phantom agent state.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still misses session-key ownership: Main resolves headers, then the model alias, then the default without consulting the session-key owner; a generic alias therefore still fails in an explicit multi-agent fleet. (src/gateway/http-utils.ts:224, cbc95bc981bd)
  • Pinned patch and complete caller cutover: The introduced diff selects session ownership in the shared resolver and forwards agentId through both HTTP callers into the existing command preparation owner. (src/gateway/http-utils.ts:263, 39e12b93d8fa)
  • Production-entry-point and authority evidence: The full PR body supplies Gateway/curl traces for chat, Responses, embeddings, contradictory selectors, allowed and forbidden trusted-proxy operators, and a revoked chat grant with unchanged provider request counts; teddytennant supplied this evidence. (39e12b93d8fa)
  • Embeddings final-effect protection: The new ceiling rejects disallowed agents before provider acquisition, while the existing authority check rejects policy changes after awaited acquisition and before embedBatch; HTTP authority captures the operator-role revision. (src/gateway/embeddings-http.ts:234, 39e12b93d8fa)
  • Previous conflict resolved without reverting main: Comparison with the previous reviewed head shows main’s worker-backed asynchronous session access retained, with ownership and conflict assertions converted to await it; live GitHub metadata reports mergeable=true. (src/gateway/http-utils.request-context.test.ts:24, 39e12b93d8fa)
  • Related fix addresses a different failure: fix(gateway): stop model overrides failing in multi-agent gateways #137913 fixed model-catalog lookup for an already-selected agent; it did not supply session-key selection in the shared HTTP resolver. The original report came from syncword. (src/gateway/http-utils.ts:196, 29b57be03d2a)

PR surface

Source +88, Tests +358, Docs +15. Total +461 across 13 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 93 5 +88
Tests 5 359 1 +358
Docs 3 23 8 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 475 14 +461

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +93/-5 lines; tests +357/-1 lines Production growth covers shared selection, conflict reporting, execution ownership, and the embeddings ceiling; tests exercise routing precedence and the authenticated HTTP authorization boundary.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The repair restores scripted HTTP requests in explicit multi-agent installations with a limited affected surface.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (20 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-09T17:31:43.792Z sha ed9f818 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-09T21:50:45.663Z sha 90dadca :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-09T23:15:00.588Z sha 0d69691 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T17:53:25.835Z sha 0d69691 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T19:35:17.668Z sha 0d69691 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T21:33:33.070Z sha ebf0374 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-12T22:05:25.462Z sha ebf0374 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T14:16:27.110Z sha d1c134a :: needs changes before merge. :: none

Reviewed October 13, 2026, 11:33 AM ET / 15:33 UTC (Revision 21).

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The precedence change looks correct: a concrete model/agent selection still wins, but the generic openclaw alias no longer forces default-agent resolution before an authoritative x-openclaw-session-key can identify its owner. Using parseAgentSessionKey plus assertKnownAgentId is also preferable to string splitting because the session-key grammar stays centralized. The explicit multi-agent/no-header regression is important to show this does not weaken AgentSelectionRequiredError for genuinely ambiguous requests.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 4, 2026
@teddytennant
teddytennant force-pushed the fix/openai-completions-agent-owner branch from a3eda25 to 4489437 Compare September 4, 2026 18:03
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Sep 4, 2026
@teddytennant

Copy link
Copy Markdown
Contributor Author

Pushed the docs half: openai-http-api.md now lists the selector order and the no-default-agent case where an agent-scoped session key supplies the owner, and the body carries a real Gateway before/after against the mock provider showing beta's model being fetched.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 4, 2026
@teddytennant
teddytennant force-pushed the fix/openai-completions-agent-owner branch from 4489437 to a18b469 Compare September 5, 2026 02:51
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 5, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
@teddytennant

Copy link
Copy Markdown
Contributor Author

rebased onto current main (70637edef6d) and pushed dce4ffc4e27.

the plugin drain readers failure was the old assertion, not the session-key owner change. reload waits for retained work before it stops admitting ordinary calls, so acceptingCalls is still true on that first wait. ci asserted false there (server-plugins.lifecycle.readers.test.ts:163). main already fixed the test to wait for the includeCalls phase after quiesce (f59e4079321). no product change for that.

readers test passed here, plus the gateway owner tests and pnpm tsgo.

new head: dce4ffc4e27af4fcf4b0e1b4d98eba09005a4a69. ci is running again: https://github.com/openclaw/openclaw/actions/runs/37944292433

@cursor
cursor Bot force-pushed the fix/openai-completions-agent-owner branch from dce4ffc to ed9f818 Compare October 9, 2026 17:23
@teddytennant

Copy link
Copy Markdown
Contributor Author

rebased onto current main (b80da189bd4) and pushed ed9f818a213.

the chat admission failures were the old fixture, not the session-key owner change. those three cases close the agent database from inside the admission callback's writer, and the drain guard rejects that (Cannot drain the Session projection reader pool while holding a store writer). leftover state then makes the next two throw Reply run already active. main already runs that revoke outside writer custody (8c22de3f1d0). no product change for that.

admission file passed here under bun (6/6), plus the gateway owner tests (184).

new head: ed9f818a213e4e5338bb0836d8495c0f4bf02913. ci is running again: https://github.com/openclaw/openclaw/actions/runs/37965991706

@teddytennant

Copy link
Copy Markdown
Contributor Author

retriggered ci with an empty commit and pushed 90dadca64d0.

checks-node-changed-compact-small-7-1 failed in src/gateway/server.chat-goal.test.ts ("keeps simultaneous identical Goal retries..."). one of the two sends came back { status: "in_flight", runId: "goal-identical-retry" } instead of { status: "started" }. that is the chat-send admission race, not the session-key owner change. the test and the admission files match current main (1ad3661ff7a). no product change.

new head: 90dadca64d04b99c768da3bfcdc218924f2d0726 (same tree as ed9f818a213). ci is running again: https://github.com/openclaw/openclaw/actions/runs/37995148363

@teddytennant

Copy link
Copy Markdown
Contributor Author

retriggered ci with an empty commit and pushed 0d6969169e9.

checks-node-changed-compact-large-24 failed in src/gateway/server.agent-artifact-apis.test.ts ("composes agent, environment, and artifact RPCs over one real Gateway"). the gateway returned Agent configuration was saved but its application to the active Gateway was not confirmed (failed). that receipt check landed on main today in #167894 (agents.create waits for config reload). this branch does not touch agents.ts, config reload, or that test. the diff is still openai-completions owner selection only.

same failure on main's scheduled CI, without this PR: https://github.com/openclaw/openclaw/actions/runs/37999811982/job/114055140161 (checks-node-compact-large-6 on f8239ea, which is on current main). no product change.

new head: 0d6969169e9d61f071081ffef7fdf01243101373 (same tree as 90dadca64d0). ci is running again: https://github.com/openclaw/openclaw/actions/runs/38002831178

@teddytennant

Copy link
Copy Markdown
Contributor Author

current-head loopback gateway + curl traces are in the evidence section (0d69691, http-utils 36a7f65dd24b).

chat completions, model openclaw, x-openclaw-session-key agent:beta:trace-owner, alpha+beta, no default: 200. mock saw beta-model and runtime agent=beta.

openclaw/alpha, and x-openclaw-agent-id alpha, against an agent:beta session key: both 400, selected agent alpha does not match the session key. mock saw nothing.

/v1/responses with that session key: 200, mock beta-model, runtime agent=beta. /v1/embeddings: 200, mock beta-embed.

upgrade from published 2026.9.9 (bcfc888): default agent main, user upgrade-thread, no session-key header, 200 on main-model. same state dir on this head, same request with a second turn: 200, still main-model, same session agent:main:openai-user:upgrade-thread, provider transcript still has the first turn.

@teddytennant

Copy link
Copy Markdown
Contributor Author

upgrade from published 2026.10.2 (b8952d4) is in the evidence section. isolated state dir, default agent main, no agents.ownership. non-default settings were thinkingDefault low, timeoutSeconds 900, identity name Upgrade Trace, theme harbor, primary openai/main-model.

chat completion, model openclaw, user upgrade-thread, no session-key header: 200. mock saw main-model and runtime name=Upgrade Trace, agent=main, session agent:main:openai-user:upgrade-thread.

this head is package 2026.9.9, so a plain gateway run refused state preparation against lastTouchedVersion 2026.10.2. restarted with OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS=1 on the same state dir. second turn 200, still main-model, provider transcript still has the first user turn and assistant OPENCLAW_E2E_TURN1, then the second user turn. those settings and lastTouchedVersion 2026.10.2 were unchanged.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 12, 2026
@teddytennant

Copy link
Copy Markdown
Contributor Author

merged upstream main into fix/openai-completions-agent-owner and pushed ebf0374.

the only conflict was the request-context test imports. kept the session-key owner assertions and upstream's runtime config snapshot setup. http-utils.ts is still blob 36a7f65dd24b. selector order and command ownership are unchanged.

guarded upgrade from published 2026.10.2 (b8952d4) is in the evidence section. no OPENCLAW_ALLOW_OLDER_BINARY_DESTRUCTIVE_ACTIONS. this head is OpenClaw 2026.10.2 (ebf0374), so a plain gateway run is not refused as an older binary. current main still stops that first run until doctor --fix migrates the agent database off schema 24. after that, plain gateway run on the same state dir: turn 2 200, same session agent:main:openai-user:upgrade-thread, provider transcript still has the turn-1 user text, assistant OPENCLAW_E2E_TURN1, then the turn-2 user text. thinkingDefault low, timeoutSeconds 900, identity Upgrade Trace / harbor, primary openai/main-model, lastTouchedVersion 2026.10.2 stayed.

focused gateway tests passed (request-context 32, openai/openresponses/embeddings/agent-run 254). oxlint, oxfmt, and pnpm tsgo on the touched gateway surface passed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@teddytennant

Copy link
Copy Markdown
Contributor Author

operator-role proof on the loopback mock. trusted-proxy profiles, not the owner token. gateway.roles: beta-operator agents=["beta"], alpha-only agents=["alpha"], both operator.write.

allowed: beta-operator POST /v1/chat/completions model openclaw session agent:beta:trace-allowed -> 200 OPENCLAW_E2E_ALLOWED_OK, provider saw beta-model, runtime agent=beta.
forbidden: alpha-only same shape for agent:beta -> 403, mock log unchanged.
revoked: hot reload set beta-operator.agents to [] after that success; same session next request -> 403, mock still unchanged.

embeddings skipped that ceiling. before the fix alpha-only POST /v1/embeddings session agent:beta returned 200 and the provider saw beta-embed. d1c134a rejects it with 403 and no provider request; beta-operator still gets beta-embed.

request-context session-key tests: 6 pass on head. merge-base resolver 5d5407a fails 4 (explicit fleet throws, default beats the session key, header and model conflicts do not throw). agreeing selector and the ownerless-fleet check pass on both.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 13, 2026
@teddytennant

Copy link
Copy Markdown
Contributor Author

resolved the conflict with current main in src/gateway/http-utils.request-context.test.ts. kept main's async session access and this pr's session-key owner selection, conflicting-selector rejection, and embeddings role ceiling. new head 39e12b9.

pnpm tsgo clean. oxfmt and oxlint clean on the touched gateway files. pnpm test passed for src/gateway/http-utils.request-context.test.ts, src/gateway/embeddings-http.role-ceiling.test.ts, src/gateway/openai-compatible-agent-run.test.ts (56), and the ownerless-fleet plus aggregate-usage cases in src/gateway/openai-http.test.ts (2).

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

A generic model with no agent header resolved to the configured default
while the command runner derived the agent from the session key, so an
agent-scoped session key was rejected as a mismatch. Use the session key's
agent when nothing else names an owner, and reject a header or model that
names a different agent than the session key.
@teddytennant
teddytennant force-pushed the fix/openai-completions-agent-owner branch from 39e12b9 to eb21142 Compare November 16, 2026 21:43
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation size: M labels Nov 16, 2026

This branch has not been deployed

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

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-review-required security-sensitive-changed size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants