Skip to content

refactor(session): inject a lifecycle clock - #953

Merged
benvinegar merged 2 commits into
mainfrom
refactor/session-lifecycle-clock
Sep 1, 2026
Merged

benvinegar merged 2 commits into
mainfrom
refactor/session-lifecycle-clock

Conversation

@benvinegar

Copy link
Copy Markdown
Member

Summary

  • add a small runtime-neutral lifecycle clock with explicit idempotent timer disposers
  • use one native unref clock for Hunk startup retry, daemon polling, producer handshake, heartbeat, and reconnect timing
  • compose that clock once at the interactive process boundary and share it through client/connection/launcher ownership
  • replace global timer test patching with a shared deterministic Test clock
  • document the public production clock contract and add deterministic plus native-contract coverage

Stack

  1. test(session): characterize lifecycle interleavings #949 — lifecycle characterization
  2. fix(session): recover from socket startup failures #950 — synchronous socket-start rollback
  3. refactor(session): model startup lifecycle states #952 — explicit startup lifecycle states
  4. This PR: plain TypeScript lifecycle clock
  5. Next: late-settlement and generation fences
  6. Then: runtime exit fixtures and bounded defect reporting

Base branch: refactor/session-startup-states. Review only the fourth commit for this PR.

Validation

  • focused connection/client/launcher/native-clock tests — 61 pass
  • native clock test repeated 10×
  • full direct unit suite — 2,137 pass in the clock implementation pass
  • bun run typecheck
  • bun run lint
  • bun run deps:check
  • bun run test:session-broker-node — 3 pass
  • bun run check:pack
  • manual Node/Bun smoke confirmed native one-shot and interval handles are unref'd and disposers are idempotent
  • two review rounds; final review found no blocker/high/medium findings

Deliberate boundaries

  • fetch abort and TCP socket timeouts remain transport-owned
  • daemon and Node/Bun adapter timers are unchanged
  • launcher lock-owner/poll interval timeout semantics are preserved rather than tightened in a refactor
  • a valid acknowledgement settling after its handshake deadline remains explicitly assigned to the next stacked late-completion fence PR
  • real Node/Bun pending-work process-exit fixtures remain assigned to the later fixture PR

No Effect, package-global scheduler, or test-only public declarations are introduced.

This PR description was generated by Pi using gpt-5.6-sol

@vercel

vercel Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hunk-web Ignored Ignored Preview Sep 1, 2026 3:36am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR introduces a runtime-neutral lifecycle clock and threads one native instance through session startup, daemon polling, authentication, heartbeat, and reconnect scheduling.

  • Adds native one-shot, interval, current-time, and delay operations with idempotent timer disposal.
  • Replaces direct lifecycle timers with injected scheduling across the generic connection, Hunk client, and daemon launcher.
  • Adds deterministic clock-based lifecycle tests and documents the exported clock contract.

Confidence Score: 5/5

The PR appears safe to merge with no concrete changed-code failure identified.

Native behavior remains equivalent to the replaced timers, timer ownership is explicitly disposable, and the shared clock is consistently threaded through startup, launcher, and connection lifecycle paths with focused coverage.

Important Files Changed

Filename Overview
packages/session-broker/src/lifecycleClock.ts Adds the public runtime-neutral clock and a native implementation with unref'd timers and idempotent disposers.
packages/session-broker/src/connection.ts Routes handshake, heartbeat, and reconnect scheduling through the injected clock while preserving lifecycle cleanup.
src/session/broker/brokerClient.ts Owns one lifecycle clock and shares it with startup retries, daemon availability checks, and the generic connection.
src/session/broker/brokerLauncher.ts Uses the injected clock consistently for launch deadlines, health polling delays, and stale-lock timing.
src/ui/runInteractiveApp.tsx Composes the production lifecycle clock once at the interactive process boundary.
test/helpers/lifecycleClockTest.ts Adds deterministic one-shot and fixed-rate scheduling for lifecycle tests without patching global timers.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  UI[Interactive process] --> Clock[Native lifecycle clock]
  Clock --> Client[SessionBrokerClient]
  Client --> Startup[Startup retry]
  Client --> Launcher[Daemon launch and health polling]
  Client --> Connection[SessionBrokerConnection]
  Connection --> Handshake[Authentication deadline]
  Connection --> Heartbeat[Heartbeat interval]
  Connection --> Reconnect[Reconnect delay]
  Client --> Stop[Client stop]
  Stop --> Startup
  Stop --> Connection
Loading

Reviews (1): Last reviewed commit: "refactor(session): inject a lifecycle cl..." | Re-trigger Greptile

Base automatically changed from refactor/session-startup-states to main September 1, 2026 03:33
@benvinegar
benvinegar force-pushed the refactor/session-lifecycle-clock branch from 68ab759 to 4879381 Compare September 1, 2026 03:33
@benvinegar
benvinegar merged commit c828427 into main Sep 1, 2026
12 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.

1 participant