mpfaffenberger / mpfaffenberger/code_puppy_core_plugins

subagent_panel: coalesce drain can deliver stream events out of order at stream end

Open
#29 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3
Forks
20
Avg merge
2d 3h
Merged PRs (30d)
20

Description

Bug

subagent_panel/coalesce_patch.py — lines 101–112 (_drain_pending_task) vs 129–144 (flush_pending_callbacks).

If the 50 ms drain fires just before a sub-agent stream ends:

  1. _drain_pending_task moves the pending events into a batch and calls loop.create_task(_fire_batch(batch)) (line 112) — the batch is scheduled, not executed.
  2. The stream wrapper's finally then calls flush_pending_callbacks(), which drains any newer events and runs them synchronously via await _fire_batch(batch) (line 144).

The newer events therefore reach the panel before the loop gets around to the earlier scheduled batch — part_end/completion data for the tail of a stream can render before the earlier part_start/text of the same stream.

Runtime consequence

The sub-agent panel tree can repaint out of order (a finished row briefly appearing before its content) — flapping on exactly the busy-swarm scenes this patch was written for.

Suggested fix

Never leave the timer's batch as a deferred task — route it through the same flush path as stream-end, or make flush_pending_callbacks cancel/absorb a scheduled drain before firing.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read subagent_panel/coalesce_patch.py, especially _drain_pending_task and flush_pending_callbacks at the cited lines, and trace how the stream wrapper calls the flush path in finally. Verify that a timer-drained batch is delivered before newer stream-end events, with part_start and text preceding part_end or completion data.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.