Skip to content

feat: send OpenAI safety_identifier via params.safetyIdentifier - #138289

Closed
lgrosales wants to merge 14 commits into
openclaw:mainfrom
lgrosales:feat/openai-safety-identifier
Closed

lgrosales wants to merge 14 commits into
openclaw:mainfrom
lgrosales:feat/openai-safety-identifier

Conversation

@lgrosales

@lgrosales lgrosales commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138287

What Problem This Solves

Operators running OpenClaw against the OpenAI Platform cannot follow OpenAI's safety identifier guidance. The built-in openai provider uses the Responses API for agent turns, and the only request-body override OpenClaw offers, params.extra_body, is applied to openai-completions bodies only. There is no plugin hook that can patch the OpenAI provider's outgoing payload either. Shared deployments (for example a Slack assistant serving a team) therefore send every request without a safety_identifier, so OpenAI cannot attribute abuse-monitoring signals or give actionable policy feedback.

Why This Change Was Made

Adds a per-model params.safetyIdentifier that is forwarded as OpenAI's safety_identifier field. The resolver and wrapper live in a sibling module, src/llm/providers/stream-wrappers/openai-safety-identifier.ts, and are applied in the openai-responses-defaults stream family the same way serviceTier is, and gated through the shared Responses payload policy (allowsSafetyIdentifier) so it is only injected for provider: "openai" on api.openai.com using Responses, the Responses transport, or Chat Completions. The ChatGPT/Codex backend, Azure OpenAI, and OpenAI-compatible proxies are not verified to accept the field and are left untouched. Caller-provided safety_identifier values win; empty, non-string, or over-64-character values (OpenAI's documented limit) are ignored with a warning. Nothing is sent unless the param is configured.

Only the camelCase spelling is recognised, deliberately. Extra params are merged across the global, per-model, and per-agent scopes by literal key before the resolver runs, so accepting a snake_case alias would let a lower-precedence scope's spelling silently win over a higher-precedence override written the other way. A single key keeps the documented scope precedence intact; a test asserts the alias is not honoured.

Non-goal: automatically deriving a per-session or per-sender identifier. That needs a design for what OpenClaw hashes and how channels expose sender identity, so this PR ships the static config value as the minimal first step.

User Impact

Operators can set a stable, hashed, non-PII identifier per OpenAI model and have it carried on every native OpenAI Platform request:

{
  "agents": {
    "defaults": {
      "models": {
        "openai/gpt-5.4": {
          "params": { "safetyIdentifier": "sha256-of-your-user-or-deployment-id" }
        }
      }
    }
  }
}

Existing configurations are unaffected. Documented in docs/gateway/config-agents/models.md and docs/providers/openai.md.

Evidence

Focused tests in src/agents/embedded-agent-runner-extraparams-openai-safety-identifier.test.ts (a sibling of the main extra-params suite, following the existing Moonshot/OpenRouter pattern so the over-cap main file does not grow) cover Responses injection, native Chat Completions injection, whitespace trimming, caller-provided precedence, and no injection for the ChatGPT/Codex backend, Azure OpenAI, proxied base URLs, empty values, non-string values, a snake_case alias (single canonical spelling), and values over OpenAI's 64-character limit.

Local validation on this branch rebased onto current main (bd8b6b7):

node scripts/run-vitest.mjs run src/agents/embedded-agent-runner-extraparams-openai-safety-identifier.test.ts src/agents/embedded-agent-runner-extraparams.test.ts
 Test Files  2 passed (2)
      Tests  153 passed (153)

node --import ./scripts/tsx.mjs scripts/check-line-cap-ratchet.mts --base upstream/main
Line-cap ratchet OK: 4 changed source files; no new violations or over-cap growth.

node scripts/run-vitest.mjs run packages/ai/src/transports/
 Test Files  62 passed (62)
      Tests  1034 passed (1034)

node scripts/run-vitest.mjs run src/plugin-sdk/provider-stream src/llm/providers/stream-wrappers/openai
 Tests  19 passed / 38 passed

node scripts/run-tsgo.mjs -p tsconfig.core.json   # exit 0, no diagnostics
oxfmt --check <changed files>                      # all files formatted
oxlint <changed files>                             # exit 0

External contract: OpenAI accepts safety_identifier on both request paths

The review bot noted it could not reach OpenAI's documentation to verify the field. The contract is pinned in OpenAI's official SDK sources, which are generated from the OpenAPI spec:

Field documentation as shipped in those SDKs, identical for both endpoints:

A stable identifier used to help detect users of your application that may be violating OpenAI's usage policies. The IDs should be a string that uniquely identifies each user, with a maximum length of 64 characters. We recommend hashing their username or email address, in order to avoid sending us any identifying information.

The 64-character maximum is enforced by this PR's resolver. Guide: https://developers.openai.com/api/docs/guides/safety-best-practices#safety_identifiers

Live trace: native OpenAI Platform requests carrying safety_identifier (HTTP 200)

Captured with OpenClaw's own debug proxy (openclaw proxy run -- openclaw agent exec ...) using this PR's build (openclaw --version → 2026.9.2 (01c96c4), the previous head; the rebase onto bd8b6b7 changed no PR files), in an isolated state directory with plugins.deny: ["codex"], agentRuntime: { id: "openclaw" } on the model, params.safetyIdentifier: "clipo-d79375b3e064b1715aa542cd43249bfe", and models.providers.openai.request.allowPrivateNetwork: true so the loopback capture proxy is permitted. The API key was supplied via an env-backed SecretRef and never appears in logs or captures; authorization headers below are redacted by the capture inspector.

Responses API (api: "openai-responses", params.transport: "sse")

harness selected: selectedHarnessId=openclaw selectedReason=forced_openclaw
[model-fetch] start    provider=openai api=openai-responses model=gpt-5.5 method=POST url=https://api.openai.com/v1/responses
[model-fetch] response provider=openai api=openai-responses model=gpt-5.5 status=200 contentType=text/event-stream; charset=utf-8
[responses] completed  provider=openai api=openai-responses model=gpt-5.5 transport=sse elapsedMs=2105
[responses] stream_done events=9 types=response.created:1,...,response.output_text.done:1,response.completed:1
agent exec envelope: {"ok":true,"status":"ok","final":"OK","provider":"openai","model":"gpt-5.5"}

Captured outbound request (capture event kind=request, captureOrigin=guarded-fetch, gzip blob 117,286 B decoded):

POST https://api.openai.com/v1/responses
headers: accept=application/json content-type=application/json authorization=<redacted> user-agent=openclaw/2026.9.2 x-stainless-package-version=7.8.0 ...
top-level body keys: context_management,include,input,instructions,max_output_tokens,metadata,model,parallel_tool_calls,prompt_cache_key,reasoning,safety_identifier,store,stream,text,tools
body excerpt: {"model":"gpt-5.5","safety_identifier":"clipo-d79375b3e064b1715aa542cd43249bfe","stream":true,"store":true,"input":[2 items],"tools":[39 items]}

Chat Completions (same provider with api: "openai-completions")

[model-fetch] start    provider=openai api=openai-completions model=gpt-5.5 method=POST url=https://api.openai.com/v1/chat/completions
[model-fetch] response provider=openai api=openai-completions model=gpt-5.5 status=200 contentType=text/event-stream; charset=utf-8
agent exec envelope: {"ok":true,"status":"ok","final":"OK","provider":"openai","model":"gpt-5.5"}
POST https://api.openai.com/v1/chat/completions
top-level body keys: max_completion_tokens,messages,model,parallel_tool_calls,prompt_cache_key,safety_identifier,store,stream,stream_options,tools
body excerpt: {"model":"gpt-5.5","safety_identifier":"clipo-d79375b3e064b1715aa542cd43249bfe","stream":true,"store":false,"messages":[3 items],"tools":[39 items]}

Both requests were accepted by api.openai.com (HTTP 200, streamed completion, model reply OK) with safety_identifier present in the body exactly as the resolver produced it.

Note for operators: the field is injected by the embedded OpenClaw runtime. Turns delegated to the Codex agent harness use its own app-server transport and are unaffected; pin agentRuntime: { id: "openclaw" } on the model (or deny the Codex plugin) where the identifier must be sent.

CI note

The earlier control-ui-performance failure (startup JS gzip 350353 B vs a 350141 B enforcement limit) came from the branch predating the 2026-09-04 baseline bump on main to 350377 B; this PR touches no Control UI code and the UI does not import any changed module. Rebasing onto current main picks up the new committed baseline.

Confirmed on current main that there are no existing occurrences of safety_identifier or safetyIdentifier in src/, packages/, extensions/, or docs/.

Written with Claude Code; the autoreview skill was not available in the authoring environment.

🤖 Generated with Claude Code

@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 docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 5, 2026, 9:15 AM ET / 13:15 UTC (Revision 15).

ClawSweeper review

What this changes

Adds an optional safetyIdentifier model setting that sends a validated identifier with native OpenAI Responses and Chat Completions requests, with documentation and focused tests.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR remains useful: current main lacks the requested capability, and the contributor supplied convincing live API traces. No blocking code defect was found; acceptance of the additive public SDK behavior remains unresolved.

