Skip to content

fix(agent): redact internal terminal errors - #18743

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
T1mn:codex/agent-terminal-error-redaction
Aug 25, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
T1mn:codex/agent-terminal-error-redaction

Conversation

@T1mn

@T1mn T1mn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #18316 and #18579.

Agent compile and persistence failures can occur after HTTP streaming starts, bypassing synchronous handler error mapping and exposing backend details in ordinary SSE and OpenAI-compatible responses.

This PR:

  • classifies these failures as internal terminal errors while preserving original causes for errors.Is and server logs;
  • redacts typed internal errors in Runner, ordinary SSE, and OpenAI stream/non-stream adapters;
  • leaves user-actionable workflow errors unchanged;
  • adds regression coverage for Runner, both protocol adapters, and the real compile-failure path.

Refs #15743.

Testing

  • CGO_ENABLED=0 go test -count=1 -run "TestRunnerRedactsInternalRunError|TestRunErrorEventPreservesPublicMessage" ./internal/agent/canvas
  • CGO_ENABLED=0 go test -count=1 -run "TestWriteChatbotRunEvent_RedactsInternalError|TestRunAgent_RealCanvas_CompileFails" ./internal/service
  • CGO_ENABLED=0 go test -count=1 -run "TestAgentChatCompletions_OpenAICompat_(NonStreamRedactsInternalRunnerError|StreamRedactsInternalRunnerError|NonStreamReturnsRunnerError|StreamSurfacesRunnerError)" ./internal/handler
  • CGO_ENABLED=0 go vet ./internal/agent/canvas ./internal/service ./internal/handler

Classify asynchronous compile and persistence failures before Runner emits them, preserving causes for server logs while adapters return a stable public message.

Refs infiniflow#15743
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 25, 2026
@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a72f799-56d0-43ca-9ee2-94db24f89784

📥 Commits

Reviewing files that changed from the base of the PR and between ff4109c and ed3b8c4.

📒 Files selected for processing (10)
  • internal/agent/canvas/run_error.go
  • internal/agent/canvas/run_error_test.go
  • internal/agent/canvas/runner.go
  • internal/handler/agent.go
  • internal/handler/agent_openai.go
  • internal/handler/agent_test.go
  • internal/service/agent.go
  • internal/service/agent_run_e2e_test.go
  • internal/service/bot_completion.go
  • internal/service/bot_completion_history_test.go
💤 Files with no reviewable changes (1)
  • internal/handler/agent.go

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


📝 Walkthrough

Walkthrough

The change adds typed internal run errors that preserve causes for logging while emitting a fixed public message. Canvas runners classify terminal errors, service paths wrap compile and persistence failures, and response adapters redact internal details in streaming and non-streaming outputs.

Changes

Internal run error redaction

Layer / File(s) Summary
Error contract and classification
internal/agent/canvas/run_error.go, internal/agent/canvas/run_error_test.go
Adds internal error constants, cause-preserving wrapping, sanitized event classification, and coverage for public and internal errors.
Runner and service propagation
internal/agent/canvas/runner.go, internal/service/agent.go, internal/service/agent_run_e2e_test.go
Adds the optional error kind, logs internal failures with context, wraps compile and persistence failures, and validates classified terminal events.
Adapter response redaction
internal/handler/agent.go, internal/handler/agent_openai.go, internal/handler/agent_test.go, internal/service/bot_completion.go, internal/service/bot_completion_history_test.go
Removes the old sanitization helper and makes OpenAI-compatible and chatbot responses use the canonical internal error message without exposing connection details.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to ed3b8

The change redacts backend details from internal terminal failures while preserving actionable workflow errors and diagnostic causes; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant AgentService
  participant CanvasRunner
  participant SSEAdapter
  participant Client
  AgentService->>CanvasRunner: return NewInternalRunError(cause)
  CanvasRunner->>CanvasRunner: preserve cause and classify terminal error
  CanvasRunner->>SSEAdapter: emit kind=internal with sanitized message
  SSEAdapter->>Client: return redacted streaming or non-streaming error
Loading

Suggested reviewers: yuzhichang, jinhai-cn

Poem

A rabbit wraps the errors tight

The cause stays safe for logging light
The public message stays the same
No secret hops beyond the frame
SSE carries a cleaner name

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 9 files. 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 and concisely describes the main change: redaction of internal terminal errors in agent flows.
Description check ✅ Passed The description includes the required Summary section, explains the problem and solution, identifies affected response paths, and lists regression tests and references.
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.

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

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

@JinHai-CN
JinHai-CN requested a review from yuzhichang August 25, 2026 09:28
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 25, 2026
@yuzhichang yuzhichang added the ci Continue Integration label Aug 25, 2026
@yuzhichang
yuzhichang merged commit 80f7421 into infiniflow:main Aug 25, 2026
9 checks passed
@T1mn
T1mn deleted the codex/agent-terminal-error-redaction branch August 25, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants