MCPcopy Create free account
hub / github.com/Facets-cloud/flow / liveSessionsForTasks

Function liveSessionsForTasks

internal/app/harness.go:149–189  ·  view source on GitHub ↗

liveSessionsForTasks returns a merged id→count map across every unique harness referenced by the given task slice. Calls each harness's LiveSessionIDs at most once. ps failures and unknown- harness errors are both swallowed per-task — the merged map only contains entries from harnesses that resolved

(tasks []*flowdb.Task)

Source from the content-addressed store, hash-verified

147// support background sessions, their registry (claude agents --json) is
148// merged in too so bg-bound tasks still light up [live].
149func liveSessionsForTasks(tasks []*flowdb.Task) map[string]int {
150 seen := map[harness.Name]bool{}
151 merged := map[string]int{}
152 for _, t := range tasks {
153 h, err := harnessForTask(t)
154 if err != nil {
155 // Task pinned to an unsupported harness — skip; the
156 // row still renders, just without a [live] marker.
157 continue
158 }
159 if seen[h.Name()] {
160 continue
161 }
162 seen[h.Name()] = true
163 if live, err := h.LiveSessionIDs(); err == nil {
164 for id, n := range live {
165 merged[id] += n
166 }
167 }
168 // Only consult the background-agent registry in bg mode. The query
169 // is a `claude agents` subprocess; firing it on every `flow list`
170 // for non-bg users would be a latency regression (and they have no
171 // bg sessions to surface). bg-mode invocations opt into the cost.
172 if spawner.IsBackground() {
173 if bg, ok := h.(harness.BackgroundLauncher); ok {
174 if agents, err := bg.BackgroundAgents(); err == nil {
175 for _, a := range agents {
176 // Only a running process counts as "live". --all
177 // surfaces exited/failed/done sessions too (pid 0);
178 // those are recoverable but not currently running, so
179 // they must not light up the [live] marker.
180 if a.SessionID != "" && a.PID > 0 {
181 merged[strings.ToLower(a.SessionID)]++
182 }
183 }
184 }
185 }
186 }
187 }
188 return merged
189}
190
191// bgAgentStatus returns the live background-agent entry for a task's bound
192// session, or nil if the task isn't bg-bound, has no session, the harness

Callers 3

listTasksCmdFunction · 0.85

Calls 5

IsBackgroundFunction · 0.92
harnessForTaskFunction · 0.85
NameMethod · 0.65
LiveSessionIDsMethod · 0.65
BackgroundAgentsMethod · 0.65