Skip to content

refactor(gateway): consolidate lifecycle lazy boundary - #74105

Merged
steipete merged 2 commits into
mainfrom
codex/gateway-lifecycle-runtime-boundary
Apr 29, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/gateway-lifecycle-runtime-boundary

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • Problem: gateway lifecycle restart/shutdown paths lazily import hashed chunks from a long-running process, so a rebuilt dist/ can remove chunks that the live gateway imports during update, restart, or shutdown cleanup.
  • Why it matters: the existing fix(gateway): stabilize lifecycle lazy build entries #74075 fix stabilized every current lifecycle import individually, but it left a hand-maintained list that would drift as more lifecycle helpers move behind lazy imports.
  • What changed: added one gateway lifecycle runtime boundary and made run-loop.ts lazy-load that stable entry instead of ten separate implementation modules.
  • What did NOT change (scope boundary): no restart semantics, config defaults, gateway protocol, or plugin behavior changes.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: src/cli/gateway-cli/run-loop.ts was intentionally lazy-loading lifecycle helpers directly from implementation modules that tsdown emits as hashed chunks unless each module is promoted to a stable entry.
  • Missing detection / guardrail: the tsdown config test covered existing stable entries but did not assert that gateway lifecycle lazy imports go through a single stable boundary.
  • Contributing context (if known): fix(gateway): stabilize lifecycle lazy build entries #74075 fixed the immediate missing chunks by listing every current lifecycle module as a stable entry, but that makes future lifecycle imports easy to miss.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/infra/tsdown-config.test.ts
  • Scenario the test should lock in: the unified dist graph contains the stable gateway lifecycle runtime entry, and run-loop.ts imports only that lifecycle runtime boundary.
  • Why this is the smallest reliable guardrail: it checks the build-entry contract and the source import shape that would otherwise drift independently.
  • Existing test that already covers this (if any): the existing unified dist graph test now includes the lifecycle runtime key.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

None.

Diagram (if applicable)

Before:
run-loop restart/shutdown -> lazy import many implementation chunks -> stale hashed chunk risk after rebuild

After:
run-loop restart/shutdown -> lazy import stable lifecycle runtime entry -> lifecycle helpers loaded behind one build boundary

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: macOS local maintainer checkout
  • Runtime/container: Node 22 / pnpm
  • Model/provider: N/A
  • Integration/channel (if any): Gateway lifecycle/build config
  • Relevant config (redacted): N/A

Steps

  1. Inspect fix(gateway): stabilize lifecycle lazy build entries #74075 and current run-loop.ts lazy imports.
  2. Replace per-module lifecycle lazy imports with a single stable lifecycle runtime boundary.
  3. Verify tsdown config and import-shape guardrails.

Expected

  • Gateway lifecycle lazy imports are reachable through one stable dist entry.
  • Future direct lifecycle imports in run-loop.ts fail the tsdown config test.

Actual

  • run-loop.ts imports only ./lifecycle.runtime.js for lifecycle helpers.
  • tsdown.config.ts emits cli/gateway-lifecycle.runtime as a stable core dist entry.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Focused/local verification:

  • pnpm test src/infra/tsdown-config.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/cli/gateway-cli/lifecycle.runtime.ts src/cli/gateway-cli/run-loop.ts src/infra/tsdown-config.test.ts tsdown.config.ts
  • pnpm check:changelog-attributions
  • pnpm build
  • OPENCLAW_LOCAL_CHECK=1 OPENCLAW_LOCAL_CHECK_MODE=throttled pnpm check:changed
  • pnpm lint:tmp:dynamic-import-warts (advisory-only; no new run-loop.ts advisory)

Testbox note: attempted blacksmith testbox run --id tbx_01kqbtr2qyhwavtspead9m6vs6 "pnpm build" and pnpm check:changed, but the client stalled in the sync phase while reporting only 4 changed tracked files plus 1 untracked file. The created box was stopped.

Human Verification (required)

  • Verified scenarios: build entry exists, run-loop import shape is guarded, focused tsdown config test passes, local build passes, broad changed gate passes locally in throttled mode.
  • Edge cases checked: post-rebase changelog conflict resolved against current origin/main; reran focused test, formatter, attribution check, and git diff --check after rebase.
  • What you did not verify: live gateway update/restart against a real installed package.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: the lifecycle runtime boundary pulls several lifecycle helpers together on first lifecycle import instead of loading each helper separately.
    • Mitigation: it remains lazy from startup, and the grouped helpers are all restart/shutdown/update lifecycle code paths already loaded in the same long-running process phase.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Apr 29, 2026
@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR consolidates the ten per-module lazy imports in run-loop.ts into a single stable lifecycle.runtime.ts boundary, registered as a named tsdown entry (cli/gateway-lifecycle.runtime). The refactor closes the stale-chunk risk introduced by hashed-chunk lazy imports and replaces the hand-maintained list from #74075 with a build-contract guardrail that will catch future regressions.

Confidence Score: 4/5

Safe to merge — purely structural refactor with no semantic changes and a new test guardrail.

Only P2 finding: the guardrail regex in the new test misses single-quoted dynamic imports, leaving a small future detection gap. No runtime behavior changes, no logic errors.

src/infra/tsdown-config.test.ts — guardrail regex coverage

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/tsdown-config.test.ts
Line: 112

Comment:
**Guardrail regex misses single-quoted dynamic imports**

The regex `/import\("([^"]+)"\)/gu` only captures double-quoted import specifiers. Any future dynamic import written with single quotes (e.g. `import('./some-module.js')`) would be silently skipped, the set would remain `{"./lifecycle.runtime.js"}`, and the test would still pass — giving a false-green guardrail.

```suggestion
    const importSpecifiers = [...readGatewayRunLoopSource().matchAll(/import\(["']([^"']+)["']\)/gu)].map(
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "refactor(gateway): consolidate lifecycle..." | Re-trigger Greptile

Comment thread src/infra/tsdown-config.test.ts Outdated
});

it("routes gateway run-loop lifecycle imports through the stable runtime boundary", () => {
const importSpecifiers = [...readGatewayRunLoopSource().matchAll(/import\("([^"]+)"\)/gu)].map(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Guardrail regex misses single-quoted dynamic imports

The regex /import\("([^"]+)"\)/gu only captures double-quoted import specifiers. Any future dynamic import written with single quotes (e.g. import('./some-module.js')) would be silently skipped, the set would remain {"./lifecycle.runtime.js"}, and the test would still pass — giving a false-green guardrail.

Suggested change
const importSpecifiers = [...readGatewayRunLoopSource().matchAll(/import\("([^"]+)"\)/gu)].map(
const importSpecifiers = [...readGatewayRunLoopSource().matchAll(/import\(["']([^"']+)["']\)/gu)].map(
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/infra/tsdown-config.test.ts
Line: 112

Comment:
**Guardrail regex misses single-quoted dynamic imports**

The regex `/import\("([^"]+)"\)/gu` only captures double-quoted import specifiers. Any future dynamic import written with single quotes (e.g. `import('./some-module.js')`) would be silently skipped, the set would remain `{"./lifecycle.runtime.js"}`, and the test would still pass — giving a false-green guardrail.

```suggestion
    const importSpecifiers = [...readGatewayRunLoopSource().matchAll(/import\(["']([^"']+)["']\)/gu)].map(
```

How can I resolve this? If you propose a fix, please make it concise.

@clawsweeper

clawsweeper Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

Keep open. This PR is maintainer-authored and has the protected maintainer label, and current main still lacks the proposed gateway lifecycle runtime boundary, stable cli/gateway-lifecycle.runtime build entry, and import-shape guard. The PR head appears focused and carries forward the related #73964 lifecycle-stability work with attribution, but it needs maintainer review/merge rather than conservative cleanup closure.

Required change before merge:

Keep this PR open for maintainer review. If accepted, land the unified gateway lifecycle runtime boundary, preserve #73964/@pashpashpash attribution, keep restart/shutdown semantics unchanged, and validate pnpm test src/infra/tsdown-config.test.ts, pnpm build, and the appropriate changed gate/Testbox path for a gateway build-boundary change.

Best possible solution:

Keep this PR open for maintainer review. If accepted, land the unified gateway lifecycle runtime boundary, preserve #73964/@pashpashpash attribution, keep restart/shutdown semantics unchanged, and validate pnpm test src/infra/tsdown-config.test.ts, pnpm build, and the appropriate changed gate/Testbox path for a gateway build-boundary change.

What I checked:

Likely related people:

  • steipete: GitHub commit history shows steipete introduced the current lazy gateway startup/run-loop import shape in e6518090 and recently maintained stable runtime entry/package build coverage in f7e942f5; local blame for the central current-main lines also maps to Peter Steinberger. The current PR is therefore routed to an existing area maintainer, not merely its proposer. (role: recent maintainer / build-boundary owner; confidence: high; commits: e651809084a1, f7e942f5714c, cc4a4bff2829; files: src/cli/gateway-cli/run-loop.ts, tsdown.config.ts, src/infra/tsdown-config.test.ts)
  • vincentkoc: GitHub commit history shows vincentkoc recently changed the same restart/run-loop lifecycle path in 1f41b8b4 for bounded restart deferral, including src/cli/gateway-cli/run-loop.ts, src/infra/restart.ts, and related gateway reload tests. That makes them a useful reviewer for restart semantics and validation risk. (role: recent adjacent gateway lifecycle maintainer; confidence: medium; commits: 1f41b8b44ba0; files: src/cli/gateway-cli/run-loop.ts, src/infra/restart.ts, src/gateway/server-reload-handlers.ts)

Remaining risk / open question:

  • The PR changes the build graph by adding a new stable cli/gateway-lifecycle.runtime dist entry; reviewers should confirm package inventory and bundled import behavior remain intended.
  • The grouped lifecycle boundary loads several restart/shutdown/update helpers together on first lifecycle import instead of per-helper lazy loading; that appears scoped but is still the main runtime tradeoff to accept.
  • The PR evidence does not include a live installed-package rebuild/restart smoke; build/test guardrails cover the static contract but not a real long-running gateway update.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3367cfaa1466.

@steipete
steipete force-pushed the codex/gateway-lifecycle-runtime-boundary branch from 7cd05a8 to 2a4b7de Compare April 29, 2026 06:33
@steipete

Copy link
Copy Markdown
Contributor Author

/clownfish automerge

@steipete steipete added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label Apr 29, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Clownfish automerge is enabled for this PR.

I added clownfish:automerge and asked ClawSweeper to review this head. If ClawSweeper requests changes, I will repair the branch and ask for another review, up to the configured round limit.

A maintainer can pause this with /clownfish stop.

@steipete
steipete force-pushed the codex/gateway-lifecycle-runtime-boundary branch from 2a4b7de to cc4a4bf Compare April 29, 2026 06:39
@steipete

Copy link
Copy Markdown
Contributor Author

/clownfish automerge

@steipete

Copy link
Copy Markdown
Contributor Author

Clownfish automerge is enabled for this PR.

I added clownfish:automerge and asked ClawSweeper to review this head. If ClawSweeper requests changes, I will repair the branch and ask for another review, up to the configured round limit.

A maintainer can pause this with /clownfish stop.

@steipete

Copy link
Copy Markdown
Contributor Author

Thanks, ClawSweeper. Clownfish picked up the repair feedback.

Source: clawsweeper[bot]
Feedback: structured ClawSweeper marker: fix-required (finding=review-feedback sha=cc4a4bff2829e2a0a3693a6e448a6615e1c00073)
Action: dispatched cluster-worker.yml for jobs/openclaw/inbox/automerge-openclaw-openclaw-74105.md in autonomous mode.
Model: gpt-5.5

I will update this PR branch, or open a safe credited replacement, if the repair worker finds a narrow fix.

@steipete
steipete force-pushed the codex/gateway-lifecycle-runtime-boundary branch from cc4a4bf to 6d7c9a5 Compare April 29, 2026 15:36
@steipete
steipete force-pushed the codex/gateway-lifecycle-runtime-boundary branch from 6d7c9a5 to 61c3217 Compare April 29, 2026 15:38
@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes:

This PR adds a gateway lifecycle runtime module, rewires run-loop.ts lifecycle dynamic imports through that single lazy boundary, registers it as a stable tsdown entry, adds tsdown/import-shape tests, and records the gateway build fix in the changelog.

