Repository navigation
fix(gateway): hold the chat root through terminal persistence - #126183
Merged
Merged
Conversation
startChatDispatch reserved the detached dispatch's root-work continuation after the ACK, and swallowed a failed reservation with ?? undefined. When the reservation did not land, the request's root was released before chat-send-dispatch-errors finalize() awaited persistGatewaySessionLifecycleEvent, so a concurrent restart drain saw zero active roots and completed while the session's terminal state was still being written. Reserve in admitChatSend instead, where the request root is provably live, and release it from the single cleanupAdmittedRun owner. Callers outside a Gateway request envelope hold no root, so their continuation is a no-op. The regression now starts a real waitForActiveGatewayRootWork() drain while persistence is blocked and asserts it cannot settle until the write is released, instead of asserting an absolute process-global counter.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
August 19, 2026 04:27
Contributor
Author
|
Merged via squash.
|
steipete
added a commit
that referenced
this pull request
Aug 19, 2026
The vi.mock of resolveGatewayModelSupportsImages in server.chat.gateway-server-chat.test.ts was added by #123847 as an isolation workaround while the gateway shard's chat failures were unexplained. The producers are fixed on main (#126183 for the root-work drain race; #126062/#125946/#126113 for detached completion binding), and the exact #126030 shard invocation is green with the mask removed (5/5 on 95ac5b2, 2/2 on this head), so the mask now only hides the real capability-resolution path from the suite.
steipete
added a commit
that referenced
this pull request
Aug 19, 2026
* test(gateway): drop the chat image-capability mask The vi.mock of resolveGatewayModelSupportsImages in server.chat.gateway-server-chat.test.ts was added by #123847 as an isolation workaround while the gateway shard's chat failures were unexplained. The producers are fixed on main (#126183 for the root-work drain race; #126062/#125946/#126113 for detached completion binding), and the exact #126030 shard invocation is green with the mask removed (5/5 on 95ac5b2, 2/2 on this head), so the mask now only hides the real capability-resolution path from the suite. * test(gateway): assert inline-image dispatch after mask removal ClawSweeper P2 on #126217: the two image sends only asserted RPC success and drain, so a silent false from the real capability resolver would offload the images and the suite would stay green without proving the discovered model's image capability. Capture the dispatch args and assert both runs deliver exactly one inline image. Teeth check: with the discovered model narrowed to text-only input, the assertion fails with images undefined (offloaded).
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 20, 2026
…aw#126183) startChatDispatch reserved the detached dispatch's root-work continuation after the ACK, and swallowed a failed reservation with ?? undefined. When the reservation did not land, the request's root was released before chat-send-dispatch-errors finalize() awaited persistGatewaySessionLifecycleEvent, so a concurrent restart drain saw zero active roots and completed while the session's terminal state was still being written. Reserve in admitChatSend instead, where the request root is provably live, and release it from the single cleanupAdmittedRun owner. Callers outside a Gateway request envelope hold no root, so their continuation is a no-op. The regression now starts a real waitForActiveGatewayRootWork() drain while persistence is blocked and asserts it cannot settle until the write is released, instead of asserting an absolute process-global counter.
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 20, 2026
* test(gateway): drop the chat image-capability mask The vi.mock of resolveGatewayModelSupportsImages in server.chat.gateway-server-chat.test.ts was added by openclaw#123847 as an isolation workaround while the gateway shard's chat failures were unexplained. The producers are fixed on main (openclaw#126183 for the root-work drain race; openclaw#126062/openclaw#125946/openclaw#126113 for detached completion binding), and the exact openclaw#126030 shard invocation is green with the mask removed (5/5 on 534f1cb, 2/2 on this head), so the mask now only hides the real capability-resolution path from the suite. * test(gateway): assert inline-image dispatch after mask removal ClawSweeper P2 on openclaw#126217: the two image sends only asserted RPC success and drain, so a silent false from the real capability resolver would offload the images and the suite would stay green without proving the discovered model's image capability. Capture the dispatch args and assert both runs deliver exactly one inline image. Teeth check: with the discovered model narrowed to text-only input, the assertion fails with images undefined (offloaded).
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.
What Problem This Solves
A Gateway chat run could lose its root-work admission before its terminal state was written, so a
restart preflight reported it was safe to restart while
persistGatewaySessionLifecycleEventwasstill in flight. The session's terminal state is then lost across the restart, with nothing logged.
The invariant is stated in
src/gateway/server-methods/chat-send-dispatch-errors.ts:finalize()upholds it by holding the root across the persistenceawait. But the root was onlyheld because of one line in
chat-send-agent-dispatch.ts, executed after the ACK:retainGatewayRootWorkAdmissionContinuation()returnsnullwhen the ALS root store is absent oralready retired, and
?? undefinedswallowed it. No continuation was registered, the initialadmission was released, and the root count reached 0 before persistence ran — silently.
This surfaced as a CI failure on an unrelated PR (#125958), job
checks-node-compact-small-3, shardagentic-control-plane-agent-chat-hosted-1, on three separate attempts:Why This Change Was Made
The reservation moves into
admitChatSend, immediately after the session work admission isregistered — the earliest point where the request's root is provably live, and before
onAdmissionOwned, attachment preparation, the ACK, andstartChatDispatch. The existingcleanupAdmittedRunclosure is the single release owner, and the early-abandonment paths release ittoo. The late setter and the silent
?? undefinedare deleted.Callers that enter
handleChatSendoutside a Gateway request envelope (internal chat entries such asskills and suggestion flows) hold no root at all, so their continuation is a no-op — there is no
request root to extend and no drain guarantee to preserve. This matters: an earlier iteration
threw when the reservation was unavailable, which broke 183 tests across those legitimate
callers. That is why the no-root case is a no-op rather than an error, and why the full
server-methodssuite is part of the evidence below.Rejected alternatives: keeping the late reservation (preserves the silent-null window); retaining
inside dispatch-error finalization (already too late if the inherited root was retired); relaxing the
assertion, retrying, or widening a timeout (masks silent terminal-state loss).
Known gap, stated plainly: the exact producer that retires the ALS root in the CI runs is not
proven. Source tracing found no normal chat caller that leaves the root scope, and
startChatDispatchis synchronous with noawaitbefore the old reservation. What is proven is theconsequence and its repair: forcing only the reservation to fail reproduces the CI signature exactly,
and reserving at admission removes the window regardless of which producer retires the root.
User Impact
A chat run whose dispatch fails now keeps the Gateway root until its terminal state is persisted, so
a restart preflight reports "not safe" until that write completes instead of waving the restart
through. No API, config, or protocol change.
Evidence
Mechanism confirmed before writing any fix. Replacing only the old retain with
setReleaseGatewayRootContinuation(undefined), changing nothing else, reproduced the CI failureverbatim:
AssertionError: expected +0 to be 1.Hypotheses tested and disproved, recorded so they are not re-tread: async release while
persistence is blocked (instrumented; count stayed 1 at t+0/25/225ms); a foreign
persistGatewaySessionLifecycleEventresolving the test's deferred early (instrumented the spy;exactly one call,
runId=idem-dispatch-error-1 phase=error rootCount=1, for both the single test andthe full file); leaked
restartDrainingfrom a sibling file (fails differently, atexpect(res.ok).toBe(true)); sibling gateway files leaking admission state (all reset; running themtogether passes).
The regression now asserts the operator-visible surface, not an internal counter. While
persistence is blocked it asserts
createSafeGatewayRestartPreflight(...)reports{ safe: false, counts: { rootRequests: 1 } }, then that it flips tosafe: trueonce the write isreleased. Proof it is load-bearing: with the reservation stubbed out the preflight reports
safe: truewhile the terminal state is still being written — i.e. the failure message now names theactual bug — and restored, it passes.
Suite results on current
main:src/gateway/server-methods— 3415 passed (186 files).src/gateway/server.chat.gateway-server-chat.test.ts— 55 passed.src/process/gateway-work-admission.test.ts— 18 passed.node scripts/run-tsgo-core-test-shards.mjs— 0 type errors.Branch-mode autoreview clean (
patch is correct). Production LOC+9/-11(net −2); tests+15/-2.Note:
waitForActiveGatewayRootWorkwas removed frommainby #126024 mid-work, so the test uses thecurrent
createSafeGatewayRestartPreflightsurface.