Repository navigation
refactor(tui): single event-loop ingress - one notifier, no self-rescheduling pollers - #700
Conversation
…p self-rescheduling pollers Replace the queue-drain ticker, agent-status poll, MCP channel-wait, and the file-explorer/diff-viewer 1s git/fs polls with a single push ingress: a tea-free domain.UINotifier backed by (*tea.Program).Send, injected into every background producer via a thread-safe container holder. The Bubble Tea Update loop is now purely reactive (renders on real events, not on a clock) and program.Send lives in exactly one place (programNotifier in cmd/chat.go). - Queue drain: delete DrainQueueTickEvent + the 500ms ticker; add DrainQueueEvent pushed from supervisor enqueue, terminal turn completion, and chat re-entry. HandleDrainQueueEvent is a pure gate (nil in every no-op branch). Add the symmetric EndToolExecution() on terminal completion so the agent is reliably idle when the drain runs - nothing strands without a poller. - Agent status: push AgentStatusUpdateEvent from the container status callback instead of a 500ms time.Sleep re-arm. - MCP: StartMonitoring pushes MCPServerStatusUpdateEvent through the notifier (initial emit from a goroutine to avoid the unbuffered-Send deadlock); drop the channel return from the MCPManager interface. - /tasks + explorer/diff: refresh off BackgroundTasksChangedEvent and in-loop ToolExecutionCompletedEvent/BashCommandCompletedEvent (+ a manual ctrl+r), deleting the 1s tickCmds; no fsnotify added to the TUI. - Computer-use forwarder routed through the same notifier. - Observability: one slow-update warn around the Update dispatch and a one-time long-running-job warn in the supervisor cleanup sweep. One-shot UI deferrals (todo auto-collapse, background-row removal) are unchanged. no docs ticket: internal-only refactor Closes #688
…n /tasks Two issues found while testing the single-notifier refactor: - Queue drain: HandleDrainQueueEvent was a pure one-shot gate, so a background-job completion event dropped at a momentarily-busy instant stranded the queue forever - the deleted 500ms ticker's repetition had been the de-facto retry. Re-arm a single bounded retry, but ONLY while work is genuinely stranded on the chat view (queue non-empty); it stops the moment the queue drains, so there is no idle clock and no /model flicker regression. - /tasks: stop gating the task view on A2A and wire the real BackgroundTaskRegistry into it directly (passed through NewChatApplication) instead of the fragile GetA2ATaskTracker().(BackgroundTaskRegistry) assertion, so background shells and subagents show whether or not A2A is enabled. Drop the "requires A2A" gate and fallback copy. Add a debug log of the per-source /tasks row counts to pinpoint any remaining empty-list case (supervisor snapshot vs A2A poller vs retention).
…l refresh The Elapsed column was frozen until the user pressed 'r', because the view only reloaded on status changes (BackgroundTasksChangedEvent) while elapsed time advances on the wall clock with no event. Add a bounded refresh tick: while the view is open and a task is actually running, a 1s tick reloads (recomputing Elapsed and catching status changes) and re-arms; the moment nothing is running it stops, so it is a contained animation tick like the spinner, not a resurrected idle poller. With the table now live, remove the now-redundant manual 'r' refresh key and its help-bar entry. Also drops the temporary /tasks diagnostic log added to pin the empty-list cause (now confirmed fixed by the direct registry wiring).
The app log dir was derived from viper's ConfigFileUsed(), which returns the home ~/.infer/config.yaml when both a home and a project config exist - so app logs went to ~/.infer/logs while the gateway logged to ./.infer/logs. Default the app log dir to config.DefaultLogsPath (./.infer/logs, relative to the working dir) so app and gateway logs sit together and follow the project. An explicit logging.dir still wins.
… to project-local ./.infer/logs
|
@claude Can you review this? make sure you use the skills /go /go-concurrency /cobra-viper /go-spec-reviewer /bubbles-v2 /bubbleteas-v2 and some other skills that might be relevant |
|
Claude finished @edenreich's task in 10m 3s —— View job Review: single event-loop ingress refactorI reviewed this through the lens of Verdict: this is a well-executed refactor. The hard parts - the deadlock-safety argument and the lock discipline - are correct, not just plausible. I found no blocking issues; two minor behavioral gaps and a few nits below. What I verified as sound ✅
Minor issues1. The live "Elapsed" tick in
2. Drain retry chains aren't deduplicated. Each Nits (non-blocking)
Tests / scopeCoverage matches the acceptance checklist well: the gate-only Nice work - the deadlock reasoning in the description checks out against the source, which is the part that's easy to get wrong. |
Addresses the ultrareview on PR #700: - /tasks live-elapsed: re-arm the refresh tick when a task appears while the view stays open, guarded by tickLive + a tickEpoch so a stale tick from a fast reopen can't form a second chain. - drain retry: collapse the N-pushes-per-busy-turn case to one timer via a dedicated DrainQueueRetryEvent + drainRetryArmed guard, which distinguishes a retry firing from a fresh external push. - uiNotifierHolder: swap the RWMutex for atomic.Pointer (swap-once, read-many). - supervisor/MCPManager notify(): drop the redundant nil-check (constructors already default a nil notifier to NoopUINotifier).
## [0.126.0](v0.125.0...v0.126.0) (2026-06-30) ### 🚀 Features * add persistent memory tool for agent ([#679](#679)) ([a487b13](a487b13)) * **agent:** interactive subagent management and unified background-work tracking ([#684](#684)) ([343e083](343e083)) ### 🐛 Bug Fixes * **chat:** bind opt+backspace and ctrl+backspace to delete-word-backward ([#697](#697)) ([173fe83](173fe83)), closes [#689](#689) [#576](#576) * **a2a:** retain completed background tasks in /tasks ([#691](#691)) ([#701](#701)) ([43b8e13](43b8e13)) * **autocomplete:** surface arguments for one-of/all-optional tool schemas ([#698](#698)) ([655b2e4](655b2e4)) ### ♻️ Code Refactoring * add .gitignore by default to the projects dir ([4717deb](4717deb)) * enable memory by default ([86c2158](86c2158)) * make infer config userspace-first ([#682](#682)) ([1e77e42](1e77e42)), closes [#680](#680) * **tui:** single event-loop ingress - one notifier, no self-rescheduling pollers ([#700](#700)) ([2ab8854](2ab8854)) * standardize comment punctuation by replacing em dashes with hyphens ([78f53a8](78f53a8)) ### 📚 Documentation * fix docs/ drift found by the README-to-codebase audit ([#687](#687)) ([413047a](413047a)), closes [#572](#572) [#686](#686) * sync README and reference docs with the codebase ([#685](#685)) ([c328423](c328423)), closes [#572](#572) [#684](#684) [#684](#684) ### 👷 CI/CD * **deps:** update CLAUDE workflow to version 0.14.5 ([eaba2b3](eaba2b3)) ### 🧹 Maintenance * add .infer to .gitignore ([08ef319](08ef319)) * **deps:** bump infer CLI v0.124.0 -> v0.125.0, infer-action v0.19.0 -> v0.19.1 ([#681](#681)) ([e9e7e21](e9e7e21)) * remove agent definitions ([4f7fd7d](4f7fd7d)) * remove unused configuration and shortcut files ([4c611db](4c611db)) * update claude-code to 2.1.191 ([729e81c](729e81c))
|
🎉 This PR is included in version 0.126.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
One background goroutine in cmd/chat pushes agentdomain.HeartbeatEvent through the UI notifier every 10 seconds. It is the only clock feeding the Update loop, so periodic freshness checks subscribe to it instead of re-arming private tea.Ticks (the pattern PR #700 removed). The input view uses it to refetch git status for changes made outside the TUI; the git call stays in a tea.Cmd and is skipped entirely when the git_branch indicator is disabled.
…npushed (#1164) Closes #1157 - New `tui.GitStatusResolvedEvent{Dirty, Unpushed}` and `fetchGitStatusCmd` (mirrors `fetchGitPRCmd`, uses `utils.RunGit`). - Refetched on `Init`, `BashCommandCompletedEvent`, every `ToolExecutionCompletedEvent` (PR refetch stays gated on Bash), and the new app heartbeat. - **Single app heartbeat**: `runUIHeartbeat` in `cmd/chat` pushes `agentdomain.HeartbeatEvent` through the UI notifier every 10s (`constants.UIHeartbeatInterval`) and stops on context cancel. It is the one clock feeding Update, in line with #700's no-self-rearming-ticks design; components that need periodic freshness subscribe to it. Handlers only return a `tea.Cmd`, no inline I/O. - `RenderInputField` takes an `iconColor`; only the leading `⎇` rune is colored, applied after truncation so long branch names and the PR number behave as before. - Warning color = uncommitted changes (wins), accent = unpushed commits or no upstream, default status color = clean. - Not a repo: `git status` fails, zero event returned, `rev-list` skipped, nothing rendered. `git_branch: false` skips the git process entirely. - Tests in `input_view_test.go`, `provider_test.go`, `cmd/chat/heartbeat_test.go`; docs updated.
Summary
Replaces every self-rescheduling loop that fed the single Bubble Tea
Updateloop with one push ingress: a tea-freedomain.UINotifierbacked by(*tea.Program).Send, injected into every background producer via a thread-safe container holder. TheUpdateloop is now purely reactive — it renders on real events, not on a clock — and because there is exactly one ingress, it's instrumented in exactly one place.Closes #688.
no docs ticket: internal-only refactor.What was removed (all re-arming pollers)
tea.Tick(500ms)→DrainQueueTickEvent, self-re-armingDrainQueueEventpushed once per real trigger; gate-only handlertime.Sleep(500ms)Cmd re-armStartMonitoringreturned a channel the app re-armed (waitForMCPStatusUpdate/mcpStatusUpdateWithChannel)MCPServerStatusUpdateEventthrough the notifiertea.Tick(1s)git/fs re-pollToolExecutionCompletedEvent/BashCommandCompletedEvent+ view-entry + manualctrl+rprogram.Send×2The only
tea.Ticks left are the three one-shot UI deferrals the design keeps (todo auto-collapse, two background-row removals).Design
internal/domain/ui_notifier.go—UINotifier interface{ Notify(any) }+NoopUINotifier(useful zero value) +NotifierFunc(test adapter).any, nottea.Msg, so the domain stays tea-free.internal/container— a thread-safeuiNotifierHolder(RWMutex + swappable inner, default Noop) is the single synchronized primitive. Producers capture it at construction and never lock;SetUINotifierswaps the inner once at startup.cmd/chat.go—programNotifier{program}is the only place(*tea.Program).Sendis ever called;services.SetUINotifier(...)runs aftertea.NewProgramand beforeprogram.Run.Correctness notes
HandleDrainQueueEventis a pure gate (returnsnilin every no-op branch — regression guard against re-introducing a ticker). Drains are pushed from three sources: supervisorenqueue, terminal turn completion (HandleChatCompleteEvent), and a single central chat-re-entry edge inUpdate. Added the symmetricEndToolExecution()on terminal completion so the agent is reliably idle when the drain runs — nothing strands without a poller.(*tea.Program).Sendis unbuffered and blocks untilRunconsumes, soNotifyis only ever called from producer goroutines; the MCP initial-status emit now runs in a goroutine.MCPManager.StartMonitoringdrops its channel return →mcp_manager_test.gorewritten to assert notifier pushes via a recording notifier (MCPManager has no generated counterfeiter fake).Observability
One slow-update warn around the
Updatedispatch (SlowUpdateThreshold) and a one-time long-running-job warn in the supervisor cleanup sweep (JobRunningLongThreshold, reusingmeta.StartedAt).Acceptance
program.Sendcalled in exactly one place (grep-proven).HandleDrainQueueEventis gate-only; asserted inchat_handler_drain_test.go./tasksupdate on real change pushed through the notifier — no clock.tickCmds deleted; no fsnotify in the TUI.EndToolExecutionsymmetry; slow-update + long-job warns via an observed zap core.task build,task test,task lint(0 issues),task fmtgreen;go test -raceclean on touched packages.Verification left for review
The interactive runtime checks from the issue (idle on
/modelshows no periodic re-render, drain-while-modal scenarios, live/tasks, diff/explorer refresh off agent edits) need a running gateway + TTY and are best confirmed manually; the behavior is covered by the unit tests above.Out of scope / unchanged
One-shot UI deferrals (todo auto-collapse, background-row removal), the agent state-machine
CheckingQueuein-turn drain, andEventBridge's floating-window multicast.