Skip to content

[Brook S8] Added Activity Stream handles and BufferedPublisher. - #378

Open
moetemp wants to merge 1 commit into
moe/brook/review/s7-workflow-streamsfrom
moe/brook/review/s8-activity-handles
Open

moetemp wants to merge 1 commit into
moe/brook/review/s7-workflow-streamsfrom
moe/brook/review/s8-activity-handles

Conversation

@moetemp

@moetemp moetemp commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

What was changed

This PR adds the Activity Stream handles (ActivityStream, SyncActivityStream, SyncSubscription) and BufferedPublisher.

  • The Activity's parameter type selects the handle class. A sync Activity gets the sync handles.
  • An Activity writes as its attempt, so a retry withdraws the Records of the earlier attempts.
  • BufferedPublisher batches the publishes of one Stream, in order, and flushes at the end of an Activity attempt.
  • close on an Activity handle raises StreamNotOwnerError with no call, since no Activity owns a Stream. A Workflow's Stream closes from Workflow code, and a client's Stream from a client. The method stays, since the API proposal gives every handle the same calls.
  • A sync call runs on the Worker's loop. _run makes the call's future before it schedules the call, so a cancel of the Activity thread after the schedule also cancels the call. With asyncio.run_coroutine_threadsafe, a cancel can leave a long poll running. A call when the Worker's loop is already closed closes its coroutine, so nothing warns at shutdown.

Depends on S7 (#377). No changelog fragment, since S9 has the Streams entry.
Part of the Brook review series.

Why?

Agents stream model tokens from an Activity. The Workflow keeps the Stream, and the Activity writes to it.

Checklist

  1. How was this tested:
    • poe lint, poe gen-docs and pytest tests/contrib/streams on both backends. The sync cancel tests ran in a loop on Python 3.13 and 3.14, alone and in parallel.
    • Fork CI passes, except the arm jobs, since the fork has no arm runners.

@moetemp moetemp added the skip-changelog Changelog entry rides another PR label Oct 25, 2026
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from b298e44 to 90966d6 Compare October 26, 2026 00:14
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch 4 times, most recently from 24f6a90 to 79cf55a Compare October 26, 2026 04:52
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from 1c5e48f to 84f1587 Compare October 26, 2026 08:44
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from 79cf55a to 15eebd7 Compare October 26, 2026 08:44
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from 84f1587 to c3f30a4 Compare October 27, 2026 09:07
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from 15eebd7 to b3da39a Compare October 27, 2026 09:07
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from c3f30a4 to b9572b1 Compare October 27, 2026 09:17
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from b3da39a to 212ef71 Compare October 27, 2026 09:17
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from b9572b1 to 925cf34 Compare October 28, 2026 01:33
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from 212ef71 to 4a67b4e Compare October 28, 2026 01:33
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from 925cf34 to cc8e51c Compare October 28, 2026 07:54
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from 4a67b4e to 0c7ec5b Compare October 28, 2026 07:54
An Activity writes as its attempt, so a retry withdraws the Records of
the earlier attempts. An Activity's `BufferedPublisher` flushes at the
end of the attempt.
@moetemp
moetemp force-pushed the moe/brook/review/s7-workflow-streams branch from cc8e51c to e7710c0 Compare October 28, 2026 08:05
@moetemp
moetemp force-pushed the moe/brook/review/s8-activity-handles branch from 0c7ec5b to 86d50a1 Compare October 28, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Changelog entry rides another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant