Skip to content

Background-job survival, sync circuit breaker, sub-50ms startup - #132

Merged
davidrhodus merged 2 commits into
mainfrom
fix/bg-survival-sync-breaker-fast-startup
Jul 26, 2026
Merged

Background-job survival, sync circuit breaker, sub-50ms startup#132
davidrhodus merged 2 commits into
mainfrom
fix/bg-survival-sync-breaker-fast-startup

Conversation

@davidrhodus

Copy link
Copy Markdown
Contributor

Summary

  • Deliberate background jobs survive the turn: processes started with run_in_background: true are no longer reaped by turn-end pre-verification cleanup, turn cancel, or retry rewinds (observed loss: two ~800 GB downloads killed at turn end). Auto-backgrounded foreground overruns are still reaped as before; everything still dies with the session or bash_kill.
  • Sync circuit breaker: a dead portal trips a persisted, cross-process cooldown (60s→15min, reset on success); all sync paths skip the network instantly while open, with records queued durably. 3s connect timeouts; fail-fast registration.
  • Sub-50ms startup: the synced TUI's host-mode auto-enable moved off the first-paint path onto a background task; HI_STARTUP_TRACE=1 gives per-milestone timing.
  • Sync is silent: portal trouble never surfaces as an error or touches the coding workflow — exit flushes, startup host enable, and session switches fail silently into the durable outbox; explicit /sessions host gets a calm availability note; only --daemon still announces retries.

Testing

  • Full suites green across hi-agent, hi-tools, hi, hi-tui (three unrelated timing tests flaked under full parallel load and pass in isolation).
  • New tests: origin-aware kill_started_after (spares deliberate, reaps adopted), turn-level deliberate_background_process_survives_turn_end, breaker cooldown doubling/reset, unreachable-endpoint breaker trip with silent follow-up flushes.
  • Live measurements in the affected workspace: one-shot 36.6s → 1.3s; TUI first frame 23–24ms across three pty runs; zero sync/error lines in output with the portal down.

🤖 Generated with Claude Code

David and others added 2 commits July 25, 2026 20:13
Turn-end pre-verification cleanup killed every background process the
turn had started — observed loss: two ~800 GB downloads reaped at turn
end hours before completion (a third escaped its group kill and
finished despite being marked killed).

Background processes now carry their origin. Deliberate work the model
started with run_in_background:true (downloads, servers) is spared by
kill_started_after — turn end, turn cancel, and retry rewinds all flow
through it — and still dies with the session or an explicit bash_kill.
Auto-backgrounded foreground overruns remain turn state and are reaped
before verification exactly as before.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…, silent best-effort

api.pipenetwork.ai outages surfaced everywhere: one-shots took 36s
(serial 10s registration/flush timeouts against a 4k-record, 63k-event
durable backlog), session switches could burn a ~100s retry ladder and
then fail the switch, TUI startup hung for tens of seconds because the
synced-session host enable awaited portal registration before first
paint, and raw reqwest errors ("operation timed out") leaked into the
transcript and exit output.

Circuit breaker (persisted in the shared sync store): the first
connect/timeout failure trips a cooldown (60s doubling to 15 min,
reset by any success) that every sync path in every hi process
respects — registration, record flush, live-event flush, and
end-session skip the network instantly while open, leaving records
queued durably. Both sync HTTP clients gain a 3s connect timeout;
ensure_registered_now fails fast once the breaker opens.

Sub-50ms startup: the synced TUI's host-mode auto-enable now runs as a
background task whose outcome the event loop applies when it lands —
first frame no longer waits on the portal. HI_STARTUP_TRACE=1 prints
per-milestone stamps plus a TUI first-frame checkpoint so startup
regressions get measured, not guessed.

Sync trouble is never shown and never affects the workflow: exit
flushes, the startup host enable, and session-switch registration are
silent on failure (records stay queued; the session runs unhosted); an
explicit /sessions host command gets a calm availability note instead
of a raw error. Only --daemon, which cannot function without sync,
still announces registration retries.

Measured in the affected workspace: one-shot 36.6s → 1.3s with the
breaker open and zero sync/error lines in the output; TUI first frame
23–24ms (was: tens of seconds).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@davidrhodus
davidrhodus merged commit 3f6f011 into main Jul 26, 2026
1 check failed
@davidrhodus
davidrhodus deleted the fix/bg-survival-sync-breaker-fast-startup branch July 26, 2026 03:37
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