Skip to content

Serve the scheduler and flow port only from the gateway process - #56

Merged
pallaoro merged 1 commit into
mainfrom
fix/serve-only-in-gateway
Sep 16, 2026
Merged

pallaoro merged 1 commit into
mainfrom
fix/serve-only-in-gateway

Conversation

@pallaoro

Copy link
Copy Markdown
Member

Problem

OpenClaw loads plugins in every process that touches config. Each load armed a TriggerScheduler and tried to bind the flow port. A hung openclaw --help on a customer box (13 days old) held port 18793 with stale code and its own scheduler; the real gateway silently skipped its server ("port already in use").

Fix

shouldServe(api, argv, env): serve only when api.registrationMode is "full" (or absent, older hosts) and argv is openclaw gateway run (or bare openclaw gateway). CLAWFLOW_NO_SERVE always wins; CLAWFLOW_SERVE=1 forces on (tests, unusual hosts). The decision is logged at register time: clawflow: registrationMode=… argv=… → serving|not serving.

Verified on a 7.1 box: the gateway's plugin-loading process is the compile-cache respawn of node /usr/bin/openclaw gateway run (same argv); PluginRegistrationMode is "full" | "discovery" | "tool-discovery" | "setup-only" | "setup-runtime" | "cli-metadata" in types-*.d.ts.

Tests

tests/should-serve.test.ts (gateway, help, cron list, discovery, setup, env switches). Full suite 228 passing. Version 1.6.3 → 1.6.4.

OpenClaw loads plugins in every process that touches config: the gateway,
but also `openclaw --help`, `openclaw cron list`, plugin discovery, setup.
Each of those armed a TriggerScheduler and tried to bind the flow port. A
CLI that exits took its timers with it; one that hung (a diagnostic
`openclaw --help` left running for 13 days on a customer box) became a
second scheduler for the same trigger records and squatted on 18793 with
stale code, which the real gateway then silently yielded to.

shouldServe() keys on two host signals: api.registrationMode must be
"full" (discovery, cli-metadata and setup loads never serve) and the
process must be the one started as `openclaw gateway run`. CLAWFLOW_SERVE=1
forces it on for tests and unusual hosts; CLAWFLOW_NO_SERVE keeps its
meaning for spawned child agents and operator CLIs and always wins. The
decision is logged at register time so a rollout can be verified from the
journal.
@pallaoro
pallaoro merged commit 0cb5f8b into main Sep 16, 2026
1 check passed
@pallaoro
pallaoro deleted the fix/serve-only-in-gateway branch September 16, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant