Skip to content

fix(dashboard): hold three fire-and-forget tasks until they finish - #25971

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
crew/conductor/dashboard-task-refs
Oct 30, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
crew/conductor/dashboard-task-refs

Conversation

@RohanK6

@RohanK6 RohanK6 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Three dashboard background jobs (the startup MCP probe, the Web Push send, and closing an expired WeChat QR client) always run to the end instead of being garbage-collected part way.

Each was started with create_task and the returned Task was dropped:

Site Job
src/kiro_crew/dashboard/server.py:1380 startup MCP probe (handlers._bg_mcp_probe)
src/kiro_crew/dashboard/state_parts/dashboard_services.py:759 Web Push fan-out (_send_web_push_all)
src/kiro_crew/dashboard/handlers/weixin_qr.py:92 close() of an expired WeChat QR client

The event loop keeps only a weak reference to a task. One that nothing else holds can be destroyed by the garbage collector before it finishes, and Python logs Task was destroyed but it is pending!.

Why it matters

When that happens the work silently stops: the MCP probe never reports, a browser push notification is never sent, or a QR client's connection is never closed. Nothing surfaces the loss except a log line.

Not a goal

What changed (motivation → approach → change)

A task nobody holds can be collected mid-run, so each of the three is now held until it finishes, using the repo's existing pattern (dashboard/server_runtime/maintenance.py:76-78):

  • server.py and dashboard_services.py add the task to the dashboard state's existing _background_tasks set and add_done_callback(_background_tasks.discard).
  • weixin_qr.py's _prune_sessions is a plain module function with no state, so it uses a module-level _CLOSE_TASKS set, as dashboard/handlers/core_stt_access.py does with _stt_background_tasks.

Backwards compatibility

Compatible: each job runs exactly as before; it is only held until done.

Removes nothing: no route, key or function is removed; three tasks gain a strong reference.

Tests

  • test/test_web_push.py::test_fan_out_task_survives_a_gc_pass and test/test_dashboard_task_refs.py::test_expired_qr_client_close_survives_a_gc_pass park the scheduled task on a future only it references, which forms an unreachable cycle, then run gc.collect(). They assert the task is still alive and held in its set, and that it leaves the set when done. On origin/main both fail: the task is destroyed and asyncio logs Task was destroyed but it is pending!.
  • test/test_dashboard_task_refs.py::test_no_dropped_task_statement checks the three files with ast for a bare create_task(...) / ensure_future(...) statement; it covers the server.py startup site, which no unit test can reach. It fails on origin/main for all three files. test_the_guard_sees_a_dropped_task checks the scanner itself.
  • All six ran 5 times in a row: green each time.
  • 346 test files that import these modules (weixin_qr, dashboard_services, dashboard_state, dashboard.server, _bg_mcp_probe, _fan_out_web_push): 13,219 passed. black, isort, flake8, mypy, comment-history, brand, line cap, harness parity and the flake-pattern ratchet: clean.

Proof: PROVEN test/test_dashboard_task_refs.py::test_no_dropped_task_statement[src/kiro_crew/dashboard/server.py], test/test_dashboard_task_refs.py::test_no_dropped_task_statement[src/kiro_crew/dashboard/state_parts/dashboard_services.py], test/test_dashboard_task_refs.py::test_no_dropped_task_statement[src/kiro_crew/dashboard/handlers/weixin_qr.py], test/test_dashboard_task_refs.py::test_expired_qr_client_close_survives_a_gc_pass, test/test_web_push.py::test_fan_out_task_survives_a_gc_pass (head 812e131ee3c0)

Manual verification

N/A — the gc tests reproduce the destruction directly; no UI changes.

Related Issues

Part of #25953

Sibling sweep

Swept: ast scan of src/kiro_crew for an Expr statement whose value calls create_task or ensure_future
Sibling: src/kiro_crew/session_allocation.py:1152 -- tracked in #25953
Sibling: src/kiro_crew/knowledge/llm_pool.py:1301 -- tracked in #25953
Sibling: src/kiro_crew/instances/ssh_tunnel_manager_child.py:453 -- tracked in #25953
Sibling: src/kiro_crew/sprites_session/terminal.py:138 -- tracked in #25953
Sibling: src/kiro_crew/subagent_manager/admission/gate.py:1484 -- tracked in #25953
Sibling: src/kiro_crew/imessage/client.py:349 -- tracked in #25953
Sibling: src/kiro_crew/slack/gateway_runtime/service_boot.py:1388 -- tracked in #25953
Sibling: src/kiro_crew/apps/worker_slots.py:154 -- tracked in #25953
Sibling: src/kiro_crew/apps/builtins/dev_fleet/fleet_state.py:1697 -- tracked in #25953
Sibling: src/kiro_crew/apps/builtins/pptx_maker/backend/routes.py:663 -- tracked in #25953

