Repository navigation
fix(dashboard): hold three fire-and-forget tasks until they finish - #25971
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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
What this change shipsInventory (4 items) — 3 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 409989e Description read[DESCRIPTION-READ] a6c5bd8769529cc8f5ca70192437870a464a22b6dae46905121052275ed34968 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
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
0fc54f9 to
409989e
Compare
|
Backend Tests shard 2 (Linux and Windows) and the Coverage Gate were red on
All three fail on a clean |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
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_taskand the returnedTaskwas dropped:src/kiro_crew/dashboard/server.py:1380handlers._bg_mcp_probe)src/kiro_crew/dashboard/state_parts/dashboard_services.py:759_send_web_push_all)src/kiro_crew/dashboard/handlers/weixin_qr.py:92close()of an expired WeChat QR clientThe 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
add_done_callback(set.discard)at each site, and this PR follows it.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.pyanddashboard_services.pyadd the task to the dashboard state's existing_background_tasksset andadd_done_callback(_background_tasks.discard).weixin_qr.py's_prune_sessionsis a plain module function with no state, so it uses a module-level_CLOSE_TASKSset, asdashboard/handlers/core_stt_access.pydoes 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_passandtest/test_dashboard_task_refs.py::test_expired_qr_client_close_survives_a_gc_passpark the scheduled task on a future only it references, which forms an unreachable cycle, then rungc.collect(). They assert the task is still alive and held in its set, and that it leaves the set when done. Onorigin/mainboth fail: the task is destroyed and asyncio logsTask was destroyed but it is pending!.test/test_dashboard_task_refs.py::test_no_dropped_task_statementchecks the three files withastfor a barecreate_task(...)/ensure_future(...)statement; it covers theserver.pystartup site, which no unit test can reach. It fails onorigin/mainfor all three files.test_the_guard_sees_a_dropped_taskchecks the scanner itself.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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)