Priority: P3
Reviewed head: 6f7fcb8ad1bc50ac521aef383ffff23c2ddc8591
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with convincing live request evidence and no blocking correctness finding; product acceptance remains separate from patch quality.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The contributor exercised the embedded OpenClaw provider wrapper through real agent execution and a capture proxy: Responses and Chat Completions requests carried the identifier and returned HTTP 200 with completed replies. The changed production modules remain identical to the preceding reviewed head. No stored-data contract changes or migrations are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The contributor exercised the embedded OpenClaw provider wrapper through real agent execution and a capture proxy: Responses and Chat Completions requests carried the identifier and returned HTTP 200 with completed replies. The changed production modules remain identical to the preceding reviewed head. No stored-data contract changes or migrations are introduced.
Evidence reviewed 15 items Pinned introduction: Inspected the verified base-to-head delta and all six introduced paths; the changes are confined to the optional parameter, endpoint capability, wrapper composition, documentation, and tests.
Current main still lacks the capability: The complete current-main search found no safetyIdentifier, safety_identifier, or safety_id occurrences across source, packages, plugins, and docs. The existing extra-body wrapper applies only to Chat Completions, so it does not solve the Responses request.
Latest release check: The public v2026.9.8 provider-stream source contains the existing OpenAI stream family and service-tier handling, but no safety-identifier handling. This is not an already-shipped replacement for the PR.
Findings None None.
Security None None.

How this fits together

The embedded OpenClaw runtime merges model settings and passes them through provider stream wrappers before sending model requests. This change adds a request field only for supported OpenAI Platform routes.

flowchart TD
  A[Operator model settings] --> B[Merged provider parameters]
  B --> C[Validate safety identifier]
  C --> D[Check provider and endpoint]
  D --> E[Native OpenAI request]
  D --> F[Other request unchanged]
  E --> G[Preserve caller value or add identifier]
Loading

Decision needed

Question Recommendation
Should the public OpenAI stream family support the opt-in static params.safetyIdentifier setting with the proposed endpoint and privacy restrictions? Accept the bounded opt-in setting: Approve the existing wrapper design with hashed operator-supplied values, caller precedence, and native Platform endpoint restrictions.

Why: Live API acceptance establishes technical feasibility, but does not authorize a new configuration capability or settle its public SDK semantics.

Before merge

  • Resolve merge risk (P1) - The public OpenAI stream family will begin forwarding a valid configured safetyIdentifier that was previously ignored; maintainer acceptance of this additive SDK contract and static identity scope is not recorded.
  • Complete next step (P2) - Record maintainer acceptance of the opt-in SDK behavior and add the focused test file's measured single-worker wall time and available CI duration to the PR evidence.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +89, Tests +234, Docs +4. Total +327 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 89 0 +89
Tests 1 234 0 +234
Docs 2 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 327 0 +327

Review metrics

Metric Value Why it matters
Configuration surface 1 optional model parameter; no new default The setting is inert until configured, limiting the compatibility decision to its newly supported behavior.
Production versus test growth production +89 lines; tests +234 lines Production growth implements one validated wrapper and its shared endpoint gate; tests protect request shaping and exclusions.

Merge-risk options

Maintainer options:

  1. Approve the additive family behavior (recommended)
    Record acceptance that configured safetyIdentifier values become outbound request fields while unconfigured requests retain existing behavior.
  2. Pause pending the provider contract
    Retain the useful implementation while the provider owner decides whether this static setting should be part of the public family.

Technical review

Best possible solution:

Keep one opt-in OpenAI-owned request wrapper, preserve caller precedence and endpoint exclusions, and make its static hashed-identity scope explicit in the accepted SDK contract.

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

Not applicable as a defect reproduction: this adds a capability absent from current main. The supplied real agent traces demonstrate the proposed field on both supported API paths.

Is this the best way to solve the issue?

Yes, technically: the existing provider family and shared endpoint policy are a narrow implementation path. Acceptance of the static configuration scope remains a maintainer choice.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an optional provider configuration improvement without reported functional breakage.
  • merge-risk: 🚨 compatibility: The existing public SDK family gains observable behavior for a configured parameter, requiring explicit contract acceptance.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The contributor exercised the embedded OpenClaw provider wrapper through real agent execution and a capture proxy: Responses and Chat Completions requests carried the identifier and returned HTTP 200 with completed replies. The changed production modules remain identical to the preceding reviewed head. No stored-data contract changes or migrations are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor exercised the embedded OpenClaw provider wrapper through real agent execution and a capture proxy: Responses and Chat Completions requests carried the identifier and returned HTTP 200 with completed replies. The changed production modules remain identical to the preceding reviewed head. No stored-data contract changes or migrations are introduced.

