Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: refresh expanded tasks from fresh snapshot#298

Merged
clangenb merged 2 commits into
mainfrom
fix/284-services-view-task-refresh
Mar 18, 2026
Merged

fix: refresh expanded tasks from fresh snapshot#298
clangenb merged 2 commits into
mainfrom
fix/284-services-view-task-refresh

Conversation

@eldara-cruncher
Copy link
Copy Markdown
Collaborator

@eldara-cruncher eldara-cruncher commented Mar 17, 2026

Summary

Fixes #284 — tasks in the services view now refresh on the fly while expanded.

Root cause

refreshExpandedTasksCmd and checkServicesCmd are dispatched concurrently from the TickMsg handler (every 2s). checkServicesCmd calls TriggerRefreshIfNeeded() which starts an async (non-blocking) background goroutine to refresh the snapshot. Meanwhile, refreshExpandedTasksCmd calls GetTasksForService()GetSnapshot() which returns the stale cached snapshot — the background refresh hasn't completed yet. On the next tick, the snapshot TTL (3s) often hasn't expired, so no new refresh is triggered. The result: tasks are perpetually read from stale data.

Collapsing and re-expanding works because the manual toggle happens at a different point in the refresh cycle — typically after the background refresh has completed — so GetSnapshot() returns fresh data.

Fix

Replace the tea.Batch of per-service closures with a single tea.Cmd that calls GetOrRefreshSnapshot() (blocking, synchronous) before fetching tasks. This guarantees the global snapshot cache is fresh when GetTasksForService() reads from it. The blocking call runs in a goroutine (tea.Cmd), so it does not freeze the UI. When the snapshot is already fresh (within 3s TTL), GetOrRefreshSnapshot() returns instantly from cache.

Flow after fix

TickMsg (every 2s)
  → checkServicesCmd goroutine (unchanged, async)
  → refreshExpandedTasksCmd goroutine:
      1. GetOrRefreshSnapshot()   ← blocks ~0.5s if stale, instant if fresh
      2. GetTasksForService(sid)  ← reads FRESH snapshot
      3. returns AllTasksLoadedMsg
  → Update() stores fresh tasks in m.serviceTasks
  → View() re-renders with updated task rows

Test plan

  • Unit tests pass (go test ./views/services/...)
  • Lint passes (golangci-lint run ./...)
  • Build passes
  • Manual: expand a service with p, scale/restart it, verify tasks update without collapsing

🤖 Generated with Claude Code

refreshExpandedTasksCmd was reading tasks from a stale cached snapshot
because it ran concurrently with checkServicesCmd, which only triggered
an async (non-blocking) refresh. Replace the tea.Batch of per-service
closures with a single tea.Cmd that calls GetOrRefreshSnapshot() once
before fetching tasks, guaranteeing fresh data.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Copy link
Copy Markdown
Collaborator

@mosonyi mosonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a manual test.
What I have changed:

  1. I wanted to do a rolling update to a version that does not exist.
  2. I pressed 'p' to see if it tried to coninuously download -> OK
  3. Pressed 'l' to see the logs -> OK
  4. Pressed ESC to go back
  5. The processes are not updating anymore automatically -> NOT OK!
  6. When I press 'p' 2 times, it updates for that particular moment, but no continuous updates anymore.

OnEnter() returned nil, so after navigating to logs and back the 2s
polling ticker was never restarted — tasks stopped auto-refreshing.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@mosonyi mosonyi self-requested a review March 18, 2026 08:59
Copy link
Copy Markdown
Collaborator

@mosonyi mosonyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manual test worked!

@clangenb clangenb merged commit 22c4743 into main Mar 18, 2026
11 checks passed
@eldara-cruncher eldara-cruncher deleted the fix/284-services-view-task-refresh branch June 5, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[servicesView] tasks do not refresh on the fly (hiding and opening them again works though)

3 participants