← Back to Pull requests

fix(lambda/grpc): code function-returned errors as FailedPrecondition #970

Open
unknown opened this pull request with 274 lines diff across 3 files
View on GitHub
unknown unknown commented on Jun 17, 2026 14:26 UTC
Author

Problem

When the lambda gRPC transport invokes a function successfully but the function's own code returns an error (invokeResp.FunctionError set), RoundTrip returned a bare fmt.Errorf. That surfaces as gRPC codes.Unknown, and our otel pipeline counts Unknown as a span error / HTTP 5xx.

At low call volume this trips the 99.99% failure-rate monitor on be-temporal-lambda-manager — a handful of function-application faults (e.g. a connector that exits Unhandled during init, or a function whose startup config fetch is rejected) pages even though nothing on the server is broken.

Fix

Recode both return paths inside the if invokeResp.FunctionError != nil block from bare error → status.Errorf(codes.FailedPrecondition, ...). A function-returned error is a caller/function-state fault, not a server fault, so FailedPrecondition (4xx, uncounted) is the correct code. The message text is preserved.

Unchanged on purpose:

  • The retryable paths above — transient-network → Unavailable, function timeout → DeadlineExceeded.

  • The invoke-failure (failed to invoke lambda function) and marshal/unmarshal paths — genuine infra/our-bug faults that stay counted.
  • No retry-behavior change: pkg/retry only retries Unavailable/DeadlineExceeded. Unknown was never retried, and neither is FailedPrecondition — so recoding is behavior-preserving for retries. (The connector-side Hello retry classifier, isRetryableHelloError, is the opposite direction — connector→c1api over a normal dial — and never sees these errors.)

    Test

    Adds a lambdaInvoker interface seam (subset of *lambda.Client; the concrete client still satisfies it, no caller changes) so RoundTrip is unit-testable, plus a regression test asserting FailedPrecondition on both function-error paths (meaningful-logs and no-meaningful-logs).

    go vet clean; go test ./pkg/lambda/grpc/ passes.

    Downstream

    c1 picks this up on the next baton-sdk release + re-vendor; be-temporal-lambda-manager's existing classifyLambdaError pass-through then carries the FailedPrecondition code through unchanged.

    🤖 Generated with Claude Code

    Diff: 274 lines (+205 / -69) across 3 files Reviewer: arreyder Review duration: 247233m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.47) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 274 lines diff across 3 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.336
    Real PR Conversation Timeline
    1 comments
    "Review active on #970"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.5% (MEDIUM) · Higher = larger blast radius
    46.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.7% · Safe to merge
    25.7%