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): wait for an in-flight Claude submission before parking
shoudi zhengfea9d47d5f75
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_conversation.go b/apps/computer/local-daemon/internal/provider/native/claude_conversation.goindex 2f30e4e1..95b7e7e7 100644--- a/apps/computer/local-daemon/internal/provider/native/claude_conversation.go+++ b/apps/computer/local-daemon/internal/provider/native/claude_conversation.go@@ -84,6 +84,13 @@ func (c *claudeConversation) markSubmitted(at time.Time) {c.mu.Unlock()}+// inputSubmitted reports that the turn's first user frame is on its way.+func (c *claudeConversation) inputSubmitted() bool {+ c.mu.Lock()+ defer c.mu.Unlock()+ return c.submitted+}+// claudeTurnStart is the moment a turn's run input reached the CLI.type claudeTurnStart struct {turnID stringdiff --git a/apps/computer/local-daemon/internal/provider/native/claude_input.go b/apps/computer/local-daemon/internal/provider/native/claude_input.goindex c98f5770..09d1cc3e 100644--- a/apps/computer/local-daemon/internal/provider/native/claude_input.go+++ b/apps/computer/local-daemon/internal/provider/native/claude_input.go@@ -63,14 +63,17 @@ func (t *claudeTurn) submitFailed(err error) {t.runCancel()}-// submittedOK checks without waiting that submission finished cleanly.+// submittedOK reports that submission finished cleanly. The CLI can answer+// the input before the submitting goroutine sees its own write return, so+// once the input is on its way this waits for that write; the write ends+// with the run context or the process. A turn whose input was never sent+// has nothing to wait for.func (t *claudeTurn) submittedOK() bool {- select {- case <-t.submitDone:- return t.submitErr == nil- default:+ if !t.proc.conv.inputSubmitted() {return false}+ <-t.submitDone+ return t.submitErr == nil}func claudeNotApplied(expected, actual string) *SteerError {diff --git a/apps/computer/local-daemon/internal/provider/native/claude_turn_test.go b/apps/computer/local-daemon/internal/provider/native/claude_turn_test.goindex 3c21b4e9..17023d49 100644--- a/apps/computer/local-daemon/internal/provider/native/claude_turn_test.go+++ b/apps/computer/local-daemon/internal/provider/native/claude_turn_test.go@@ -621,3 +621,32 @@ func TestClaudeEventBackpressure(t *testing.T) {t.Fatal("emit blocked or overwrote the buffered event")}}++// A result can be read while the submitting goroutine has written the input+// but not yet recorded that its write returned. Parking then must wait for+// the submission instead of treating it as failed.+func TestClaudeSubmittedOKWaitsForInFlightSubmission(t *testing.T) {+ p := &claudeProcess{}+ p.conv = claudeNewConversation(p)+ turn := &claudeTurn{proc: p, submitDone: make(chan struct{})}+ if turn.submittedOK() {+ t.Fatal("a turn without submitted input reported a clean submission")+ }+ p.conv.markSubmitted(time.Now())+ calling := make(chan struct{})+ answered := make(chan bool, 1)+ go func() {+ close(calling)+ answered <- turn.submittedOK()+ }()+ <-calling+ close(turn.submitDone)+ if !<-answered {+ t.Fatal("an in-flight submission that then succeeded was reported as failed")+ }+ failed := &claudeTurn{proc: p, submitDone: make(chan struct{}), submitErr: errors.New("write failed")}+ close(failed.submitDone)+ if failed.submittedOK() {+ t.Fatal("a failed submission was reported as clean")+ }+}diff --git a/apps/computer/local-daemon/internal/provider/native/codex_fake_test.go b/apps/computer/local-daemon/internal/provider/native/codex_fake_test.goindex 3bb90696..be9da322 100644--- a/apps/computer/local-daemon/internal/provider/native/codex_fake_test.go+++ b/apps/computer/local-daemon/internal/provider/native/codex_fake_test.go@@ -53,7 +53,8 @@ type codexFakeTurn struct {// Gate holds the turn open until the file named by FAKE_GATE exists. The// fake writes FAKE_GATE+".started" first.Gate bool `json:"gate,omitempty"`- // DelayMs holds turn/completed back for this long.+ // DelayMs holds turn/completed back for this long while the fake keeps+ // answering other requests.DelayMs int `json:"delayMs,omitempty"`}@@ -304,7 +305,6 @@ func (s *codexFakeServer) turn(id json.RawMessage, compact bool) (int, bool) {time.Sleep(10 * time.Millisecond)}}- time.Sleep(time.Duration(script.DelayMs) * time.Millisecond)turn := map[string]any{"id": s.current, "status": script.Status}if script.Error != "" {turn["error"] = map[string]any{"message": script.Error, "codexErrorInfo": script.ErrorInfo}@@ -312,7 +312,19 @@ func (s *codexFakeServer) turn(id json.RawMessage, compact bool) (int, bool) {if script.Usage != nil {turn["usage"] = script.Usage}- s.send(map[string]any{"method": "turn/completed", "params": map[string]any{"threadId": s.thread, "turn": turn}})+ completed := map[string]any{"method": "turn/completed", "params": map[string]any{"threadId": s.thread, "turn": turn}}+ if script.DelayMs > 0 && !script.Exit {+ // Codex keeps serving requests while a turn runs, so the delay must+ // not block the read loop: a request sent after turn/start is+ // answered before turn/completed.+ go func() {+ time.Sleep(time.Duration(script.DelayMs) * time.Millisecond)+ s.send(completed)+ }()+ return 0, false+ }+ time.Sleep(time.Duration(script.DelayMs) * time.Millisecond)+ s.send(completed)if script.Exit {return 0, true}