fix(sdk,semaphore): an action that may have run is an unknown outcome, not an error; retry a failed task status read (archie #2001)
publish / publish (push) Successful in 1m12s

This commit is contained in:
sam committed 2026-11-16 03:57:20 +11:00
1 parent 8df55d3225
commit 53ba618b0b
4 files changed
+81 -9

No files matched your search

+6 -2
View File
@@ -89,14 +89,18 @@ func (s *server) Resolve(ctx context.Context, req *connectorv1.ResolveRequest) (
}
// Invoke runs the action and reports the digest of the input it ran, so the
// host can check it ran the judged action.
// host can check it ran the judged action. An action that may have taken
// effect is reported as an unknown outcome, with what went wrong as its
// output, never as an error: the host must not treat it as not having run.
func (s *server) Invoke(ctx context.Context, req *connectorv1.InvokeRequest) (*connectorv1.InvokeResponse, error) {
a, err := s.actor()
if err != nil {
return nil, err
}
out, unknown, err := a.Invoke(ctx, req.GetAction(), req.GetInput(), req.GetIdempotencyKey())
if err != nil {
if err != nil && unknown {
out = []byte(err.Error())
} else if err != nil {
return nil, status.Errorf(codes.Unknown, "invoke: %v", err)
}
return &connectorv1.InvokeResponse{
+53
View File
@@ -0,0 +1,53 @@
package connector
import (
"context"
"encoding/json/jsontext"
"errors"
"testing"
connectorv1 "github.com/samcharles93/archipelago/sdk/connector/v1"
)
type stubActor struct {
unknown bool
err error
}
func (stubActor) Describe() Description { return Description{} }
func (stubActor) Resolve(context.Context, string, jsontext.Value) (*connectorv1.ResolveResponse, error) {
return &connectorv1.ResolveResponse{}, nil
}
func (a stubActor) Invoke(context.Context, string, jsontext.Value, string) (jsontext.Value, bool, error) {
return nil, a.unknown, a.err
}
// TestAnActionThatMayHaveRunIsNotAFailure guards the unknown outcome: an
// action that fails after it may have taken effect must reach the host as
// outcome_unknown, not as an error, or the host treats it as not having run
// and may run it again.
func TestAnActionThatMayHaveRunIsNotAFailure(t *testing.T) {
tests := []struct {
name string
actor stubActor
wantErr bool
wantUnknown bool
}{
{name: "a failure before any effect is an error", actor: stubActor{err: errors.New("bad input")}, wantErr: true},
{name: "a failure after a possible effect is unknown", actor: stubActor{unknown: true, err: errors.New("lost track of task 9")}, wantUnknown: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &server{build: func(Config) (Connector, error) { return tt.actor, nil }}
if _, err := s.Configure(t.Context(), &connectorv1.ConfigureRequest{}); err != nil {
t.Fatal(err)
}
resp, err := s.Invoke(t.Context(), &connectorv1.InvokeRequest{Action: "a", Input: []byte(`{}`)})
if (err != nil) != tt.wantErr || resp.GetOutcomeUnknown() != tt.wantUnknown {
t.Fatalf("err = %v, unknown = %v; want error %v, unknown %v", err, resp.GetOutcomeUnknown(), tt.wantErr, tt.wantUnknown)
}
})
}
}