Skip to content

fix(archive): stop "Archive running task?" dialog firing on idle tasks#3064

Merged
adboio merged 1 commit into
mainfrom
posthog-code/fix-archive-running-dialog
Jul 1, 2026
Merged

fix(archive): stop "Archive running task?" dialog firing on idle tasks#3064
adboio merged 1 commit into
mainfrom
posthog-code/fix-archive-running-dialog

Conversation

@adboio

@adboio adboio commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Problem

The "Archive running task?" confirmation was popping up on nearly every archive, even for tasks that weren't running.

The guard in SidebarMenu.tsx was:

task.taskRunStatus === "in_progress" || task.isGenerating

where taskRunStatus falls back to task.latest_run.status. That persisted status is only kept current by the backend for cloud runs (it flips to completed/failed/cancelled when the sandbox finishes or crashes).

Local runs never get a terminal status written back — nothing PATCHes the run when the local agent goes idle or the app closes — so latest_run.status stays "in_progress" forever. Once there's no live session, the guard read that stale status and treated the task as running.

Fix

Moved the predicate into core as a pure, tested helper (packages/core/src/sidebar/taskRunning.ts, mirroring runEnvironment.ts) and corrected the logic:

export function isTaskActivelyRunning(task: TaskData): boolean {
  if (task.isGenerating) return true;
  return task.taskRunEnvironment === "cloud" && task.taskRunStatus === "in_progress";
}
  • Local tasks count as running only while a prompt is actually in flight (isGenerating); the stale persisted status is ignored.
  • Cloud tasks keep the reliable, backend-tracked in_progress signal — behaviour unchanged.

This matches the existing session-based "running" logic in canvasGenerationStatus.ts and how TaskIcon already gates run-status semantics to cloud tasks.

Testing

  • New parameterised test taskRunning.test.ts (12 cases), including the exact regression: stale local in_progress with no live prompt → not running.
  • pnpm --filter @posthog/core test → 185 files / 1859 tests pass.
  • typecheck (core + ui) and biome lint clean.

Note (out of scope)

The mobile guard (apps/mobile/.../archiveGuard.ts) uses raw !isTerminalStatus(latest_run.status), which has the same latent flaw for local tasks — only sound today because mobile is cloud-only. Left untouched here.

…tasks

The archive confirmation was gated by:

    task.taskRunStatus === "in_progress" || task.isGenerating

where taskRunStatus falls back to task.latest_run.status. That persisted
status is only kept current by the backend for cloud runs. Local runs never
get a terminal status written back when the agent goes idle or the app
closes, so latest_run.status stays "in_progress" forever — meaning the dialog
fired on archive for essentially every local task the user had ever run.

Move the predicate into core as a tested pure helper (isTaskActivelyRunning)
and only trust the persisted status for cloud runs. Local tasks now count as
running only while a prompt is actually in flight (isGenerating), matching the
existing session-based "running" logic in canvasGenerationStatus.ts and how
TaskIcon already gates run-status semantics to cloud tasks.

Adds a parameterised regression test covering the stale-local-in_progress case.

Generated-By: PostHog Code
Task-Id: 9f81df96-fa22-49c3-a559-7cb273296093
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit b0d2ef0.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(archive): stop the "Archive running ..." | Re-trigger Greptile

@adboio adboio requested a review from a team July 1, 2026 16:43
@adboio adboio added the Stamphog This will request an autostamp by stamphog on small changes label Jul 1, 2026 — with Graphite App
@adboio adboio marked this pull request as ready for review July 1, 2026 19:05
@adboio adboio removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 1, 2026
@adboio adboio added the Stamphog This will request an autostamp by stamphog on small changes label Jul 1, 2026 — with Graphite App

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well-targeted bug fix: extracts a pure predicate into @posthog/core (correct layer), fixes the stale in_progress status problem for local runs, and ships 12 parameterised test cases that explicitly cover the regression. Architecture rules are satisfied — @posthog/ui importing from @posthog/core is explicitly permitted, and the function has no host dependencies.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Focused, well-tested bug fix: extracts a pure predicate to the correct layer and corrects the stale in_progress status problem for local runs. No showstoppers.

@adboio adboio merged commit 073091a into main Jul 1, 2026
30 checks passed
@adboio adboio deleted the posthog-code/fix-archive-running-dialog branch July 1, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant