Skip to content

Move the engine seam and the sync orchestration to Effect - #301

Merged
DocksDocks merged 11 commits into
mainfrom
294-move-the-engine-seam-and-the-sync-orchestration-to-effect
Dec 2, 2026
Merged

DocksDocks merged 11 commits into
mainfrom
294-move-the-engine-seam-and-the-sync-orchestration-to-effect

Conversation

@DocksDocks

Copy link
Copy Markdown
Owner

Plan run: #294 Move the engine seam and the sync orchestration to Effect

Child of #290 (step seam). Reviewed head: fe26962c. Checks: see the pull request.

What changed

  • New cli/src/engine-native/bridge.ts: bridgeSync and bridgePromise run code that is not Effect yet as Effect.uninterruptible over Effect.try and Effect.tryPromise, with the typed failure LegacyStepFailed. Move the process layer, the file helpers, and the kit store to Effect #297 removes the file.
  • runEngineNative returns an Effect with the typed failures LegacyStepFailed, LockAcquireError, KitHomeInvalid, and LeaseHeld. cli/src/engine.ts maps each failure and each defect to the same user text as before.
  • EngineContext is a Context.Service that holds the plain run context. The terminal lease is a scoped resource, and withExclusive uses a one-permit semaphore.
  • syncDispatch.ts: the home lock and the folder locks are scoped resources in one scope. ompSync.ts and modes.ts run as Effect code with bridges.
  • Signals: while an engine run is active, SIGINT and SIGTERM exit at once. The public channel exits 130 for both signals; the raw channel exits 130 for SIGINT and 143 for SIGTERM, as before.
  • The logger stays synchronous; a write error that is not EPIPE still throws at once.
  • Guidance: DESIGN.md and the engine, sync, omp, host, and tidy skills describe the Effect seam.
  • Tests: bridge.test.ts, syncPipelineFailure.test.ts, syncSignals.test.ts (POSIX), and larger logger, syncLock, and engine suites. The signal suite runs the CLI under a supervisor in a fixture root that no sweep removes. No fixture process sends a signal to another process.
  • No version bump: the behavior that users see does not change.

Delegated decisions

  • Bridge rule in one module (bridge.ts). Rejected: inline bridges. Reversibility: Move the process layer, the file helpers, and the kit store to Effect #297 deletes it. Record: Research "One bridge module".
  • The ledger recordFailure stays a synchronous append until Move the omp passes and the kit store to Effect #296. Record: Research "The ledger".
  • Each lock retry opens its own SQLite connection (2400 cycles in 74 ms). Rejected: a shared connection. Record: Research "Lock retries".
  • Signals exit at once during an engine run; Move the process layer, the file helpers, and the kit store to Effect #297 owns the fiber cutover. Record: Research "Signals".
  • Signal test fixture: signals come only from inside the CLI process (a test-only preload); cleanup uses request files, stub tickets, and a non-recursive rmdir; an unconfirmed root stays in the system temporary folder. Rejected: kills of saved process ids or group ids. Record: Research "Signal test fixture", after the second stall and the user answer Continue yolo.

Reviews

Verification (on fe26962c)

  • unit (14 files): exit 0, 247 passed. toggles: exit 0, 91 passed. signals: exit 0, 6 passed.
  • goldens: both suites OK, no golden change. red-dry, red-mut: exit 1 with prove-red OK.
  • dry (./docks-kit sync --dry-run), types (bun run check:types), ci-tools, smoke (bun run smoke:package): exit 0.
  • gate (bun run check): exit 0, 6493 passed, 12 skipped.
  • No fixture root and no fixture process was left after the runs.

Limits and failures

  • Local checks ran on Linux x64 only; Full CI covers Ubuntu, macOS, and Windows. The signal suite is POSIX only.
  • Two code-review stalls on the signal fixture; the user answered Continue yolo once.
  • Some bun run check runs of the implementer failed once under load (talk/transport.test.ts, a vitest cache file); each file passed alone, and the rerun passed.

Kept resources

  • After Merge now: none.
  • After Leave pull request open: the worktree issue-294 and the local and remote branch 294-move-the-engine-seam-and-the-sync-orchestration-to-effect.

After merge

Checklist

  • bun run check passes
  • Tested locally end to end (unit, toggles, signals, goldens, prove-red, dry, types, ci-tools, smoke, gate)
  • Code review passed

Closes #294

- bridgeSync and bridgePromise run a legacy call as Effect.uninterruptible over Effect.try or
  Effect.tryPromise, with the typed LegacyStepFailed (step, message, cause), so an interrupt waits
  until the legacy work settles and no scope closes under it (#290, bridge rule D1).
- Tests: an interrupt during a bridged Promise ends only after it settles; a rejection or a throw
  becomes LegacyStepFailed with its step and message.

Verified: bun x --no-install vitest run (unit and toggles rows of plan #294); bun run check:types; bun cli/scripts/verify-ci-tools.ts; bun run golden:dryrun --prove-red; bun run golden:mutation --prove-red; bun run smoke:package; ./docks-kit sync --dry-run; bun run check
Steps lease and seam of #294 (one commit: syncDispatch consumes the new lease API):
- logger.ts: acquireTerminal is a scoped resource (LeaseHeld); withExclusive takes an Effect under
  a one-permit Semaphore and fails with LeaseReentered before it waits. The write rethrows stay.
- runEngineNative returns an Effect over the engine layers and FileSystem; help, usage refusals,
  and an invalid lock wait are typed failures turned into their exit codes; ExitError is gone.
- engineSync takes the home lock, resolves the folders under it, then takes the folder locks, in
  one scope, with the current sync poll (wall clock, deadline before preparation, last attempt).
- ompSync and modeToolchain are Effects; every call into later-owned code goes through bridge.ts.
- engine.ts and main.ts map each failure and defect to the same failure text as before.
- Tests move to the Effect run; a new case shows that an interrupt during a bridged pass keeps
  the home and folder locks until the pass settles.

Verified: bun x --no-install vitest run (unit and toggles rows of plan #294); bun run check:types; bun cli/scripts/verify-ci-tools.ts; bun run golden:dryrun --prove-red; bun run golden:mutation --prove-red; bun run smoke:package; ./docks-kit sync --dry-run; bun run check
- The ExitError, dispatch, lock-release, and failure-path rules, the run signature, the ompSync
  anchor, the lock of sync in tidy-context, and the parser and service-wiring entries of DESIGN.md.

Verified: bun x --no-install vitest run (unit and toggles rows of plan #294); bun run check:types; bun cli/scripts/verify-ci-tools.ts; bun run golden:dryrun --prove-red; bun run golden:mutation --prove-red; bun run smoke:package; ./docks-kit sync --dry-run; bun run check
- Signals: while an engine run is active, SIGINT or SIGTERM exits at once (public 130; raw 130 and
  143 as before); in-process interrupts still wait for bridged work. Spawned tests on POSIX.
- The seams report the later cleanup error when a finalizer throws after a failure, as finally did.
- Logger: atomic lease claim published after the first draw; per-section exclusive markers across
  loggers; a nullish buffered-write throw stays a failure.
- Bridge: failure text without coercion (unknown error); kitHome() through bridgeSync as KitHomeInvalid.
- Tests: both folder locks and no AGENTS.md write in the interrupt case, gated fibers settled in
  finally, TestClock deadline cases, the ledger before a failed pass, a public env-globals dry run,
  tryAcquireKitLock in the lock fixtures.
- Guidance: dispatch pointers, interrupt-only ledger skip, HelpShown, withExclusive usage.

Verified: bun x --no-install vitest run (unit, toggles, signals rows and syncPipelineFailure.test.ts); bun run check:types; bun run golden:dryrun; bun run golden:mutation; bun run check
- The engine-run signal listeners run first (prependListener), so a delivered signal exits 130.
- The signal test runs the CLI in its own process group, kills only that group in teardown,
  watches exit and spawn errors from launch, and runs a second sync to its end after the signal.
- failureText reads an Error message at most once and falls back to unknown error on any throw.
- acquireTerminal reserves the lease before the first draw, so a reentrant acquire gets LeaseHeld.
- The verbose dry-run test clears PI_CONFIG_DIR, OMP_PROFILE, and PI_PROFILE.
- Guidance: the mode-selection anchor, and the failed-pipeline ledger conditions in DESIGN.md,
  the sync-orchestration skill, and dispatch-flow.md.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, syncPipelineFailure.test.ts, skillMetadata.test.ts); bun run check:types; bun run golden:dryrun; bun run golden:mutation; bun run check
Repairs of code-review round 3 of #294:
- Teardown signals a saved group only while its leader CLI still runs, so a reused id is never hit.
- The waiting stub omp exits when its parent is gone or after 90 s, so a cancelled worker leaves
  no stub that holds the CLI and its locks.
- One case deadline; each phase gets only the time left.
- The reentry fixture sets its one-shot guard before the nested acquire runs.

Verified: bun x --no-install vitest run (unit, toggles, signals rows); bun run check:types; bun run check
Repairs of code-review round 4 of #294:
- A fixture supervisor leads its own process group, runs the CLI as its child, relays its pid and
  exit, and on control-pipe close stops the CLI and then its group; the worker signals no saved id.
- The stub captures its parent and arms its timers before readiness; a relative 90 s limit exits 1.
- One performance.now() case deadline.
- A spawned public run under BunRuntime.runMain with a failing logger finalizer, waiting at an
  interruptible lock sleep, exits 130 on one signal; it exits 1 when the listeners are appended.
- engineFailureDetail prints the message that LegacyStepFailed and KitHomeInvalid captured.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, skillMetadata.test.ts); bun run check:types; bun run check
Repairs of code-review round 5 of #294 (stall rule: new approach for process identity):
- The waiting stub signals its own verified parent CLI, and the listener-order entry signals itself,
  on a request file; the worker and the supervisor send no signal to any pid.
- The supervisor checks that it leads its group, kills only that group, and ends it on a failed
  report write or a stdout error as on stdin EOF.
- Fixture PATH holds only the stubs and Bun; graceful worker cancellation stops the supervisors
  before the temporary folders go (goldenResources registerBeforeTemporaryDirRemoval).
- Supervisor completion comes from close, which also follows a failed spawn.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, skillMetadata.test.ts); bun run check:types; bun run lint; bun run check
Repairs of code-review round 6 of #294, after the second stall (user: Continue yolo):
- A test-only preload in the CLI raises the requested signal on its own process; no fixture
  process signals another pid or group. Cleanup asks the CLI the same way.
- One fixture root per case (docks-kit-signal-fixture-, matched by no sweep) with its home, caches,
  stubs, launch folders, and a working folder with no .env; bun runs with --no-env-file; the CLI
  PATH holds only stubs.
- Stubs take a ticket in active/ and drop it as their last act; teardown removes the root only
  after every launch is confirmed and a non-recursive rmdir of active/ succeeds.
- goldenResources: stop callbacks run inside the promise boundary; stub folders can be placed.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, skillMetadata.test.ts); bun run check:types; bun run lint; bun run check
Repairs of code-review round 7 of #294:
- The supervisor publishes cli.pid atomically; the waiting stub waits for a valid record.
- Teardown handles only the fixtures of the current case; a kept root leaves tracking.
- A stub whose ticket create fails exits 1; ticket release is armed right after the create.
- Stubs write started and stub-exited records by invocation id; confirmation needs both.
- Ticket code is generated only for supervised stub folders (no ambient variable).
- A partial fixture root is removed on setup failure; cancellation prints its diagnostics.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, skillMetadata.test.ts); bun run check:types; bun run lint; bun run check
Repairs of code-review round 8 of #294:
- A stub releases its ticket by renaming it to its stub-exited record; a failed rename keeps it.
- A failed cli.pid publication asks the CLI to end and blocks confirmation; the waiting stub
  also stops when its parent changes.
- Overlapping teardown paths recheck tracking before retries and reports.
- Lifecycle comments list startup and exit actions in their real order.

Verified: bun x --no-install vitest run (unit, toggles, signals rows, skillMetadata.test.ts); bun run check:types; bun run lint; bun run check
@DocksDocks DocksDocks linked an issue Dec 2, 2026 that may be closed by this pull request
@DocksDocks
DocksDocks marked this pull request as ready for review December 2, 2026 01:28
@DocksDocks
DocksDocks merged commit c8024b5 into main Dec 2, 2026
10 checks passed
@DocksDocks
DocksDocks deleted the 294-move-the-engine-seam-and-the-sync-orchestration-to-effect branch December 2, 2026 01:36
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.

Move the engine seam and the sync orchestration to Effect

1 participant