♻️ Unify task / coroutine lifecycles#1168
Merged
Merged
Conversation
85ba85e to
6bd6b4f
Compare
commit: |
1efed88 to
51128fd
Compare
51128fd to
c1f13ba
Compare
846cffa to
59a6ed4
Compare
jbolda
reviewed
May 31, 2026
59a6ed4 to
fb6980c
Compare
fb6980c to
e5fbb50
Compare
Merging this PR will improve performance by ×2.1
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | effection-inline.recursion |
2,775.7 µs | 521.5 µs | ×5.3 |
| 👁 | Memory | effection-inline.recursion |
3.3 KB | 4.1 KB | -18.46% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing unified-lifecycle (3cfd672) with v4 (096ebda)
Footnotes
-
18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
jbolda
approved these changes
Jun 4, 2026
e47f4f7 to
c45669e
Compare
c45669e to
42c199b
Compare
There were correctness issues in v4 that arose when halting. They all
stemmed from the fact that different parts of the codebase had
different ideas about when a task was actually "done" — especially
when that task was halted. This led to multiple races around the
question.
This rectifies the situation in the following ways:
1. Every coroutine has a single definite future that can only be
resolved when the coroutine is completely exhausted.
2. The task future is derived entirely from the coroutine's future.
3. The task's halt() future is also derived entirely from the
coroutine's future.
For tasks, error / success / halt all flow through the same code path:
the complete conclusion of the coroutine's body. The only way to see
_any_ of these values is for the reducer to ask the coroutine to
produce { done: true, value: T }. Previously, we were just dropping
this on the floor and resolving a future in a finally {} block of the
body.
This entailed making the coroutine layer smarter than before, but
the result is a simpler architecture. Rather than being managed by a
host of reducers, delimiters, and error boundaries, the coroutine is
now the primary organ of evaluation. Coroutines themselves — not
instructions — are added to and removed from the reducer queue, so
there is no after-the-fact validation of instructions to drop stale
ones. A coroutine that changes its internal state between ticks is
still fresh when it is dequeued. This eliminated the need for tickets.
We were also able to make trap() the single abstraction for error
containment. There is no longer a separate error boundary at the
task level.
42c199b to
3cfd672
Compare
This was referenced Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
There were correctness issues in v4 that arose when halting. They all stemmed from the fact that different parts of the codebase had different ideas about when a task was actually "done" — especially when that task was halted. This led to multiple races around the question.
Approach
This rectifies the situation in the following ways:
For tasks, error / success / halt all flow through the same code path: the complete conclusion of the coroutine's body. The only way to see any of these values is for the reducer to ask the coroutine to produce { done: true, value: T }. Previously, we were just dropping this on the floor and resolving a future in a finally {} block of the body.
This entailed making the coroutine layer smarter than before, but the result is a simpler architecture. Rather than being managed by a host of reducers, delimiters, and error boundaries, the coroutine is now the primary organ of evaluation. Coroutines themselves — not instructions — are added to and removed from the reducer queue, so there is no after-the-fact validation of instructions to drop stale ones. A coroutine that changes its internal state between ticks is still fresh when it is dequeued. This eliminated the need for tickets.
We were also able to make trap() the single abstraction for error containment. There is no longer a separate error boundary at the task level.