Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions e2e/admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ func TestAdminInstallUninstall(t *testing.T) {
t.Log("=== E2E test complete ===")
}

// isConcurrentHeadUpdate reports the GitHub 422 returned when another actor
// moves a PR head while update-branch is processing it. The onboarding
// reconciler legitimately rewrites fullsend/onboard, so the next merge
// attempt must re-read the PR state instead of failing the E2E run.
func isConcurrentHeadUpdate(err error) bool {
Comment thread
ifireball marked this conversation as resolved.
Resolved
var apiErr *gh.APIError
return errors.As(err, &apiErr) &&
apiErr.StatusCode == http.StatusUnprocessableEntity &&
strings.Contains(strings.ToLower(apiErr.Message), "expected head sha") &&
strings.Contains(strings.ToLower(apiErr.Message), "current head ref")
}

// mergeEnrollmentPR finds and merges the enrollment PR for test-repo so the
// shim workflow is active on the default branch.
// In PR-based install mode, enrollment is deferred: repo-maintenance triggers
Expand Down Expand Up @@ -289,8 +301,16 @@ func mergeEnrollmentPR(t *testing.T, env *e2eEnv) {
}

var apiErr *gh.APIError
if !errors.As(mergeErr, &apiErr) || apiErr.StatusCode != http.StatusConflict {
break // not a 409, fail immediately
if !errors.As(mergeErr, &apiErr) {
break // not a retryable GitHub API error
}
if apiErr.StatusCode == http.StatusUnprocessableEntity && isConcurrentHeadUpdate(mergeErr) {
t.Logf("Merge attempt %d: PR head changed during update-branch (422), retrying", attempt+1)
time.Sleep(5 * time.Second)
continue
}
if apiErr.StatusCode != http.StatusConflict {
break // not a retryable merge conflict
}

t.Logf("Merge attempt %d: 409 conflict, updating PR branch and retrying", attempt+1)
Expand Down
52 changes: 52 additions & 0 deletions e2e/admin/admin_test_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//go:build e2e

package admin

import (
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/assert"

gh "github.com/fullsend-ai/fullsend/internal/forge/github"
)

func TestIsConcurrentHeadUpdate(t *testing.T) {
tests := []struct {
name string
err error
want bool
}{
{
name: "wrapped update-branch head race",
err: fmt.Errorf("merge failed: %w", &gh.APIError{
StatusCode: http.StatusUnprocessableEntity,
Message: "expected head sha didn’t match current head ref",
}),
want: true,
},
{
name: "other unprocessable entity",
err: &gh.APIError{
StatusCode: http.StatusUnprocessableEntity,
Message: "pull request is not mergeable",
},
want: false,
},
{
name: "merge conflict",
err: &gh.APIError{
StatusCode: http.StatusConflict,
Message: "head branch is out of date",
},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, isConcurrentHeadUpdate(tt.err))
})
}
}
3 changes: 3 additions & 0 deletions e2e/behaviour/features/dispatch/base-dispatch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Feature: Base-composed harness dispatch
slug: fullsend-ai-local-base
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
"""
# Variant 1: local child with local base
And a custom harness "local-child" with base "local-base" and:
Expand All @@ -31,6 +32,7 @@ Feature: Base-composed harness dispatch
slug: fullsend-ai-remote-base
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
"""
# Variant 2: local child with remote (URL) base
And a custom harness "remote-base-child" with URL base "remote-base" and:
Expand Down Expand Up @@ -68,6 +70,7 @@ Feature: Base-composed harness dispatch
slug: fullsend-ai-trigger-base
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: >
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
6 changes: 6 additions & 0 deletions e2e/behaviour/features/dispatch/dispatch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-issue-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down Expand Up @@ -40,6 +41,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-pr-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand All @@ -52,6 +54,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-issue-only-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -76,6 +79,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-enabled-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -88,6 +92,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-disabled-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -111,6 +116,7 @@ Feature: Harness CEL dispatch
slug: fullsend-ai-review-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "review_submitted"
Expand Down
6 changes: 6 additions & 0 deletions e2e/behaviour/features/dispatch/fork-dispatch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-pr-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand All @@ -24,6 +25,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-issue-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -36,6 +38,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-pr-killed
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand All @@ -48,6 +51,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-pr-nofork
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand Down Expand Up @@ -75,6 +79,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-pr-killswitch
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand All @@ -93,6 +98,7 @@ Feature: Fork PR dispatch
slug: fullsend-ai-fork-pr-sync
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "change_proposal"
&& event.transition.kind == "label_changed"
Expand Down
1 change: 1 addition & 0 deletions e2e/behaviour/features/dispatch/hooks-loaded.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Feature: Sandbox security hooks are loaded via --settings
slug: fullsend-ai-hooks-smoke
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Feature: Emoji reaction status notifications
slug: fullsend-ai-reaction-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
7 changes: 7 additions & 0 deletions e2e/behaviour/features/dispatch/url-dispatch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-url-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -34,6 +35,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-local-ping
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -46,6 +48,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-url-mixed
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -67,6 +70,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-good-local
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -79,6 +83,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-bad-hash
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -105,6 +110,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-good-allowed
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand All @@ -117,6 +123,7 @@ Feature: URL-sourced harness dispatch
slug: fullsend-ai-no-allow
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
1 change: 1 addition & 0 deletions e2e/behaviour/features/runtime/agent-settings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Feature: Per-agent runtime and model on agents: entries in config.yaml
slug: fullsend-ai-pi-override
model: opus
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
1 change: 1 addition & 0 deletions e2e/behaviour/features/runtime/pi.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: pi runtime runs an agent unattended
slug: fullsend-ai-pi-smoke
model: haiku
image: ghcr.io/fullsend-ai/fullsend-sandbox:latest
policy: policies/base.yaml
trigger: |
event.entity.kind == "work_item"
&& event.transition.kind == "label_changed"
Expand Down
20 changes: 15 additions & 5 deletions internal/agentnew/assets.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package agentnew

import (
"bytes"
_ "embed"
"fmt"

"github.com/fullsend-ai/fullsend/internal/scaffold"
)

// BasePolicy returns the base sandbox policy a generated agent's harness
// names: filesystem, landlock and process rules with no network section, so
// egress comes only from the harness's providers (ADR 0065). The behaviour
// suite commits it for scenario harnesses, because OpenShell 0.1 refuses a
// sandbox with no policy and a policy file that declares no fields.
func BasePolicy() []byte {
return bytes.Clone(basePolicy)
}

//go:embed templates/policies/base.yaml
var basePolicy []byte

// sharedAssets returns the scaffold files a generated agent depends on but
// does not own: the sandbox policy, the role's providers and profiles, and
// the schema validator when the validation loop is enabled.
Expand All @@ -22,11 +36,7 @@ import (
func sharedAssets(role Role, validationLoop bool) ([]File, error) {
files := []File{}

policy, err := templates.ReadFile("templates/policies/base.yaml")
if err != nil {
return nil, fmt.Errorf("reading base policy: %w", err)
}
files = append(files, File{Path: "policies/base.yaml", Data: policy, Mode: 0o644, Shared: true})
files = append(files, File{Path: "policies/base.yaml", Data: BasePolicy(), Mode: 0o644, Shared: true})

// Providers and profiles are referenced by path rather than by bare
// name. A bare name with no definition on disk does not fail loudly: the
Expand Down
19 changes: 19 additions & 0 deletions internal/agentnew/assets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package agentnew

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBasePolicy_IsTheTemplateAndACopy(t *testing.T) {
want, err := templates.ReadFile("templates/policies/base.yaml")
require.NoError(t, err)

got := BasePolicy()
assert.Equal(t, string(want), string(got))

got[0] = 'X'
assert.Equal(t, string(want), string(BasePolicy()), "a caller's edit must not change later results")
}
13 changes: 10 additions & 3 deletions internal/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ func ensureProviderArgs(ctx context.Context, name string, args, updateArgs, extr

// isTransientProviderErr reports whether err is one of the openshell
// errors produced by concurrent runs racing on the same gateway: a missing
// or not-yet-reimported profile, or an optimistic-concurrency rejection of
// a provider update ("provider was modified concurrently (current
// resource_version: N)").
// or not-yet-reimported profile (OpenShell 0.0.x: "unsupported provider type
// or profile"; 0.1.x: "provider profile '<id>' not found; import a matching
// profile"), or an optimistic-concurrency rejection of a provider update
// ("provider was modified concurrently (current resource_version: N)").
//
// NOTE: This matches literal text from the openshell CLI's stderr output.
// If openshell changes its error wording in a future version, this check
Expand All @@ -547,9 +548,15 @@ func isTransientProviderErr(err error) bool {
}
msg := strings.ToLower(err.Error())
return strings.Contains(msg, "unsupported provider type or profile") ||
providerProfileNotFoundRe.MatchString(msg) ||
providerModifiedConcurrentlyRe.MatchString(msg)
}

// providerProfileNotFoundRe matches OpenShell 0.1.x's error for a provider
// whose profile is not (yet) registered, which a concurrent run's
// ImportProfile delete+reimport produces. \W+ spans the CLI's line wrap.
var providerProfileNotFoundRe = regexp.MustCompile(`provider\W+profile\W+'[^']+'\W+not\W+found`)

// providerModifiedConcurrentlyRe matches openshell's optimistic-concurrency
// error. The CLI wraps the message across lines with a box-drawing gutter
// (`"provider was modified` / `│ concurrently (current resource_version: 2)"`),
Expand Down
Loading
Loading