Repository navigation
fix(py/agents): redact custom agent exception text in failed turns - #7112
huangjeff5 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Genkit Python SDK's agent runtime to redact foreign exception messages, replacing them with a generic 'internal error' to prevent raw exception details from leaking to clients. The original tracebacks are instead logged on the server side using log_dropped_failure. Feedback on the changes suggests avoiding logging asyncio.CancelledError as an error to prevent polluting production logs during normal client cancellations.
| message = INTERNAL_FINISH_MESSAGE | ||
| redacted = True |
There was a problem hiding this comment.
Logging asyncio.CancelledError as an ERROR with a traceback on every normal cancellation or client disconnect can severely pollute production logs and trigger false alarms in error monitoring systems. Since cancellation is a normal lifecycle event and does not represent a leaked failure cause, we should avoid calling log_dropped_failure for it by setting redacted to False when the exception is a CancelledError.
| message = INTERNAL_FINISH_MESSAGE | |
| redacted = True | |
| message = INTERNAL_FINISH_MESSAGE | |
| redacted = not isinstance(exc, asyncio.CancelledError) |
|
Closing: migrated to standalone repository genkit-ai/genkit-python (PR #41): genkit-ai/genkit-python#41 |
A custom agent that raises a plain exception now records
INTERNAL/internal erroron the failed turn, notstr(exc). The original exception goes to the server log with its traceback. This is the same rulegenerateuses for a raising tool.AgentOutput.errorand snapshot errors reach HTTP callers in a 200 response body, so before this change any exception text, including credentials and DSNs, went straight to the client.Main Changes
to_error_detailsusedstr(exc)for anything that wasn't aGenkitError. Prompt agents didn't leak, becausegenerateboxes tool and model errors first. Custom agents had no such step. Non-Genkit exceptions now becomeinternal error, using generate'sINTERNAL_FINISH_MESSAGE. Status classification is unchanged:TimeoutErrormaps toDEADLINE_EXCEEDEDandCancelledErrortoCANCELLED.to_error_detailsnow calls generate'sboxed_finish_message. AGenkitErrororPublicErrorkeeps its status and message. AnINTERNALGenkitErrorwith a foreigncause=is redacted, because its message is usually the wrapped text. That matches what a flow does when it wraps aRuntimeError(seeexp_agents_import_test). One exception:interrupt_escape_error's "Interrupt raised outside a tool" keeps its framework-authored message, since the attached cause there is anInterrupt, not foreign text.log_dropped_failure, which gets a newagent=field so the log line names the culprit. A prompt agent whose tool crashes is still logged only once.generatealready logged the tool error, and the runtime sees aGenkitErrorthat already carriesinternal error, so it has nothing new to hide.Parity
go/ai/exp/agent.goclientSafeError): the store keeps the full text. When the agent is served,AgentOutput.Errorand snapshot errors are rewritten to the generic status message unless the error isPublicErrorfor the env is dev. Python now redacts at record time, so the stored snapshot is redacted too. Python has no "served" context marker, and a snapshot read back overgetSnapshotis client-visible either way.js/ai/src/agent.tstoErrorDetails): still recordse.messageunredacted. Same bug, follow-up PR.Tests
custom agent raises ValueError→INTERNAL/internal error, secret absent from the wire shape, one ERROR log naming the agent with the original exception.custom agent raises GenkitError(NOT_FOUND, ...)→ passes through, no log.prompt agent with crashing tool→internal error, logged once (tool site only).to_error_detailsparametrized: addsPublicErrorpassthrough and the redactedINTERNALwrapper with a foreign cause.customAgentFailingnow raisesGenkitError('intentional failure'), because the shared spec reads that message back off the snapshot. The detach test now asserts the redacted snapshot.