Skip to content

fix(awaitreply): redact await reply responses - #95

Open
XnLemon wants to merge 1 commit into
mainfrom
codex/phase2-await-reply-error-redaction
Open

fix(awaitreply): redact await reply responses#95
XnLemon wants to merge 1 commit into
mainfrom
codex/phase2-await-reply-error-redaction

Conversation

@XnLemon

@XnLemon XnLemon commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Objective

Close one Phase2 model-visible response redaction gap in the await_user_reply framework tool.

Changes

  • Redact invalid JSON error messages returned by await_user_reply.
  • Redact MarkAwaitingUserReply failure messages before returning them as tool responses.
  • Redact the success response agent_name field to avoid exposing sensitive agent labels.
  • Add regression coverage for non-standard Authorization, api_key, and multi-value Cookie secrets in model-visible response fields.

Validation

  • go test ./tool/awaitreply
  • go vet ./tool/awaitreply
  • git diff --check
  • open-code-review subagent review: 0 High / 0 Medium / 0 Low

Known Risks / Limitations

  • Scope is intentionally limited to await_user_reply tool response fields.

Follow-up

  • Continue Phase2 closure sweep across remaining model-visible error and governance output surfaces in the next stacked increment.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

English

Overview

  • Redacts model-visible await_user_reply response fields using the platform redactor.
  • Covers invalid JSON errors, MarkAwaitingUserReply failures, and successful responses’ agent_name.
  • Adds regression coverage for Authorization, api_key, and multi-value Cookie secrets.

Compatibility and behavioral risks

  • The tool’s response text may now contain redaction placeholders instead of original sensitive values.
  • Tool behavior and public declarations remain unchanged; redaction falls back to the original message if the redactor cannot be initialized.
  • Scope is limited to await_user_reply response fields, reducing impact on unrelated tools.

Recommended validation

  • Run go test ./tool/awaitreply.
  • Run go vet ./tool/awaitreply.
  • Run git diff --check.
  • Confirm responses never expose raw authorization, API key, or cookie secrets.
中文

变更概述

  • 使用平台脱敏器处理 await_user_reply 返回给模型的字段。
  • 覆盖无效 JSON 错误、MarkAwaitingUserReply 失败信息,以及成功响应中的 agent_name
  • 增加针对 Authorizationapi_key 和多值 Cookie 密钥的回归测试。

兼容性与行为风险

  • 工具响应中的敏感值可能会被替换为脱敏占位符。
  • 工具行为和公开声明保持不变;如果脱敏器无法初始化,则回退到原始消息。
  • 变更仅限于 await_user_reply 响应字段,对其他工具影响有限。

建议验证步骤

  • 运行 go test ./tool/awaitreply
  • 运行 go vet ./tool/awaitreply
  • 运行 git diff --check
  • 确认响应中不会泄露原始 Authorization、API key 或 Cookie 密钥。

Walkthrough

The await_user_reply tool now redacts sensitive content in error messages and successful AgentName responses, with tests covering authorization tokens and multiple secret-like fields.

中文:工具现在会清理错误信息和成功响应中的敏感内容,并通过测试验证令牌及多种秘密字段的脱敏行为。

Changes

Await-reply response redaction

Layer / File(s) Summary
Redaction helper and response wiring
tool/awaitreply/await_reply_tool.go
Adds a platform redaction helper with an original-text fallback and applies it to error messages and AgentName responses. 中文:新增脱敏辅助函数,并覆盖错误信息及 AgentName
Redaction behavior tests
tool/awaitreply/await_reply_tool_test.go
Tests masking of authorization tokens and multiple secret-like substrings. 中文:测试授权令牌及多种秘密字段的替换效果。

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: redacting await reply responses.
Description check ✅ Passed The description matches the implemented redaction updates and added regression coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/phase2-await-reply-error-redaction

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

@XnLemon
XnLemon force-pushed the codex/phase2-permission-reason-redaction-sweep branch from 868f193 to 4cbcd6e Compare July 11, 2026 13:38
@XnLemon
XnLemon force-pushed the codex/phase2-await-reply-error-redaction branch from 948d294 to cc081c0 Compare July 11, 2026 13:38
@XnLemon
XnLemon changed the base branch from codex/phase2-permission-reason-redaction-sweep to main July 13, 2026 02:23
@XnLemon
XnLemon force-pushed the codex/phase2-await-reply-error-redaction branch from cc081c0 to 9e88b28 Compare July 13, 2026 02:34

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tool/awaitreply/await_reply_tool.go (1)

