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): decline a yield after a Run moved sessions and share tool review
jeffrey6e0345bdc99e
diff --git a/apps/computer/local-daemon/README.md b/apps/computer/local-daemon/README.mdindex 2b84c3ff..9ad5e9a3 100644--- a/apps/computer/local-daemon/README.md+++ b/apps/computer/local-daemon/README.md@@ -284,8 +284,10 @@ for a browser sign-in when signed out.turn-started event before `session/load`, because loading takes secondsand the Room shows the Agent working from that event. The executor can thenno longer start a fresh session, so the adapter opens `session/new` in the- same process and the terminal result carries the new session. A Run that- resumes after a yield ends as `session_not_found` instead. A Run yields to+ same process and the terminal result carries the new session. Such a Run+ announced the old session, so the Daemon declines a scheduler yield for it+ and lets it finish. A Run that resumes after a yield ends as+ `session_not_found` instead. A Run yields tothe scheduler only after native work, because its session holds no promptbefore that.- A tool call is named by Antigravity's own tool name, such asdiff --git a/apps/computer/local-daemon/internal/daemon/daemon.go b/apps/computer/local-daemon/internal/daemon/daemon.goindex 41c11eae..a9c01c37 100644--- a/apps/computer/local-daemon/internal/daemon/daemon.go+++ b/apps/computer/local-daemon/internal/daemon/daemon.go@@ -202,6 +202,10 @@ type activeOperation struct {inputMu sync.Mutexfinishing boolpendingInputs map[string]*pendingOperationInput+ // sessionMoved is set when the Run continued in a new native session+ // after announcing its retained one; it then declines a scheduler+ // yield, whose follow-up would resume the session that is gone.+ sessionMoved atomic.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.goindex 81081999..9c62e239 100644--- a/apps/computer/local-daemon/internal/daemon/daemon_test.go+++ b/apps/computer/local-daemon/internal/daemon/daemon_test.go@@ -416,6 +416,35 @@ func TestDaemonDoesNotReportCancelledWhenProviderCleanupIsUnconfirmed(t *testingtestDaemonDrainCleanup(t, true)}+func TestSchedulerYieldIsDeclinedAfterTheSessionMoved(t *testing.T) {+ d, err := newTestDaemon(t, Options{ComputerID: "computer-1", ControlPlane: fakeControlPlane{stream: &fakeStream{}}, IdentityStore: fakeStore{}, OperationResolver: fakeOperationResolver{}})+ if err != nil {+ t.Fatal(err)+ }+ start := daemonOperationStart("moved", "agent-1")+ ctx, cancel := context.WithCancel(t.Context())+ defer cancel()+ active := &activeOperation{identity: operationIdentity(start), cancel: cancel}+ active.sessionMoved.Store(true)+ d.activeOperations[start.OperationID] = active+ yield := operationCancelCommand(start)+ yield.Payload = mustJSON(map[string]string{"reason": schedulerYield})+ if err := d.handleOperationCancel(yield); err != nil {+ t.Fatal(err)+ }+ if ctx.Err() != nil || active.reason != "" {+ t.Fatalf("the yield cancelled the Run: reason %q", active.reason)+ }+ stop := operationCancelCommand(start)+ stop.Payload = mustJSON(map[string]string{"reason": "user_stop"})+ if err := d.handleOperationCancel(stop); err != nil {+ t.Fatal(err)+ }+ if ctx.Err() == nil || active.reason != "user_stop" {+ t.Fatalf("a Stop did not cancel the Run: reason %q", active.reason)+ }+}+func TestSchedulerYieldRequiresConfirmedCleanup(t *testing.T) {for _, tc := range []struct {name stringdiff --git a/apps/computer/local-daemon/internal/daemon/operation_start.go b/apps/computer/local-daemon/internal/daemon/operation_start.goindex b4d1cde8..866c9481 100644--- a/apps/computer/local-daemon/internal/daemon/operation_start.go+++ b/apps/computer/local-daemon/internal/daemon/operation_start.go@@ -94,6 +94,7 @@ func (d *Daemon) handleOperationStart(ctx context.Context, stream transport.Stre}}active := &activeOperation{identity: identity, ctx: operationCtx, cancel: cancel}+ spec.SessionMoved = func() { active.sessionMoved.Store(true) }emitEvent := d.operationEventEmitter(command, identity, active)if spec.OperationKind == "run.start" {// Only run.start rewrites the per-run CLI files, after the Contextdiff --git a/apps/computer/local-daemon/internal/daemon/operations.go b/apps/computer/local-daemon/internal/daemon/operations.goindex cb7244a1..41d7a776 100644--- a/apps/computer/local-daemon/internal/daemon/operations.go+++ b/apps/computer/local-daemon/internal/daemon/operations.go@@ -147,6 +147,12 @@ func (d *Daemon) handleOperationCancel(command protocol.Command) error {if payload.Reason == "" {payload.Reason = "Operation cancelled"}+ if payload.Reason == schedulerYield && active.sessionMoved.Load() {+ // The Run finishes instead; Agent Service accepts a natural+ // terminal after it asked for a yield.+ slog.Info("runner.operation.yield_declined", "operation_id", command.OperationID, "reason", "session_moved")+ return nil+ }active.reason = payload.Reasonactive.cancel()}diff --git a/apps/computer/local-daemon/internal/provider/executor.go b/apps/computer/local-daemon/internal/provider/executor.goindex b97d6b3d..b4585548 100644--- a/apps/computer/local-daemon/internal/provider/executor.go+++ b/apps/computer/local-daemon/internal/provider/executor.go@@ -32,7 +32,11 @@ const operationProviderPrepareKind = "internal.provider.prepare"type OperationSpec struct {// A continuation prompt requires the exact native history of the interrupted Task.- ResumeAfterYield bool+ ResumeAfterYield bool+ // SessionMoved is called when a started Run continues in a new native+ // session because its retained one is gone. The Run announced the old+ // session, so it must not yield to it.+ SessionMoved func()HumanInteractions bool// PermissionReview sends the Runtime's own permission prompts to the// Runtime permission review (Agent Service declares it per Run).@@ -566,7 +570,7 @@ func (e Executor) Start(ctx context.Context, spec OperationSpec, emit EmitFunc)AssignSessionID: spec.CreateProviderSessionID,ResumeID: spec.ResumeSessionID,ResumeRequired: spec.ResumeSessionID != "",- FreshSessionOnRefusal: !spec.ResumeAfterYield,+ FreshSession: freshSession(spec),Budget: spec.Timeout,ComputerArgs: append([]string(nil), spec.ExtraArgs...),AgentArgs: append([]string(nil), spec.CustomArgs...),@@ -860,6 +864,19 @@ func (spec OperationSpec) ReviewsPermissions() bool {return spec.PermissionReview && spec.OperationKind == "run.start"}+// freshSession lets a started Run continue in a new native session, except+// one resuming after a yield, whose prompt continues the old session.+func freshSession(spec OperationSpec) func() {+ if spec.ResumeAfterYield {+ return nil+ }+ return func() {+ if spec.SessionMoved != nil {+ spec.SessionMoved()+ }+ }+}+// startsFreshSession reports whether a Run whose retained native session the// Runtime refused may continue in a new session instead of failing.func startsFreshSession(spec OperationSpec, result native.Outcome) bool {diff --git a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.goindex 955868a3..edd391e3 100644--- a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go+++ b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go@@ -216,9 +216,10 @@ func (t *antigravityTurn) exchange(prompt string, servers []any) Outcome {// The Run already started on the retained session, so the executor// can no longer continue it in a new one; this process does, and the// terminal result carries the new session.- if !startedEarly || !spec.FreshSessionOnRefusal {+ if !startedEarly || spec.FreshSession == nil {return t.resumeRefused(failed("session_not_found", refusal))}+ spec.FreshSession()if t.profile.Logger != nil {t.profile.Logger.Warn("runtime.session.fresh_start", "provider", "antigravity", "reason", "session_not_found")}@@ -545,22 +546,29 @@ func (t *antigravityTurn) permission(frame acpFrame) {_ = t.proc.conn.respond(frame.ID, map[string]any{"outcome": map[string]any{"outcome": "cancelled"}})}-// antigravityReview builds the permission review of one tool call. A-// command is reviewed as a shell command so the shared shell rules apply.+// antigravityReview builds the permission review of one tool call.func antigravityReview(call acpUpdate, workspace string) permission.Request {- input := antigravityInput(call.RawInput)+ return toolReview("antigravity", antigravityToolName(call), call.Kind == "execute", antigravityInput(call.RawInput), workspace)+}++// toolReview builds the permission review of one call of a Runtime that+// hands the Daemon its tool calls. A command call is reviewed as a shell+// command, from its input's "command", so the shared shell rules apply.+func toolReview(runtime, tool string, isCommand bool, input map[string]any, workspace string) permission.Request {+ if input == nil {+ input = map[string]any{}+ }encoded, _ := json.Marshal(input)- tool := antigravityToolName(call)command := ""- if call.Kind == "execute" {+ if isCommand {command, _ = input["command"].(string)tool = "Bash"}request := permission.Request{Action: permission.Action{- Runtime: "antigravity", Surface: permission.Surface(tool, command), Tool: tool,+ Runtime: runtime, Surface: permission.Surface(tool, command), Tool: tool,Command: command, Input: string(encoded),}}- if tool == "Bash" {+ if isCommand {request.Evidence = permission.ScriptEvidence(command, workspace)}return requestdiff --git a/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/antigravity_runtime_test.goindex f918fa46..4989c7e4 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@@ -404,7 +404,8 @@ func TestAntigravityStartsAResumedRunBeforeTheSessionLoads(t *testing.T) {func TestAntigravityContinuesAnEarlyStartedRunInANewSession(t *testing.T) {h := newAgyHarness(t, "unknown-session", nil)- run, err := h.runtime.Start(t.Context(), "again", RunSpec{Dir: h.dir, ResumeID: "moved-session", ExposeTurnStarted: true, FreshSessionOnRefusal: true})+ moved := 0+ run, err := h.runtime.Start(t.Context(), "again", RunSpec{Dir: h.dir, ResumeID: "moved-session", ExposeTurnStarted: true, FreshSession: func() { moved++ }})if err != nil {t.Fatal(err)}@@ -418,8 +419,8 @@ func TestAntigravityContinuesAnEarlyStartedRunInANewSession(t *testing.T) {starts = append(starts, event)}}- if len(starts) != 1 || starts[0].SessionID != "moved-session" {- t.Fatalf("turn-started events=%+v", starts)+ if len(starts) != 1 || starts[0].SessionID != "moved-session" || moved != 1 {+ t.Fatalf("turn-started events=%+v, moved %d times", starts, moved)}if requests := h.requests(t); len(requests["session/new"]) != 1 || len(requests["session/prompt"]) != 1 {t.Fatalf("requests=%v", requests)diff --git a/apps/computer/local-daemon/internal/provider/native/pi_review.go b/apps/computer/local-daemon/internal/provider/native/pi_review.goindex a4800293..41f29ed3 100644--- a/apps/computer/local-daemon/internal/provider/native/pi_review.go+++ b/apps/computer/local-daemon/internal/provider/native/pi_review.go@@ -78,28 +78,6 @@ func (t *piTurn) review(payload string) piVerdict {if json.Unmarshal([]byte(payload), &call) != nil || call.ToolName == "" {return piVerdict{Message: "The tool call could not be read for permission review"}}- verdict := t.reviewer.Review(t.runCtx, piReview(call.ToolName, call.Input, t.dir))+ verdict := t.reviewer.Review(t.runCtx, toolReview("pi", call.ToolName, call.ToolName == "bash", call.Input, t.dir))return piVerdict{Allow: verdict.Decision == permission.Allow, Message: verdict.Message}}--// piReview builds the permission review of one call. A bash call is-// reviewed as a shell command so the shared shell rules apply.-func piReview(tool string, input map[string]any, workspace string) permission.Request {- if input == nil {- input = map[string]any{}- }- encoded, _ := json.Marshal(input)- command := ""- if tool == "bash" {- command, _ = input["command"].(string)- tool = "Bash"- }- request := permission.Request{Action: permission.Action{- Runtime: "pi", Surface: permission.Surface(tool, command), Tool: tool,- Command: command, Input: string(encoded),- }}- if tool == "Bash" {- request.Evidence = permission.ScriptEvidence(command, workspace)- }- return request-}diff --git a/apps/computer/local-daemon/internal/provider/native/runtime.go b/apps/computer/local-daemon/internal/provider/native/runtime.goindex 0fd05151..36b421b7 100644--- a/apps/computer/local-daemon/internal/provider/native/runtime.go+++ b/apps/computer/local-daemon/internal/provider/native/runtime.go@@ -93,10 +93,11 @@ type RunSpec struct {ResumeID stringAssignSessionID stringResumeRequired bool- // FreshSessionOnRefusal lets a Runtime that reported its turn started+ // FreshSession, when set, lets a Runtime that reported its turn started// before its retained session loaded continue in a new session when the// session is gone, as the executor does for one that reported nothing.- FreshSessionOnRefusal bool+ // The Runtime calls it before it opens the new session.+ FreshSession func()PrepareOnly boolWarmMCP boolMCPReady func(context.Context) error