Repository navigation
Make an actor's calls use a running request's I/O channels - #8700
Conversation
There was a problem hiding this comment.
Superseded by the review of
ae1500a1.
This review, of d94d2280
✅ Approved — No issues found. The selector that getIoChannelFactory() now uses is behind the IO_CHANNELS_FROM_RUNNING_REQUEST autogate, matches how incomingRequests and waitedForWaitUntil are maintained, and gives the old behavior when the gate is off.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues found. The change only picks which already-attached IncomingRequest's I/O channel factory serves an actor's outgoing calls, and it is behind an autogate.
📖 AGENTS.md: ✅ LGTM
This pull request doesn't change any AGENTS.md guidance. The new autogate follows the documented pattern of adding a key to WORKERD_AUTOGATES in src/workerd/util/autogate.h.
📋 Code Quality: ✅ LGTM
I checked IoContext::getIncomingRequestForIoChannels() against the code that maintains incomingRequests and waitedForWaitUntil. I found no problems.
- Selector:
delivered()adds each request to the front ofincomingRequests, so the loop returns the newest request that hasn't been drained. When every request has returned, it falls back togetCurrentIncomingRequest(), which is the reference the old code returned. waitedForWaitUntil: It is set indrain(),cancelPendingWorkForHibernation()andfinishScheduled(). A request that is destroyed without a drain is taken off the list, so the selector never sees a stale entry. A stateless context holds only one request, so nothing changes there.- Gate off: The selector returns the current request, the same as before.
- Tests: The gate-on tests cover both cases: an older request that is still running is chosen, and once both requests have returned the newest one is used. The gate-off test confirms the old behavior. The locals are destroyed in a safe order.
- Known limitation: Metrics, spans and the clock are still attributed through
getCurrentIncomingRequest(). The pull request description already lists this under Limitations.
⚡ Performance: ✅ LGTM
getIoChannelFactory() now does a linear scan of incomingRequests. That list holds only the requests currently attached to the actor, and the scan stops at the first request still running. When the gate is off, the autogate check returns right away. The added cost is negligible.
📝 Documentation: ✅ LGTM
The updated comments on waitedForWaitUntil, getIoChannelFactory() and getIncomingRequestForIoChannels() match what the code does.
Reviewed commit: d94d2280
d94d228 to
ae1500a
Compare
There was a problem hiding this comment.
Superseded by the review of
bf696860.
This review, of ae1500a1
✅ Approved — No issues found. The only change since the last review adds the autogate key in the standard format, and the gated selector still behaves correctly with the gate on and off.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues. The change only selects which of the actor's own attached requests supplies the I/O channel factory for its outgoing calls, and it is behind an autogate.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md guidance is affected. The new autogate follows the documented pattern of adding a key to WORKERD_AUTOGATES.
📋 Code Quality: ✅ LGTM
This commit only adds the IO_CHANNELS_FROM_RUNNING_REQUEST key to WORKERD_AUTOGATES in src/workerd/util/autogate.h, using the documented format. The selector logic and its tests are unchanged and still correct:
- Gate on: the newest request that hasn't returned is chosen. If every request has returned, the newest request is used.
- Gate off: the behavior is the same as before this pull request.
⚡ Performance: ✅ LGTM
The added cost is negligible. The scan covers only the requests attached to the actor and stops at the first one that hasn't returned. With the gate off, it returns right away.
📝 Documentation: ✅ LGTM
The comments match what the code does.
Reviewed commit: ae1500a1
ae1500a to
bf69686
Compare
There was a problem hiding this comment.
Superseded by the review of
d0be81eb.
This review, of bf696860
✅ Approved — No issues found. The only change since the last review adds the autogate key in the standard format, and the gated selector still behaves correctly with the gate on and off.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues. The change only selects which of the actor's own attached requests supplies the I/O channel factory for its outgoing calls, and it is behind an autogate.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md guidance is affected. The new autogate follows the documented pattern of adding a key to WORKERD_AUTOGATES.
📋 Code Quality: ✅ LGTM
This commit only adds the IO_CHANNELS_FROM_RUNNING_REQUEST key to WORKERD_AUTOGATES in src/workerd/util/autogate.h, using the documented format. The selector logic and its tests are unchanged and still correct:
- Gate on: the newest request that hasn't returned is chosen. If every request has returned, the newest request is used.
- Gate off: the behavior is the same as before this pull request.
⚡ Performance: ✅ LGTM
The added cost is negligible. The scan covers only the requests attached to the actor and stops at the first one that hasn't returned. With the gate off, it returns right away.
📝 Documentation: ✅ LGTM
The comments match what the code does.
Reviewed commit: bf696860 — same changes as ae1500a1, so this is that commit's review (no new review was run; line numbers are as of ae1500a1)
An actor's IoContext hands out the IoChannelFactory of its newest IncomingRequest. After that request returns, it stays the newest while the actor waits for background work, so a request that returned long ago keeps governing the calls that other, still-running requests make. An embedder can stamp each outgoing call with its request's metadata, such as a loop-depth TTL. A callback into the actor arrives with a lower TTL than the request that caused it, becomes the newest request, and stays so after it returns. The next calls of a longer-lived request then spend the callback's lower TTL, and each further round of callbacks lowers it again, until calls fail with "Subrequest depth limit exceeded". This happens, for example, when an actor runs code in a Dynamic Worker whose tail worker reports back to the actor, or when a client session drives Dynamic Workers that call back into the actor. Under the new IO_CHANNELS_FROM_RUNNING_REQUEST autogate, getIoChannelFactory() returns the factory of the newest request that has not returned, or of the newest request if every request has returned. Limitations: - Work that a request leaves running after it returns isn't tied to the request that started it, so it uses the newest running request, whose TTL may differ from its starter's. Propagating the request through async context would fix this fully. - A request counts as running until its call ends, and a JS RPC call ends only once its caller releases it, after the caller has the result. Calls that the actor makes while a callback is running, including just after it has replied, spend the callback's lower TTL. Once the callback ends, calls spend the running request's TTL again, so the TTL drops further only if each round's calls are made while the previous round's callback is still running. - Spans and metrics are still attributed to the newest request. - Timers also come from the selected factory. All requests to an actor share its clock, so they are unaffected.
bf69686 to
d0be81e
Compare
There was a problem hiding this comment.
✅ Approved — No issues found. The only change since the last review adds the autogate key in the standard format, and the gated selector still behaves correctly with the gate on and off.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security issues. The change only selects which of the actor's own attached requests supplies the I/O channel factory for its outgoing calls, and it is behind an autogate.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md guidance is affected. The new autogate follows the documented pattern of adding a key to WORKERD_AUTOGATES.
📋 Code Quality: ✅ LGTM
This commit only adds the IO_CHANNELS_FROM_RUNNING_REQUEST key to WORKERD_AUTOGATES in src/workerd/util/autogate.h, using the documented format. The selector logic and its tests are unchanged and still correct:
- Gate on: the newest request that hasn't returned is chosen. If every request has returned, the newest request is used.
- Gate off: the behavior is the same as before this pull request.
⚡ Performance: ✅ LGTM
The added cost is negligible. The scan covers only the requests attached to the actor and stops at the first one that hasn't returned. With the gate off, it returns right away.
📝 Documentation: ✅ LGTM
The comments match what the code does.
Reviewed commit: d0be81eb — same changes as ae1500a1, so this is that commit's review (no new review was run; line numbers are as of ae1500a1)
An actor's
IoContexthands out theIoChannelFactoryof its newestIncomingRequest. A request that has returned stays the newest whilethe actor waits for background work, so it keeps governing the calls
that other, still-running requests make.
An embedder that stamps each outgoing call with its request's metadata,
such as a loop-depth TTL, then sees a callback's lower TTL carried into
a longer-lived request's later calls, round after round, until calls
fail with "Subrequest depth limit exceeded".
Under the new
IO_CHANNELS_FROM_RUNNING_REQUESTautogate,getIoChannelFactory()returns the factory of the newest request thathas not returned, or of the newest request if every request has
returned.
Limitations
running request, not the request that started it. Propagating the
request through async context would fix this fully.
Calls the actor makes while a callback is running, including just
after it replies, spend the callback's TTL. This recovers once the
callback ends, so it does not accumulate the way the original bug
does.
Testing
incoming-request-test: selector unit tests, gate on and off.the ratchet with the gate off (
15 14 13 12 11) and show a constantbudget with it on; 200/200 runs across all variants.