Skip to content

perf(session): coalesce family reads during subagent bursts - #229

Merged
Tarquinen merged 2 commits into
devfrom
coalesce-family-reads
Nov 21, 2026
Merged

Tarquinen merged 2 commits into
devfrom
coalesce-family-reads

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

When several subagents start at once, each one restarted the session's family read and relisted shells and jobs, so a burst of ten walked the family ten times.

Now a family request during a read in flight queues exactly one follow-up read. Only the last answer marks the family fresh, and leaving the screen drops the queued read. Shells and jobs are relisted on a new event stream instead, and jobs also when a family answer finds a new subagent, so a child's early background script still shows.

Ports iOS anomalyco/opencode-ios#298 (fd33dc04, CoalescedRead). Unlike iOS, CoalescedRead is a plain data class, because the Android store drops a state equal to the last one. Nothing visible changes.

Verified with the four ported iOS tests (three fail on dev), a test that drives a burst through the real Store (it fails with the always-equal version), a test for a new subagent's early job, and a full scripts/check.sh on the Android VM.

Every FamilyRefreshRequested (Home sends one per new subagent) cancelled the
family read in flight, started it over, and relisted shells and jobs. Ten
subagents starting at once walked the family ten times.

Ports iOS #298 (fd33dc04, CoalescedRead): a family request while a read is in
flight queues exactly one follow-up read. Only the last answer of a queued run
sets familyReadAt, and leaving the screen forgets the queued read. Shells and
jobs aren't family, so FamilyRefreshRequested no longer relists them; a new
event stream (EventStreamConnected) does, so a reconnect still catches missed
shell exits and job settles.

Tests: ported aBurstOfSubagentsWalksTheFamilyTwice,
onlyTheLastQueuedFamilyAnswerMakesItFresh, leavingTheScreenForgetsTheFamilyWalk
and aNewStreamRelistsShells; the first three fail with the old
FamilyRefreshRequested. The two reconnect job tests now reconnect through
EventStreamConnected, as on iOS, and three reconnect tests stub the new lists.

Verified: full scripts/check.sh on the Android VM passes.
Review fixes for coalesced family reads:
- CoalescedRead is a plain data class. The Store drops a state equal to the
  last one, so the always-equal version lost the in-flight and queued flags
  and every burst restarted the read again (new store-level test).
- A carried screen's Task resets familyRead when it cancels the family read,
  so a read cancelled there can't leave later requests queued forever.
- A family answer that finds new members relists jobs, so a child's job that
  started before the child was known still shows.
- Drop unused sessionFamily stubs in the reconnect job tests; fix the jobs
  file comment; exhaustive tests now expect the familyRead flags.

Verified: the store-level test fails on the previous commit (2 reads, not 1);
full scripts/check.sh on the Android VM passes.
@Tarquinen
Tarquinen merged commit 584c905 into dev Nov 21, 2026
2 checks passed
@Tarquinen
Tarquinen deleted the coalesce-family-reads branch November 21, 2026 03:18
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.

1 participant