Skip to content

test(gateway): consolidate run-loop.test.ts - #166012

Merged
steipete merged 2 commits into
mainfrom
steipete/deslop-restart-t-run-loop-20261006
Oct 6, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/deslop-restart-t-run-loop-20261006

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Consolidates repeated foreground Gateway lifecycle test setup and equivalent scenario structure in run-loop.test.ts and its exclusive support files.

User Impact

No user-visible behavior or production changes. All 167 expanded test cases remain, including issue-number regressions, startup/stop ownership races, real file-log persistence, and seven real SQLite/package/helper-process integration rows.

Why This Change Was Made

Merge queued-startup success/failure, update upgrades at close/lock release, native refusal/uncertainty, and external signal authorization into input tables. Exclusive support files consolidate EOF, cleanup deadlines, replacement during boot, captured Stop retries, and failed supervisor handoffs. Small local factories own repeated setup; existing deferred helpers replace handwritten promise bookkeeping. Remove redundant log/call assertions only where the same test still proves the effect.

The baseline already includes #165980's consolidation. This uses the requested target escape hatch: the main file shrinks 10.27%, and the file plus all exclusive supports shrinks 8.26%, below the 35% target. No meaningful case was deleted to reach a quota.

File (src/cli/gateway-cli/) Before After Net
run-loop.test.ts 1,976 1,773 -203
run-loop-request.test-support.ts 566 513 -53
run-loop-force.test-support.ts 264 263 -1
run-loop-shutdown-budget.test-support.ts 242 217 -25
run-loop-shutdown-completion.test-support.ts 654 563 -91
run-loop-stop.test-support.ts 649 558 -91
run-loop-update-respawn.test-support.ts 489 439 -50
run-loop-package-lifecycle.test-support.ts 647 642 -5
run-loop-package-helper.test-support.ts 352 351 -1
Unchanged exclusive external-handoff/hosted-stop/startup supports 459 459 0
Total 6,298 5,778 -520

Production LOC delta: 0, required by this test-only lane. Shared run-loop.test-support.ts and run-loop-mocks.test-support.ts remain unchanged because other test files import them. Two pre-existing unused-export findings are documented below; their production owners remain outside this lane.

Merged cases and remaining proof
Previous test(s) Remaining test/row
queues SIGUSR2 received before the run-loop installs its restart waiter; processes queued SIGUSR2 when restart startup fails before returning a server processes SIGUSR2 queued before startup returns a server (startup fails: %s), false/true. Exact start/reset/lock counts and failure input retained.
reopens a fresh generation only after a definitive native stop refusal; reports uncertain native stop without clean-stop success or in-process recovery recovers only after a definitive native stop refusal ($outcome), refused/uncertain. Disposal join, original detail strings, exit codes, replacement count and retired-host rejection retained.
clears stale restart state before routing external SIGUSR2 through the scheduler; clears the in-flight restart token when an unauthorized SIGUSR2 is ignored clears the SIGUSR2 token before applying external restart policy (allowed: %s), true/false. Scheduling order, no-close/no-restart, real admission state and exact deny warnings retained.
upgrades an accepted restart when an update arrives during shutdown; reads an update upgrade after asynchronous lock release upgrades an accepted restart when an update arrives during %s, close/lock release. Original platform/process-ownership inputs retained; both now assert exact persisted update handoff.
does not start a replaced runtime after awaited beginBoot does not resume a replaced runtime during $phase (pending Stop: $pendingStop), beginBoot/false. Original error input and assertions retained.
joins graceful shutdown on host EOF without consuming restart intent; stops a closing restart when the host lifeline closes joins host EOF shutdown (closing restart=%s), false/true. Real stream EOF, close join and no successor retained.
reports failure when foreground provider service cleanup times out after server close; preserves a recorded close failure when launchd final cleanup crosses the deadline reports $supervisor cleanup timeout after server close (close failed=$closeFails), foreground/false and launchd/true. Exact timing and failure diagnostic retained.
retains the restart deadline when a managed update arrives after final cleanup fails; retains $signal deadlines when $failure throws after server close retains $signal deadlines after $failure throws (managed update=$managedUpdate), all three original rows. Exact thrown error types, update owner, cancellation, deadline and watchdog behavior retained.
retains pending foreground completion until Stop retries the captured settlement; retries the captured foreground Stop operation after %s settlement retries the captured foreground Stop operation after %s settlement, pending-completion/false/reject. Original completion, cancellation and settlement inputs retained.
falls back in-process when a launchd update handoff fails to spawn; keeps running when an external update restart handoff cannot be persisted falls back in-process when $name, both original platform/failure inputs, second start and failure sentinel retained.
Budget-rendering log assertions Same budget table retains exact exposed budget, actual abort/deadline behavior, pending-close diagnostics; direct run-loop-shutdown-budget.test.ts retains log-format coverage.
File-log timeout warning/duplicate exit call shape bounds the file-log flush before a $signal exit now additionally asserts no exit at timeout minus 1, followed by exact exit at timeout.
Still-starting child kill-call spies and warning preserves a real foreground successor after shared readiness reports still-starting still requires the real child to acknowledge opening its TCP listener after parent exit, then remain alive.
Intermediate no-respawn assertions and repeated Stop log string Final no-respawn/one-start proof in the same tests; does not start a second active-work drain for repeated shutdown signals still proves exactly one held drain and closed admission.

No complete behavioral case deleted. Both #83131 tests remain unchanged, and #165670 real connection-work diagnostics and #165980 authorization/supervisor tables remain covered.

Why the remaining large blocks cannot safely meet 35%

The single runGatewayLoop describe delegates these families:

  • Main startup/admission blocks distinguish first-boot failure, failed cleanup, pre-return queued restart, admitted startup cancellation, independent worker interruption, and retired startup capabilities. Their gates establish different ownership/order contracts.
  • Main multi-generation restart verifies actual global-state clearing, event generation rotation and admission reset across three iterations. Cron retirement order and bounded incomplete drains remain distinct.
  • Main hosted stop/update blocks retain response-root lifetime, self-waiting native-client cancellation, late update ownership changes, and exact-helper cancellation. Combining unlike state transitions further would make one branching fixture harder to audit.
  • Request/forced-restart supports already table-drive installation changes during boot, lock reacquisition, active drain and updater settlement, plus forced restart budgets. Every timing window is independently meaningful.
  • Shutdown budget/completion supports retain real connection-work close diagnostics, timeline-file flush ordering, real EPIPE handlers and exact native/foreground deadlines. EOF and timer setup are now shared.
  • Foreground Stop/update supports distinguish cancellation at parking, provider cleanup, lock reacquisition, drain, close, updater settlement, readiness and final log flush; their captured owner and child-close joins differ.
  • Package lifecycle and its helper retain seven real SQLite/process/IPC/listener cases and failure-preserving cleanup. Mock replacements cannot prove those ownership and durable-settlement boundaries.
  • Unchanged external-handoff, hosted-stop and startup supports are already compact tables for distinct handoff authority, disposal overlap, cleanup outcomes and platform recovery guidance.

Evidence

Provider: blacksmith-testbox; profile: openclaw-check; final lease: tbx_01m484jqqdn4dy8nf2t85frf44; final head: bc5fbf34cd2019fa7df97a52f11e59e60127ee01. The final corrected test bytes were validated on the lease before committing, and all nine file hashes match the commit. The lease is stopped.

pnpm test src/cli/gateway-cli/run-loop.test.ts --maxWorkers=1: 167/167 passed in all seven final runs (one cold baseline conditioning run, then three warm pairs). Same lease, dependency tree and production source; each baseline restores the original test bytes and each candidate restores the committed test bytes. All touched source hashes were printed before running.

Warm sample Before wall After wall
1 85.69s 93.21s
2 72.21s 76.40s
3 80.04s 64.15s
Median 80.04s 76.40s

Median wall time decreased 3.64s (4.5%); mean decreased from 79.31s to 77.92s. Runner variation is substantial, so this establishes no measured median cost increase, not a reliable performance speedup. The cold conditioning run was 118.00s and is excluded. Real SQLite/package/helper-process and listener coverage accounts for the seconds-long integration cases; mocks cannot replace those contracts.

node scripts/run-vitest.mjs src/cli/gateway-cli/run-loop.launchd.test.ts src/cli/gateway-cli/lifecycle-import-boundary.test.ts --maxWorkers=1: 2 files / 7 tests passed (9.98s Vitest duration). These are the other importers of the unchanged shared harness.

Three mutation probes each failed the corresponding consolidated rows, with the original production file restored byte-for-byte in finally after each probe:

Broken production behavior Test that caught it Observed failure
Allow unauthorized external SIGUSR2 through the scheduler clears the SIGUSR2 token before applying external restart policy (allowed: false) Scheduler expected uncalled, called once; allow row still passed.
Treat definitive native stop refusal as uncertain recovers only after a definitive native stop refusal (refused) Expected replacement generation never started; uncertain row still passed.
Ignore an update upgrade after asynchronous close/lock release upgrades an accepted restart when an update arrives during close and … during lock release Exact persisted handoff was full-process instead of update-process.

Each probe used pnpm test src/cli/gateway-cli/run-loop.test.ts --maxWorkers=1 -t <case name> on the same lease. All full unfiltered runs passed 167 cases.

Changed-gate gap: node scripts/check-changed.mjs passed its preceding guards, formatting, core graph boundary and CLI test typecheck, then failed the full-tree dead-export scan on two findings outside the PR:

  • extensions/voice-call/src/webhook/realtime-call-session-control.ts: unused export OUTBOUND_GREETING_FALLBACK_MS (the constant is still used internally).
  • src/agents/model-catalog.runtime.ts: unused loadManifestModelCatalog re-export (the underlying implementation has real consumers through model-catalog.ts).

Baseline proof on the same lease restored all nine original test files from parent 0fdc8ac2734c12af89b0d8a29e424bf7e7110030, ran node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts, and reproduced both exact findings with exit 1. No production changes were made to address them.

The first CI run caught two attributable static errors: an unused fixture binding and a timer Promise executor's implicit return. Both are fixed in the final commit, reviewed again (scoped-clean, no actionable P0–P2 findings), and verified with the same nine-file node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <files> command: zero warnings/errors. The complete 167-case suite passed again on the corrected bytes (104.52s wall including fresh compiler preparation). These two lint corrections preserve behavior; the warm measurements above are from the preceding semantically identical test version.

The main consolidation also received independent scoped-clean autoreview. Scoped oxfmt and git diff --check passed; no local tests, typechecks or builds ran.

Earlier lease tbx_01m4839xvpk5ae2bv14rvckfc1 also passed baseline and initial consolidated suites (167 cases each). A subsequent file sync timed out before tests; that lease was stopped. Queued replacement tbx_01m484221t3h9g4q5q37d3jp51 was stopped when the branch head changed. No failed test result was retried to obtain green.

Exact-head CI: run 37438434099, SUCCESS for bc5fbf34cd2019fa7df97a52f11e59e60127ee01; all PR checks are complete and passing, including openclaw/ci-gate. Previous run 37436125142 passed every test job and failed only the two static issues corrected above (plus its aggregate CI gate). Do not merge or enable auto-merge.

Successful final Node test jobs consumed 972 aggregate job-wall seconds (includes setup and the CI-selected sibling scope): checks-node-compact-small-2 106s, checks-node-changed-1 194s, checks-node-changed-2 133s, checks-node-compact-small-1 210s, checks-node-changed-4 106s, checks-node-changed-3 149s, checks-node-changed-boundary 74s.

Merge equivalent lifecycle cases and share scenario setup while retaining all 167 expanded cases, issue regressions, and real process/SQLite coverage. Production code is unchanged. Baseline and consolidated suite passed on Testbox; independent review is clean.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XL labels Oct 6, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@steipete
steipete marked this pull request as ready for review October 6, 2026 08:26
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 6, 2026, 4:54 AM ET / 08:54 UTC (Revision 3).

ClawSweeper review

What this changes

Consolidates Gateway startup, shutdown, and update tests through shared local setup and scenario tables while retaining distinct lifecycle outcomes.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This remains useful test maintenance beyond the merged baseline. No introduced correctness defect was found, and the earlier evidence request is addressed; the author's explicit no-merge hold remains active.

Priority: P3
Reviewed head: bc5fbf34cd2019fa7df97a52f11e59e60127ee01

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused consolidation with retained boundary coverage, explicit cost measurements, and mutation checks; the author hold is a workflow constraint.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies a MEMBER-authored test-only PR, so contributor runtime proof is exempt. The changed tests exercise the existing Gateway run-loop entrypoint; the matching body now reports baseline/candidate passes, shared-consumer checks, and mutation sensitivity. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies a MEMBER-authored test-only PR, so contributor runtime proof is exempt. The changed tests exercise the existing Gateway run-loop entrypoint; the matching body now reports baseline/candidate passes, shared-consumer checks, and mutation sensitivity. No stored-data contract changes.
Evidence reviewed 8 items Verified introduced scope: The pinned merge-base-to-head delta changes only lifecycle tests and test support. Production code, dependencies, workflows, public APIs, and persisted formats are unchanged.
Retained lifecycle contracts: Introduced tables retain native refusal versus uncertainty, queued startup success versus failure, external signal allowance versus denial, and update upgrades during close versus lock release. The real successor case still requires the child to open its listener after parent exit and remain alive.
Shared reset and diagnostic coverage: The unchanged shared beforeEach resets supervisor decisions, restart intent, update ownership, cleanup mocks, and admission. The direct shutdown-budget suite retains log-format coverage; consolidated integration rows retain deadline and cancellation assertions.
Findings None None.
Security None None.

How this fits together

The foreground Gateway run loop receives process signals and host requests, then coordinates active-work draining, cleanup, and stop or restart handoffs. These tests protect the ordering and completion of that lifecycle.

flowchart TD
  A[Startup and process signals] --> B[Gateway run loop]
  C[Host requests] --> B
  B --> D[Admission and request policy]
  D --> E[Drain and cleanup]
  E --> F[Stop or restart handoff]
  G[Lifecycle test fixtures] --> B
  F --> H[Outcome assertions]