Evidence

What I checked:

  • Pinned introduction: Inspected the verified base-to-head delta and all six introduced paths; the changes are confined to the optional parameter, endpoint capability, wrapper composition, documentation, and tests. (6f7fcb8ad1bc)
  • Current main still lacks the capability: The complete current-main search found no safetyIdentifier, safety_identifier, or safety_id occurrences across source, packages, plugins, and docs. The existing extra-body wrapper applies only to Chat Completions, so it does not solve the Responses request. (src/agents/openai-completions-payload-policy.ts:86, f71437a98f53)
  • Latest release check: The public v2026.9.8 provider-stream source contains the existing OpenAI stream family and service-tier handling, but no safety-identifier handling. This is not an already-shipped replacement for the PR. (src/plugin-sdk/provider-stream.ts, fc23bc864e45)
  • Endpoint and value safeguards: Read the complete resolver and payload-policy owner. Values are trimmed and bounded to 64 characters; warnings expose only type or length. Injection requires provider openai, a supported API, and api.openai.com, and preserves an existing payload value. (src/llm/providers/stream-wrappers/openai-safety-identifier.ts:24, 6f7fcb8ad1bc)
  • Public SDK behavior change: The existing public stream-family builder now consumes safetyIdentifier and attaches its wrapper. The new helpers are not re-exported as additional public functions, but the existing family's observable behavior changes; no maintainer acceptance is recorded. (src/plugin-sdk/provider-stream.ts:140, 6f7fcb8ad1bc)
  • Affirmative OpenAI dependency contract: The wrapper explicitly injects OpenAI's wire field and enforces its stated limit, making the OpenAI request contract applicable. The pinned official SDK declares safety_identifier on Responses create parameters with the 64-character limit and hashing guidance. (src/resources/responses/responses.ts:1272, 41f85bde828c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the focused test file's measured single-worker wall time and available CI duration in the PR evidence.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-14T09:58:24.784Z sha 25db2a2 :: blocked before merge. :: none
  • reviewed 2026-09-14T11:20:19.626Z sha 8b394f6 :: blocked before merge. :: none
  • reviewed 2026-09-14T12:13:53.604Z sha 21c4b21 :: blocked before merge. :: none
  • reviewed 2026-09-21T14:06:47.555Z sha f685aaf :: blocked before merge. :: none
  • reviewed 2026-09-21T14:22:40.765Z sha 7284500 :: blocked before merge. :: none
  • reviewed 2026-09-21T15:54:03.988Z sha 435b2f5 :: blocked before merge. :: none
  • reviewed September 27, 2026, 8:29 PM ET / September 28, 2026, 00:29 UTC (Revision 13) sha unknown :: blocked before merge. :: none
  • reviewed 2026-10-05T12:41:48.931Z sha 2674f0d :: blocked before merge. :: none

@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 endpoint gating is appropriately conservative: the field is injected only for native OpenAI Platform requests, not because a provider merely calls itself OpenAI. Preserving caller-provided safety_identifier and ignoring empty/invalid config avoids surprising request mutation. Keeping identity derivation out of scope is also correct; a static configured identifier should not silently become a per-user privacy policy.

@lgrosales

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed 910851d5: cap safetyIdentifier at OpenAI's documented 64-character limit with a focused test, and added SDK-pinned external contract references for safety_identifier on both Responses and Chat Completions to the PR body (the Evidence section now also states the live-trace status).

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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
@lgrosales
lgrosales force-pushed the feat/openai-safety-identifier branch from 910851d to 01c96c4 Compare September 7, 2026 15:42
@lgrosales

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed 01c96c42 (rebased onto current main 5d36078):

  • Addressed the P2 alias-precedence finding by exposing a single canonical spelling, params.safetyIdentifier. The snake_case alias is no longer accepted, so the literal-key scope merge cannot let a lower-precedence spelling win; a test now asserts the alias is ignored.
  • Docs moved with main's reorganisation to docs/gateway/config-agents/models.md.
  • The control-ui-performance failure was the pre-rebase branch measuring against the old committed startup-JS baseline; main bumped it on 2026-09-04 and this PR touches no Control UI code. Rebase picks up the new baseline.
  • Live api.openai.com trace remains outstanding; the PR body's Evidence section states why and cites the SDK-pinned field contract.

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@lgrosales

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Pushed 3b466fc0 (rebased onto current main bd8b6b7, no changes to PR files). The Evidence section now includes redacted live traces captured with openclaw proxy run using this PR's build: HTTP 200 from api.openai.com on both the Responses API and Chat Completions with safety_identifier present in the outbound body, plus the operator note that the field is injected by the embedded OpenClaw runtime (pin agentRuntime: openclaw where the Codex harness would otherwise handle the turn).

