Skip to content

Keep gateway lifecycle loaders stable across rebuilds - #73964

Closed
pashpashpash wants to merge 4 commits into
mainfrom
codex/stabilize-gateway-lifecycle-lazy-boundaries
Closed

pashpashpash wants to merge 4 commits into
mainfrom
codex/stabilize-gateway-lifecycle-lazy-boundaries

Conversation

@pashpashpash

Copy link
Copy Markdown
Contributor

This fixes the rebuild failure mode where a running gateway keeps a lazy import boundary into a hashed dist chunk and then loses that chunk underneath itself during a rebuild.

We already had the right architectural idea in tsdown.config.ts: long-lived runtime boundaries should resolve through stable filenames. The problem was that the restart, shutdown, and heartbeat paths were only partially enrolled in that rule. Some first-hop lifecycle imports still compiled to hashed chunk names, so a live gateway could strand its own control paths even though the high-level build policy was already correct.

This change does not add runtime fallbacks, retries, or extra recovery branches. It makes the lifecycle modules themselves explicit tsdown entries so the existing lazy imports resolve to stable build paths. That keeps the fix in the build graph, where the problem actually lives.

I kept the scope to the first-hop modules that can fire after startup from an already-running gateway process: the run-loop restart and drain helpers, the shutdown prelude and close handler, and the heartbeat runtime loader. There is also a focused tsdown config test now, so we keep this contract visible instead of silently drifting back to hashed lifecycle chunks later.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: telegram Channel integration: telegram size: L 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 bundles two distinct changes: it promotes a set of first-hop gateway lifecycle modules to explicit tsdown entries (giving them stable filenames that survive a hot rebuild), and it overhauls resolvePrivateCommandRouteTargets so that /diagnostics and /export-trajectory results are routed to same-surface owner DMs first, falling back to the first owner route in commands.ownerAllowFrom when the originating surface has no private route.

Both changes are well-tested. The messageProvider and accountId corrections in the diagnostics/export-trajectory handlers ensure the exec-approval context matches the actual delivery channel rather than always reflecting the invocation channel, which was the underlying data bug the routing change exposed.

Confidence Score: 4/5

Safe to merge; no bugs found. The PR title describes only one of the two features introduced.

No P0 or P1 issues found. The routing logic, owner-key matching, and sort comparator are all correct and backed by comprehensive tests. The score stops at 4 rather than 5 because the PR title only describes the tsdown change, while the majority of the diff implements a separate private-routing feature for sensitive commands.

No files require special attention for correctness; src/auto-reply/reply/commands-private-route.ts is the most complex new code but is thoroughly exercised by the accompanying test file.

Reviews (1): Last reviewed commit: "Stabilize gateway lifecycle lazy boundar..." | Re-trigger Greptile

@steipete steipete left a comment

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.

Thanks for jumping on this. I found two things I think should be fixed before merge.

  1. Slack cross-surface private routing will drop valid owners.

commands-private-route.ts builds candidate owner keys from the returned route target. Slack's native approver resolver maps an approver to to: "user:<id>", but the new key builder only adds user:<id>, user:user:<id>, and slack:user:<id>. That means an owner allow entry like slack:U123, which is the natural/documented Slack form, does not match and the route is filtered out.

Relevant paths:

  • src/auto-reply/reply/commands-private-route.ts:144
  • extensions/slack/src/approval-native.ts:159

I think this needs normalization that understands kind:id targets before applying the channel prefix, or at least adds slack:<id> when channel === "slack" && to.startsWith("user:"). Please add a regression test for a Discord-origin private command routing to a Slack owner configured as slack:U....

  1. The lifecycle stable-entry list still misses config/config on the restart path.

buildGatewayLifecycleLazyEntries() adds several first-hop lazy imports, but src/cli/gateway-cli/run-loop.ts still calls loadRuntimeConfigModule() during signal/restart handling to read gateway.reload.deferralTimeoutMs. That import is ../../config/config.js, and it is not in the new stable lifecycle entries. After a rebuild, a running gateway can still hit this lazy boundary while processing restart/shutdown and land back on a deleted hashed chunk.

Relevant paths:

  • tsdown.config.ts:204
  • src/cli/gateway-cli/run-loop.ts:44
  • src/cli/gateway-cli/run-loop.ts:280

Please either add config/config as a stable entry or preload/cache it before the long-lived boundary can be invalidated, and add it to the stability test so the exact restart-time import is covered.

One non-blocking note: this PR combines the private-command routing behavior and the gateway lifecycle bundling fix. Both are useful, but the title/description should call out both, or this should split so the release note and review surface are clearer.

@openclaw-clownfish

Copy link
Copy Markdown
Contributor

Clownfish could not safely update this branch, so it opened a narrow replacement PR instead.

Replacement PR: #74075
Source PR: #73964
Credit preserved: @pashpashpash is carried forward as co-author in the replacement PR.
Closing this PR to keep review focused on the replacement. The contribution is carried forward, not discarded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord channel: telegram Channel integration: telegram docs Improvements or additions to documentation maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants