feat(tui): Phase 1 — Observer foundation, scheduler slots, history - #73
Merged
Conversation
Orchestrator-side scaffolding for the TUI. No renderer yet (Phase 2);
the surface is renderer-agnostic so the same Observer can feed a
future `vx ui` historical browser and embedder use cases.
Five additions, no behavior change for non-TUI runs:
1. `src/orchestrator/observer.ts` — tagged-union ObserverEvent
(runStart, taskStart, taskStdout/Stderr, cacheProbe, taskComplete,
remoteCache, runEnd), Observer interface, makeSafeObserver wrapper
that swallows throws so a buggy consumer never crashes the run.
Logger stays parallel (terminal framed-block output); Observer is
the structural sink.
2. RunOptions.observer wired through orchestrator.run(). Emit sites:
runStart after header; taskStart from scheduler onStart(node, slot);
cacheProbe in execute-task after cache.get(hash); taskComplete from
scheduler onFinish; runEnd after formatRunSummary.
3. Scheduler now allocates lowest-free-index worker slots and passes
`slot: number` to execute() + onStart(). Stable allocation so a
future Workers view renders [1] always-busy / [N] idle-gap visibly.
4. Cache.getTaskHistory(taskIds) — one batched SQL CTE with
ROW_NUMBER() OVER (PARTITION BY project, task) capped at 50 per
pair. Threaded through prepareRun so runStart carries a
HistoryTable for every node (cheap; sub-ms in practice).
5. LayeredCacheOptions.onRemoteRequest fires for every GET/PUT with
{ op, hash, bytes?, latencyMs, ok }. wrapWithRemoteCache forwards
it into observer.emit({ kind: 'remoteCache', ... }).
Tests: 414 → 434. New: 5 observer, 5 scheduler-slot, 4 cache-history,
3 layered-cache callback, 3 orchestrator end-to-end observer.
https://claude.ai/code/session_016HXj6HW6bxSn8EYuKcxTD9
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
Phase 1 of the TUI roadmap (specced in PR #72): orchestrator-side
scaffolding. No renderer in this PR — the surface is
renderer-agnostic so the same Observer can feed a future
vx uihistorical browser and embedder use cases. Phase 2 (OpenTUI
components +
--tuiflag) builds on top.No behavior change for non-TUI runs. Tests: 414 → 434.
What ships
src/orchestrator/observer.ts— tagged-unionObserverEvent(
runStart|taskStart|taskStdout|taskStderr|cacheProbe|taskComplete|remoteCache|runEnd), anObserverinterface, andmakeSafeObserver(inner)that swallowsthrows from
inner.emitso a buggy consumer never crashes the run.Logger stays parallel — it owns terminal framed-block output;
Observer is the structural sink.
RunOptions.observerwired throughorchestrator.run().Emit sites match the design doc (
docs/design/tui-design.md§3):runStartafter header writes.taskStartfrom the scheduler'sonStart(node, slot).cacheProbefromexecute-task.tsaftercache.get(hash)(
hit-local|hit-remote|miss|no-cache).taskCompletefrom scheduler'sonFinish.runEndafterformatRunSummary, before--summarize/--profilewrites.Scheduler worker-slot allocation.
runGraphnow allocateslowest-free-index slots from
[0, concurrency)and passesslot: numbertoexecute()+onStart(). Stable allocation soa future Workers view renders
[1]always-busy /[N]idle-gapvisibly across runs.
Cache.getTaskHistory(taskIds)— one SQL CTE withROW_NUMBER() OVER (PARTITION BY project, task)capped at 50 rowsper pair. Returns
TaskHistoryMapofruns / avg / p50 / p99 / successRate / hitRate / recent[10]. Threaded throughprepareRunso the
runStartevent carrieshistoryTablepopulated for everynode in the graph (cheap; one batched read).
LayeredCacheOptions.onRemoteRequestcallback fires for everyremote GET/PUT with
{ op, hash, bytes?, latencyMs, ok }.wrapWithRemoteCache(local, log, observer)forwards it intoobserver.emit({ kind: 'remoteCache', ... }).Test plan
bun src/bin.ts run format— cleanbun src/bin.ts run lint— 0 warnings, 0 errorsbun src/bin.ts run test— 434 pass, 0 failtests/observer.test.ts), 5 scheduler-slot(
tests/scheduler.test.ts), 4 cache-history(
tests/cache.test.ts), 3 layered-cache callback(
tests/layered-cache.test.ts), 3 end-to-end observer wiring(
tests/orchestrator.test.ts)https://claude.ai/code/session_016HXj6HW6bxSn8EYuKcxTD9
Generated by Claude Code