Skip to content

fix(runtime): recover long-idle sessions, survive terminal loss, journal crashes - #61

Merged
kahme247 merged 2 commits into
ompweb-dev:mainfrom
mikannse:fix/long-idle-recovery
Sep 13, 2026
Merged

kahme247 merged 2 commits into
ompweb-dev:mainfrom
mikannse:fix/long-idle-recovery

Conversation

@mikannse

@mikannse mikannse commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

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/sessions fetch gets a 15s deadline (a wedged-but-listening server previously left the initial spinner pending forever); the list now also refreshes on visibilitychange → visible and online — 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 of agentRunning; 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: journal uncaughtException / 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 detached omp --mode rpc-ui children (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/sessions until process restart.
  • lib/omp/mcp-config.ts: the synchronous execFileSync("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 — clean
  • npm run lint — zero warnings
  • npm test — 552 pass, 1 skipped (one new test)
  • npm run build — succeeds
  • Behavioral: SIGSTOP/SIGCONT of a production next start fully self-heals (rules out the freeze class); SIGHUP to a running launcher terminates the child tree and frees the port; dispatching a real online event 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.log records a crash entry (with the offending rejection/stack) or a stall entry (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.

@mikannse
mikannse force-pushed the fix/long-idle-recovery branch from f457ee3 to a50ca41 Compare September 10, 2026 06:38
…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
kahme247 force-pushed the fix/long-idle-recovery branch from a50ca41 to 2aba9cc Compare September 13, 2026 14:38
… 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.
@kahme247
kahme247 merged commit a29b77d into ompweb-dev:main Sep 13, 2026
3 checks passed
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.

2 participants