fix: sanitize error details on log update path, set MCP raw-storage flag, remove redundant error serialization - #4913
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 15 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughAdds an internal helper in core/bifrost.go to explicitly set the raw-storage-in-logs context flag for standalone MCP tool executions before invoking MCP tools. Reworks plugins/logging to replace helper-based error-detail marshaling with ChangesMCP raw-storage flag and error sanitization
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
plugins/logging/main.go (1)
1613-1621: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFabricated nil-response error bypasses
sanitizeErrorForLogging.The doc comment at Line 115 states every
ErrorDetailsParsedassignment (Log and MCPToolLog alike) must go throughsanitizeErrorForLogging, but this branch constructs the error directly. It's harmless today (noExtraFieldspopulated), but it's an easy trap for a future edit that adds raw payload fields here without sanitization.♻️ Suggested fix for consistency with the documented invariant
} else { entry.Status = "error" - entry.ErrorDetailsParsed = &schemas.BifrostError{ + entry.ErrorDetailsParsed = sanitizeErrorForLogging(&schemas.BifrostError{ IsBifrostError: true, Error: &schemas.ErrorField{ Message: "MCP tool execution returned nil response", }, - } + }, p.contentLoggingEnabled(ctx), false) }🤖 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 `@plugins/logging/main.go` around lines 1613 - 1621, The nil-response error branch in the logging path is constructing entry.ErrorDetailsParsed directly instead of using the required sanitizeErrorForLogging flow. Update the MCP tool logging logic that sets entry.Status and entry.ErrorDetailsParsed to route this fabricated “MCP tool execution returned nil response” case through sanitizeErrorForLogging, matching the invariant documented for ErrorDetailsParsed assignments and keeping the behavior consistent with other Log and MCPToolLog error handling.
🤖 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 `@core/bifrost.go`:
- Around line 2779-2800: ensureMCPRawStorageContext is mutating the shared
bifrost.ctx via BifrostContextKeyShouldStoreRawInLogs, which can leak the
raw-storage decision across unrelated standalone MCP calls. Update
ExecuteChatMCPTool/ExecuteResponsesMCPTool to use a request-scoped context copy
or compute the effective raw-storage value locally before PostMCPHook handling,
and keep ensureMCPRawStorageContext from writing onto the reused instance
context when ctx is nil or shared.
---
Nitpick comments:
In `@plugins/logging/main.go`:
- Around line 1613-1621: The nil-response error branch in the logging path is
constructing entry.ErrorDetailsParsed directly instead of using the required
sanitizeErrorForLogging flow. Update the MCP tool logging logic that sets
entry.Status and entry.ErrorDetailsParsed to route this fabricated “MCP tool
execution returned nil response” case through sanitizeErrorForLogging, matching
the invariant documented for ErrorDetailsParsed assignments and keeping the
behavior consistent with other Log and MCPToolLog error handling.
🪄 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: 1226fb79-7b9b-4874-8e35-a5c9184f8077
📒 Files selected for processing (7)
core/bifrost.gocore/changelog.mdplugins/logging/changelog.mdplugins/logging/main.goplugins/logging/operations.goplugins/logging/operations_test.goplugins/logging/sanitize_test.go
…lag, remove redundant error serialization Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
30e57eb to
f4e93f8
Compare
Merge activity
|

Summary
Two related logging correctness bugs are fixed: standalone MCP tool executions did not set the raw-storage context flag before calling
PostMCPHook, so logging consumers received an uninitialized value; and theupdateLogEntrypath assignedErrorDetailsdirectly toErrorDetailsParsedwithout sanitizing it first, allowing raw request/response payloads to reach the store even when content logging was disabled.Changes
ensureMCPRawStorageContextwhich computes and setsBifrostContextKeyShouldStoreRawInLogson the context before standalone MCP tool executions (ExecuteChatMCPTool/ExecuteResponsesMCPTool). In-pipeline tool calls already carry this key from the LLM request path, so an existing value is never overwritten. Because there is no provider config on the standalone path, only the per-request override is honored.applyErrorDetailsToEntryandapplyErrorDetailsToMCPEntry. Their immediate-serialization behavior was based on a now-incorrect assumption thatErrorDetails(the string field) takes precedence;logstore.SerializeFieldsactually serializesErrorDetailsParsedand overwritesErrorDetailson every write path. Callers now assignsanitizeErrorForLogging(...)directly toErrorDetailsParsedand letSerializeFieldshandle serialization.updateLogEntrynow passesErrorDetailsthroughsanitizeErrorForLoggingbefore assigning it toErrorDetailsParsed, closing the update-path leak.applyStreamingOutputToEntryfollows the same pattern for streaming error entries.ErrorDetailsParsed != nilinstead of also checking the string field, which was redundant after the above change.ErrorDetailsis populated bySerializeFieldsrather than immediately, and a new end-to-end test (TestUpdateLogEntrySanitizesErrorDetails) verifies the update-path sanitization against a real store.Type of change
Affected areas
How to test
go test ./core/... ./plugins/logging/...The new
TestUpdateLogEntrySanitizesErrorDetailstest inserts an initial log entry, applies an update carrying raw payloads with content logging disabled, and asserts that the storederror_detailscolumn contains neitherRAW_REQUEST_MARKERnorRAW_RESPONSE_MARKERwhile still containing the error message.Breaking changes
Security considerations
Raw request and response payloads were leaking into the log store on two paths (standalone MCP executions and the
updateLogEntrypath) whendisable_content_loggingwas set. Both leaks are now closed. No new secrets, auth surfaces, or PII handling is introduced.Checklist
docs/contributing/README.mdand followed the guidelines