Skip to content

fix(aws): preserve safeguards in Bedrock Invoke requests - #8071

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
lushuntian:codex/aws-bedrock-safeguards
Oct 28, 2026
Merged

seefs001 merged 1 commit into
QuantumNous:mainfrom
lushuntian:codex/aws-bedrock-safeguards

Conversation

@lushuntian

@lushuntian lushuntian commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Agent

  • Tool: Codex Desktop;代码与测试由 AI 辅助编写。
  • Tool version: 会话运行时 0.163.0-alpha.11
  • Model (full id): gpt-6-astra
  • Host: Desktop
  • Date (UTC): 2026-10-28

Links

User request

  • Verbatim: “提交issues和pr,提出这个AWS DTO缺失问题和修复建议”
  • Later constraints or corrections from the user: 无。

Out of scope — refuse

  • Matched: no。修改 AWS AK/SK 的普通请求转换,不是透传模式或第三方服务兼容。
  • If yes: 不适用。

Open gate — do not open unless all are satisfied

  • Out of scope (including pass-through-only forwarding): no
  • Usage / configuration / integration: no
  • Required issue facts present without invention: yes
  • Verification is actual commands or steps and observed results: yes,见 Verification。
  • Body is short and factual; no unfiltered AI-generated text: yes
  • Open: yes
  • If no: 不适用。

Kind

  • Bug fix

Issue facts

  • Actual behavior: 通用 Claude DTO 接收 safeguards,AWS DTO 解码时丢弃;beta 保留,但响应审核结果为空。
  • Impact: 调用方请求的服务端工具审核未执行。
  • Frequency: 同一 AWS 渠道核实的有效非流式、流式各一次均为空;错误对象一次也被忽略。回归中六个带字段子用例在修复前失败。
  • Evidence: 同凭据、区域、模型的 AWS 直连有 available / evaluated / not_flagged;本地检查最终 SDK Body,补字段前后有确定差异。
  • Applicable types: Relay,POST /v1/messages,AWS 33 / AK/SK,claude-sonnet-5 → global.anthropic.claude-sonnet-5,us-east-1;复现显式关闭全局和渠道透传。其他类型不适用;完整请求和对照见 Issue。

Change

给 AwsClaudeRequest 增加 Safeguards json.RawMessage(json:"safeguards,omitempty"),使 formatRequest 和 buildAwsRequestBody 的转换保留该字段。省略参数时不会新增字段;格式校验仍交给上游,错误对象不会再被静默丢弃。

Research

Duplicate / prior art

Docs and code

  • 官方渠道文档:配置/参数覆盖不能修复解码时字段被丢弃。
  • DeepWiki Claude 说明:核对 AWS/Claude 适配路径。
  • README:支持 Anthropic Messages 与 AWS 上游。
  • Code: relaykit/dto/claude.go 已接收字段;relay/channel/aws/dto.go 缺字段;relay-aws.go 的流式和非流式都使用重新序列化的 AWS DTO。

Alternatives considered

  • Option A: 补齐现有 DTO 字段,保持现有转换规则。
  • Option B: 改成任意未知字段透传,扩大协议行为变化。
  • Why this approach: 单字段修复即可解决已定位的丢参,不需要修改通用转换框架。

Files

Path Why
relay/channel/aws/dto.go 增加可选 Safeguards 字段。
relay/channel/aws/relay_aws_test.go 检查流式、非流式最终 SDK Body,并验证省略字段时旧请求不变。

Behavior

  • Before: safeguards 在 AWS DTO 解码时消失,错误格式也被忽略。
  • After: 保留调用方输入;省略参数的输出字节与原有请求一致。
  • Explicit non-goals / leftover work: 不自动注入 beta,不改变审核策略或执行工具;没有部署本修复。

Verification

  • Commands and results: Windows amd64 / Go 1.26.10。在官方 main 01da3a55 的独立源码目录运行:
    • go test -overlay=baseline.overlay.json ./relay/channel/aws -run '^TestDoAwsClientRequest_PreservesSafeguards$' -count=1 -v:overlay 仅将 AWS DTO 映射回修复前版本;六个带字段子用例失败,两个 omitted 子用例通过。
    • go test ./relay/channel/aws -count=1:加入字段后整个 AWS 包通过(0.162s),包括新增的八个子用例;omitted 两例断言原请求字节完全一致。
    • gofmt -l relay/channel/aws/dto.go relay/channel/aws/relay_aws_test.go:无输出;对两个文件执行 git diff --no-index --check:无空白错误。
  • Manual steps and observed result: 2026-10-28 对同一 AWS 凭据/区域/模型直连和经网关做对照。直连有效数组返回非空且匹配实际 tool_use.id 的评估(流式、非流式);beta-only 返回空数组;错误对象返回 400。网关有效数组和错误对象都返回 200 / []。请求见 Issue;未执行模型生成的工具调用。
  • UI: 不适用,后端 DTO 修复。
  • Tests: 扩展现有测试文件,覆盖 omitted、empty_array、dangerous_tool_use、invalid_object,分别检查两种 SDK 请求类型;使用假凭据,不发起外部调用。
  • Databases / providers / platforms: 本地 Windows / Go;上述 AWS us-east-1 直连和未修复网关。测试不依赖数据库。
  • Not verified: 修复后的线上端到端请求;其他 AWS 模型、区域、Mantle、Converse、其他供应商。

Risks

  • Failure modes: 上游不支持或请求格式错误时会返回其校验错误;此前被静默丢弃的错误对象可能从 200 变为 400。
  • Billing / quota / auth impact: 未修改相关代码或 usage;新增能力是否可用由上游判断。
  • Follow-ups: 部署后用相同对照请求核验实际评估结果。

Scope check

  • Single focused change: yes
  • Secrets included: no
  • Out of scope (Coding Plan / reverse-engineered channel / third-party wrapper / Codex / pass-through-only forwarding): no

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d982c4fe-83d8-4d19-90bd-74b90a497d25
Commits

Reviewing files that changed from the base of the PR and between 01da3a5 and 6dd2183.

Files selected for processing: 2
  • relay/channel/aws/dto.go
  • relay/channel/aws/relay_aws_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The AWS Claude request DTO now includes an optional safeguards field stored as raw JSON. Tests cover streaming and non-streaming requests, checking that omitted values preserve the legacy body and supplied values remain in the outbound JSON.

Changes

AWS safeguards request conversion

Layer / File(s) Summary
Safeguards field and request preservation tests
relay/channel/aws/dto.go, relay/channel/aws/relay_aws_test.go
AwsClaudeRequest adds an optional raw JSON safeguards field. Tests cover omitted, empty-array, dangerous-tool-use, and invalid-object values with pass-through disabled. They check both streaming modes and verify that omission leaves the legacy body unchanged.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: calcium-ion, seefs001

Merge Risk: Minimal · up to 6dd21

No actionable merge-blocking risk was identified in the safeguards change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(aws): preserve safeguards in Bedrock Invoke requests" matches the main change. The DTO change adds an optional Safeguards json.RawMessage field to AwsClaudeRequest, so Invoke request co…
Linked Issues check Passed No active directly linked coding issue remains. Issue #8070 is closed and supplies historical context only. Therefore, no linked-issue coding requirement applies.
Out of Scope Changes check Passed The changes stay within the reported AWS DTO defect. AwsClaudeRequest adds the optional Safeguards field, and the test covers streaming, non-streaming, omitted, valid, and invalid values. The PR d…
Full details: Title check

Explanation

The title "fix(aws): preserve safeguards in Bedrock Invoke requests" matches the main change. The DTO change adds an optional Safeguards json.RawMessage field to AwsClaudeRequest, so Invoke request conversion keeps the caller's safeguards value. The added test TestDoAwsClientRequest_PreservesSafeguards covers this behavior. The title is specific and concise, and it names the affected area (AWS) and the feature (safeguards in Bedrock Invoke requests).

Full details: Out of Scope Changes check

Explanation

The changes stay within the reported AWS DTO defect. AwsClaudeRequest adds the optional Safeguards field, and the test covers streaming, non-streaming, omitted, valid, and invalid values. The PR does not add beta injection, change safeguard policy, alter tool execution, or add generic field forwarding.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the request with care,
A safeguards field now travels there.
Through streams and single calls it goes,
The empty case keeps its old prose.
The test hops by, then rests its ears.

Comment @coderabbitai help to get the list of available commands.

@seefs001
seefs001 merged commit 49271d2 into QuantumNous:main Oct 28, 2026
1 check passed
hydraxman pushed a commit to MindxMotion/MEM-AI that referenced this pull request Oct 28, 2026
Select nine upstream fixes from QuantumNous/new-api main at 49271d2. Preserve OIDC, root-managed integration clients, bounded diagnostics, canonical mem-ai routes, and existing dependencies. Do not include pricing, schema, frontend, or deployment changes.

Keep the AWS safeguards regression without importing unrelated thinking-binding tests from three-way context. Add canceled-context stream coverage alongside the upstream non-stream regression.

