Repository navigation
refactor(gateway): simplify queued cancellation bookkeeping - #177787
Conversation
Use the existing current-row event owner instead of the queued Stop display handshake, preserving cancellation, metadata and owned cleanup settlement. Remove the retired global inventory retry while retaining concrete-session predispatch recovery.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0ea16b706
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const publication = createQueuedCollectorPublication({ | ||
| context: params.context, | ||
| // The event owner prepares current row truth; cancellation retains its exact result. | ||
| emitSessionsChanged(params.context, { |
There was a problem hiding this comment.
Keep cancellation receipts inside the kill hold
For a queued collector, this call only schedules the ordinary asynchronous row publication and then returns from onSnapshot, allowing withSubagentKillScope to release the retained run/session before the event is prepared. If the same run/session is replaced or row preparation fails in that interval, Stop can report a successful cancellation while subscribers receive no killed receipt—or receive an abort event describing the replacement as queued. Cancellation receipts must be prepared and published synchronously while the kill hold and exact generation are still retained.
AGENTS.md reference: src/gateway/AGENTS.md:L50-L50
Useful? React with 👍 / 👎.
| throw sessionId === undefined | ||
| ? changed() | ||
| : new WorkerPlacementInventoryChangedError(changedMessage); |
There was a problem hiding this comment.
Preserve the typed error for inventory invalidation
When prepareMaintenancePlacements() captures an inventory-wide observation (sessionId === undefined) and any placement commits before inventory.assertCurrent(), this branch now throws a plain Error. The consumer in node-workspace-retain-coordinator.ts:408-415 retries stale preparation only for WorkerPlacementInventoryChangedError, so this normal invalidation is instead logged as a failed retention publication and no retain RPC is sent until some unrelated future reschedule. Keep inventory invalidation typed even though it no longer needs the affected-session set.
Useful? React with 👍 / 👎.
|
Reviewed both P2 suggestions against the exact head. The queued-Stop display timing is an explicit best-effort tradeoff in this cleanup campaign, not a lost cancellation result. The kill owner still retains the exact run/session, metadata FIFO, dispatch hold, cleanup settlement and synchronous early/final snapshot observations. The inventory-error suggestion follows a path that the current maintenance owner does not expose. |
|
Codex review: needs maintainer review before merge. What this changesThis PR routes queued Stop notifications through the existing session-event owner and removes an unreachable maintenance retry. Example: Stop cancels queued collector run collector-42 while session-row display preparation is blocked.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open as useful maintainer-approved cleanup; source inspection supports both declined review suggestions, and no actionable introduced defect was found. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway Stop requests enter the subagent cancellation owner, which retains exact run/session ownership and settles cleanup; a separate session-event owner prepares and broadcasts authorized roster updates. flowchart TD
A[Gateway Stop request] --> B[Subagent cancellation owner]
B --> C[Session writer and cleanup]
C --> D[Exact Stop result]
B --> E[Session event owner]
E --> F[Current recipient projection]
F --> G[Session subscribers]
Technical reviewBest possible solution: Use the existing cancellation owner for exact Stop outcomes and cleanup, and the existing event owner for best-effort current-row notifications. Do we have a high-confidence way to reproduce the issue? This is a refactor rather than an established release bug; source tracing confirms the display dependency and unreachable global retry, and no target code was executed. Is this the best way to solve the issue? The change uses existing owners, removes the replaced adapter and private protocol, preserves concrete-session recovery, and retains distinct cancellation and cleanup tests. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2ccb5e7b30d8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -176, Tests +54. Total -122 across 17 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 19, 2026, 6:41 PM ET / 22:41 UTC. |
|
Merged via squash.
|
The queued cancellation refactor in #177787 deliberately stopped waiting for display readiness. Pause the real cancellation preparation instead so the replacement-collector case still proves the typed leaf refusal and preserves successor runs, descendants, and transcript assertions.
…#177787) Use the existing current-row event owner instead of the queued Stop display handshake, preserving cancellation, metadata and owned cleanup settlement. Remove the retired global inventory retry while retaining concrete-session predispatch recovery.
The queued cancellation refactor in openclaw#177787 deliberately stopped waiting for display readiness. Pause the real cancellation preparation instead so the replacement-collector case still proves the typed leaf refusal and preserves successor runs, descendants, and transcript assertions.
…fecycle suites - session-recipient-authority.incognito-actor: upstream made incognito sessions memory-only actor owned (openclaw#170712) and deleted the old actor modules. The suite now creates and writes incognito sessions through the memory owner (acquireSessionActorStorage + commitMemory, bound with runWithSessionActorStorage) and keeps every invariant: capture through the collaboration path is refused with the dedicated-owner message; capture while the binding is active is refused (and never creates the native store); a native epoch for the key is not current; a narrowing visibility patch through the memory writer does not run afterPersistInTransaction and leaves authority non-current. Ownership is now decided by the incognito key, so the old "native capture before any actor exists" step has no equivalent: the suite seeds the epoch row directly and checks a durable control key is current while the incognito key is not. - session-history-budget-owner: `typescript/unstable/ast` became `typescript/ast` with the TypeScript update, as upstream imports it. - session-utils.queued-collector-rollback-custody: openclaw#177787 removed killSubagentRunAdmin / control.preparePublication and openclaw#175837 context.chatAbortControllers; the Stop is now held right after its committed kill write (spy on markSubagentRunTerminated), still inside the retirement publication the collector waits on. Assertions unchanged; the failure case fails the Stop after that write. - session-delivery-queue.storage-lifecycle: upstream openclaw#174696 removed suppressTextDelivery from SessionDeliveryAgentRunUpdate and deleted the same two lines from its own copy of this case; this fork split does the same. Proof on this tree (run-vitest, 3 shards): storage-lifecycle 7/7, incognito-actor 2/2, history-budget-owner 13/13, rollback-custody 2/2. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Queued-subagent Stop still carries a separate display-preparation handshake, and session lifecycle writes still carry a retry for a placement-inventory error that their maintenance owner no longer produces.
User Impact
Stop keeps its exact cancellation result, prevents an accepted queued child from launching, and still waits for real metadata writes and owned cleanup. Its session-list notification becomes an ordinary best-effort notification: it may coalesce with another update or arrive after the response, and a replacement session is presented as the current row rather than as the cancelled predecessor. A slow or failed display read no longer holds up or fails an otherwise successful Stop.
There is no config, schema, migration, retention, permission, protocol, or released SDK change. Concrete worker-placement invalidation still refuses stale effects and retains the existing one-time node-retention retry before dispatch. No deployment or live Gateway change is included.
Why This Change Was Made
Cancellation and display publication have different owners. The cancellation owner already retains the original session, joins its pending metadata through the write FIFO, captures the truthful outcome, prevents launch, and settles cleanup. The ordinary
sessions.changedowner already prepares current rows, applies recipient visibility/presentation, coalesces notices, falls back to a refresh notice on display-preparation failure, and joins admitted publications at shutdown. Stop should use that owner rather than export a nested asynchronous publication callback solely to prepare a roster frame.This deletes the 100-line queued-collector publication adapter and its private preparation type, captured display row/read view, published-run suppression, and active/consumed callback bookkeeping. An optional synchronous snapshot observer replaces the private callback handshake. Both early and final observations remain under
SubagentKillSession.withPublication; observers that return a value or Promise are still rejected. The public kill request/result and finalonResultcontracts are unchanged. Notices contain the authorized session key/agent andreason: "abort", deliberately omitting the captured predecessor session ID.The placement cleanup follows the existing ownership cutover rather than removing a live retry. Maintenance preservation now reads a baseline plus current committed/pending postimages and exposes
assertUsable, not the strict inventory observation assertion. Its old changed-session-ID collection, specialized global retry attribution, retry-onlydidCommitflag, and one-use lifecycle preparation closure therefore have no remaining maintenance consumer. Observations need only a boolean revocation fact. The lifecycle write awaits its existing prepared-write owner once and forwards the optional committed callback through all three existing worker/reclamation/native acknowledgment paths.Best-effort tradeoffs accepted
The specialized
WorkerPlacementInventoryChangedErrorclass and concrete-session diagnostic remain.prepareRuntimeRefreshstill supplies strict per-session observations, and the node workspace-retention coordinator still retries one invalidated preparation only whiledispatch.startedis false. Once a pruning command has been handed to transport, no retry is introduced. The global maintenance view cannot enter that strict error branch: its returned assertion isassertUsable. Pending postimages may add protection but cannot withdraw committed protection. Empty-recovery caching, cache bounds, workspace-result custody, native settlement, and archive/release behavior remain unchanged.Reset/delete tombstones, transcript events, generic event policy, model/provider readiness, and the excluded session-memory subsystem are not changed. This is not a general claim that lifecycle notices may replace exact mutation receipts.
Complete change scope and provenance
Against base
17c7c4ed05e5d6076a4252b2803212628a6ce246, the candidate changes 17 files: ten production files, including one deletion, and seven tests. Production is +240/-416 (176 net lines removed); tests are +183/-129 (54 net lines added); the entire diff is +423/-545 (122 net lines removed). These include formatting and the fixture repairs, not measured latency or allocation results.Production scope:
subagent-control-kill-scope.ts,subagent-control-kill.ts, andsubagent-control.types.ts: remove the private preparation protocol and retain synchronous early/final observation under the existing cancellation publication owner.chat-abort-runtime.tsand deletedchat-abort-queued-collector-publication.ts: keep the exact cancelled-task predicate and authorization conditions; use ordinary keyed session-change notices instead of preparing a predecessor display snapshot.placement-turn-authority.ts,placement-read-authority.ts, andplacement-turn-authority.types.ts: replace invalidating-ID sets with boolean observation invalidation, retaining pending/indeterminate/lifecycle and cache semantics; narrow strict authority reads to their actual concrete-session callers.placement-inventory-changed-error.ts: retain the live error class/message and remove only its unused session-ID payload.session-accessor.sqlite-projection.ts: remove the unreachable maintenance retry and retry-only callback wrapper; preserve prepared-write admission, preservation compatibility, all three acknowledgment paths, canonical repair, archive publication, and execution release. Most of this file's displayed diff is deindentation after removing the one-use wrapper.The seven changed tests are queued-collector admission, settlement, and ordinary behavior; subagent metadata publication, result publication, and refresh settlement; and node workspace retention. Added test setup holds real kill writes, cleanup, metadata refresh, or the ordinary display-preparation owner rather than the deleted callback. It preserves truthful settled/rejected/replaced outcomes, one response, no launch, no invented timing/lastRunId, successor preservation, display fallback, and final release. Existing node-retention retry and no-post-dispatch-retry assertions remain; only obsolete error-constructor payloads change.
Historical provenance:
assertUsable, superseding that global retry path. Those are campaign/regression observations, not a claim of independently established human production prevalence.37d210e4aaf3811c27d5d7191027cf9f0da08425, added the still-live concrete-session retention retry. That error class, diagnostic, single retry, and predispatch barrier are intentionally preserved. The older proposal to delete the entire error module is not used.Evidence
Focused evidence covers all 18 owner files: 187 passing owner cases, plus
the 14-case suppression audit (201 distinct passing cases across 19 files).
Execution was serial with isolated HOME/OpenClaw/XDG state and maxWorkers1.
The original coordinator-interrupted run completed 32 coordinator and 21
turn-authority cases before interruption; those two unchanged files are reused,
not represented as a successful interrupted overall run.
Current completed stages:
isolated wrapper. The file's 211.73 seconds includes 61.84 seconds cold worker
preparation and real native admission/cancellation/metadata composition.
exposed six authored fixture failures in two other files; it is not called green.
the 14-case audit; 177.78 seconds isolated wrapper. They retain cleanup rejection,
session replacement, exact results, no launch, and terminal-metadata qualification.
rollback, lost-reply acknowledgment, retained refresh and metadata settlement;
248.87 seconds isolated wrapper.
Complete changed-file typed lint passed; affected fixture lint was rerun after
repairs (41.53 seconds for two files, then 30.61 seconds after removing the early
flush). Final formatting passed for all 16 live changed TypeScript files.
No timeout, retry, skip, suppression, or kept assertion was weakened.
The fixture failures were diagnosed from actual output, not called inherited or
load-only. One fixture reserved a successor without activating it behind capacity,
then tried an active-only release during teardown; it now creates the real queued
state and withdraws before releasing capacity. Admission's no-any-event assertion
confused a legitimate urgent deletion notice with the held Stop notice; it now
positively requires deletion and narrowly checks the Stop notice. Settlement no
longer requires a notice or flush before cleanup, but keeps every no-premature
metadata/storage/result assertion and the final qualified event.
Independent complete-candidate review plus scoped fixture follow-ups is complete;
all actionable findings were resolved. The missed refresh callback and early
flush were accepted and repaired. Two reported concerns were declined after
source inspection: maintenance returns assertUsable while the concrete retention
retry remains specialized, and the event owner emits lastRunId both top-level
and nested, so existing top-level matchers are valid. Findings verdicts are not
relabeled clean.
All 184 original captured paths were reconciled: no current changed path was
uncaptured. Four residual differences are formatter-only; the other four are
the separately reviewed fixtures. The three current follow-up capsules (41,
68 and 72 complete inputs) were reverified after normal signed hooks. The
checkout is clean at signed head
c0ea16b706b6f23fcc4cbbe00ca75f6b3ed60a05.Exact committed import inspection covered all 17 changed files / 571 references.
Six added direct imports are shortcuts for existing literal baseline paths,
including the two production edges formerly routed through the deleted adapter.
Each old path was inspected; the shortcuts cannot merge previously distinct
dependency components. This is bounded delta/witness proof, not a fresh global
runtime-cycle count or a full local madge sweep.
No schema/config/protocol/dependency/released-SDK or Phase E change. Retired
adapter/type symbols have no remaining source/docs/config references.
Exact-head hosted CI is the broad gate; no fresh global cycle count, live provider,
deployment, or broad local-build success is claimed.