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): wait for queued timing records before removing runtime homes
shoudi zheng0215d17e647a
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 72f944e0..f3f47316 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -64,7 +64,7 @@ jobs:match "$node|^(apps/desktop/|apps/computer/local-daemon/|apps/computer/package\.json|packages/|contracts/generated/typescript/)" desktopmatch "$node|^contracts/" contractsmatch '^(apps/teamhub/|skills/|contracts/generated/go/|contracts/fixtures/|\.golangci\.yml|Makefile|\.github/)' teamhub- match '^(apps/computer/local-daemon/|contracts/generated/go/runnergateway/|Makefile|\.github/)' computer-go+ match '^(apps/computer/local-daemon/|apps/computer/run-test\.sh|contracts/generated/go/runnergateway/|contracts/runner-gateway/fixtures/|scripts/managed-tools-|scripts/local-computer-node-distributions\.mjs|scripts/test-fixtures/managed-tools-fixture\.mjs|Makefile|\.github/)' computer-gorepository-gate:runs-on: ubuntu-latestdiff --git a/apps/computer/local-daemon/internal/daemon/provider_prepare_claude_argv_unix_test.go b/apps/computer/local-daemon/internal/daemon/provider_prepare_claude_argv_unix_test.goindex 8a4ebaf5..4de7236f 100644--- a/apps/computer/local-daemon/internal/daemon/provider_prepare_claude_argv_unix_test.go+++ b/apps/computer/local-daemon/internal/daemon/provider_prepare_claude_argv_unix_test.go@@ -115,6 +115,9 @@ func newClaudeRig(t *testing.T, script string) claudeRig {d.cancelProviderPrepares(providerPrepareAll, "test_cleanup")_, _ = native.StopParkedResidentsForContext("context-1")d.WaitForOperations()+ // The stop path queues its last diagnostics record into the Runtime+ // home asynchronously; it must land before TempDir removal.+ native.FlushTimings()})return claudeRig{daemon: d, resolver: resolver, stream: stream, argvLog: argvLog, root: root}}diff --git a/apps/computer/local-daemon/internal/daemon/provider_prepare_join_unix_test.go b/apps/computer/local-daemon/internal/daemon/provider_prepare_join_unix_test.goindex 7ca4d433..c57ea2cb 100644--- a/apps/computer/local-daemon/internal/daemon/provider_prepare_join_unix_test.go+++ b/apps/computer/local-daemon/internal/daemon/provider_prepare_join_unix_test.go@@ -99,6 +99,9 @@ func newJoinProviderFixture(t *testing.T, runtime string) joinProviderFixture {// A run leaves its process parked in the process-wide table, which later tests would see._, _ = native.StopParkedResidentsForContext("context-1")d.WaitForOperations()+ // The Codex stop path queues its last diagnostics record into the+ // Runtime home asynchronously; it must land before TempDir removal.+ native.FlushTimings()})return fixture}diff --git a/apps/computer/local-daemon/internal/provider/claude_resident_credentials_unix_test.go b/apps/computer/local-daemon/internal/provider/claude_resident_credentials_unix_test.goindex 9540c5a3..43ef3ff4 100644--- a/apps/computer/local-daemon/internal/provider/claude_resident_credentials_unix_test.go+++ b/apps/computer/local-daemon/internal/provider/claude_resident_credentials_unix_test.go@@ -55,7 +55,12 @@ func TestClaudeCredentialChangeStopsParkedResidentBeforeWriting(t *testing.T) {t.Fatal(err)}t.Setenv("PATH", root+string(os.PathListSeparator)+os.Getenv("PATH"))- t.Cleanup(func() { _, _ = native.StopAllParkedResidents() })+ t.Cleanup(func() {+ _, _ = native.StopAllParkedResidents()+ // The stop path queues its last diagnostics record into the Runtime+ // home asynchronously; it must land before TempDir removal.+ native.FlushTimings()+ })login := func(token string) {t.Helper()credential := `{"claudeAiOauth":{"accessToken":"` + token + `","expiresAt":4102448400000}}`diff --git a/apps/computer/local-daemon/internal/provider/executor_codex_config_args_unix_test.go b/apps/computer/local-daemon/internal/provider/executor_codex_config_args_unix_test.goindex 18351b80..b59bdb2e 100644--- a/apps/computer/local-daemon/internal/provider/executor_codex_config_args_unix_test.go+++ b/apps/computer/local-daemon/internal/provider/executor_codex_config_args_unix_test.go@@ -69,6 +69,9 @@ donefor _, cfg := range captured {_, _ = native.StopCodexHomeForMaintenance(cfg.Env["CODEX_HOME"])}+ // The stop path queues its last diagnostics record into the Runtime+ // home asynchronously; it must land before TempDir removal.+ native.FlushTimings()})env := func() map[string]string {return map[string]string{"HOME": root, "CODEX_HOME": shared, "TEAMHUB_CONFIG": "/private/teamhub.json", "TEAMHUB_PROFILE": "runtime", "PATH": "/trusted:/bin", "LINGER_TEST_SED": sedPath}diff --git a/apps/computer/local-daemon/internal/provider/native/streams_test.go b/apps/computer/local-daemon/internal/provider/native/streams_test.goindex 702839de..9fec8d00 100644--- a/apps/computer/local-daemon/internal/provider/native/streams_test.go+++ b/apps/computer/local-daemon/internal/provider/native/streams_test.go@@ -5,6 +5,7 @@ import ("bytes""context""errors"+ "fmt""io""log/slog""reflect"@@ -279,6 +280,40 @@ func TestTimingQueueNeverBlocks(t *testing.T) {}}+type collectHandler struct {+ mu sync.Mutex+ messages []string+}++func (h *collectHandler) Enabled(context.Context, slog.Level) bool { return true }+func (h *collectHandler) Handle(_ context.Context, record slog.Record) error {+ h.mu.Lock()+ defer h.mu.Unlock()+ h.messages = append(h.messages, record.Message)+ return nil+}+func (h *collectHandler) WithAttrs([]slog.Attr) slog.Handler { return h }+func (h *collectHandler) WithGroup(string) slog.Handler { return h }++func TestTimingQueueFlushHandlesQueuedRecords(t *testing.T) {+ queue := newTimingQueue(8)+ // A flush with nothing queued returns.+ queue.flush()+ handler := &collectHandler{}+ logger := slog.New(handler)+ for i := range 8 {+ if !queue.enqueue(logger, time.Now(), fmt.Sprintf("record-%d", i)) {+ t.Fatalf("record-%d dropped", i)+ }+ }+ queue.flush()+ handler.mu.Lock()+ defer handler.mu.Unlock()+ if len(handler.messages) != 8 {+ t.Fatalf("handled %d records before flush returned, want 8: %v", len(handler.messages), handler.messages)+ }+}+type captureHandler struct {records chan slog.Record}diff --git a/apps/computer/local-daemon/internal/provider/native/timing.go b/apps/computer/local-daemon/internal/provider/native/timing.goindex 9f65bbb2..a17e2f64 100644--- a/apps/computer/local-daemon/internal/provider/native/timing.go+++ b/apps/computer/local-daemon/internal/provider/native/timing.go@@ -22,6 +22,8 @@ const timingQueueCapacity = 64type timingRecord struct {logger *slog.Loggerrecord slog.Record+ // flushed marks a flush sentinel: the worker closes it instead of logging.+ flushed chan struct{}}// timingQueue hands lifecycle observations to one background worker. A@@ -57,6 +59,10 @@ func (q *timingQueue) enqueue(logger *slog.Logger, at time.Time, event string, afunc (q *timingQueue) drain() {ctx := context.Background()for item := range q.records {+ if item.flushed != nil {+ close(item.flushed)+ continue+ }handler := item.logger.Handler()if handler.Enabled(ctx, slog.LevelInfo) {_ = handler.Handle(ctx, item.record)@@ -68,3 +74,18 @@ func (q *timingQueue) drain() {func recordTiming(logger *slog.Logger, at time.Time, event string, attrs ...any) {processTimings.enqueue(logger, at, event, attrs...)}++// flush blocks until every record queued before the call has been handled.+// The sentinel's send blocks: only real records are dropped when full, and the+// single FIFO worker handles everything queued ahead of it first.+func (q *timingQueue) flush() {+ q.once.Do(func() { go q.drain() })+ done := make(chan struct{})+ q.records <- timingRecord{flushed: done}+ <-done+}++// FlushTimings blocks until every timing record queued before the call has+// been handled. It exists so tests can wait for diagnostics written into a+// Runtime home before removing it; hot-path callers never use it.+func FlushTimings() { processTimings.flush() }