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.

fix(computer): bound the Antigravity background wait and keep declining resent yields

jeffrey89c83e59c040
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index 682fe5be..91390600 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -285,9 +285,11 @@ for a browser sign-in when signed out.
and the Room shows the Agent working from that event. The executor can then
no longer start a fresh session, so the adapter opens `session/new` in the
same process and the terminal result carries the new session. Such a Run
- announced the old session, so the Daemon declines one scheduler yield for it
- and lets it finish. Agent Service sends a later Stop as its own cancel; a
- resent yield cancels the Run. A Run that resumes after a yield ends as
+ announced the old session, so the Daemon declines every scheduler yield for
+ it, including the one Agent Service resends after a reconnect, and lets it
+ finish. Agent Service sends a later Stop as its own cancel with its own
+ reason. An Agent Service released before this sends no such cancel, so its
+ Stop cannot end such a Run. A Run that resumes after a yield ends as
`session_not_found` instead. A Run yields to
the scheduler only after native work, because its session holds no prompt
before that.
@@ -300,7 +302,9 @@ for a browser sign-in when signed out.
the Run ends, which would kill the command and lose the reply. So a turn
that ends with an open tool call keeps the Run open. The Run ends once no
tool call is open and the session has sent nothing for 15 seconds. ACP has
- no event for the end of such a continuation.
+ no event for the end of such a continuation. If `agy` exits during the wait,
+ the Run fails. The wait ends after 30 minutes, because a backgrounded
+ server never finishes and a Run has no time budget.
- The Run's reply is its last text message, even when tool calls follow it,
because Agent Service reads the reply from the stream the same way.
- The Daemon's instructions go in `_meta.antigravity.systemPrompt.append`, and
diff --git a/apps/computer/local-daemon/internal/daemon/daemon.go b/apps/computer/local-daemon/internal/daemon/daemon.go
index e5df5a99..a9c01c37 100644
--- a/apps/computer/local-daemon/internal/daemon/daemon.go
+++ b/apps/computer/local-daemon/internal/daemon/daemon.go
@@ -206,9 +206,6 @@ type activeOperation struct {
// after announcing its retained one; it then declines a scheduler
// yield, whose follow-up would resume the session that is gone.
sessionMoved atomic.Bool
- // yieldDeclined is set once a yield was declined. An Agent Service
- // that resends the same yield as the user's Stop then cancels the Run.
- yieldDeclined bool
}
func New(options Options) (*Daemon, error) {
diff --git a/apps/computer/local-daemon/internal/daemon/daemon_test.go b/apps/computer/local-daemon/internal/daemon/daemon_test.go
index 1eeb8faa..52469acc 100644
--- a/apps/computer/local-daemon/internal/daemon/daemon_test.go
+++ b/apps/computer/local-daemon/internal/daemon/daemon_test.go
@@ -435,13 +435,20 @@ func TestSchedulerYieldIsDeclinedAfterTheSessionMoved(t *testing.T) {
if ctx.Err() != nil || active.reason != "" {
t.Fatalf("the yield cancelled the Run: reason %q", active.reason)
}
- // An Agent Service that keeps the yield command resends it as the
- // user's Stop, which must cancel the Run.
+ // Agent Service resends the retained yield after a reconnect.
if err := d.handleOperationCancel(yield); err != nil {
t.Fatal(err)
}
- if ctx.Err() == nil || active.reason != schedulerYield {
- t.Fatalf("a resent yield did not cancel the Run: reason %q", active.reason)
+ if ctx.Err() != nil || active.reason != "" {
+ t.Fatalf("a resent yield cancelled the Run: reason %q", active.reason)
+ }
+ stop := operationCancelCommand(start)
+ stop.Payload = mustJSON(map[string]string{"reason": "Stopped by user"})
+ if err := d.handleOperationCancel(stop); err != nil {
+ t.Fatal(err)
+ }
+ if ctx.Err() == nil || active.reason != "Stopped by user" {
+ t.Fatalf("Stop did not cancel the Run: reason %q", active.reason)
}
}
diff --git a/apps/computer/local-daemon/internal/daemon/operations.go b/apps/computer/local-daemon/internal/daemon/operations.go
index b80cbf64..debf7224 100644
--- a/apps/computer/local-daemon/internal/daemon/operations.go
+++ b/apps/computer/local-daemon/internal/daemon/operations.go
@@ -147,10 +147,11 @@ func (d *Daemon) handleOperationCancel(command protocol.Command) error {
if payload.Reason == "" {
payload.Reason = "Operation cancelled"
}
- if payload.Reason == schedulerYield && active.sessionMoved.Load() && !active.yieldDeclined {
+ if payload.Reason == schedulerYield && active.sessionMoved.Load() {
// The Run finishes instead; Agent Service accepts a natural
- // terminal after it asked for a yield.
- active.yieldDeclined = true
+ // terminal after it asked for a yield. Agent Service resends the
+ // same yield on every reconnect, so each one is declined; the
+ // user's Stop arrives as a cancel with its own reason.
slog.Info("runner.operation.yield_declined", "operation_id", command.OperationID, "reason", "session_moved")
return nil
}
diff --git a/apps/computer/local-daemon/internal/provider/native/antigravity_fake_test.go b/apps/computer/local-daemon/internal/provider/native/antigravity_fake_test.go
index 7d87c3e5..6c1003ef 100644
--- a/apps/computer/local-daemon/internal/provider/native/antigravity_fake_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/antigravity_fake_test.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "strings"
"sync"
"time"
)
@@ -178,12 +179,18 @@ func (f *agyFakeProcess) prompt(id json.RawMessage, sessionID string) {
if f.mode == "hang" {
select {}
}
- if f.mode == "background" {
+ if strings.HasPrefix(f.mode, "background") {
// Antigravity ends the turn while the command runs in the background
// and continues on its own once it finishes.
f.update(sessionID, map[string]any{"sessionUpdate": "agent_message_chunk", "content": map[string]any{"type": "text", "text": "Running in the background."}})
f.result(id, map[string]any{"stopReason": "end_turn"})
time.Sleep(50 * time.Millisecond)
+ switch f.mode {
+ case "background-exit":
+ os.Exit(0)
+ case "background-stuck":
+ select {}
+ }
}
f.update(sessionID, map[string]any{"sessionUpdate": "tool_call_update", "toolCallId": "call-1", "status": "completed", "content": []any{
map[string]any{"type": "content", "content": map[string]any{"type": "text", "text": "a.txt"}},
diff --git a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go
index 72d49741..1e73611b 100644
--- a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go
+++ b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go
@@ -29,6 +29,11 @@ const (
// finishes. Tests lower it.
var antigravityQuietWindow = 15 * time.Second
+// antigravityBackgroundLimit bounds that wait, since a production Run has no
+// budget and a background command, such as a server, may never finish.
+// Tests lower it.
+var antigravityBackgroundLimit = 30 * time.Minute
+
// antigravityRuntime runs each Operation in its own `agy acp` process. The
// conversation lives in Antigravity's own store and is reopened by id with
// session/load, so no process is parked between turns.
@@ -287,9 +292,14 @@ func (t *antigravityTurn) exchange(prompt string, servers []any) Outcome {
Usage *antigravityTokens `json:"usage"`
}
_ = json.Unmarshal(raw, &result)
- if result.StopReason == "end_turn" && !t.awaitBackground() {
- _, _ = t.cancelPrompt(session.SessionID)
- result.StopReason = "cancelled"
+ if result.StopReason == "end_turn" {
+ switch err := t.awaitBackground(); {
+ case errors.Is(err, errACPClosed):
+ return failed("", "Antigravity exited before the turn finished")
+ case err != nil:
+ _, _ = t.cancelPrompt(session.SessionID)
+ result.StopReason = "cancelled"
+ }
}
outcome := Outcome{ElapsedMs: time.Since(started).Milliseconds()}
t.mu.Lock()
@@ -322,8 +332,11 @@ func (t *antigravityTurn) exchange(prompt string, servers []any) Outcome {
// Antigravity moves a long command to the background, ends the turn, and
// continues on its own once the command finishes; the process stops when the
// Run ends, so the Run waits for every open tool call and then for the
-// session to go quiet. It reports false when the Run was cancelled first.
-func (t *antigravityTurn) awaitBackground() bool {
+// session to go quiet. It returns errACPClosed when Antigravity exits first
+// and the run context's error when the Run is cancelled first. After
+// antigravityBackgroundLimit the turn ends as it is, like a command that
+// never reports a terminal status.
+func (t *antigravityTurn) awaitBackground() error {
t.mu.Lock()
open := len(t.tools) > 0
if open {
@@ -332,24 +345,33 @@ func (t *antigravityTurn) awaitBackground() bool {
}
t.mu.Unlock()
if !open {
- return true
+ return nil
}
if t.profile.Logger != nil {
t.profile.Logger.Info("runtime.turn.background_wait", "provider", "antigravity")
}
+ limit := time.NewTimer(antigravityBackgroundLimit)
+ defer limit.Stop()
tick := time.NewTicker(antigravityQuietWindow / 30)
defer tick.Stop()
for {
select {
case <-t.runCtx.Done():
- return false
+ return t.runCtx.Err()
+ case <-t.proc.conn.closed:
+ return errACPClosed
+ case <-limit.C:
+ if t.profile.Logger != nil {
+ t.profile.Logger.Warn("runtime.turn.background_limit", "provider", "antigravity")
+ }
+ return nil
case <-tick.C:
}
t.mu.Lock()
settled := len(t.tools) == 0 && time.Since(t.lastUpdate) >= antigravityQuietWindow
t.mu.Unlock()
if settled {
- return true
+ return nil
}
}
}
diff --git a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.go
index da9b55aa..e0d3f59c 100644
--- a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.go
@@ -450,3 +450,30 @@ func TestAntigravityWaitsForACommandItMovedToTheBackground(t *testing.T) {
t.Fatalf("the background command's result was lost: %+v", result)
}
}
+
+func TestAntigravityEndsTheBackgroundWaitWhenAgyExits(t *testing.T) {
+ h := newAgyHarness(t, "background-exit", nil)
+ run, err := h.runtime.Start(t.Context(), "list files", RunSpec{Dir: h.dir})
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, outcome := drainAgy(t, run)
+ if outcome.Status != statusFailed || outcome.Error != "Antigravity exited before the turn finished" {
+ t.Fatalf("outcome=%+v", outcome)
+ }
+}
+
+func TestAntigravityBoundsTheBackgroundWait(t *testing.T) {
+ limit := antigravityBackgroundLimit
+ antigravityBackgroundLimit = 300 * time.Millisecond
+ t.Cleanup(func() { antigravityBackgroundLimit = limit })
+ h := newAgyHarness(t, "background-stuck", nil)
+ run, err := h.runtime.Start(t.Context(), "list files", RunSpec{Dir: h.dir})
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, outcome := drainAgy(t, run)
+ if outcome.Status != statusCompleted || outcome.Output != "Running in the background." {
+ t.Fatalf("outcome=%+v", outcome)
+ }
+}