99-105: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Keep the redaction fallback fail-closed.

Returning message when platform.NewRedactor() fails defeats this security boundary and can expose the raw error or agent name. The current no-argument constructor appears not to fail with the shown implementation, but use a safe fixed placeholder or propagate the error instead of failing open.

Suggested fail-closed fallback
  redactor, err := platform.NewRedactor()
  if err != nil {
-   return message
+   return "****"
  }
中文

确保脱敏失败时采用故障关闭策略。

platform.NewRedactor() 失败时返回原始 message,会绕过该安全边界并泄露原始错误或 agent 名称。根据当前实现,无参数构造函数似乎不会失败,但仍应返回固定安全占位符或传播错误,避免故障时明文泄露。

As per path instructions, security boundaries and error semantics must remain safe for untrusted model-visible data.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tool/awaitreply/await_reply_tool.go` around lines 99 - 105, Update
redactResponseMessage so a failure from platform.NewRedactor() uses a fixed safe
placeholder or propagates the error instead of returning the raw message.
Preserve redaction for successful initialization and ensure no untrusted content
is exposed through the fallback.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tool/awaitreply/await_reply_tool_test.go`:
- Around line 50-65: Extend TestTool_CallRedactsModelVisibleResponseFields with
end-to-end tests covering the invalid-request response path and the
MarkAwaitingUserReply error path in Call. Assert each returned Message is
redacted while the internally stored route retains the original unredacted agent
name, using the existing test setup and externally observable behavior rather
than testing helper implementation details.

---

Nitpick comments:
In `@tool/awaitreply/await_reply_tool.go`:
- Around line 99-105: Update redactResponseMessage so a failure from
platform.NewRedactor() uses a fixed safe placeholder or propagates the error
instead of returning the raw message. Preserve redaction for successful
initialization and ensure no untrusted content is exposed through the fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0193c0ca-af44-49ab-92f9-f0bd5b1e1450

📥 Commits

Reviewing files that changed from the base of the PR and between 361e2a4 and 9e88b28.

📒 Files selected for processing (2)
  • tool/awaitreply/await_reply_tool.go
  • tool/awaitreply/await_reply_tool_test.go

Comment on lines +50 to +65
func TestTool_CallRedactsModelVisibleResponseFields(t *testing.T) {
tl := New()
inv := &agent.Invocation{
AgentName: "clarifier Authorization: ApiKey raw-token",
}
ctx := agent.NewInvocationContext(context.Background(), inv)

got, err := tl.Call(ctx, []byte(`{}`))
require.NoError(t, err)

resp, ok := got.(Response)
require.True(t, ok)
require.True(t, resp.Success)
require.NotContains(t, resp.AgentName, "raw-token")
require.Contains(t, resp.AgentName, "Authorization: ****")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover every Call response path, not only the helper.

These tests verify successful AgentName redaction and helper patterns, but they would still pass if the invalid-request branch at Line 73 or the MarkAwaitingUserReply error branch at Line 89 stopped redacting Message. Add end-to-end tests for both branches, and assert that the stored route still contains the original unredacted agent name.

As per path instructions, tests should prioritize external behavior, boundary/error paths, and regression scenarios over implementation details.

中文

覆盖 Call 的所有响应路径,而不仅是辅助函数。

当前测试验证了成功响应中的 AgentName 脱敏和辅助函数的规则,但即使 Line 73 的非法请求分支或 Line 89 的 MarkAwaitingUserReply 错误分支停止脱敏,测试仍可能通过。请为这两个分支增加端到端测试,并断言内部保存的路由仍使用原始、未脱敏的 agent 名称。

Also applies to: 110-129

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tool/awaitreply/await_reply_tool_test.go` around lines 50 - 65, Extend
TestTool_CallRedactsModelVisibleResponseFields with end-to-end tests covering
the invalid-request response path and the MarkAwaitingUserReply error path in
Call. Assert each returned Message is redacted while the internally stored route
retains the original unredacted agent name, using the existing test setup and
externally observable behavior rather than testing helper implementation
details.

Source: Path instructions

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.

2 participants