The prior checks-node-compact-large-11 failure was src/agents/worktrees/git.test.ts > rejects incomplete required stdout (stack overflow instead of the output-limit error); this PR does not touch that code and the test passes locally on this branch.

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@lgrosales
lgrosales force-pushed the feat/openai-safety-identifier branch from 46d89cd to 3b466fc Compare September 8, 2026 09:19
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. 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 8, 2026
@lgrosales

lgrosales commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

CI note for maintainers: the checks-node-compact-* shards have failed on every run of this PR, each time on a test outside the files this PR touches. The PR diff has no changes under src/agents/worktrees, src/agents/subagents, src/gateway, scripts/, or test/scripts, and per CONTRIBUTING I have not touched those tests here.

Currently failing on main-tip PRs generally (not specific to this branch):

Flaky timing/resource failures (pass locally, other PRs pass the same shards):

Was failing on main itself (2026-10-05), resolved by merging main:

Resolved by merging main:

Fixed in this PR: the checks-fast-baseline-ratchets line-cap failure on f685aaf (growth in over-cap stream-wrappers/openai.ts and embedded-agent-runner-extraparams.test.ts) is addressed by moving the safety-identifier code and its tests into sibling modules; both files are back to their main line counts and the ratchet passes locally.

The branch is merged up to current main (2026-10-05: resolved a conflict from upstream dropping the explicit OpenAIResponsesPayloadCapabilities type in favor of an inferred return type; the allowsSafetyIdentifier capability carries over unchanged). A job rerun needs repository write access.

lgrosales and others added 3 commits September 8, 2026 10:38
Add a per-model `params.safetyIdentifier` / `params.safety_identifier` that
OpenClaw forwards as OpenAI's `safety_identifier` request field on native
OpenAI Platform Responses and Chat Completions requests, so abuse-monitoring
signals can be attributed to a deployment or hashed end user.

- Gate injection through the shared Responses payload policy
  (`allowsSafetyIdentifier`): api.openai.com only; the ChatGPT/Codex
  backend, Azure OpenAI, and OpenAI-compatible proxies are untouched.
- Caller-provided `safety_identifier` values win; empty, non-string, or
  oversized values are ignored with a warning.
- Wire the wrapper into the `openai-responses-defaults` stream family
  alongside `serviceTier`.
- Cover Responses, Chat Completions, snake_case alias, caller precedence,
  and non-native routes in the extra-params test suite; document the param.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… limit

OpenAI documents `safety_identifier` as a per-user string with a maximum
length of 64 characters. Reject longer values with a warning instead of
forwarding them, add a focused test, and note the limit in the config docs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…precedence intact

Extra params are merged across global, per-model, and per-agent scopes by
literal key before the resolver runs, so accepting a snake_case alias let a
lower-precedence scope's spelling win over a higher-precedence override.
Recognise only `params.safetyIdentifier`, cover the rejected alias in tests,
and update the docs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@lgrosales
lgrosales force-pushed the feat/openai-safety-identifier branch from 3b466fc to 1485d51 Compare September 8, 2026 09:39
lgrosales and others added 8 commits September 14, 2026 10:44
…identifier

# Conflicts:
#	docs/providers/openai.md
…g modules

main now enforces a line-cap ratchet that rejects growth in files already over
their cap. The safety-identifier resolver and wrapper move from
stream-wrappers/openai.ts into stream-wrappers/openai-safety-identifier.ts, and
their focused tests move from embedded-agent-runner-extraparams.test.ts into
embedded-agent-runner-extraparams-openai-safety-identifier.test.ts, following
the existing provider-sibling pattern. No behavior change; both original files
return to their main line counts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @lgrosales for the proposal and careful privacy notes. Current main already forwards an explicit params.extraBody.safety_identifier (alias extra_body) on native api: "openai-completions" requests through the shared policy from #153451 (50324f6). A configuration-to-serialized-request probe passed for both aliases; leaving it unset omitted the field.

I landed the credited docs replacement #189686 to make that existing path discoverable. Closing in favor of that configuration path. Direct openai-responses configurations and the native Codex runtime remain outside this passthrough, and the docs state that limitation. No identity is automatically derived. Thank you!

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Send OpenAI safety_identifier via a params.safetyIdentifier model param

3 participants