Repository navigation
fix: support email send for go backend - #16895
Conversation
📝 WalkthroughWalkthroughAdds a registered Email workflow component with SMTP delivery, templated fields, recipient parsing, and soft failures. Runtime canvas states now initialize ChangesEmail and runtime execution
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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 `@internal/agent/component/email.go`:
- Around line 78-99: After resolving the subject in EmailComponent.Invoke,
remove all carriage return and newline characters before placing subject into
the args map. Preserve the resolved subject content otherwise, and ensure the
sanitized value is what reaches the email tool’s Subject header.
In `@internal/agent/tool/email.go`:
- Around line 165-230: Update sendEmailSTARTTLS and sendEmailSMTPS so the entire
SMTP session has a bounded timeout, not just the SMTPS connection setup. Replace
smtp.SendMail in sendEmailSTARTTLS with explicit dialing and smtp.NewClient,
apply a deadline to the connection covering Hello, authentication, message
delivery, writes, and shutdown, and incorporate ctx cancellation/deadline into
that bound. Apply equivalent deadline handling in sendEmailSMTPS and preserve
existing SMTP behavior and error propagation.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ddca67df-7260-407c-9636-d653a912858b
📒 Files selected for processing (7)
internal/agent/canvas/scheduler.gointernal/agent/component/email.gointernal/agent/component/email_test.gointernal/agent/runtime/state.gointernal/agent/runtime/state_test.gointernal/agent/tool/email.gointernal/service/agent.go
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/agent/tool/email.go (1)
262-267: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winDo not return an error if the email has already been accepted.
If
wc.Close()on line 259 succeeds, the SMTP server has replied with a250 OKand accepted the message for delivery. Returningctx.Err()after this point masks a successful delivery as a failure, which can cause the upstream workflow execution to retry the node and send duplicate emails.Once the data transmission completes successfully, you should ignore subsequent context cancellations and
Quit()errors.🐛 Proposed fix to prevent retries of successful emails
- if err := ctx.Err(); err != nil { - return err - } - if err := client.Quit(); err != nil && err != io.EOF { - return err - } + // The email has been accepted by the server. We ignore context cancellation + // and Quit errors here to prevent the caller from retrying a successful delivery. + if ctx.Err() == nil { + _ = client.Quit() + } return nil🤖 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 `@internal/agent/tool/email.go` around lines 262 - 267, Update the post-transmission cleanup after wc.Close succeeds so it returns success regardless of subsequent ctx.Err() or client.Quit() failures. Remove the context-error check and ignore Quit errors in this completed-delivery path, while preserving error handling for failures before wc.Close succeeds.
🧹 Nitpick comments (1)
internal/agent/tool/email.go (1)
207-224: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDefer closing the raw connection to avoid manual resource management.
Currently,
rawConnis only closed manually ifHandshakeContextfails. DeferringrawConn.Close()immediately after successful dialing guarantees the socket is always cleaned up (even in the rare event of a panic during the handshake), and it safely allows removing the manual error-path closure. It is completely safe to close the underlying connection multiple times.♻️ Proposed refactor
rawConn, err := dialer.DialContext(ctx, "tcp", addr) if err != nil { return err } + defer rawConn.Close() setEmailDeadline(ctx, rawConn) stopWatch := watchEmailContext(ctx, rawConn) defer stopWatch() conn := tls.Client(rawConn, &tls.Config{ServerName: p.SMTPHost, MinVersion: tls.VersionTLS12}) if err := conn.HandshakeContext(ctx); err != nil { - _ = rawConn.Close() return err } defer conn.Close()🤖 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 `@internal/agent/tool/email.go` around lines 207 - 224, Update sendEmailSMTPS immediately after a successful dial to defer rawConn.Close(), then remove the explicit rawConn.Close() from the HandshakeContext error path while preserving the existing error return and TLS connection cleanup.
🤖 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.
Outside diff comments:
In `@internal/agent/tool/email.go`:
- Around line 262-267: Update the post-transmission cleanup after wc.Close
succeeds so it returns success regardless of subsequent ctx.Err() or
client.Quit() failures. Remove the context-error check and ignore Quit errors in
this completed-delivery path, while preserving error handling for failures
before wc.Close succeeds.
---
Nitpick comments:
In `@internal/agent/tool/email.go`:
- Around line 207-224: Update sendEmailSMTPS immediately after a successful dial
to defer rawConn.Close(), then remove the explicit rawConn.Close() from the
HandshakeContext error path while preserving the existing error return and TLS
connection cleanup.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3111aa45-b051-4d85-860a-c7fe6b0b5d30
📒 Files selected for processing (2)
internal/agent/component/email.gointernal/agent/tool/email.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/agent/component/email.go
Summary
As title