Maintainer follow-up before merge:

This is an open implementation PR with a protected maintainer label and active automerge/repair context, so the next step is normal maintainer review rather than queuing another ClawSweeper repair job.

Review details

Best possible solution:

Have a maintainer review and, if accepted, land the focused lifecycle runtime boundary while preserving #73964/@pashpashpash attribution, keeping gateway restart/shutdown semantics unchanged, and validating the tsdown guardrail plus build/changed-gate coverage appropriate for a gateway build-boundary change.

What I checked:

Likely related people:

  • steipete: Local blame maps the current main run-loop.ts lifecycle lazy loader block and buildCoreDistEntries() stable runtime entry block to Peter Steinberger, and the provided discussion also identifies prior gateway run-loop/build-boundary commits by the same maintainer. (role: recent maintainer / build-boundary owner; confidence: high; commits: 3a875e754928, e651809084a1, f7e942f5714c; files: src/cli/gateway-cli/run-loop.ts, tsdown.config.ts, src/infra/tsdown-config.test.ts)
  • vincentkoc: The provided prior review context points to recent restart/run-loop lifecycle work in commit 1f41b8b4, making this a useful reviewer for restart semantics even though the current PR is primarily a build-boundary refactor. (role: recent adjacent gateway lifecycle maintainer; confidence: medium; commits: 1f41b8b44ba0; files: src/cli/gateway-cli/run-loop.ts, src/infra/restart.ts, src/gateway/server-reload-handlers.ts)
  • pashpashpash: Related Keep gateway lifecycle loaders stable across rebuilds #73964 describes the same rebuilt-package stale hashed chunk failure and this PR explicitly carries that work forward with attribution, so they are relevant context for the intended lifecycle-stability behavior. (role: source lifecycle-stability contributor; confidence: medium; commits: 9ea4916905ef; files: src/cli/gateway-cli/run-loop.ts, tsdown.config.ts, src/infra/tsdown-config.test.ts)

Remaining risk / open question:

  • The PR adds a new stable package build entry, so reviewers should confirm the emitted package inventory and runtime import behavior remain intended.
  • The PR body reports local build and changed-gate proof, but a live installed gateway update/restart was not verified in the provided context.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 240362bf6d0e.

@steipete
steipete merged commit 616f24f into main Apr 29, 2026
64 of 67 checks passed
@steipete
steipete deleted the codex/gateway-lifecycle-runtime-boundary branch April 29, 2026 15:45
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
* refactor(gateway): consolidate lifecycle lazy boundary

* test(gateway): cover quoted lifecycle imports
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
* refactor(gateway): consolidate lifecycle lazy boundary

* test(gateway): cover quoted lifecycle imports
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
* refactor(gateway): consolidate lifecycle lazy boundary

* test(gateway): cover quoted lifecycle imports
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
* refactor(gateway): consolidate lifecycle lazy boundary

* test(gateway): cover quoted lifecycle imports
@vincentkoc

Copy link
Copy Markdown
Member

Clownfish 🐠 reef automerge status

This repair lap finished without changing the PR. Clownfish checked the reef and found no safe patch to push this time.

Target: #74105
Executor outcome: no planned fix actions.
Worker summary: No Clownfish repair action remains for this automerge cluster. The canonical PR #74105 is already merged and closed, and the current target checkout at main 6382536 contains the lifecycle runtime boundary plus the quoted-import guardrail that addressed the Greptile P2 review finding. Historical source/replacement PRs are already closed and need no mutation.

Worker actions:

  • keep_closed on #74105: skipped - Canonical automerge PR is already merged and current main contains the repaired implementation; closed refs are evidence-only.
  • keep_closed on #74075: skipped - Already closed superseded replacement; no close/comment/merge action is allowed or needed.
  • keep_closed on #73964: skipped - Already closed source PR whose lifecycle fix and contributor credit were carried forward by the merged canonical PR.

No push, rebase, replacement PR, merge, or ClawSweeper re-review happened this swim.

fish notes: model gpt-5.5, reasoning medium.

vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
* refactor(gateway): consolidate lifecycle lazy boundary

* test(gateway): cover quoted lifecycle imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge cli CLI command changes maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants