Skip to content

Commit ba3df00

Browse files
committed
feat: step failed opcode
1 parent eeeb087 commit ba3df00

File tree

67 files changed

+1266
-638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1266
-638
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/inngest/inngestgo
22

3-
go 1.24
3+
go 1.24.0
44

55
require (
66
github.com/coder/websocket v1.8.12
77
github.com/fatih/structs v1.1.0
88
github.com/google/uuid v1.6.0
99
github.com/gosimple/slug v1.12.0
1010
github.com/gowebpki/jcs v1.0.0
11-
github.com/inngest/inngest v1.11.11-0.20250903154644-c3be9c4c8b45
11+
github.com/inngest/inngest v1.11.14-0.20250926175522-7a60b676feb8
1212
github.com/oklog/ulid/v2 v2.1.1
1313
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
1414
github.com/sashabaranov/go-openai v1.35.6
@@ -29,7 +29,7 @@ require (
2929
github.com/lmittmann/tint v1.1.0 // indirect
3030
github.com/pmezard/go-difflib v1.0.0 // indirect
3131
golang.org/x/net v0.41.0 // indirect
32-
golang.org/x/sys v0.33.0 // indirect
32+
golang.org/x/sys v0.36.0 // indirect
3333
golang.org/x/text v0.26.0 // indirect
3434
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
3535
google.golang.org/grpc v1.73.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
3434
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
3535
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
3636
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
37-
github.com/inngest/inngest v1.11.11-0.20250903154644-c3be9c4c8b45 h1:bk8rHGoa73umGpHKhIAFXgE7Bfh1pYv/6G8ZTv1FAxo=
38-
github.com/inngest/inngest v1.11.11-0.20250903154644-c3be9c4c8b45/go.mod h1:tt65lGtXioLxvpELpS1Y7/3ESrCaantUitJsqoQrVtM=
37+
github.com/inngest/inngest v1.11.14-0.20250926175522-7a60b676feb8 h1:z9l3Yk1nN6pDRmZjy2NQZ2jTV+jyHYOrs02+0kRxL6E=
38+
github.com/inngest/inngest v1.11.14-0.20250926175522-7a60b676feb8/go.mod h1:R5TKH7aKwziyiUOM7NxYqZxmsO78J/hCLT1frU5idzQ=
3939
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
4040
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
4141
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -83,8 +83,8 @@ golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
8383
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
8484
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
8585
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
86-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
87-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
86+
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
87+
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
8888
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
8989
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
9090
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 h1:fc6jSaCT0vBduLYZHYrBBNY4dsWuvgyff9noRNDdBeE=

handler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,13 +844,19 @@ func (h *handler) invoke(w http.ResponseWriter, r *http.Request) error {
844844
// For that reason, we check those values first.
845845
noRetry := sdkerrors.IsNoRetryError(err)
846846
retryAt := sdkerrors.GetRetryAtTime(err)
847+
847848
if len(ops) == 1 && ops[0].Op == enums.OpcodeStepError {
848849
// Now we've handled error types we can ignore step
849850
// errors safely.
850851
err = nil
851852
}
852853

853-
// Now that we've handled the OpcodeStepError, if we *still* ahve
854+
// Handle OpcodeStepFailed for permanent step failures
855+
if len(ops) == 1 && ops[0].Op == enums.OpcodeStepFailed {
856+
noRetry = true
857+
}
858+
859+
// Now that we've handled the OpcodeStepError, if we *still* have
854860
// a StepError kind returned from a function we must have an unhandled
855861
// step error. This is a NonRetryableError, as the most likely code is:
856862
//

internal/sdkrequest/request.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type CallCtx struct {
2929
StepID string `json:"step_id"`
3030
Stack CallStack `json:"stack"`
3131
Attempt int `json:"attempt"`
32+
MaxAttempts *int `json:"max_attempts"`
3233
}
3334

3435
type CallStack struct {

step/run.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,32 @@ func Run[T any](
8686
mutated := out.Result
8787
err = out.Error
8888
if err != nil {
89-
// If tihs is a StepFailure already, fail fast.
89+
// If this is a StepFailure already, fail fast.
9090
if errors.IsStepError(err) {
9191
mgr.SetErr(fmt.Errorf("unhandled step error: %s", err))
9292
panic(sdkrequest.ControlHijack{})
9393
}
9494

95+
isNoRetry := errors.IsNoRetryError(err)
96+
maxAttemptsReached := shouldUseStepFailed(mgr)
97+
9598
marshalled, _ := json.Marshal(mutated)
9699

97-
// Implement per-step errors.
98-
mgr.SetErr(err)
100+
// Determine opcode based on retry eligibility
101+
opcode := enums.OpcodeStepError
102+
errorName := "Step error"
103+
104+
if isNoRetry || maxAttemptsReached {
105+
opcode = enums.OpcodeStepFailed
106+
errorName = "Step failed"
107+
}
108+
99109
mgr.AppendOp(ctx, sdkrequest.GeneratorOpcode{
100110
ID: hashedID,
101-
Op: enums.OpcodeStepError,
111+
Op: opcode,
102112
Name: id,
103113
Error: &sdkrequest.UserError{
104-
Name: "Step failed",
114+
Name: errorName,
105115
Message: err.Error(),
106116
Data: marshalled,
107117
},
@@ -177,3 +187,12 @@ func loadExistingStep[T any](
177187
val, _ := reflect.ValueOf(v).Elem().Interface().(T)
178188
return val, nil
179189
}
190+
191+
func shouldUseStepFailed(mgr sdkrequest.InvocationManager) bool {
192+
callCtx := mgr.Request().CallCtx
193+
if callCtx.MaxAttempts == nil {
194+
return false
195+
}
196+
197+
return callCtx.Attempt+1 >= *callCtx.MaxAttempts
198+
}

vendor/github.com/inngest/inngest/pkg/enums/batch.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/inngest/inngest/pkg/enums/batch_enumer.go

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/inngest/inngest/pkg/enums/opcode.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/inngest/inngest/pkg/enums/opcode_enumer.go

Lines changed: 32 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/inngest/inngest/pkg/enums/outdated_throttle_reason.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)