Loading

Before merge

  • Complete next step (P2) - Obtain explicit release of the author's continuing no-merge and no-auto-merge hold before landing.
Agent review details

Security

None.

PR surface

Tests -520. Total -520 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 9 742 1262 -520
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 742 1262 -520

Review metrics

Metric Value Why it matters
Test cost comparison 3 warm pairs; median 80.04s baseline, 76.40s candidate Reported measurements show no median cost increase, with enough runner variation to avoid claiming a reliable speedup.
Mutation sensitivity 3 production mutations caught The consolidated rows still detect unauthorized scheduling, incorrect refusal handling, and missed update upgrades.

Technical review

Best possible solution:

Keep compact lifecycle tables and local fixture factories while preserving distinct race, persistence, and process-lifetime contracts without increasing test cost.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this consolidates tests rather than reporting a product defect. Introduced hunks and the production owner were inspected; tests were not executed during this read-only review.

Is this the best way to solve the issue?

Yes: local setup reuse and scenario tables fit the existing test owner while retaining meaningful lifecycle distinctions and stronger final-outcome assertions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against cf2388dedd72.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This is focused test maintenance with no production or user-visible behavior change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies a MEMBER-authored test-only PR, so contributor runtime proof is exempt. The changed tests exercise the existing Gateway run-loop entrypoint; the matching body now reports baseline/candidate passes, shared-consumer checks, and mutation sensitivity. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced scope: The pinned merge-base-to-head delta changes only lifecycle tests and test support. Production code, dependencies, workflows, public APIs, and persisted formats are unchanged. (src/cli/gateway-cli/run-loop.test.ts:278, bc5fbf34cd20)
  • Retained lifecycle contracts: Introduced tables retain native refusal versus uncertainty, queued startup success versus failure, external signal allowance versus denial, and update upgrades during close versus lock release. The real successor case still requires the child to open its listener after parent exit and remain alive. (src/cli/gateway-cli/run-loop-update-respawn.test-support.ts:221, bc5fbf34cd20)
  • Shared reset and diagnostic coverage: The unchanged shared beforeEach resets supervisor decisions, restart intent, update ownership, cleanup mocks, and admission. The direct shutdown-budget suite retains log-format coverage; consolidated integration rows retain deadline and cancellation assertions. (src/cli/gateway-cli/run-loop-mocks.test-support.ts:433, bc5fbf34cd20)
  • Complete captured body inspected: REST returned the complete 13,404-unit body, whose SHA-256 exactly matches the captured source identity ed3463288f8aa921da773d9fbae25db0e663f8989d69fa25b995d43fe64915fa. Previously omitted ranges were therefore inspected without substituting a changed body. (bc5fbf34cd20)
  • Earlier evidence request addressed: The captured body reports paired baseline/candidate 167-case passes, seven shared-consumer tests, and three mutation probes that fail the intended consolidated rows. Final corrected bytes passed all 167 cases and changed-file lint. Warm measurements preceded the two semantic-preserving lint corrections. The full changed gate stopped on two dead exports also reproduced with the original tests; this is not an all-green gate claim. These are reported Testbox results, not tests executed by this reviewer. (bc5fbf34cd20)
  • Continuing author hold: The complete matching body still explicitly says “Do not merge or enable auto-merge.” Publishing the requested evidence does not implicitly release that hold. (bc5fbf34cd20)

Likely related people:

  • Peter Steinberger: Raw commit 58163bd adds src/cli/gateway-cli/run-loop.test-support.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 58163bdb326f; files: src/cli/gateway-cli/run-loop.test-support.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-06T08:25:25.204Z sha 24d8603 :: needs changes before merge. :: none
  • reviewed 2026-10-06T08:31:32.677Z sha 24d8603 :: needs changes before merge. :: none

Remove an unused runtime binding and avoid returning a timer from a Promise executor. Fresh review is clean; changed-file lint and all 167 run-loop cases pass on Testbox. Full changed checks expose two pre-existing unused exports reproduced with the original tests.
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 6, 2026
@steipete
steipete merged commit 607d5ee into main Oct 6, 2026
132 checks passed
@steipete
steipete deleted the steipete/deslop-restart-t-run-loop-20261006 branch October 6, 2026 09:08
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
* test(gateway): consolidate run-loop.test.ts

Merge equivalent lifecycle cases and share scenario setup while retaining all 167 expanded cases, issue regressions, and real process/SQLite coverage. Production code is unchanged. Baseline and consolidated suite passed on Testbox; independent review is clean.

* test(gateway): fix consolidation lint checks

Remove an unused runtime binding and avoid returning a timer from a Promise executor. Fresh review is clean; changed-file lint and all 167 run-loop cases pass on Testbox. Full changed checks expose two pre-existing unused exports reproduced with the original tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant