fix(openclaw-adapter): start HTTP server before core.init() to unblock viewer at startup#1857
Open
34262315716 wants to merge 1 commit into
Open
Conversation
…k viewer at startup
Move startHttpServer() before core.init() in the OpenClaw adapter so the
viewer port (:18799) is available immediately, even when core.init()
blocks on orphan episode recovery and dirty reward rescoring from
previous sessions.
Previously the startup sequence was:
bootstrapMemoryCoreFull() -> await core.init() -> startHttpServer()
^ blocks for minutes
under API rate limits
Now it is:
bootstrapMemoryCoreFull() -> startHttpServer() -> void core.init()
^ responds immediately
^ runs in background
This mirrors the fix in PR MemTensor#1842 (bridge.cts) applied to the OpenClaw
adapter. The HTTP server routes work without core.init() because:
- /api/v1/ping returns a hardcoded response
- /api/v1/health calls core.health() which works with the bootstrapped
core (SQLite already open, providers already created)
- routes only check shutDown, not initialized
- The SQLite database is fully accessible after bootstrapMemoryCoreFull()
core.init() now runs as a background task. If it fails, the viewer
continues serving cached data in degraded mode.
Ref: MemTensor#1841 (original report: daemon viewer blocked by core.init())
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1841 (OpenClaw adapter portion)
Summary
Reorders the OpenClaw adapter startup sequence in
adapters/openclaw/index.tsso the HTTP viewer server binds its port beforecore.init()runs.core.init()is now a fire-and-forget background task.This is the same fix as PR #1842 but applied to the OpenClaw adapter (
adapters/openclaw/index.ts) instead of the Hermes daemon (bridge.cts).Problem
In the OpenClaw adapter, the startup sequence was:
core.init()performs orphan episode recovery includingrecoverDirtyClosedEpisodes(), which calls the LLM to rescore each dirty episode. Under API rate limiting, this can block for minutes.Since the HTTP server starts after init, the viewer port (
:18799) remains unresponsive during this time. Users see a blank page or connection refused when opening the viewer immediately after an OpenClaw restart.Fix
/api/v1/pingand/api/v1/healthimmediatelycore.init()runs as a background task (core.init().catch(...))Why this is safe
/api/v1/pingreturns a hardcoded response — no core state needed/api/v1/healthcallscore.health()which returnsok: falsebefore init — the viewer can show a starting-up statebootstrapMemoryCoreFull()before either stepbefore_prompt_build,agent_end, etc.) callensureLive()which only checksshutDown, notinitialized— turns can proceed concurrently with background initChanges
apps/memos-local-plugin/adapters/openclaw/index.tsstartHttpServerbeforecore.init(), run init as background taskTesting
curl http://127.0.0.1:18799/api/v1/pingshould respond within seconds, even before init completes~/.openclaw/memos-plugin/logs/forbackground core.init() completedorbackground core.init() failedafter a delayRef: #1841, #1842