Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

test(computer): scale the Linux probe budget tests instead of waiting out production budgets

shoudi zheng48d93795cc8b
diff --git a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
index 60134dc1..0c6086e2 100644
--- a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
+++ b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
@@ -15,11 +15,55 @@ import (
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider/native"
)
+// Scaled probe budgets keep the Linux budget regressions fast: a cold start
+// takes coldStart, more than a third of the scaled cap, and still finishes
+// about twice under it; three sequential cold starts exceed one stage budget.
+const (
+ scaledAuthProbeCap = 1500 * time.Millisecond
+ scaledDiscoveryStageBudget = 2 * time.Second
+ scaledColdStart = 800 * time.Millisecond
+)
+
+// scaleProbeBudgets lowers the package-level probe budgets for one test. Its
+// callers must not run in parallel with any test that probes a Runtime.
+func scaleProbeBudgets(t *testing.T) {
+ t.Helper()
+ previousCap, previousBudget := authProbeCap, discoveryStageBudget
+ authProbeCap, discoveryStageBudget = scaledAuthProbeCap, scaledDiscoveryStageBudget
+ t.Cleanup(func() { authProbeCap, discoveryStageBudget = previousCap, previousBudget })
+}
+
+func TestProbeBudgetDefaults(t *testing.T) {
+ if got := authProbeCap; got != 15*time.Second {
+ t.Fatalf("authentication probe cap = %v, want 15s", got)
+ }
+ for _, scenario := range []struct {
+ goos string
+ want time.Duration
+ }{{"linux", 30 * time.Second}, {"windows", 30 * time.Second}, {"darwin", 15 * time.Second}} {
+ if got := defaultDiscoveryStageBudget(scenario.goos); got != scenario.want {
+ t.Fatalf("%s discovery stage budget = %v, want %v", scenario.goos, got, scenario.want)
+ }
+ }
+ if got := discoveryStageBudget; got != defaultDiscoveryStageBudget(runtime.GOOS) {
+ t.Fatalf("discovery stage budget = %v, want the %s default", got, runtime.GOOS)
+ }
+ for _, scenario := range []struct{ timeout, want time.Duration }{
+ {0, 15 * time.Second}, {-time.Second, 15 * time.Second}, {30 * time.Second, 15 * time.Second},
+ {15 * time.Second, 15 * time.Second}, {200 * time.Millisecond, 200 * time.Millisecond},
+ } {
+ if got := boundedAuthTimeout(scenario.timeout); got != scenario.want {
+ t.Fatalf("boundedAuthTimeout(%v) = %v, want %v", scenario.timeout, got, scenario.want)
+ }
+ }
+}
+
func TestCodexAuthenticationColdStartWithinLinuxBudget(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Linux authentication budget regression")
}
- executable, environment := codexAuthProbeFixture(t, `/bin/sleep 6
+ scaleProbeBudgets(t)
+ executable, environment := codexAuthProbeFixture(t, `/bin/sleep 0.8
echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":false}}'`)
current := DiscoveryResult{Diagnostics: []RuntimeDiagnostic{{Type: "codex", Status: "ready", ExecutablePath: executable}}}
started := time.Now()
@@ -28,8 +72,8 @@ echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":false}}'`)
if err != nil {
t.Fatal(err)
}
- if elapsed <= 5*time.Second || elapsed >= 15*time.Second {
- t.Fatalf("probe duration = %v, want between 5s and 15s", elapsed)
+ if elapsed < scaledColdStart || elapsed >= scaledAuthProbeCap {
+ t.Fatalf("probe duration = %v, want between %v and %v", elapsed, scaledColdStart, scaledAuthProbeCap)
}
if diagnostic := result.Diagnostics[0]; diagnostic.Status != "ready" || diagnostic.Error != nil {
t.Fatalf("delayed authentication = %+v", diagnostic)
@@ -43,6 +87,7 @@ func TestDiscoverCodexColdInitializeWithinLinuxBudget(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Linux discovery budget regression with POSIX fixtures")
}
+ scaleProbeBudgets(t)
for _, scenario := range []struct {
name string
timeout, deadline time.Duration
@@ -61,7 +106,7 @@ func TestDiscoverCodexColdInitializeWithinLinuxBudget(t *testing.T) {
if [ "$1" = "--version" ]; then echo 'codex-cli 0.144.1'; exit 0; fi
read initialize
echo initialize >> "$LAUNCH_TRACE"
-/bin/sleep 8
+/bin/sleep 0.8
echo '{"id":1,"result":{"userAgent":"test"}}'
if read initialized && read account; then
case "$account" in
@@ -92,6 +137,9 @@ fi
if diagnostic.Error != nil || result.Installations["codex"].Status != "ready" {
t.Fatalf("slow initialize did not produce a ready installation: %+v", result)
}
+ if elapsed := time.Since(started); elapsed <= scaledDiscoveryStageBudget {
+ t.Fatalf("discovery took %v, want three cold starts to exceed one stage budget %v", elapsed, scaledDiscoveryStageBudget)
+ }
} else if diagnostic.Error == nil || diagnostic.Error.Code != "RUNTIME_DIAGNOSTIC_FAILED" || !strings.Contains(diagnostic.Error.Message, "deadline") || time.Since(started) > 5*time.Second {
t.Fatalf("short discovery deadline not preserved: %+v, elapsed = %v", diagnostic, time.Since(started))
}
@@ -107,6 +155,7 @@ func TestCodexAuthenticationFailureDiagnostics(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Linux authentication budget regression with POSIX fixtures")
}
+ scaleProbeBudgets(t)
const (
timeoutMessage = "Codex authentication probe timed out or was canceled"
processMessage = "Codex authentication probe process or RPC failed"
@@ -117,7 +166,7 @@ func TestCodexAuthenticationFailureDiagnostics(t *testing.T) {
timeout, deadline time.Duration
minimum time.Duration
}{
- {"timeout at Linux cap", `/bin/sleep 30`, timeoutMessage, 30 * time.Second, 0, 15 * time.Second},
+ {"timeout at Linux cap", `/bin/sleep 30`, timeoutMessage, 30 * time.Second, 0, scaledAuthProbeCap},
{"short caller timeout", `/bin/sleep 30`, timeoutMessage, 200 * time.Millisecond, 0, 200 * time.Millisecond},
{"short parent deadline", `/bin/sleep 30`, timeoutMessage, 15 * time.Second, 200 * time.Millisecond, 200 * time.Millisecond},
{"process exit", `exit 7`, processMessage, time.Second, 0, 0},
diff --git a/apps/computer/local-daemon/internal/provider/discovery.go b/apps/computer/local-daemon/internal/provider/discovery.go
index 9e600ccc..0e1053f5 100644
--- a/apps/computer/local-daemon/internal/provider/discovery.go
+++ b/apps/computer/local-daemon/internal/provider/discovery.go
@@ -105,6 +105,17 @@ func ValidateRuntimeSelection(types []string) error {
return nil
}
+// discoveryStageBudget is each discovery stage's default budget; tests lower it
+// while no discovery runs.
+var discoveryStageBudget = defaultDiscoveryStageBudget(runtime.GOOS)
+
+func defaultDiscoveryStageBudget(goos string) time.Duration {
+ if goos == "windows" || goos == "linux" {
+ return 30 * time.Second
+ }
+ return 15 * time.Second
+}
+
func Discover(ctx context.Context, options DiscoveryOptions) (DiscoveryResult, error) {
options.Environment = terminalEnvironment(ctx, platformEnvironment(options.Environment))
return discoverResolved(ctx, options), nil
@@ -113,10 +124,7 @@ func Discover(ctx context.Context, options DiscoveryOptions) (DiscoveryResult, e
func discoverResolved(ctx context.Context, options DiscoveryOptions) DiscoveryResult {
budget := options.Timeout
if budget <= 0 {
- budget = 15 * time.Second
- if runtime.GOOS == "windows" || runtime.GOOS == "linux" {
- budget = 30 * time.Second
- }
+ budget = discoveryStageBudget
}
definitions := runtimeDefinitions
if len(options.Runtimes) > 0 {
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
index 2b216a58..40c0696a 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
@@ -20,7 +20,7 @@ const claudeFakeKey = "CLAUDE_FAKE_MODE"
// claudeFakeSlowOutput is how long a resident "slow" or "late" turn holds its
// output; timing assertions compare against it rather than a wall-clock guess.
-const claudeFakeSlowOutput = 500 * time.Millisecond
+const claudeFakeSlowOutput = 300 * time.Millisecond
func init() {
if mode := os.Getenv(claudeFakeKey); mode != "" {
@@ -251,7 +251,7 @@ func (f *claudeFake) resident() int {
signal.Notify(terms, syscall.SIGTERM)
go func() {
<-terms
- time.Sleep(500 * time.Millisecond)
+ time.Sleep(200 * time.Millisecond)
f.record("exits", fmt.Sprintf("%d %d", os.Getpid(), time.Now().UnixNano()))
os.Exit(0)
}()
@@ -384,7 +384,8 @@ func (f *claudeFake) resident() int {
}}})
}
if strings.Contains(prompt, "pause") {
- time.Sleep(time.Second)
+ // Long enough for a test to act 300ms into the turn.
+ time.Sleep(600 * time.Millisecond)
}
reason := "completed"
if strings.Contains(prompt, "reason") {
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
index d923a435..3dc979b8 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
@@ -188,7 +188,8 @@ func TestClaudeSteerCancelledWhileWaiting(t *testing.T) {
results := make(chan result, 1)
run := claudeStart(t, home.profile, "slow", RunSpec{ExposeTurnStarted: true})
_, outcome, _ := claudeTimed(t, run, func(started Event) {
- ctx, cancel := context.WithTimeout(t.Context(), 200*time.Millisecond)
+ // Expires well inside claudeFakeSlowOutput, so the turn is still waiting.
+ ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond)
defer cancel()
begin := time.Now()
_, err := run.Steer(ctx, SteerRequest{ExpectedTurnID: started.TurnID, Input: "go"})
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
index a8138e71..d125fd24 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
@@ -74,7 +74,8 @@ func (c *claudeLogCapture) await(t *testing.T, prefix string, n int) []claudeLog
func claudeEnableResidency(t *testing.T, cap int) {
t.Helper()
previousGrace := claudeTerminationGrace
- claudeTerminationGrace = time.Second
+ // Three times the slow-term fake's exit delay, so it still exits by itself.
+ claudeTerminationGrace = 600 * time.Millisecond
withResidentCap(t, claudeResidents, cap)
t.Cleanup(func() {
_, _ = StopAllParkedResidents()
diff --git a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
index a5b66667..b809afb8 100644
--- a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
@@ -626,8 +626,8 @@ func TestCodexUsagePerTurnOnReusedProcess(t *testing.T) {
func TestCodexSteering(t *testing.T) {
fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, nil)
spec := fake.spec()
- spec.SilenceBudget = time.Second
- spec.FirstProgressBudget = time.Second
+ spec.SilenceBudget = 400 * time.Millisecond
+ spec.FirstProgressBudget = 400 * time.Millisecond
run, err := fake.runtime(nil).Start(context.Background(), "go", spec)
if err != nil {
t.Fatal(err)
@@ -951,7 +951,7 @@ func TestCodexSteerNeedsConsumptionEvidence(t *testing.T) {
fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, map[string]string{"FAKE_MODES": tc.mode})
fake.version = "0.166.0"
spec := fake.spec()
- spec.SilenceBudget = time.Second
+ spec.SilenceBudget = 400 * time.Millisecond
spec.ExposeTurnStarted = true
run, err := fake.runtime(nil).Start(context.Background(), "go", spec)
if err != nil {
diff --git a/apps/computer/local-daemon/internal/provider/protocol_probe.go b/apps/computer/local-daemon/internal/provider/protocol_probe.go
index 4f8f44e3..8b86e5d2 100644
--- a/apps/computer/local-daemon/internal/provider/protocol_probe.go
+++ b/apps/computer/local-daemon/internal/provider/protocol_probe.go
@@ -21,6 +21,10 @@ const maxProbeOutputBytes = 1024 * 1024
var errProbeOutputLimit = errors.New("Runtime probe output exceeded one MiB")
+// authProbeCap bounds every authentication probe; tests lower it while no
+// probe runs.
+var authProbeCap = 15 * time.Second
+
type runtimeProbeOutcome struct {
Status string
Code string
@@ -224,7 +228,7 @@ func boundedAuthTimeout(timeout time.Duration) time.Duration {
// is busy, macOS included: a busy MacBook let `claude auth status` miss a
// five second budget and flipped a working Agent to unavailable. Preserve
// shorter caller budgets and the enclosing discovery context.
- maximum := 15 * time.Second
+ maximum := authProbeCap
if timeout <= 0 || timeout > maximum {
return maximum
}