Repository navigation
refactor(gateway): share delivery and lifecycle handling - #167775
Conversation
Share repeated Gateway variant handling and lifecycle projections while preserving authority checks, error precedence, public wire/state shapes, and user-facing text. Consolidate chat delivery, session reset/read paths, credential selection, public conversation responses, approval projections, and paired lifecycle operations. Retain all existing assertions; adapt one internal startup fixture and shrink two assertion-ratchet entries. The full per-file deep pass covers the top-level Gateway production scope. Release-note context: internal refactor with no user-visible behavior change.
Keep model-account connection methods and their named Promise results in the existing SDK shape. Retain the original approval matcher and its short-circuit evaluation order, and keep shared terminal-field construction in a private module. The final candidate preserves behavior while removing 758 net production lines. Core types, focused lint, independent P0-P2 review, and wrapper-closure/suppression guards passed; full runtime and SDK comparison proof follows on the signed head.
Keep unrecognized FsSafeError codes on the existing generic fallback through an explicit default branch. Rename the private degradation filter parameter to avoid shadowing the owner-held state. Neither change alters public declarations or runtime outcomes. Focused lint and independent P0-P2 review passed.
Keep the captured heartbeat flag for the first buffered-text filter, but omit it from the paced publication callback as on main. This preserves the existing ownership lookup after a deferred transcript publication.
|
🦞👀 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: needs maintainer review before merge. What this changesThe Gateway, OpenClaw’s request and conversation server, shares repeated delivery, transcript-reading, credential-selection, and lifecycle handling while preserving existing behavior. Review scores
ProductKind: Refactor · Worth it: Yes Merge readiness✅ Ready for maintainer review This PR remains a useful, maintainer-directed cleanup with distinct work beyond current main. No concrete introduced correctness or security defect was established. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe Gateway receives HTTP requests, client commands, and agent events, then coordinates conversation delivery, stored transcripts, and runtime lifecycle operations. These changes consolidate its internal handling before responses and events reach clients. flowchart TD
A[HTTP requests and client commands] --> C[Existing admission and authorization]
B[Agent events] --> D[Shared Gateway handling]
C --> D
D --> E[Transcript and approval owners]
E --> F[Current ownership and publication checks]
D --> F
F --> G[Client responses and conversation events]
Technical reviewBest possible solution: Keep the shared implementations with their existing variant-specific checks, ordering, and public contracts. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR proposes a behavior-preserving refactor, not a reported user defect; this read-only review executed no target code. Is this the best way to solve the issue? Yes: the diff consolidates equivalent handling into small shared implementations while retaining distinct error precedence, authority checks, and lifecycle ownership. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0513aeae6a87. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -717, Tests +2, Other -1. Total -716 across 69 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 9, 2026, 6:57 AM ET / 10:57 UTC. |
|
Exact-head CI attribution for
The Workboard browser graph (81 repository files), conservative build-driver graph (174 files), committed manifest, relevant package declarations, and lockfile are unchanged from main to this PR's tested merge. None of the 69 lane paths occurs in either inspected graph. The peer PR also leaves these inputs unchanged. This is matching inherited-failure evidence, not a claim that the asset check passed. Main's earlier Workboard refactor changed six browser inputs without refreshing the committed manifest; regeneration belongs to that separate owner. Local proof on the exact PR head: complete changed check passed; production types and all 27 test type graphs passed; all three Knip scans returned zero findings; runtime and Madge cycles are zero; SDK comparison has no API changes; affected runtime proof passed 16 files / 420 tests; wrapper/source-closure/eager-bootstrap and lint-suppression proof passed 3 files / 23 tests. The broad local run's historical failures and reporting gaps remain documented in the PR. Independent review and the completed exact-head ClawSweeper review found no actionable issue. The security and dependency guards passed. The ClawSweeper review records test-driven proof rather than standalone installed-Gateway proof; no new authority behavior is claimed. This supplies the campaign-authorized inherited-failure exception for a squash merge pinned to the exact head above. The production reduction remains 717 lines under the documented 500–999-line coverage exception. |
…7775) Share repeated Gateway delivery, transcript, credential, approval, and lifecycle handling while preserving authority checks, error precedence, public wire/state contracts, and user-facing text. Remove 717 net production lines across 67 top-level Gateway files. Keep every existing test assertion; adapt one internal startup fixture and shrink two assertion-ratchet entries. The complete changed check, production and 27 test type graphs, Knip scans, zero-cycle checks, SDK API comparison, 420 affected runtime tests, and 23 wrapper/suppression tests passed on the reviewed head. Hosted selected test/lint/type/boundary lanes passed. The Workboard generated-manifest check and its downstream CI gate were admitted as an independently reproduced inherited failure; full attribution and historical local proof limits are recorded on the PR. No user-visible behavior change.
What Problem This Solves
This maintainer-directed cleanup reduces duplicate Gateway delivery and lifecycle code.
User Impact
No user-visible behavior changes. Features, configuration, protocol and persisted shapes, flags, and user-facing text remain unchanged.
Why This Change Was Made
Shared implementations now cover chat delivery and display projection, session reset and transcript reads, credential selection, public conversation responses, approval projections, and paired lifecycle operations. Variant-specific authority checks, error precedence, lazy loading, and cleanup ordering remain explicit.
The candidate removes 717 net production lines across 67 production files in the top-level Gateway scope. One existing test fixture follows grouped internal maintenance options; all assertions remain unchanged. Two assertion-ratchet entries shrink to reflect removed assertions. No new suppressions or budget changes.
The completed deep pass removes 0.36% of the 198,748-line production scope; the complete coverage log is below. Larger extraction prototypes were rejected when preserving their contracts left negligible or negative savings. The conflict-only rebase retained overlapping simplifications already on main; the 717-line figure counts only the remaining branch contribution and uses the campaign's 500–999-line exception.
Current candidate:
0b26c00bccd0be8b93d7245ea0afe84254484c68, based on9490c112abba4c22eabc5cc5b85120d2a5e3f6aa. The final conflict-only rebase preserves main's durable error publication, current-owner check and live startup registry callback alongside the shared delivery path.Evidence
0b26c00: all 16 affected files and 420 tests passed in 1,006.61 seconds, with zero skips or unhandled errors. Coverage includes persistence success/failure ordering, the real WebSocket terminal/history flow, stale dispatch ownership, startup registry adoption, paced chat, and the changed startup fixture.9490c112and0b26c00snapshots completed in 1,486.92 seconds with no entrypoint or export changes.node scripts/check-changed.mjspassed in 2,096.98 seconds. Runtime and Madge report zero cycles. The final wrapper inventory/source-closure, eager-bootstrap and lint-suppression batch passed all 23 tests across three files in 59.95 seconds. Hosted CI 37919932189 completed on this head. Every selected lane passed except the inherited Workboard generated-asset check; the CI gate reports that single downstream failure. The detailed attribution is below and in the pinned-head evidence comment.The full-directory selection executed across the recorded continuations, but there is no single-head green local directory result. Historical failures and unavailable final reporting for 127 original focused files remain documented below. No assertions, retries, skips, or timeout budgets were weakened. The unchanged startup fixture's before/after standalone wall times were 133.07s/133.38s on the original refactor revisions; the hosted changed-test matrix passed; per-file CI timing was not recovered, and no estimate is supplied.
Exact-head CI failure attribution
build-artifactsjob 113785696942 completedpnpm buildsuccessfully in 159.1 seconds, then failedplugins:assets:checksolely onextensions/workboard/openclaw.plugin.json. Unrelated PR #167662 reproduced the exact same failure on the same main parent at job 113785188584. The browser/build-driver inputs, committed manifest and dependencies are unchanged by this lane; none of its paths occurs in the inspected generation graphs.openclaw/ci-gatejob 113789070112 failed only because of that build-assets check. Its selected-lane accounting confirms all other selected lanes passed and every skipped lane was unselected. No cancelled or missing selected job is waived. The combined commit status mirrors that CI result; dependency and security-sensitive guards passed.The completed ClawSweeper review is bound to
0b26c00, lists no findings and no before-merge items, and explicitly retains the test-driven proof limitation. The campaign's inherited-failure exception is used without describing CI as fully green or changing the unrelated Workboard output.Earlier local proof and full-directory coverage
404a0a2, production types and all 27 test-type graphs passed, as did ratchets, formatting, boundaries, coercion and deprecated-API checks. Changed-core lint, script lint, native schema, database-first, media-download, sidecar-loader and webhook-order guards also passed. Runtime and Madge cycle checks both report zero cycles. Both pairing-auth guards passed.bindCliQuestionAnswerAuthority,prepareSessionEventTargetForHost,readSessionEntryCreationTransitionandRESTART_CONTINUATION_CONTEXT_PREFIX. These exact production findings also appear in main CI run 37889372602, job 113686778698 at53868c16088fd9cc86e84340178d8291c7a6f133. Their definitions, consumers and analyzer inputs were unchanged by this lane. Main subsequently repaired all four in3b3cd5939993f16017b6747cbcf80a83b49006ef, now included in the final base. All three final-head scans pass with zero entries; the earlier failed scans remain historical evidence.9490c112abba4c22eabc5cc5b85120d2a5e3f6aato0b26c00bccd0be8b93d7245ea0afe84254484c68completed in 1,486.92 seconds with no added/removed entrypoints or export changes. Both inputs were pinned detached worktrees, with the updated compiler/dependencies. The same result was previously observed on d574; this is a fresh final-head comparison.b3196dfand candidate4b1056b,pnpm test src/gateway/server-startup-early.test.ts --maxWorkers=1wall times were 133.07s and 133.38s, mostly transform/setup. The fixture is byte-identical from that candidate to 0b26 and passed again in the final affected suite. Assertions are unchanged; no performance improvement is claimed. The hosted changed-test matrix passed; per-file CI timing was not recovered, and no estimate is supplied.server.sessions.create.dispatch.test.ts. It finished with 26 passes and one failure in 595.19 seconds. The trace pins the first failure to thesessions.createresponse beforesessions.list; all title callbacks were consumed by their own cases. The earlier ten-failure cluster was not reproduced and its cause remains unresolved. Instrumentation was removed with exact-byte verification.The original full-directory process, on pre-rebase candidate
a2c27d8291c27c66fa2e1f983afb9566865d0ce6with Node 26.10.0, was interrupted without its final aggregate or result-cache write. Its log retained 21,039 passing, 35 failing and 20 existing skipped case observations across 1,620 files. Native scheduling joins every project group before advancing; source inspection plus complete per-group file observations establish that the earlier 1,598 selected files settled before Gateway-methods began. Their final file statuses, late teardown errors and overall outcome are unavailable, so this is execution coverage with a reporting gap, not a green directory run.The methods group had 420 unobserved files and 22 with uncertain completion. Its first native recovery on
f70eba292069e41420bf35cc0684316071be931a/ Node 26.5.0 was also interrupted, but the existing resource reporter retained terminal receipts for 71 files: 67 passed and four failed. There were 2,389 passing, five failing and one existing skipped case observations across 73 files; two case-seen files without terminal receipts remain unfinished. No final aggregate or detailed assertion stack survived. The 371 unfinished files are preserved as literal whole-file targets; completed files are not rerun merely to replace the lost aggregate.A subsequent continuation was stopped and joined through native SIGINT before any cases because a fresh merge check found a real conflict in
server-chat.ts. The second conflict-only rebase producedd574d52c55462c921d434cd2fa87c96e15c942e2onfd2fa6b904a2069bf9c2c150302475dffdc51e29. Main's new transcript-publication holds and disposal drain remain intact; its positional flush callback now adapts to the lane's existing delivery object. The other two lane commits are patch-identical. That continuation settled 31 files with passing native receipts before it was deliberately stopped and joined to preserve one more interaction with main's deferred publication: the first paced heartbeat filter uses captured metadata, while the deferred publication receives the same visibility-only metadata as main. That correction is signed in404a0a2.The final native continuation on
404a0a2/ Node 26.5.0 completed all 357 selected whole files: 354 passed and three existing opt-in benchmark files were skipped. It passed 3,129 cases with 16 existing skips and zero unhandled errors, exiting 0 after 7,532.72 seconds with clean source. The selection was the 352 unfinished files plus five affected chat files; native scheduling, reporters, case order and deadlines were unchanged. The exact union of all original 442 methods targets has no missing files across the recorded continuations: 435 passed, four retained historical failures and three existing skips. That mixed-head accounting does not erase the four failures or establish a single-head green directory result.All 148 original focused targets have execution evidence. Ten have completed passing receipts on 0b26; 11 have completed prior-head results (10 passed and one failed); the remaining 127 have earlier settled-group execution with unavailable final-file reporting. No focused target lacks execution evidence, but this is not a claim that all focused files passed. The original selection's remaining 30 infra files and E2E target already executed on f70. The rebase does not promote earlier proof into current-head execution or erase unresolved failures.
The old candidate is not main. Source, runtime, selection, caches and overlapping workloads differ, so these runs do not establish a load cause or inherited failure. Existing failures remain recorded even when a focused replay passes. No assertions, skips, retries, or timeout budgets were changed.
Investigated local failures and remaining uncertainty
The interrupted broad run retained 35 observed failing cases; its final aggregate and detailed assertion diffs were lost. The source-level attributions below retain the unknowns rather than inferring successful file status. Complete fixtures, relevant owners and the lane diff were inspected for each group. No safe task-caused repair has been established from these observations, and none is claimed as an inherited-CI waiver.
server.plugins-install-authority.test.tsserver-methods/chat.reset-visible-yield.test.tsgateway-concurrent-streams.test.tssession-row-projection.backfill.test.tsgateway-active-memory.test.tssession-row-projection.category.test.tssession-history-broadcast.worker.test.tsserver.config-patch.test.tsserver-kernel.test.tsserver-agent-database-startup.test.tsserver.sessions.create.lifecycle.test.tsserver-plugins.lifecycle.channels.test.tsserver.app-sdk-composed-resources.test.tsserver-close.model-acquisition.test.tsserver.chat-abort-sibling-fanout.test.tsserver.sessions-send.test.tsserver-plugins.activation-health.test.tsserver.agent-execution-shutdown.test.ts3d943a769258e45a48c5491d32bc9c759add8ed5). The original pending response remains unlocalized; no current-head passing result or causal fix is claimed from source alone.server-plugins.lifecycle.readers.test.tsserver.sessions.inbound-worktree-writer.test.tstalk/handlers/client-native-control.test.tsserver-methods/models-auth-login.catalog.integration.test.tsserver-methods/models-auth-refresh.catalog.integration.test.tsThe separate f70 45-file run failed ten cases in
server.sessions.create.dispatch.test.tsand three ingateway.test.ts. Creation dispatch first had three RPC response deadlines followed by title-case deadlines. An unconsumed one-shot callback can survive between cases, but the instrumented whole-file replay did not reproduce cross-case consumption; only the first repository creation response timed out again. Gateway E2E had a 120-second first-case deadline, then metadata-admission refusal, then a logging-reload poll that saw no debug level. The fixture permits timed-out bodies to outlive shared reset, making interference plausible but unproven. Auth/pairing assertions were not reported failing. The whole-file diagnostic passed all 13 cases, including those three, without changing assertions or deadlines. Its first startup consumed 56.985 seconds, health 2.767 seconds and close 0.213 seconds; the original timeout phase remains unknown.The interrupted f70 methods resume also observed a failure in
server-methods/update.test.ts, in the transferred internal activating-notice case. The condensed boolean error favors the five-second callback-completion poll, but the unavailable final stack prevents excluding the shared response-schema assertion or claiming acknowledgement/activation completed. The notice callback sets its flag only after checking transcript content and the completed ledger step; its exception reason is swallowed and the fixture deletes the helper log. The internal path bypasses the mocked outbound notice module and generated-media delivery changed by this lane. The same test passed on the older candidate in 9.088 seconds and failed in this run in 56.448 seconds, but head/runtime/workload differences prevent causal attribution. No safe lane-caused repair has been established.The same f70 resume observed two failures in
server-methods/session-catalog-privacy.test.ts: a 120-second deadline in remote-publication/mixed-adoption coverage, then a missing-profile error in the next resident-delivery case. The first pending phase is unlocalized. The fixture freezes its internal timers and does not pass the test cancellation signal into its asynchronous work, so a timed-out body can outlive teardown and later restore global registry/timer/environment/config state. The second error may come from ambient-store role lookup or a retained catalog; neither a deleted row nor a causal cascade is established. Later audience cases passed. The fixture and direct list/visibility/lifetime/profile owners are unchanged in the lane; no safe task-caused repair was established.The resume also timed out in
sessions-reset-subagent-cleanup.test.ts'scollector cleanup retry: unchangedvariant. Despite the filename, that variant does not call the refactored reset body: it retries real session deletion after a simulated first transport failure, then reads the retained collector result. The pending phase remains unlocalized between the retry/deletion work and the signal-less collector wait. All three subsequent reset variants passed. The synchronous reset error-helper consolidation preserves guard order and error shapes; no direct task-caused defect was identified.The f70 methods resume also timed out in
session-catalog-import.integration.test.tsduring the ordinary import/re-import case. The deliberately stalled model loader is installed only after projection startup, and ordinary import supplies no model/catalog loader to session creation; no direct wait on that loader was found. The pending phase, assertion progress and first-case cancellation/join remain unproven. Managed file teardown reached retirement and the eleven later cases passed, which does not prove the original timed-out promise settled. The relevant fixture/import/create/history owners are unchanged; no safe task-caused repair or inherited-failure attribution was established.The earlier visible-yield investigation kept the 90-second deadline. The same corrected candidate
1ef71c2c0a76514d6d2768e8b521ae73c8d8577ftimed out in the original checkout but passed the first case in a clean control in 69.4 seconds. The original base passed there in 54.4 seconds and then-current main9932db4167dc65d8e12f7b503effd4506b3c6d1fin 72.0 seconds, all on Node 26.5.0. A Node 26.10.0 main attempt timed out and is excluded from that matched-runtime comparison. No source or timeout change fixed the original failure. The later full-suite trace reached a provider at 87.4 seconds and yielded at 89.62 seconds; startup delay and cleanup completion remain unisolated.The d574 wrapper/source/suppression batch completed with 22 passed cases and one failed lease-bootstrap case in
test/scripts/eager-import-closure.test.ts. The child returnedstatus: null; its signal, error code and stdout were not recorded. A 30-second child deadline exists, but the observed result does not prove timeout termination or identify the last completed child step. The extracted child source graph has zero overlap with the lane's changed files; static inventory, source closure and suppression checks passed. Earlier whole-file passing proof does not explain this termination or establish a fix. The final whole-file batch on 0b26 passed all 23 cases across three files; this bootstrap case passed in 7.749 seconds with the original deadline and assertions. That later pass does not explain the original termination or establish a causal fix.Complete file-by-file production coverage log
All 890 baseline production modules (198,748 physical lines) were read end to end. Six test-support files totaling 1,814 lines were excluded from production. Three new internal shared modules are listed with a zero baseline. Net removed is measured against rebased main
9490c112abba4c22eabc5cc5b85120d2a5e3f6aaat candidate0b26c00bccd0be8b93d7245ea0afe84254484c68and includes additions; zero means no remaining lane diff. Baseline LOC retains the original source-reading census atb3196dfda33555857eae9cd52ea29367a91bd9ea. Tests, fixtures/support, generated files, declarations, and the shrink-only ratchet maintenance are excluded from the production reduction.The deeper pass also implemented and rejected candidates that added indirection without meaningful reduction or conflated distinct authority, custody, failure, and platform contracts. Tests were retained as the behavioral specification.