Pattern harvest

Rule candidate: lint
Pattern: a statement that calls create_task or ensure_future and discards the returned task

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@RohanK6
RohanK6 requested review from a team and KiroCrewCaptain as code owners October 29, 2026 21:31
@RohanK6
RohanK6 requested a review from cruisercohen October 29, 2026 21:31
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 409989ec9506eb1025283d9c9693cbf3aa329527 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 409989ec9506eb1025283d9c9693cbf3aa329527 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The PR uses the repo's existing pattern of a strong set plus a done-callback, adds no new surface and takes nothing away.

Notes

[DESIGN-REVIEWED] 409989e

Description read

[DESCRIPTION-READ] 8c04ef2b06e8efcfeefc9d24a26802d7f99382c280e22afa74422c3240d850ce

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 409989ec9506eb1025283d9c9693cbf3aa329527 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Each of the three sites now uses the same strong-set pattern as about 60 other dashboard sites. The ten unfixed siblings are listed in the description and tracked in #25953.

Notes

  • Item 4 — symptom-level: GUARDED = (...three paths...) limits the bare-create_task AST guard to the three fixed files, so the cause it targets ("a statement that calls create_task … and discards the returned task") stays open in the 10 sibling files the description lists. Subtraction: when Dropped asyncio.create_task results can be garbage-collected mid-run #25953 lands, replace the per-file GUARDED tuple with the one repo-wide lint the author's own "Pattern harvest" names, rather than growing this list.

What this change ships

Inventory (4 items) — 3 justified

Intent: make three dashboard background jobs (MCP probe at startup, Web Push send, closing an expired WeChat QR client) always run to the end. This is a FIX.

  1. The startup MCP probe can no longer be garbage-collected before it reports — justified
  2. Web Push sends can no longer be dropped part way through — justified
  3. An expired WeChat QR client's close() always finishes, held by a new module-level _CLOSE_TASKS set — justified
  4. A new test fails if any of the three files gets a bare create_task(...) statement again — symptom-level: guards 3 files, not the 10 siblings

[FIRST-PRINCIPLES-REVIEWED] 409989e

Description read

[DESCRIPTION-READ] a6c5bd8769529cc8f5ca70192437870a464a22b6dae46905121052275ed34968

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 409989ec9506eb1025283d9c9693cbf3aa329527 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 409989e

Verdict parsed from the review's SHA-scoped output markers for commit 409989ec9506eb1025283d9c9693cbf3aa329527.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 409989ec9506eb1025283d9c9693cbf3aa329527 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 409989ec9506eb1025283d9c9693cbf3aa329527 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 409989e

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 409989ec9506eb1025283d9c9693cbf3aa329527 false-positive: <reason, 20 to 500 characters>

The startup MCP probe, the Web Push fan-out and the close of an
expired WeChat QR client were started with create_task and the
returned Task was dropped. The event loop keeps only a weak reference
to a task, so the garbage collector could destroy one mid-run and the
work would never finish ("Task was destroyed but it is pending!").

Hold each in a strong set and discard it when done: the dashboard
state's existing _background_tasks for the probe and the push, and a
module-level set for the QR close, which has no state to reach.

Part of #25953
@RohanK6
RohanK6 force-pushed the crew/conductor/dashboard-task-refs branch from 0fc54f9 to 409989e Compare October 29, 2026 22:24
@RohanK6

RohanK6 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Backend Tests shard 2 (Linux and Windows) and the Coverage Gate were red on 0fc54f9ed9, from three tests outside this diff:

  • test_dir_fd_create_race_ratchet.py::test_no_lock_file_is_created_with_a_nonexclusive_open
  • test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget
  • test_subagent_prompt_hooks.py::test_hook_time_is_not_charged_to_the_first_prompt_watchdog

All three fail on a clean origin/main checkout at b5dc1567f1. Main fixed them in 7e09632e3e (#25947), so this branch is rebased onto it as 409989ec95; the three pass locally there. Coverage Gate failed only because the shards did.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 29, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 30, 2026 00:06

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: holds three dashboard fire-and-forget tasks (QR client close, MCP probe, web push fan-out) until they finish.

@KiroCrewCaptain
KiroCrewCaptain merged commit 4915d21 into main Oct 30, 2026
95 of 96 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the crew/conductor/dashboard-task-refs branch October 30, 2026 00:07
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 30, 2026
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