Skip to content

fix(desktop): make the tasks badge and rows mirror live work - #2634

Merged
vastsa merged 5 commits into
vastsa:mainfrom
skyler-developer:fix/background-tasks-running-badge
Nov 27, 2026
Merged

vastsa merged 5 commits into
vastsa:mainfrom
skyler-developer:fix/background-tasks-running-badge

Conversation

@skyler-developer

@skyler-developer skyler-developer commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 概要

The tasks tab badge counted tasks that appeared while the panel was not on
screen and only cleared when the user re-entered the tab, so ended tasks kept
it raised; finished rows also lingered for a 10-second grace window. Both now
share one rule (#2632):

  • The badge is the session's running-task count, derived from the rows the
    container can render: it rises when a task starts and falls as tasks end,
    hiding at zero. Entering a tab, collapsing the container, or switching to
    Todo never changes it. The old newCount bookkeeping
    (observeSessionTasks / clearBadge) is removed; taskDock.newTasks is
    replaced by the existing taskDock.runningCount label (9 locales).
  • A finished task's row leaves the container as soon as its end state
    arrives — no grace window. The one kept row is the task whose output preview
    is open, and the preview pin lives only while the panel on screen shows the
    tasks side: collapsing the container, the visible panel becoming Todo
    (including todos coming back after a fallback), or switching sessions closes
    the preview, so a finished row cannot reappear later with no output on
    screen (fix(desktop): make the tasks badge and rows mirror live work #2634 review). The panel that resolves decides, not the remembered
    choice: a remembered Todo whose side emptied has already fallen back to
    Tasks, and a read opened there survives the task ending.
  • Removal stays a view action with a live-task guard: only a terminal task
    can be removed — in practice the expanded row of a task that just ended.
  • Registry records, output, task execution, stop, and continuation behavior
    are untouched; only panel display changed.

Deviation from the acceptance criteria, stated up front: a row being actively
read stays while its preview is on screen, and a running task's preview
survives a hidden panel and picks the same read back up on return. Every
other ended row disappears immediately.

Also updated the spec sections that documented the old badge and grace
window (docs/spec/03-runtime/03-tools-and-permissions.md,
docs/spec/04-ux/09-interaction-patterns.md,
docs/spec/06-delivery/e2e/tools-and-workspace.md) and rewrote the four
affected node --test suites for the new rule.

Requirement link / 需求关联

  • Linked requirement issue / 已关联对应的需求 Issue:Closes #2632
  • Issue explains the background and the expected outcome / Issue 已说明需求背景和期望效果
  • UI changes carry a fitting reference: screenshot, sketch, or demo / 涉及 UI 的改动已提供合适的截图、设计参考或 Demo
  • UI changes include before / after screenshots, uploaded to the PR (not committed to the repo) / UI 变更已附修改前后截图(直接上传到 PR,不要提交进仓库)

UI checkbox note: this is a state-derivation change behind the existing
markup (one aria-label key swap); no visual layout changed, so no screenshots
were taken. I can attach them on request by running the app with seeded
tasks.

Validation / 验证

Task candidate: e78627803 (branch fix/background-tasks-running-badge,
containing origin/main cc972c3d1; git merge-base --is-ancestor origin/main HEAD passes)

Run in the task worktree (deps via pnpm install --ignore-scripts --frozen-lockfile):

  • pnpm build:js — pass
  • pnpm --filter @pi-desktop/desktop typecheck — pass
  • pnpm lint — pass (style tokens OK)
  • node --test on the six targeted suites
    (background-tasks.test.mjs, background-tasks-bar-visibility.test.mjs,
    background-tasks-dock-state.test.mjs,
    background-tasks-dock-render.test.mjs,
    background-tasks-row-toggle.test.mjs, todo-dock-rendering.test.mjs) —
    58 pass / 0 fail

Regressions added across the review rounds on #2634: the visible-preview
case, the start → open output → collapse / switch to Todo → finish → reopen
case, the auto-tab no-interruption case
(background-tasks-bar-visibility.test.mjs); unit tests for
resolveDockTab / sidesFor / visibleDockTab / isReading
(background-tasks-dock-state.test.mjs), including the remembered Todo →
no todos → open log → finish chain from the maintainer review; and a third
scenario in the isolated Electron tab scenario
(scripts/e2e/task-dock-tabs.tsx) that clears all todos after a remembered
Todo choice, opens the log on the fallback Tasks panel, ends the task, and
asserts the log survives.

NOT RUN, with reasons:

  • Full pnpm test / full node --test test/*.test.mjs suite — ~26 known
    environment failures on this host (Electron binary not downloaded because
    of --ignore-scripts; Host RPC unavailable). Targeted suites above cover
    the changed surface.
  • Electron E2E (scripts/e2e-task-dock-tabs.mjs and the other isolated
    scenarios) — needs a runnable Electron build, not available in the
    --ignore-scripts install. The tab scenario script was reviewed by trace
    and bundles cleanly (esbuild); the maintainer has run both scenarios
    against earlier merge candidates.

Independent CR (subagent review) returned APPROVE across all rounds; the
final round's one P2 (a stale private copy of the reading rule in
background-tasks-bar-visibility.test.mjs asserting the rejected semantics)
and all P3 notes were fixed in e78627803. Remaining recorded non-blocking
note: pre-existing dead e2e probe scripts/e2e/background-tasks.tsx
referencing a deleted component (out of scope, left for cleanup).

Rollback / 回滚

Renderer-layer commits only; revert the branch to restore the old badge and
grace-window behavior. No persisted data, protocol, or host-side change, so
rollback needs no migration.

(Posted via an AI assistant at my direction; I own the content.)

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I confirmed the underlying issue on main: the badge counts unseen arrivals and never decrements when tasks finish. Deriving it from running tasks removes that cause. One acceptance case still needs resolving before landing: #2632 says a completed row should disappear immediately. The stated exception is for output the user is actively reading, but selectVisibleTasks(sessionTasks, expandedId) keeps the row even if the dock was collapsed or switched to Todo before the task ended (setCollapsed / openTodoTab leave expandedId unchanged). That leaves a finished row that can reappear later despite no output being on screen. Please preserve the pin while the preview is visible, keep cancellation accessible for continuation-pending rows, and add a start → open output → collapse or switch to Todo → finish → reopen regression alongside the visible-preview case. If the existing spec intentionally preserves hidden previews too, please agree on that exception in #2632 rather than closing it with different acceptance rules.

skyler-developer added a commit to skyler-developer/PI-Desktop that referenced this pull request Nov 27, 2026
The pin on a row being read kept the row alive while its preview was not
even on screen: collapsing the container or switching to Todo left the
preview id in place, so a finished row could reappear when the panel came
back. The preview now closes as soon as the tasks panel leaves the screen
(collapse, Todo tab, or a session switch), and the row leaves with it.

Addresses the review on vastsa#2634.
@skyler-developer
skyler-developer force-pushed the fix/background-tasks-running-badge branch from 4afd909 to af7535e Compare November 27, 2026 16:36
@skyler-developer

Copy link
Copy Markdown
Contributor Author

Thanks for the precise review — the hidden-preview gap is fixed in af7535e0c (rebased onto current main da30a57b8).

  • Pin lifetime. The pin now lives only while the tasks panel is actually on screen. tasksPanelVisible(dock, sides) (not collapsed, tab resolves to tasks) decides it, and the hook closes the preview (expandedId) the moment that stops holding — collapse, a switch to Todo, and a session switch all end the read, so a finished row cannot reappear later with no output on screen. The "row being read" exception is now exactly the one you stated: output the user is actively reading, while it is on screen.
  • Cancellation. Continuation-pending rows are live rows and untouched; "Cancel continuation" stays on them.
  • Regressions. background-tasks-bar-visibility.test.mjs gained both requested cases: the visible-preview case (row survives the task ending underneath it) and start → open output → collapse / switch to Todo → finish → reopen (row must not reappear). tasksPanelVisible and sidesFor (now shared from dock-state.ts, so the render, badge, and preview rules share one tab decision) have their own unit tests, and the source contract test pins the closing effects.
  • Spec. 03-runtime/03-tools-and-permissions.md and the E2E scenario doc now state the pin exists only while the tasks panel is on screen.

One pre-existing edge I want to flag rather than quietly keep: a user who never chose a tab (auto tab rule) with in-progress todos can still have the panel auto-switch to Todo when the last running task ends, which closes the preview mid-read. The tab rule itself is unchanged from main, so this behavior exists there today; the acceptance in #2632 doesn't cover it. Happy to pin the panel while reading in a follow-up if that's the intended rule.

(Posted via an AI assistant at my direction; I own the content.)

The tasks tab badge counted tasks that appeared while the panel was not
on screen and only cleared when the user re-entered the tab, so ended
tasks kept it raised; finished rows also lingered for a 10-second grace
window. Both now share one rule: the badge is the session's running-task
count, derived from the rows, and a finished task's row leaves as soon as
its end state arrives — only the row whose output is open stays, so a
log being read cannot vanish underneath it.

fixes vastsa#2632
The pin on a row being read kept the row alive while its preview was not
even on screen: collapsing the container or switching to Todo left the
preview id in place, so a finished row could reappear when the panel came
back. The preview now closes as soon as the tasks panel leaves the screen
(collapse, Todo tab, or a session switch), and the row leaves with it.

Addresses the review on vastsa#2634.
@skyler-developer
skyler-developer force-pushed the fix/background-tasks-running-badge branch from af7535e to c274574 Compare November 27, 2026 16:49
Two edges of the preview-pin rule. The auto tab rule could switch the
panel to Todo when the last running task ended mid-read, taking the
panel — and the row being read — away; an open read now keeps the tasks
panel on screen. And a running task's preview survived nothing: it now
survives a collapse or a Todo switch, so returning to the tasks tab
picks up the same read, while a task that ends while hidden takes its
pin with it, so a finished row still cannot reappear.
@skyler-developer

Copy link
Copy Markdown
Contributor Author

Follow-up in ed05f5899: two edges of the pin rule that a full-diff review surfaced before you re-reviewed.

  • The auto tab rule no longer switches the panel away from an open read. Before this, a user who never chose a tab, with an in-progress todo, could have the panel switch to Todo when the last running task ended mid-read — taking the row being read with it. An open preview now keeps the tasks panel on screen; choosing Todo is still what ends a read.
  • A running task's preview survives a collapse or a Todo switch. Returning to the tasks tab picks up the same read. A task that ends while its panel is hidden takes its pin with it, so a finished row still cannot reappear with no output on screen — the case from your review stays fixed.

This also reconciles the E2E scenario E2E-TASK-DOCK-tab-content-isolation (scripts/e2e/task-dock-tabs.tsx, "Open log must survive switching"): the running-task fixture now genuinely passes under the new rule, where the previous round would have failed it. The probe itself needed no change. Spec sections updated to state the split rule.

Validation: 45 + 11 targeted node --test pass, typecheck and lint clean; Electron probe not run on this host (no unpacked Electron binary under --ignore-scripts), verified by stepping through the probe's assertions against the new code paths.

(Posted via an AI assistant at my direction; I own the content.)

@vastsa

vastsa commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for the two follow-ups. I verified the current merge candidate (ac591d00f on cc972c3d1): all 49 targeted tests and both isolated Electron task-dock scenarios passed, and the previously reported hidden-preview case is addressed. One follow-up edge still contradicts the visible-read rule: choose Todo, then remove/clear all todos so the dock falls back to showing Tasks without changing the remembered choice. Open a running task’s log and let it finish. The resolved panel is still Tasks, but reading is false because dock.chosenTab is todo; the cleanup effect clears expandedId and drops the log mid-read. Please base the pin on the actual visible panel (while still preserving the no-interruption rule for automatic tab selection), and cover remembered Todo → no todos → open log → finish. I have not merged pending that case.

A remembered Todo choice ended a read even while the panel actually on
screen was Tasks: clearing every todo makes the dock fall back to Tasks
without changing the choice, and a log opened on that panel was dropped
mid-read when its task ended, because the pin rule looked at the
remembered choice instead of the panel that resolves.

The rule moves into dock-state as `isReading`, which decides from the
resolved panel while keeping the no-interruption guarantee for
automatic tab selection. The e2e tab scenario now covers remembered
Todo → no todos → open log → finish, and the spec wording follows the
resolved-panel semantics.

Closes the follow-up case from the vastsa#2634 review.
@skyler-developer

Copy link
Copy Markdown
Contributor Author

Fixed in e78627803 — thanks for the precise edge.

  • The pin now follows the panel on screen. The rule moved into dock-state.ts as isReading(dock, sides, expandedId): it decides from the panel that resolves, so a remembered Todo whose side emptied — which falls back to Tasks without changing the choice — keeps a read opened there alive through the task ending. Choosing Todo still ends a read while the Todo side has content, and todos coming back while the ended task's log is open closes the pin then, since the visible panel returns to Todo.
  • The no-interruption rule for automatic tab selection is preserved: with no user choice recorded, an open read still keeps Tasks on screen (visibleDockTab unchanged).
  • Coverage: the remembered Todo → no todos → open log → finish chain is now the third scenario in scripts/e2e/task-dock-tabs.tsx (the fixture task ends on demand and the log must survive it), plus behavioral cases in background-tasks-dock-state.test.mjs and background-tasks-bar-visibility.test.mjs.

Validation: 58 targeted node --test (6 dock/bar suites) pass, pnpm build:js, desktop typecheck, and lint are green, and the e2e script bundles cleanly — the isolated Electron run itself is NOT RUN on my side (no Electron binary in this checkout; same caveat as the previous rounds, you ran it against the merge candidate).

(Posted via an AI assistant at my direction; I own the content.)

@vastsa

vastsa commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for the follow-up. I rechecked e78627803 on cc972c3d1: 58 targeted tests and all three isolated Electron task-dock scenarios passed. The new scenario confirms that a remembered Todo falls back to Tasks when the Todo side empties, and that the open log stays visible when the task finishes. This addresses the previous review finding. I am holding merge until the current integration checks finish.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Verified the current GitHub integration candidate 86bc56f04 (ecc643916 on cb68af0d0). All 58 targeted tests and all three isolated Electron task-dock scenarios pass, including the remembered-Todo fallback. The badge now follows the live rows instead of accumulating arrivals, and the read pin does not retain hidden finished work. The prior changes request is resolved.

@vastsa
vastsa merged commit 6214e55 into vastsa:main Nov 27, 2026
6 checks passed
zergfff added a commit to zergfff/PI-Desktop-fork that referenced this pull request Nov 30, 2026
Ported from vastsa/PI-Desktop v0.24.0-beta.7 (bug fixes only; the release's
features were left for a later rebase):

vastsa#2625 quarantine rejected outbox appends instead of retrying them forever
vastsa#2574 settle live turns and tool rows when the sidecar dies mid-stream
vastsa#2578 native Pi turns stay stoppable after a reload
vastsa#2634 the task badge mirrors work that is still running
vastsa#2639 let Arabic and Hebrew paragraphs choose their own side
vastsa#2640 stop a renderer crash loop with one GPU-less relaunch, then a dialog
vastsa#2642 reject differing spellings of one tool argument
vastsa#2655 compaction summaries open on demand in the transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants