Skip to content

Commit ae19168

Browse files
committed
fix(sandbox): wait out OpenShell 0.1.2's first settings poll before network use
OpenShell 0.1.2's supervisor polls its settings every 10 s, and its first poll needlessly reloads the policy and closes connections in flight (NVIDIA/OpenShell#3809, fixed upstream by fullsend-ai#3819 after 0.1.2). The sandbox log shows it as "L7 tunnel closed before inspection because policy changed: policy generation is stale". A run's first network request usually lands around then: the GitHub pre-flight check saw EOF, and pi's first model request saw "terminated" and had to retry. Before the pre-flight check, wait until 12 s have passed since the sandbox became Ready. Bootstrap already uses most of that, so a run typically waits 3-5 s. Remove this once fullsend pins an OpenShell release with fullsend-ai#3819. Verified on OpenShell 0.1.2 (macOS arm64): with the wait, two pi triage runs opened their first connection at +12.4 s / +12.9 s and neither retried. Without it, one of four control runs had the first OpenAI request closed at +10.1 s by the stale-policy denial and retried. Assisted-by: Claude Signed-off-by: Wayne Sun <[email protected]>
1 parent 385030f commit ae19168

3 files changed

Lines changed: 111 additions & 0 deletions

File tree

‎internal/cli/openshell_settle.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/fullsend-ai/fullsend/internal/ui"
8+
)
9+
10+
// openShellFirstPollSettle is how long after a sandbox becomes Ready the
11+
// runner waits before the sandbox's first network request.
12+
//
13+
// OpenShell 0.1.2's supervisor polls its settings every 10 s
14+
// (OPENSHELL_POLICY_POLL_INTERVAL_SECS, default 10). Its first poll treats the
15+
// unchanged provider environment as changed, reloads the policy and
16+
// terminates connections in flight (NVIDIA/OpenShell#3809, fixed by #3819
17+
// after 0.1.2). A request that is open at that moment fails: the GitHub
18+
// pre-flight check sees EOF, an agent's first model request sees
19+
// "terminated". Waiting past that first poll keeps both clear of it; the 2 s
20+
// over the poll interval covers the supervisor's startup before the loop.
21+
//
22+
// Remove this once fullsend pins an OpenShell release that includes #3819.
23+
const openShellFirstPollSettle = 12 * time.Second
24+
25+
// Test seams.
26+
var (
27+
settleNow = time.Now
28+
settleSleep = time.Sleep
29+
)
30+
31+
// waitForOpenShellFirstPoll sleeps for whatever remains of
32+
// openShellFirstPollSettle since readyAt and returns how long it waited.
33+
// It returns immediately when that much time has already passed, so slow
34+
// bootstraps pay nothing.
35+
func waitForOpenShellFirstPoll(readyAt time.Time, printer *ui.Printer) time.Duration {
36+
remaining := openShellFirstPollSettle - settleNow().Sub(readyAt)
37+
if remaining <= 0 {
38+
return 0
39+
}
40+
if printer != nil {
41+
printer.StepInfo(fmt.Sprintf("Waiting %.1fs for the sandbox's first policy poll (OpenShell #3809)", remaining.Seconds()))
42+
}
43+
settleSleep(remaining)
44+
return remaining
45+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cli
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/assert"
9+
10+
"github.com/fullsend-ai/fullsend/internal/ui"
11+
)
12+
13+
func useSettleClock(t *testing.T, now time.Time) *[]time.Duration {
14+
t.Helper()
15+
var slept []time.Duration
16+
origNow, origSleep := settleNow, settleSleep
17+
settleNow = func() time.Time { return now }
18+
settleSleep = func(d time.Duration) { slept = append(slept, d) }
19+
t.Cleanup(func() { settleNow, settleSleep = origNow, origSleep })
20+
return &slept
21+
}
22+
23+
func TestWaitForOpenShellFirstPoll_WaitsForTheRemainder(t *testing.T) {
24+
readyAt := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
25+
slept := useSettleClock(t, readyAt.Add(7*time.Second))
26+
var buf bytes.Buffer
27+
28+
got := waitForOpenShellFirstPoll(readyAt, ui.New(&buf))
29+
30+
assert.Equal(t, 5*time.Second, got)
31+
assert.Equal(t, []time.Duration{5 * time.Second}, *slept)
32+
assert.Contains(t, buf.String(), "first policy poll")
33+
assert.Contains(t, buf.String(), "#3809")
34+
}
35+
36+
func TestWaitForOpenShellFirstPoll_NoWaitOncePast(t *testing.T) {
37+
readyAt := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
38+
for _, elapsed := range []time.Duration{openShellFirstPollSettle, 30 * time.Second} {
39+
slept := useSettleClock(t, readyAt.Add(elapsed))
40+
var buf bytes.Buffer
41+
42+
got := waitForOpenShellFirstPoll(readyAt, ui.New(&buf))
43+
44+
assert.Zero(t, got, "elapsed %s", elapsed)
45+
assert.Empty(t, *slept, "elapsed %s", elapsed)
46+
assert.Empty(t, buf.String(), "no message when nothing is waited (elapsed %s)", elapsed)
47+
}
48+
}
49+
50+
func TestWaitForOpenShellFirstPoll_NilPrinter(t *testing.T) {
51+
readyAt := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
52+
slept := useSettleClock(t, readyAt)
53+
54+
got := waitForOpenShellFirstPoll(readyAt, nil)
55+
56+
assert.Equal(t, openShellFirstPollSettle, got)
57+
assert.Equal(t, []time.Duration{openShellFirstPollSettle}, *slept)
58+
}

‎internal/cli/run.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,9 @@ func runAgent(ctx context.Context, agentName, fullsendDir, outputBase, targetRep
17141714
printer.StepFail("Failed to create sandbox")
17151715
return fmt.Errorf("creating sandbox: %w", err)
17161716
}
1717+
// Anchor for waitForOpenShellFirstPoll (OpenShell #3809) before the first
1718+
// network request.
1719+
sandboxReadyAt := time.Now()
17171720
finalizeSandboxSpan(sandboxSpan, nil)
17181721

17191722
if len(runScopedProviders) > 0 {
@@ -2167,6 +2170,11 @@ func runAgent(ctx context.Context, agentName, fullsendDir, outputBase, targetRep
21672170
}
21682171
}
21692172

2173+
// 9b-1. Let OpenShell 0.1.2's first settings poll pass before any network
2174+
// request; it terminates connections in flight (OpenShell #3809). Remove
2175+
// with openShellFirstPollSettle once the pin includes the upstream fix.
2176+
waitForOpenShellFirstPoll(sandboxReadyAt, printer)
2177+
21702178
// 9b-2. Pre-flight GitHub API connectivity check.
21712179
// Validates that the sandbox can reach api.github.com through the proxy
21722180
// before starting the agent. Without this, agents that depend on gh CLI

0 commit comments

Comments
 (0)