Repository navigation
fix(gateway): session lifecycle plugin hooks skip deferred cleanup after the request closes - #148089
Conversation
|
🦞👀 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. Reviewed October 1, 2026, 11:11 PM ET / October 2, 2026, 03:11 UTC (Revision 9). ClawSweeper reviewWhat this changesThe branch lets deferred session-start and session-end plugin work finish after requester closure, strengthens lifecycle regressions, and repairs shared test fixtures. Merge readiness✅ Ready for maintainer review The repair remains necessary on current main. The latest integration resolves the prior conflict blocker, preserves reviewed behavior, and introduces no actionable correctness or security finding. Priority: P2 Review scores
Verification
How this fits togetherGateway session operations and reply initialization emit lifecycle events to plugins. The work-admission owner tracks those callbacks so deferred effects can complete while shutdown accounts for outstanding work. flowchart TD
A[Gateway session operation] --> C[Session lifecycle emitter]
B[Reply initialization] --> C
C --> D[Existing admission checks]
D --> E[Detached work scope]
E --> F[Plugin callback and deferred effects]
F --> G[Release Gateway drain reservation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +9, Tests +162. Total +171 across 15 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing detached-work owner consistently for deferred lifecycle callbacks while preserving bounded transcript access and Gateway drain accounting. Do we have a high-confidence way to reproduce the issue? Yes. Hold a lifecycle callback, close its originating request scope, then release it into tracked work; current main retains the closed scope, and the captured paired proof records the failure. Is this the best way to solve the issue? Yes. Reusing the existing detached continuation repairs the lifetime mismatch without introducing another admission owner or changing public contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against acfd767f1502. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
…request scope closes
d1ea42c to
46f5d3b
Compare
|
Published repair: Refreshed the patch for the current Gateway hook owner and covered the same closed-request bug in reply rollover end/start hooks. Fresh before/after production-owner proof reproduces missing deferred effects and 141 focused tests passed, followed by 26 affected tests after the final owner extraction. Core/test types, lint, formatting, and file-size ratchets passed. Full canonical changed checks also passed, including all 28 core test graphs. Fresh canonical autoreview over the complete five-file candidate passed at its default P0 threshold with no findings. Exact-head hosted CI and native landing gates remain to be completed. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Apply the existing upstream readiness synchronization from dd2a7ba (openclaw#162869). Preserve the expected enabled state and existing deadline.
|
Current head: The shared effort-picker failure is covered by the existing upstream repair in PR 162869, merged as The adopted upstream hunk waits for the same Proof: the upstream hosted real-Gateway job explicitly passed this scenario in 9.74s after the correction (14.75s including fixture). The byte-identical hunk also passed both routes locally against freshly built PR 148089 head The local run used the supported serial config because the prebuilt CI config requires a clean committed tree; no freshness gate was bypassed. The original local head also passed, so that replay alone was not used to claim a fix. Original failing CI logs and merge identities were retained. Exact-head CI for each adopted PR remains separate from this upstream/local proof. Measured test cost from the retained final 26-test extraction run: Available hosted timing: CI run 36926894979 on head The separate OAuth reply-entry CI failure was replayed with freshly built exact source: all9 cases passed unmodified. Fresh hosted CI remains required; that local replay alone is not called a repair. |
|
Final candidate: CI integration repair: the main reply-path thinking change ( The repair exposes the existing owner’s Before/after validation: the published head passed all nine cases; adding the exact CI cleanup helper still passed all nine. Adding the exact CI reply-thinking modules reproduced the hosted result (six failed, three passed) in the original case order. A focused catch/rethrow diagnostic captured the exact missing-export exception and call chain. The corrected original-order run passed all nine cases (188.478 seconds, exit 0). Exact CI production/helper source hashes match the failed run. Every source overlay was restored and all runners joined. Scope: sanitized macOS Node 24.19 run through the canonical Vitest wrapper; existing provider-attempt fakes with real reply dispatch/state owners. This is a source-overlay reproduction of the CI integration difference, not a full Linux checkout rerun or a live provider login. Exact candidate hosted CI remains required. Fresh bounded Codex autoreview (P0) is scoped-clean with no findings for the two-line helper repair. Original PR production review remains separate. |
Keep metadata-only mock factories independent of the prepared runtime owner to avoid re-entering the pending current-plugin-metadata-snapshot mock. Move the unchanged fixture and migrate all callers without a re-export.
Integrate the SDK retirement facts already present in CI merge 5195ee48 to preserve the unchanged compatibility support patch. The resulting tree is byte-identical to that tested CI tree plus the reviewed fixture move.
(cherry picked from commit 144f278)
|
Final local repair and integration proof for The original lifecycle repair remains unchanged: Gateway/reply session hooks use the existing detached work owner so deferred effects survive requester closure while Gateway roots drain on completion or failure. Retained paired proof uses real emitters, the global hook runner, disk-loaded callbacks, real scope ownership, and file effects. The closed-request baseline loses those effects; the candidate completes them and drains roots 1 → 0. Original coverage was 141 cases across ten files, with 26 final affected cases rerun. This initializes the typed registry directly and does not claim public plugin loading or deployed provider/channel transport. The remaining CI blocker was a test import cycle, not an OAuth product failure. The earlier real-comparator mock repair in Final source/lock qualification passed the original nine OAuth cases plus 177 cases across all seven fixture-caller files. OAuth with normal runtime preparation took 622.087 seconds; the caller shards took 53.890 seconds. The initial paired graph used matched donor dependencies; the final 186 used the exact CI lock and private physical dependencies after canonical preparation rejected external compiler symlinks. No guard was bypassed. The normal merge with pinned main node scripts/check-changed.mjs \
--base 8f9b234c21c6bd208efab57cfc8746c492978bfa \
--head e5bd0d4b72ea1fcbdfc911a7b06263b4e1e965d9Result: exit 0, 421.598 seconds, all selected stages for 20 changed paths, no skip flags, clean Git status. Log SHA256: Fixture extraction: production 0, test/support +56/-55. Final delta against pinned main: hook production +19/-10; shared compatibility metadata +22/-14; tests/support +274/-77; docs +8/-3. The body retains the original before/after table, measured lifecycle test costs, proof limits, source continuity, and ClawSweeper timing response. Checkpoint ancestry: @clawsweeper re-review The six support files already match landed PR #163127 byte-for-byte. Their historical three-dot diff can remain visible because that support was independently squashed; integration adds no new compatibility content. |
|
🦞👀 Re-review progress:
|
|
Final fixture repair for The latest fixture repair is commit Hosted CI 36953180176 on the published parent failed two exact receipt arrays: same-model retries were still expected to have switched routes. The actual CI source is Paired proof uses the original full 27-case order on the exact CI source and frozen lock ( Measured one-worker cost: baseline Vitest 27.82s, repaired Vitest 21.64s; full commands 436.963s / 423.570s, including canonical runtime preparation. The corrected command requested fresh runtime preparation after creation of its isolated Git validation identity; no cache/freshness guard was bypassed. The upstream nine controls took 26.582s command wall; receipt-owner controls 13.150s. Historical Linux CI reports 17.16s Vitest / 28.34s wrapper for the failing file. This patch adds no test case or new CI work; these measurements are not a performance-savings claim. The canonical changed gate for the single additional file passed exit 0 in 128.260s, including the selected agents-root core-test type graph, scoped typed lint, formatting and all normal guards. The retained earlier full 20-path gate remains a separate 421.598s pass. Fresh canonical Codex Tests/checks used macOS Node 24.19.0, matching the failing CI Node version; frozen dependency installation used Node 24.21.0 and pnpm 12.5.1, with package/workspace/lock inputs unchanged. Task HOME/TMP/store were isolated and secretless. The final branch child preserves the parent's older dependency state; local paired proof intentionally pins the actual CI merge composition and its different lock. This is host receipt/policy proof with the existing synthetic provider attempt seams, not live external provider or Codex API evidence. No external contract changed. The body preserves original hook before/after observations, previous 186-case fixture proof and 421.598s full gate, exact source continuity, limitations, supporting merged PRs, test cost, and contributor credit. This mechanical fixture correction does not modify those production owners. Fresh exact-head hosted CI and native landing qualification remain separate. |
Preserve the qualified lifecycle and fixture repairs while retaining the already-landed compatibility inventory corrections from main.
|
Integration qualification for Candidate All 15 feature paths preserve their qualified content: 14 are byte-identical to the exact CI projection used for the latest receipt proof, including auto-merged Fresh exact-717 integration checks: 71/71 existing cases across three isolated-completion consumer files, two canonical one-worker shards, 30.192s command wall (19.97s and 7.39s Vitest). The selected agents-root type graph passed in 5.253s; formatting of both composed files and diff whitespace passed. Package/workspace/lock and test/check entry points match the prior exact-CI proof; frozen installation took 8.444s and did not change those inputs. Runtime/check Node is 24.19.0; install Node was 24.21.0. All processes joined; raw tracked-source and task-process audits are clean. The retained original-order receipt proof remains 2 failed/25 passed before →27/27 after, with nine selected upstream controls and four receipt-authority controls (40 distinct cases; 125 unrelated sibling cases intentionally unselected). The 128.260s one-file gate and scoped-clean canonical autoreview remain attached to that exact repair. Earlier 186-case fixture and 421.598s full-gate proof remain historical evidence. The original 141-case lifecycle run is also historical: main #163169 rewrote an automatic-reset sibling test from three cases into one combined scenario, so no unchanged-byte/current-rerun claim is made for that file. Latest full ClawSweeper revision 8 on 1add (2026-10-02T02:57:01.840Z) found no code/security defect and retained sufficient proof. Its two merge blockers and rank-up move are addressed by the exact-main conflict resolution, preserved fallback provenance, and bounded integration checks above. Fresh hosted CI and native landing on Detailed prior receipt proof and lifecycle/fixture proof retain their original source identities and limits. No aggregate of historical overlapping test counts is claimed. |
|
Merged via squash.
|
…ter the request closes (openclaw#148089) * fix(gateway): let session lifecycle hooks finish deferred work after request scope closes * test(ui): await effort picker readiness Apply the existing upstream readiness synchronization from 9ba56c1 (openclaw#162869). Preserve the expected enabled state and existing deadline. * test: expose prepared runtime config comparison in E2E mocks * test(agents): decouple empty metadata fixture from runner mocks Keep metadata-only mock factories independent of the prepared runtime owner to avoid re-entering the pending current-plugin-metadata-snapshot mock. Move the unchanged fixture and migrate all callers without a re-export. * fix(plugins): queue compatibility removals pending reader migration (cherry picked from commit 144f278) * test(agents): distinguish same-model retries from fallback receipts --------- Co-authored-by: Vincent Koc <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]>
…nd keyed agent roster changes (#163623) * fix(test): align reply-entry fallback E2E with concise error copy The reply-entry fallback E2E still expected the pre-#163381 rate-limit and auth-failure copy, so its two OpenAI cases fail on main. Hourly main CI skips src E2E files, so the break stayed invisible there. Assert the new pinned rate-limit copy and the exported auth copy constant. The anthropic-attempt count still catches the original fallbackConfigured defect, which surfaced as "temporarily rate-limited" after a fallback attempt. The non-OpenAI failures reported on 2026-10-01 were a separate, already-fixed fixture gap: #161103 added reply-path thinking-catalog hydration that calls preparedModelRuntimeConfigsMatch through the prepared-model-runtime module, and the shared E2E mock lacked that export until #148089. No product change. * fix(test): migrate Gateway E2E fixtures to keyed agent rosters #162612 made ordinary config reads reject a populated agents.list, but the dreaming restart-cleanup and WhatsApp login-authority E2E fixtures still wrote legacy rosters to disk. Both Gateways now refuse to start (code 78 or InvalidConfigError) before any assertion runs, which fails Gateway E2E shard 1/4 on main. Hourly main CI does not run these files. Write the canonical shapes Doctor produces: a sole keyed main entry for the WhatsApp fixture, and explicit ownership with main as the system agent for the two-agent dreaming fixture. Assertions are unchanged.
…nd keyed agent roster changes (openclaw#163623) * fix(test): align reply-entry fallback E2E with concise error copy The reply-entry fallback E2E still expected the pre-openclaw#163381 rate-limit and auth-failure copy, so its two OpenAI cases fail on main. Hourly main CI skips src E2E files, so the break stayed invisible there. Assert the new pinned rate-limit copy and the exported auth copy constant. The anthropic-attempt count still catches the original fallbackConfigured defect, which surfaced as "temporarily rate-limited" after a fallback attempt. The non-OpenAI failures reported on 2026-10-01 were a separate, already-fixed fixture gap: openclaw#161103 added reply-path thinking-catalog hydration that calls preparedModelRuntimeConfigsMatch through the prepared-model-runtime module, and the shared E2E mock lacked that export until openclaw#148089. No product change. * fix(test): migrate Gateway E2E fixtures to keyed agent rosters openclaw#162612 made ordinary config reads reject a populated agents.list, but the dreaming restart-cleanup and WhatsApp login-authority E2E fixtures still wrote legacy rosters to disk. Both Gateways now refuse to start (code 78 or InvalidConfigError) before any assertion runs, which fails Gateway E2E shard 1/4 on main. Hourly main CI does not run these files. Write the canonical shapes Doctor produces: a sole keyed main entry for the WhatsApp fixture, and explicit ownership with main as the system agent for the two-agent dreaming fixture. Assertions are unchanged.
Related: #146349, already addressed by #146350; no new closing claim.
What Problem This Solves
Deferred plugin
session_endandsession_startwork can fail after the request that reset, deleted, or rolled over the session closes. The callback retains a Gateway reservation but inherits a closed async work scope, so tracked cleanup never completes.User Impact
Deferred lifecycle work, such as a plugin memory flush, can finish after requester closure. Gateway shutdown continues to account for it and releases the reservation on completion or failure. Hook payloads, invocation permissions, configuration, public SDK contracts and persisted data do not change.
Why This Change Was Made
Use the existing detached continuation at all four Gateway/reply lifecycle emitters. It creates a fresh async work scope while preserving the existing admission fences and drain ownership. Reply start/end dispatch now lives together in the session-hook owner; browser cleanup and directly awaited shutdown keep their distinct lifetime contracts.
The test support exposes the existing prepared-config comparator and moves the pure empty metadata factory to type-only support, removing an import cycle across all eight consumers. Two receipt expectations now follow the already-landed routing owner: same-model retries remain ordinary selections, while real fallback preserves its recorded stage and reason. Counts, targets, skipped-candidate absence, test order and timeouts remain intact.
Evidence
The retained before/after probe uses real lifecycle emitters, production hook dispatch, disk-loaded callbacks, async scopes and file effects, with the request fully closed before releasing the callback:
The real reply initialization/SQLite regression also covers start and end together. Registry initialization is direct: this proves the lifecycle owner boundary, not public plugin loading or deployed provider/channel transport. Retained lifecycle and fixture evidence.
The paired receipt proof reproduces the exact CI failure in original 27-case order: 2 failed/25 passed →27/27 passed. Nine selected fallback controls and four receipt-authority controls also pass (40 distinct cases; 125 unrelated sibling cases intentionally unselected). Vitest times are 27.82s before and 21.64s after; build-inclusive commands are 436.963s and 423.570s. The scoped canonical gate passed in 128.260s and fresh canonical autoreview found no findings. These are cost observations, not a speedup claim.
Final Integration and Validation
Final candidate:
71799815480d3d13454c270c0d5b27214df0d02b. The merge preserves current main's compatibility inventory in all six former support files; none remains in the final diff. Both compatibility conflicts are resolved without restoring retired entries or changing deadlines. Current-main fallback provenance remains unchanged.On this exact integration, 71/71 existing isolated-completion consumer cases passed in 30.192s wall; the selected agents-root type graph, composed-file formatting, whitespace, runtime AST equivalence and source/process audits passed. The 15 feature paths match the previously qualified CI projection, apart from a runtime-identical mock type annotation. Package/workspace/lock inputs match that local proof; this is not a claim about subsequent main dependency updates. All invoked processes joined.
Earlier 186-case fixture proof and the 421.598s full gate remain linked historical evidence. The original 141-case lifecycle suite is not claimed to be an unchanged current rerun: main refactored one automatic-reset sibling test. Fresh exact-head hosted CI and the required aggregate gate passed. CI checked merge
1b60abc3562f01bdb8bdb0d698b32a747f090774on main81f65e98ad4ec5270c864d641950eb2067f84802, preserving all 15 PR paths. That newer main uses dotenv18.0.3; the retained local proof uses18.0.1. Source/dependency continuity through native baseline7fc0cfb379f4ba6f3eefd75a1e342f56dc859415was reviewed separately. Native prepare/merge are the final operations.ClawSweeper revision 9 reviews this exact head, reports no code/security finding and sufficient behavior proof, and explicitly resolves the prior integration blocker. Before merge: None; no current rank-up moves.
Scope and Review Notes
Final 15-file delta: production +19/-10 (net +9); tests/support +241/-79; docs 0. Production growth consolidates reply-start dispatch into the existing lifecycle owner and documents its non-obvious lifetime invariant while shrinking the oversized initializer. No new config, schema, protocol, dependency, fallback or persistence behavior.
The distinct
before_resetfire-and-forget lifetime remains a named follow-up audit because its precommit contract differs; no additional failure is claimed here. Original contributor: @xialonglee. Preserve existing assignee @fuller-stack-dev.