Repository navigation
fix(gateway): move managed update lease operations off the main thread - #200169
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 Summary: ✅ CompletedThis 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: 7b0c73371e
ℹ️ 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".
| try { | ||
| owner.launcherStartIdentity = child.pid | ||
| ? identityStore.processIdentity(child.pid, child.spawnargs).startIdentity | ||
| ? (await identityStore.processIdentity(child.pid, child.spawnargs)).startIdentity |
There was a problem hiding this comment.
Register readiness listeners before awaiting process identity
If the helper emits its readiness response while the worker is resolving its process identity, that response is lost: observeManagedServiceUpdateHandoffClose() has already attached a data listener, putting stdout into flowing mode, but waitForHandoffResponse() is not installed until after this await. Previously the synchronous identity lookup prevented stdout events from being dispatched in this interval. A fast helper or slow identity query can therefore leave an otherwise ready update waiting until the recovery timeout; an exit during the same interval also precedes registration of onExit. Install the readiness and exit observers before yielding to the worker.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesThis PR moves Gateway-side managed-update lease operations and helper staging into the existing handoff worker. Example: A managed Gateway update prepares its coordinator database and helper runtime.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this useful maintainer-authored PR open. The previous readiness race is repaired, and source review found no remaining actionable code defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway update requests enter the managed handoff owner, which coordinates lease custody and a detached updater; the serving parent now awaits worker results before lifecycle effects. flowchart TD
A[Gateway update request] --> B[Parent handoff lifecycle]
B --> C[Existing handoff worker]
C --> D[Coordinator lease database]
C --> E[Staged helper runtime]
B --> F[Detached update helper]
F --> D
F --> G[Updater and service restart]
Technical reviewBest possible solution: Keep lease decisions in the existing worker and lifecycle decisions in the parent, preserving the current helper and custody contracts. Do we have a high-confidence way to reproduce the issue? Fetched main performs synchronous lease and staging operations on the serving path, and the supplied baseline measurement observes those calls; no target code was executed during this read-only review. Is this the best way to solve the issue? Extending the existing worker is a coherent repair that retains the established lease authority, migrates asynchronous consumers, and addresses the introduced observer-ordering regression. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4a0e45492b89. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +312, Tests +325, Docs +7, Other +139. Total +783 across 34 files. Added test files: 3. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 HistoryReview history (1 earlier review cycle)
Reviewed November 16, 2026, 12:21 PM ET / 17:21 UTC (Revision 2). |
|
Addressed the one open item in 9514a09:
The real-process regressions hold a real worker identity reply while the actual staged helper emits READY or a child exits. Both timed out before the fix; both now settle correctly. Final focused proof is 26/26, affected type/lint/line-cap checks pass, and fresh Codex review is scoped-clean P0–P2. The same commit repairs the CI startup fixture at server-startup-readiness.test-support.ts:60: it now gates the actual async stat operation instead of the retired access call, keeping the same assertions. Both CI cases reproduce on exact main parent 2516bca; #200038 introduced that fixture mismatch. Both repaired cases pass. This attribution does not waive the new head's CI. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
openclaw#200169) * fix(gateway): move managed handoff lease metadata off main thread * fix(gateway): observe handoff readiness before worker identity waits
…aw#194058) Failed-update triage now captures the operator's environment before managed candidate admission, so a coding agent installed only on the operator's PATH is still offered when the Gateway service's PATH differs. Restores the operator-environment contract from openclaw#134490 and keeps the launch confirmation from openclaw#143139. Proof: shipped CLI on isolated Linux (Crabbox) with a running systemd Gateway: accept launches the operator-only agent, decline starts nothing, base 18bee8e reports no agent found; published 2026.11.1 upgrades to the fix with settings intact. Co-authored-by: TorstenW <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: steipete <[email protected]> (cherry picked from commit 7c702c3) Release adaptation: Capture invoking operator env before candidate admission, forward to interactive triage only; preserve latest target selectors, confirmation and lease cleanup ordering. Exact three authorized production paths plus real lifecycle regression. Follow-up dispositions: ad4863d fix: preserve the running installation when an agent updates its Gateway (openclaw#201570); dc73ec0 fix: let updates finish when another tool briefly reads OpenClaw's databases (openclaw#202541); d07b530 fix: clarify PostgreSQL schema upgrades for Git installs (openclaw#202098); e60ea9f test(update): add a Git release upgrade-survivor scenario (openclaw#201956); 2ef6f7b fix(update): build and serve Git releases outside node_modules (openclaw#201917); dbc1aa0 fix: keep the openclaw command and Gateway working after updating a pnpm install (openclaw#201735); f5e7641 fix: Git checkout updates across a schema change no longer end as post-update-failed after the new release starts (openclaw#201600); 2183caf fix: Git checkout updates no longer fail before the new release starts on a schema change or a busy database (openclaw#201463); 47e8649 fix: explain why Doctor cannot restore a scheduled job’s account (openclaw#201550); 8f2cfd4 fix: remove updater-only restrictions from agent maintenance guidance; cb5cfb2 fix: keep a doubtful killed-update recovery on the repair path (openclaw#201361); 24cb734 fix: keep carried-over scheduled jobs running after updates (openclaw#200653); d1276e1 feat(doctor): check OpenClaw ID member roles and honor an optional roles default (openclaw#197785); 0a39956 fix: finish updates when another tool reads OpenClaw's databases during the update (openclaw#201330); ea1c9d5 fix(update): settle remounted package publications before admission (openclaw#201336); 66b5212 fix(update): isolate malformed retained-install markers (openclaw#201199); 7e79c83 fix: let the next update finish a killed source checkout update (openclaw#201009); d905d8a fix: let the next update finish a killed update after the machine restarted (openclaw#200994); fdf0c95 fix: let the next update finish a killed update that had already installed the new version (openclaw#200866); 0c19bcd chore(release): close out 2026.11.5 on main (openclaw#200577); a1940e0 fix(matrix): keep explicit recovery available during deferred migration (openclaw#200805); 18b4776 improve: explain package baseline drift during updates (openclaw#200802); 1ad4cad fix(doctor): reclaim macOS updater runtimes blocked by non-updater processes (openclaw#200732); 427c857 fix: keep one missing archived transcript from blocking every update (openclaw#200733); 802e3f7 fix(update): keep valid cold archives from blocking updates (openclaw#200659); 23fca1a fix: let the next update continue after a killed update when nothing is left to repair (openclaw#200680); 3afe212 fix: let Doctor publish unchanged plugin migrations in any order (openclaw#200658); f65e4db fix(doctor): reclaim runtimes blocked by unrelated Linux processes (openclaw#200657); dab086c fix(update): let candidate Doctor read plugin dependencies from the staged package (openclaw#200595); 3447bee fix(update): keep updates going when the predecessor writes during its stop (openclaw#200569); 0ce9c77 fix: let the next update settle a package publication that a killed update left behind (openclaw#200550); ae31ea3 fix(update): repair handoffs in the journal-pinned lease store (openclaw#200532); 74020ea fix: continue updates when initial SQLite capture is stale (openclaw#200328); 6747b1e feat(update): run Git checkout installs from releases behind the release link (openclaw#199706); e3f8a67 fix(state): keep completed retained agent stores out of startup upgrade (openclaw#200284); 3c512c5 fix(gateway): move managed update lease operations off the main thread (openclaw#200169); ea69fcb chore(release): close out 2026.11.4 on main (openclaw#199956); 618bf31 fix(state): bound startup upgrade copies and pruning to owned state (openclaw#199929); e4a3093 perf(update): replace the candidate canary with a runtime contract check (openclaw#198268); 5dbf569 fix(update): plugin failures never fail an update or Gateway health; 764761e fix(update): refuse missing host prerequisites in one line and record a cause per attempt; 4c4fef4 fix(ui): update dialog claims installation before progress is confirmed (openclaw#199254); 136e1f6 fix(update): retrying an update from a dev checkout is refused after a killed update (openclaw#198673); 3bd03da fix(update): avoid duplicate database copies while the Gateway is stopped (openclaw#198148); 68a839b fix: isolate held agent databases until explicit restoration (openclaw#198180); e333f7e chore(ci): drop retired test-lines allocation records (3/3) (openclaw#197657); fd6fa47 fix: converge Gateway updates with environment-only service overrides (openclaw#196371); 7cf5e75 fix: clarify split-install updates and blocked Doctor repairs (openclaw#196342); 6ff8c86 fix(update): retain lazy sqlite catalog generation (openclaw#197095); 930e1f7 fix: keep stable updates and recovery free of premature migrations (openclaw#196474); a15f737 fix: preserve external plugin data during update rehearsal (openclaw#196301); 92798ae fix: updates survive interrupted heartbeat runs (openclaw#195656); c1e55e2 fix(update): restore LaunchAgent registration after repair contention (openclaw#195406); 715c610 fix(doctor): repair retained ISO session end timestamps (openclaw#194685); 689cfc8 fix(update): reclaim dead closing triage repair leases (openclaw#194503); 86bc89e fix(doctor): keep standing Codex parameter advice out of retirement blockers (openclaw#193650); 691bc8d fix(backup): read the backup engine without copying the live database (openclaw#194234); 000542f fix(backup): backups and updates fail on slow storage when a header probe batch misses its deadline (openclaw#194239); 31a65d5 fix(update): skip --no-lazy-fetch on Git versions without it (openclaw#194198); e45e99d fix(update): preserve dev update sources in tag-only Git clones (openclaw#193109) Validation: Baseline2 intended operator-agent failures/32 controls passed; candidate34/34passed (194058-green.log). Accept launches synthetic operator-only CLI with expected env, decline starts nothing. Isolated updater flow, not live systemd/upgrade qualification. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 6689fd575ada8fe40a9593784deac18ec73041cd) (cherry picked from commit 92e7a9fa223b0dc35801f25f70be90b472d9a6b7)
Related: #200136
What Problem This Solves
Fixes: preparing a managed Gateway update can block the event loop on lease-database and helper-file metadata operations before the helper starts.
User Impact
Gateway requests remain responsive during handoff preparation and lease operations. Process identity, cross-process single flight, Stop settlement, and legacy handoff validation stay enforced. Cold preparation now starts a worker and costs more CPU and elapsed time; the measurements below make that tradeoff explicit. No configuration, schema, dependency, or external protocol changes.
Why This Change Was Made
The Team 25c9790 incident on 2026-11-16 at 05:02 PST exposed a 1.97 s btrfs transaction wait in a main-thread catalog lock create, causing a 2,002 ms event-loop stall. #200136 removed that redundant catalog lock. This audit found another synchronous boundary inside managed update preparation.
The existing handoff-engine worker now owns coordinator admission, lease operations, process identity checks, and runtime staging. The serving parent keeps lifecycle decisions and awaits the worker's authoritative results. Captured Stop work retains that worker until cancellation and settlement finish. The lease remains necessary across the helper/executor boundary; synchronous helper and CLI contracts remain available off the serving path.
Runtime production delta is +312 lines: a typed async facade and worker commands replace main-thread lease operations, with settlement logic moved into the existing current-owner module. No new lease authority or cache is added. A separate ancestry-module extraction could reduce the worker's eager dependency graph; it is deferred to preserve the existing validation contract in this focused fix.
Evidence
The real pre-spawn guard fails on the exact parent 6670297 and passes after moving both lease admission and helper staging. Focused final proof includes the actual-entry guard, 26 Gateway refusal/diagnostic cases, and 23 single-flight cases; prior full affected lifecycle suites cover real parent/helper subprocesses, cancellation, and Stop. Codex autoreview is scoped-clean P0–P2.
pnpm check:changedcompleted; its one task-owned fixture lint error was repaired and targeted lint passed. The two unchanged dead exports reproduce on the exact parent and originate in 24385a2 / #200056.Five A/A controls and five A/B pairs used fresh Node 26.12.1 processes, a real compiled worker, a private 12 KiB coordinator, and a deliberately refused helper-spawn boundary. The surrounding synthetic fixture has a 35 GiB agent DB, 5,000 sessions, and 62,000 workspace files; this owner does not scan that unrelated content. No Team data or live service was used. Filesystem: APFS, not btrfs.
A/A owner medians were 54.58 / 53.79 ms; allocation controls varied 5.88–8.35 MB. All 20 processes completed and reached exactly one refused spawn. The serving path starts one lease worker; offline callers without an admitted database engine may also use the existing engine-inspection worker. These are byte-verified compiled Vitest-artifact measurements, not production-package startup measurements; package chunking/minification may change the cold cost. No warmup or cache hides it.
One earlier local lifecycle run failed because its helper outcome file was absent; its original helper log was removed by fixture cleanup. Focused, full affected, and exact-parent replays passed, which does not prove a fix or establish an inherited failure. The assertion now preserves the helper log on recurrence. This uncertainty remains explicit for exact-head CI. The first CI run 43907208459 exposed two stale startup-readiness fixture cases. Both fail on exact CI main parent 2516bca; #200038 / 5bd858c switched runtime viability from fs.access to a child probe and fs.stat without updating the fixture gate. The fixture now waits on fs.stat with the same assertions, and both cases pass. PostgreSQL conformance 3/3 was cancelled in that run; no inherited classification is claimed for that cancellation.
ClawSweeper also identified a task-caused observer-ordering race: helper stdout was already flowing while identity validation awaited the worker, so early readiness or exit could be missed. The parent now installs both observers before yielding and retains their results through identity validation. Two real-process regressions fail before the repair and pass afterward, covering actual staged-helper readiness and an early child exit during a held identity reply. Launcher validation lives beside the existing child-process controls; it preserves failed-spawn and kill behavior. The timing table covers the unchanged pre-spawn lease/staging region; this subsequent observer-ordering repair is proved separately.
Repair head
9514a09e8963bcf2067b3c18e9666a39a8c65695passed 26 final focused cases, affected type/lint/format and line-cap checks, with fresh Codex review clean P0–P2. Exact-head CI 43916191379 succeeded. The final-head ClawSweeper re-review has zero open items after the numbered response covering its original finding. Native preparation is complete; landing is pending.