Repository navigation
fix(runtime): recover long-idle sessions, survive terminal loss, journal crashes - #61
Merged
Merged
Conversation
mikannse
force-pushed
the
fix/long-idle-recovery
branch
from
September 10, 2026 06:38
f457ee3 to
a50ca41
Compare
…nal crashes A server left running while the user is away could leave the open page unable to load anything (empty sidebar, endless Loading) until the process was restarted, with no trace of why. Harden both sides: - SessionSidebar: refresh the session list when the tab becomes visible again or the network returns — the SSE reconnect after laptop sleep / network change carries no list invalidation. - useAgentSession: a CLOSED event stream now retries with capped backoff even while the agent is idle; previously only running sessions were retried, leaving idle streams dead silently until a page reload. - process-lifecycle: translate SIGHUP into a graceful SIGTERM tree kill so a CLI launcher losing its terminal disposes the detached omp children instead of orphaning them. - instrumentation: journal uncaughtException/unhandledRejection and event-loop stalls to ~/.omp/omp-web/diagnostics.log, so a crash-vs-stall wedge is diagnosable from disk when no terminal is watching. - session-reader: an unsettled in-flight list load stops being coalesced after 60s instead of pinning the wedge until process restart. - mcp-config: bound the synchronous git rev-parse with a 10s timeout so a hung spawn cannot block the entire event loop.
kahme247
force-pushed
the
fix/long-idle-recovery
branch
from
September 13, 2026 14:38
a50ca41 to
2aba9cc
Compare
… MCP fallback caching, label sleep gaps - useAgentSession: connectEvents drops any pending backoff timer first so a send-during-backoff cannot orphan a timer that later tears down the healthy stream; contract test pins it. - session-reader: a watchdog-retired load can no longer overwrite fresher cache data when it resolves late (retired flag). - mcp-config: transient git failures return the cwd fallback without poisoning the 30s project-root cache. - instrumentation: stall watchdog compares CPU time so laptop sleep is journaled as sleep, not a misleading stall.
This was referenced Sep 13, 2026
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.
Summary
User-reported: after leaving ompweb idle for tens of minutes (machine awake, terminal still open), the sidebar session list goes blank/spinning, the open conversation fails with "Session not found" / "load failed" errors, and only restarting the ompweb process recovers — a plain page reload does not. That signature means the server process is alive but its session APIs keep failing, and the incident leaves no trace anywhere.
Static audit found no single unbounded path (all RPC commands, git spawns and dispose chains are timeout-bounded; SSE routes clean up via abort+cancel; the session watcher retries with backoff). So this PR (a) fixes the concrete defects found on both sides, (b) makes the failure mode self-recovering, and (c) journals crashes/stalls so the next incident identifies its root cause from disk.
Change
Client:
components/SessionSidebar.tsx: the/api/sessionsfetch gets a 15s deadline (a wedged-but-listening server previously left the initial spinner pending forever); the list now also refreshes onvisibilitychange → visibleandonline— after laptop sleep / network flap the SSE reconnect carries no list invalidation.hooks/useAgentSession.ts+useAgentSession-stream.ts: a CLOSED event stream (fatal per EventSource: 404/409/500/proxy timeout) now retries with capped backoff (1s → 30s, reset on open) regardless ofagentRunning; previously only running sessions were retried, so idle streams died silently until a page reload. Pending extension dialogs survive reconnects only if the stream comes back.hooks/useAgentSession.test.mjs: source-contract test pinning the retry, backoff, and reset.Server:
instrumentation.ts: journaluncaughtException/unhandledRejection(then exit, preserving Node's crash semantics) and an event-loop stall watchdog to~/.omp/omp-web/diagnostics.log(1MB rotation). A server that dies or wedges while no terminal watches leaves a record.bin/process-lifecycle.js: SIGHUP is translated to a graceful SIGTERM tree kill. A CLI launcher is its terminal's foreground process group; losing the terminal used to kill the tree without exit handlers, orphaning the detachedomp --mode rpc-uichildren (two processes could then touch the same session file).lib/session-reader.ts: the coalesced in-flight list load stops being handed to new callers after 60s, so one never-settling load cannot pin/api/sessionsuntil process restart.lib/omp/mcp-config.ts: the synchronousexecFileSync("git", rev-parse …)gets a 10s timeout — a hung spawn would block the entire event loop, making every API unresponsive until restart.Verification
npx tsc --noEmit— cleannpm run lint— zero warningsnpm test— 552 pass, 1 skipped (one new test)npm run build— succeedsnext startfully self-heals (rules out the freeze class); SIGHUP to a running launcher terminates the child tree and frees the port; dispatching a realonlineevent triggers exactly one list refresh.Follow-up
The root cause of the reported incident is not yet pinned: the incident state (in-process degradation after long idle) needs on-disk evidence. With this PR,
~/.omp/omp-web/diagnostics.logrecords acrashentry (with the offending rejection/stack) or astallentry (event-loop block duration) at the moment it happens — the next occurrence identifies which of the three candidate mechanisms (resource degradation / sync stall / crash) is real. Meanwhile the client degrades to a visible error + auto-retry instead of an eternal spinner.