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): keep an Antigravity Run open for a backgrounded command

jeffrey66c6cc7be771
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.md
index d1951cfc..9fec96e9 100644
--- a/apps/computer/local-daemon/README.md
+++ b/apps/computer/local-daemon/README.md
@@ -294,6 +294,13 @@ for a browser sign-in when signed out.
- A tool call is named by Antigravity's own tool name, such as
`run_command`; its title is the whole command line, which the call's
redacted input already shows.
+- `run_command` moves a command that outlasts its `WaitMsBeforeAsync` to the
+ background and ends the turn with `end_turn`. Once the command finishes,
+ Antigravity continues on its own with no new prompt. The process stops when
+ 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.
- The Daemon's instructions go in `_meta.antigravity.systemPrompt.append`, and
its MCP servers in the session's `mcpServers`.
- `session/request_permission` goes to the Run's permission review when the
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 a27e8ccc..932b5136 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
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"sync"
+ "time"
)
// The test binary doubles as a fake `agy acp` when agyFakeEnv names a mode.
@@ -177,10 +178,20 @@ func (f *agyFakeProcess) prompt(id json.RawMessage, sessionID string) {
if f.mode == "hang" {
select {}
}
+ if 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)
+ }
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"}},
}})
f.update(sessionID, map[string]any{"sessionUpdate": "agent_message_chunk", "content": map[string]any{"type": "text", "text": "Found "}})
f.update(sessionID, map[string]any{"sessionUpdate": "agent_message_chunk", "content": map[string]any{"type": "text", "text": "a.txt"}})
+ if f.mode == "background" {
+ return
+ }
f.result(id, map[string]any{"stopReason": "end_turn", "usage": map[string]any{"inputTokens": 10, "outputTokens": 4, "thoughtTokens": 2, "cachedReadTokens": 3}})
}
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 edd391e3..04380e23 100644
--- a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go
+++ b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go
@@ -23,6 +23,12 @@ const (
antigravityEventBuffer = 256
)
+// antigravityQuietWindow is how long a session with no open tool call must
+// stay silent before a background continuation counts as finished.
+// Antigravity starts the continuation about four seconds after the command
+// finishes. Tests lower it.
+var antigravityQuietWindow = 15 * time.Second
+
// 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.
@@ -110,6 +116,8 @@ type antigravityTurn struct {
textID string
output strings.Builder
tools map[string]bool
+ // lastUpdate is when the prompted session last reported anything.
+ lastUpdate time.Time
}
func (t *antigravityTurn) emit(event Event) {
@@ -279,6 +287,10 @@ 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"
+ }
outcome := Outcome{ElapsedMs: time.Since(started).Milliseconds()}
t.mu.Lock()
outcome.Output = strings.TrimSpace(t.output.String())
@@ -305,6 +317,43 @@ func (t *antigravityTurn) exchange(prompt string, servers []any) Outcome {
return outcome
}
+// awaitBackground holds a turn that ended while a tool call still runs.
+// 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 {
+ t.mu.Lock()
+ open := len(t.tools) > 0
+ if open {
+ // The continuation is a new message; the reply is the last one.
+ t.textID = ""
+ t.output.Reset()
+ }
+ t.mu.Unlock()
+ if !open {
+ return true
+ }
+ if t.profile.Logger != nil {
+ t.profile.Logger.Info("runtime.turn.background_wait", "provider", "antigravity")
+ }
+ tick := time.NewTicker(antigravityQuietWindow / 30)
+ defer tick.Stop()
+ for {
+ select {
+ case <-t.runCtx.Done():
+ return false
+ case <-tick.C:
+ }
+ t.mu.Lock()
+ settled := len(t.tools) == 0 && time.Since(t.lastUpdate) >= antigravityQuietWindow
+ t.mu.Unlock()
+ if settled {
+ return true
+ }
+ }
+}
+
// cancelPrompt asks Antigravity to end the running prompt. The process is
// stopped right after, so the cancelled stop reason is not awaited.
func (t *antigravityTurn) cancelPrompt(sessionID string) (json.RawMessage, error) {
@@ -408,6 +457,9 @@ func (t *antigravityTurn) update(params json.RawMessage, observed time.Time) {
if !prompting && update.SessionUpdate == "user_message_chunk" {
t.replayedPrompts++
}
+ if prompting {
+ t.lastUpdate = observed
+ }
t.mu.Unlock()
if !prompting {
return
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 4989c7e4..73953862 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
@@ -426,3 +426,27 @@ func TestAntigravityContinuesAnEarlyStartedRunInANewSession(t *testing.T) {
t.Fatalf("requests=%v", requests)
}
}
+
+func TestAntigravityWaitsForACommandItMovedToTheBackground(t *testing.T) {
+ quiet := antigravityQuietWindow
+ antigravityQuietWindow = 300 * time.Millisecond
+ t.Cleanup(func() { antigravityQuietWindow = quiet })
+ h := newAgyHarness(t, "background", nil)
+ run, err := h.runtime.Start(t.Context(), "list files", RunSpec{Dir: h.dir})
+ if err != nil {
+ t.Fatal(err)
+ }
+ events, outcome := drainAgy(t, run)
+ if outcome.Status != statusCompleted || outcome.Output != "Found a.txt" {
+ t.Fatalf("outcome=%+v", outcome)
+ }
+ var result Event
+ for _, event := range events {
+ if event.Kind == EventToolOutput {
+ result = event
+ }
+ }
+ if result.Output != "a.txt" || result.Status != "completed" {
+ t.Fatalf("the background command's result was lost: %+v", result)
+ }
+}