Upstream sources:
bc795cc fix:修复stop为非字符串和[]string的协议转换问题 (QuantumNous#7935)
4d962e4 fix(relaykit): preserve tool argument numbers in Claude responses (QuantumNous#7996)
0165fef fix(relaykit): preserve Gemini text alongside tool calls (QuantumNous#7998)
34003e9 test: stabilize channel affinity cache keys (QuantumNous#8009)
01da3a5 perf(relay): stop recompiling param override regexes on every request (QuantumNous#8061)
ad56112 fix(relay): apply GPT-6 chat parameter rules to gpt-6.1-sol and gpt-6.1-terra (QuantumNous#8064)
3f926c3 fix(metrics): count completed streams after context cancellation (QuantumNous#7638)
5478811 fix: count completed non-stream relays after context cancellation (QuantumNous#7844)
49271d2 fix(aws): preserve safeguards in Bedrock Invoke requests (QuantumNous#8071)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kyuhwi-choi pushed a commit to attodev/new-api that referenced this pull request Oct 30, 2026
woncc added a commit to 86669666/new-api that referenced this pull request Nov 1, 2026
…#8071) (#131)

Co-authored-by: sunday <74896751+lushuntian@users.noreply.github.com>
shirosoralumie648 added a commit to shirosoralumie648/newapi-rev that referenced this pull request Nov 5, 2026
Sync 75 upstream commit(s) via merge (fork history preserved).

Upstream commits:
- 7061447 fix(auth): 校验 Redis 鉴权缓存完整性 (QuantumNous#8200)
- ba5f736 fix(gemini): bill embeddings from upstream usageMetadata (QuantumNous#8182)
- 94b5216 feat(vertex): add per-channel v1beta1 endpoint switch (QuantumNous#8179)
- 83b18fe feat(channel): return created IDs with input mappings (QuantumNous#8164)
- 52c1730 feat(gemini): add Argon fields and reasoning mappings (QuantumNous#8177)
- 9b473a3 fix(twofa): restart the failure count after a lockout expires (QuantumNous#8172)
- 45746ee feat(relay): add opt-in HTTP/2 health checks (QuantumNous#8059)
- c046559 feat(plugins): bill gemini omni by the tokens vertex reports (QuantumNous#8153)
- 651d5a2 fix(xai): preserve token details in stream usage conversion (QuantumNous#6420)
- 70e6af6 perf: read and edit request JSON and base64 with moego (QuantumNous#8148)
- d0abbf6 feat(plugins): generate video with Gemini Omni on Vertex AI channels (QuantumNous#8142)
- ea343c4 fix(plugins): charge relayed streams even when the reserve or task insert fails (QuantumNous#8121)
- fe57cba fix(plugins): prefer Kling's returned price (list_price) for Kling 4.0 cash billing (QuantumNous#8125)
- 1424ffd fix(plugins): load plugins that declare their own /{key} address (QuantumNous#8119)
- 8b253de fix(plugins): keep Kling 4.0 durations in range and map every video size (QuantumNous#8118)
- c59f6fd feat(plugins): serve task plugins at the vendors' own paths and answer as the vendors do (QuantumNous#8117)
- 37d23dc fix(profile): honor global sidebar visibility (QuantumNous#7429)
- 7743627 fix(deps): upgrade DOMPurify to 3.4.17 (QuantumNous#8116)
- 883eeb8 feat(plugins): warn about task models a plugin cannot charge
- 1e8c707 chore(deps): bump @codemirror/language from 6.12.4 to 6.13.1 in /web (QuantumNous#8102)
- 6e78cb3 chore(deps): bump marked from 18.0.6 to 18.1.2 in /web (QuantumNous#8103)
- 9fc70bb chore(deps-dev): bump @tanstack/react-query-devtools in /web (QuantumNous#8104)
- cef7820 chore(deps-dev): bump knip from 6.27.0 to 6.43.0 in /web (QuantumNous#8105)
- 1695171 chore(deps): bump tailwind-merge from 3.6.0 to 3.7.0 in /web (QuantumNous#8106)
- 7fa815e chore(deps-dev): bump fast-uri from 3.1.7 to 3.1.9 in /electron (QuantumNous#8007)
- ee0f0ac chore(deps-dev): bump electron from 41.10.6 to 42.11.16 in /electron (QuantumNous#8008)
- 837b814 chore(deps): bump undici in /electron (QuantumNous#8006)
- 3150dfe chore(deps): bump github.com/go-jose/go-jose/v4 from 4.1.4 to 4.1.6 (QuantumNous#8112)
- a3851c2 fix: save Turnstile keys before enabling (QuantumNous#7960)
- 4193734 fix(logger): keep gin access and recovery logs on the current log file after rotation (QuantumNous#8098)
- f366017 Merge commit from fork
- 829f082 fix: unmount authenticated layout on sign-out to stop credential-less refetches (QuantumNous#8110)
- 9eda50a Merge commit from fork
- a2defd2 Merge commit from fork
- e449cc7 feat: sample immediate task successes in model performance metrics (QuantumNous#8067)
- fcc241c fix: start affinity fallback at the highest channel priority (QuantumNous#8078)
- b08ee86 fix(cloudflare): preserve embedding response data (QuantumNous#8041)
- 26c488c fix(relay): allow Azure channels to opt in to Responses WebSocket (QuantumNous#8047) (QuantumNous#8075)
- 55515db fix(relay): terminate streams on exact bare done markers (QuantumNous#8074)
- 49271d2 fix(aws): preserve safeguards in Bedrock Invoke requests (QuantumNous#8071)
- 5478811 fix: count completed non-stream relays after context cancellation (QuantumNous#7844)
- ad56112 fix(relay): apply GPT-6 chat parameter rules to gpt-6.1-sol and gpt-6.1-terra (QuantumNous#8064)
- 01da3a5 perf(relay): stop recompiling param override regexes on every request (QuantumNous#8061)
- 34003e9 test: stabilize channel affinity cache keys (QuantumNous#8009)
- 0165fef fix(relaykit): preserve Gemini text alongside tool calls (QuantumNous#7998)
- 4d962e4 fix(relaykit): preserve tool argument numbers in Claude responses (QuantumNous#7996)
- f1569d1 fix(pricing): classify dynamic per-request billing correctly (QuantumNous#8010)
- bc795cc fix:修复stop为非字符串和[]string的协议转换问题 (QuantumNous#7935)
- 9823ebc fix(billing): bill cache_creation_input_tokens reported in prompt_tokens_details (QuantumNous#7909)
- e835b1b chore(deps): bump axios from 1.18.1 to 1.20.0 in /web (QuantumNous#7835)
- 5c8032d chore(deps): bump react-i18next from 17.0.10 to 17.1.0 in /web (QuantumNous#7981)
- 0b667ca chore(deps): bump i18next from 26.3.6 to 26.5.3 in /web (QuantumNous#7979)
- 4105bd0 chore(deps): bump input-otp from 1.4.2 to 1.5.0 in /web (QuantumNous#7980)
- b6b85ca chore(deps): bump react-resizable-panels from 4.12.2 to 4.14.6 in /web (QuantumNous#7982)
- 1dafb19 fix(gemini): preserve top-level imageConfig in chat conversion
- 0034b24 fix(task): wait up to 72 hours before timing out tasks
- a404460 chore(web): upgrade Bun to 1.4.4 and use bun check
- 33c61a2 fix: prevent stale values when switching edit drawer records (QuantumNous#7989)
- 30748c6 fix(logging): 隐藏访问日志中的查询凭据 (QuantumNous#7972)
- 7fb6e57 fix(channels): preserve advanced custom body passthrough settings (QuantumNous#7971)
- e9d4d63 feat(billing): bill OpenAI 12-hour prompt cache writes at their own price (QuantumNous#7965)
- d0b840e fix(relay): keep the client's JSON Schema property order
- d8e6561 feat(web): copy model names from usage log details
- 8802113 feat(task): let ordinary channels compete on shared plugin endpoints
- eb169e7 feat(pricing): adjust synced upstream prices by the site exchange rate
- e2321a5 chore(web): sort locale keys
- db80ac8 fix(task): let task plugins validate their own requests
- dbe97be feat(task): pass client request headers to task plugin drivers
- 556517f feat(task): accept multipart bodies on native plugin routes
- 94cc3ff fix(billing): bill Claude cache writes that arrive without a 5m/1h split
- 7e65967 fix(relay): stop cutting off slow clients during large stream events
- 0c2af97 fix(relay): finish delivered Responses streams without false disconnect errors (QuantumNous#7956)
- 7d8b912 fix: upgrade Go to 1.26.10 for CVE-2026-111943 (QuantumNous#7942)
- 4d36f2c chore(deps-dev): bump vitest from 4.1.10 to 5.0.4 in /web (QuantumNous#7838)
- eea05e0 chore(deps): bump github.com/klauspost/compress from 1.18.3 to 1.18.7 (QuantumNous#7931)

Local tests not run (CI-only).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS Bedrock AK/SK 请求转换丢失 safeguards,服务端工具审核未执行

2 participants