Repository navigation
feat(tui): show each story's worked time in the task table #1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,6 +255,15 @@ def __init__(self, run_dir: Path): | |
| # FAULT keeps the offset — only genuine absence or a shrink (truncation / | ||
| # rewrite) restarts from zero — so recovering re-reads nothing twice. | ||
| self.fault: str | None = None | ||
| # How many times the reader has gone back to the start after reading | ||
| # something: a fold over every row (`StoryClocks`) must start over when | ||
| # this moves, or the rows read again are folded twice. | ||
| self.restarts = 0 | ||
|
|
||
| def _restart(self) -> None: | ||
| if self._offset: | ||
| self.restarts += 1 | ||
| self._offset = 0 | ||
|
|
||
| def read_new(self, *, pin: RunState | None = None) -> list[dict[str, Any]]: | ||
| entries = self._read_new() | ||
|
|
@@ -292,19 +301,19 @@ def _read_new(self) -> list[dict[str, Any]]: | |
| return [] | ||
| self.fault = None | ||
| if sig is None: | ||
| self._offset = 0 | ||
| self._restart() | ||
| return [] | ||
| size = sig[1] | ||
| if size < self._offset: | ||
| self._offset = 0 | ||
| self._restart() | ||
| if size == self._offset: | ||
| return [] | ||
| try: | ||
| with self.path.open("rb") as f: | ||
| f.seek(self._offset) | ||
| chunk = f.read(size - self._offset) | ||
| except (FileNotFoundError, NotADirectoryError): | ||
| self._offset = 0 # gone between the stat and the open: absence | ||
| self._restart() # gone between the stat and the open: absence | ||
| return [] | ||
| except OSError as e: | ||
| self.fault = f"journal.jsonl unreadable ({_describe(e)})" | ||
|
|
@@ -331,6 +340,206 @@ def _read_new(self) -> list[dict[str, Any]]: | |
| return entries | ||
|
|
||
|
|
||
| # ------------------------------------------------------------- story clocks | ||
|
|
||
| # Journal kinds that start a task's clock from zero: a fresh pick, a sweep bundle, | ||
| # or a standalone replay of a kept unit (`unitreplay`, which picks no story). | ||
| _CLOCK_START_KINDS = frozenset({"story-start", "bundle-start", "unit-replay-start"}) | ||
| # A resume that restarts a task's work from scratch: it starts over a clock the | ||
| # task already has, and starts none of its own; a task with no clock yet (a sweep's | ||
| # triage or migration leg, or a blocked task re-run through `resolve`, none of | ||
| # which gets a start row) gets one at its first `session-start` instead. | ||
| _CLOCK_RESTART_KIND = "resume-restart" | ||
| # Kinds that stop a task's clock for good, unless later work on it reopens it. | ||
| _CLOCK_END_KINDS = frozenset( | ||
| { | ||
| "story-done", | ||
| "story-escalated", | ||
| "story-deferred", | ||
| "story-skipped", | ||
| "story-awaiting-operator", | ||
|
Comment on lines
+356
to
+360
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With worktree isolation enabled, a non-spawn Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 3bd15a1: |
||
| # worktree isolation defers a unit it cannot mount without a story-deferred | ||
| "worktree-open-failed", | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| ) | ||
| # A sweep's triage and migration legs end with a row that names no task: the | ||
| # leg's task key (`sweep.TRIAGE_KEY`, plus `-<cycle>` from the second triage | ||
| # cycle on, and `sweep.MIGRATE_KEY`) by the kind that ends it. Spelled out | ||
| # rather than imported: `sweep` is heavy and this module stays import-light. | ||
| _SWEEP_LEG_END_KINDS = {"sweep-triage-result": "sweep-triage", "sweep-migrated": "sweep-migrate"} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a pre-upgrade migration ( Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing: this needs a pre-upgrade migration resumed after a manual ledger repair that then finds nothing to convert. None of the run journals I checked contain a migration at all, so I'm keeping the PR to paths real runs take. |
||
| # Kinds after which an ended task is being worked again (a resume that carries on | ||
| # rather than restarting): its clock carries on from the time it already showed. | ||
| _CLOCK_REOPEN_KINDS = frozenset( | ||
| { | ||
| "session-start", | ||
| "resume-review", | ||
| "resume-verify", | ||
| "resume-reverify", | ||
| "resume-commit", | ||
| "resume-env-dispatch", | ||
| } | ||
| ) | ||
|
Comment on lines
+372
to
+381
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a deferred or escalated task continued through Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 52dd57e: |
||
| # Kinds that hold every clock until the next `run-resume`. | ||
| _RUN_HOLD_KINDS = frozenset({"run-paused", "run-stop"}) | ||
| # Rows the resuming process writes ahead of its `run-resume` (`cli.cmd_resume`): | ||
| # not a sign the previous engine was alive, so they never move the cutoff a | ||
| # resume after an unrecorded engine death holds the clocks from. | ||
| _RESUME_PRELUDE_KINDS = frozenset( | ||
| {"root-identity-recorded", "root-identity-rebound", "rearm-code-root-restamped"} | ||
| ) | ||
|
|
||
|
|
||
| def _entry_ts(entry: Mapping[str, Any]) -> float | None: | ||
| """An entry's finite numeric `ts`, or None (a malformed or unreadable row).""" | ||
| raw = entry.get("ts") | ||
| if not isinstance(raw, (int, float)) or isinstance(raw, bool): | ||
| return None | ||
| try: | ||
| stamp = float(raw) | ||
| except OverflowError: | ||
| return None | ||
| return stamp if math.isfinite(stamp) else None | ||
|
|
||
|
|
||
| @dataclass | ||
| class _Clock: | ||
| """One task's clock: `worked` seconds banked, and the wall time the current | ||
| counting stretch began (`since`), None while the clock is held.""" | ||
|
|
||
| worked: float = 0.0 | ||
| since: float | None = None | ||
| ended: bool = False | ||
| quota_wait: bool = False | ||
|
|
||
|
|
||
| class StoryClocks: | ||
| """Wall time each task in a run has spent being worked, folded from its | ||
| journal one batch at a time, for the task table's `time` column. | ||
|
|
||
| A clock starts at zero on `story-start` / `bundle-start` / | ||
| `unit-replay-start`, or at the first `session-start` of a task that has | ||
| none (a sweep's triage or migration leg, a blocked task re-run through | ||
| `resolve`), and starts over on a `resume-restart` of a task that has one, | ||
| since the work starts over. | ||
|
|
||
| It holds while the run is paused or stopped (`run-paused` / `run-stop` | ||
| until `run-resume`) and while the task's own session waits out a usage-limit | ||
| reset (`quota-wait-started` until `quota-wait-ended`, or until a | ||
| `run-resume`: a wait the engine died in is never closed). A `run-resume` | ||
| with no hold before it follows an engine that died without a record: the | ||
| clocks are held from the last entry before it, the run's last sign of life | ||
| (the resuming process's own prelude rows excepted). | ||
|
|
||
| A clock stops on the task's terminal kind (done, escalated, deferred, | ||
| skipped, awaiting-operator, worktree-open-failed, or the triage / migration | ||
| leg's result row); a later session or carry-on resume for that task reopens | ||
| it where it stopped. | ||
|
|
||
| Fed every journal entry from the start (the dashboard keeps only a bounded | ||
| tail, so this folds as it goes). Pure: no I/O, never raises on a malformed | ||
| entry; an entry without a finite `ts` or a string `kind` is skipped.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self._clocks: dict[str, _Clock] = {} | ||
| self._task_story: dict[str, str] = {} # session task_id -> story key | ||
| self._held = False | ||
| self._last_ts: float | None = None | ||
|
|
||
| def feed(self, entries: list[dict[str, Any]]) -> None: | ||
| for entry in entries: | ||
| ts = _entry_ts(entry) | ||
| kind = entry.get("kind") | ||
| if ts is None or not isinstance(kind, str): | ||
| continue | ||
| self._apply(entry, kind, ts) | ||
| if kind not in _RESUME_PRELUDE_KINDS: | ||
| self._last_ts = ts if self._last_ts is None else max(self._last_ts, ts) | ||
|
|
||
| def elapsed(self, now: float | None) -> dict[str, float]: | ||
| """Seconds per task key. `now` is the wall time a running clock counts | ||
| up to; None (a run with no live engine) stops running clocks at the last | ||
| journal entry instead.""" | ||
| until = now if now is not None else self._last_ts | ||
| out: dict[str, float] = {} | ||
| for key, clock in self._clocks.items(): | ||
| total = clock.worked | ||
| if clock.since is not None and until is not None: | ||
| total += max(0.0, until - clock.since) | ||
| out[key] = total | ||
| return out | ||
|
|
||
| def _counting(self, clock: _Clock) -> bool: | ||
| return not (clock.ended or clock.quota_wait or self._held) | ||
|
|
||
| @staticmethod | ||
| def _hold(clock: _Clock, ts: float) -> None: | ||
| if clock.since is not None: | ||
| clock.worked += max(0.0, ts - clock.since) | ||
| clock.since = None | ||
|
|
||
| def _release(self, clock: _Clock, ts: float) -> None: | ||
| if clock.since is None and self._counting(clock): | ||
| clock.since = ts | ||
|
|
||
| def _apply(self, entry: dict[str, Any], kind: str, ts: float) -> None: | ||
| raw_key = entry.get("story_key") | ||
| key = raw_key if isinstance(raw_key, str) and raw_key else None | ||
| if kind in _CLOCK_START_KINDS or kind == _CLOCK_RESTART_KIND: | ||
| if key is not None and (kind in _CLOCK_START_KINDS or key in self._clocks): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a stories-mode run first encounters a blocked or sentinel story, Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in f70896d: a task with no clock now gets one at its first session-start, so a resolved wedged story is timed. |
||
| clock = self._clocks[key] = _Clock() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a sweep resumes an accepted Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not changing: sweeps have no spec-approval gate ( |
||
| self._release(clock, ts) | ||
| return | ||
| if kind == "session-start": | ||
| task_id = entry.get("task_id") | ||
| if key is None and isinstance(task_id, str) and task_id: | ||
| key = _story_key_from_task_id(task_id, str(entry.get("role") or "")) | ||
| if isinstance(task_id, str) and task_id and key is not None: | ||
| self._task_story[task_id] = key | ||
| if key is not None and key not in self._clocks: | ||
| clock = self._clocks[key] = _Clock() | ||
| self._release(clock, ts) | ||
| if kind in _SWEEP_LEG_END_KINDS: | ||
| leg = _SWEEP_LEG_END_KINDS[kind] | ||
| for name, clock in self._clocks.items(): | ||
| if name == leg or name.startswith(leg + "-"): | ||
| self._hold(clock, ts) | ||
| clock.ended = True | ||
| elif kind in _CLOCK_END_KINDS: | ||
| clock = self._clocks.get(key) if key is not None else None | ||
| if clock is not None: | ||
| self._hold(clock, ts) | ||
| clock.ended = True | ||
| elif kind in _CLOCK_REOPEN_KINDS: | ||
| clock = self._clocks.get(key) if key is not None else None | ||
| if clock is not None and clock.ended: | ||
| clock.ended = False | ||
| clock.quota_wait = False | ||
|
Comment on lines
+514
to
+516
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the engine dies without closing a quota wait during a review/fix continuation after Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 6c24926: |
||
| self._release(clock, ts) | ||
| elif kind in ("quota-wait-started", "quota-wait-ended"): | ||
| task_id = entry.get("task_id") | ||
| story = self._task_story.get(task_id) if isinstance(task_id, str) else None | ||
| clock = self._clocks.get(story) if story is not None else None | ||
| if clock is not None: | ||
| self._hold(clock, ts) | ||
| clock.quota_wait = kind == "quota-wait-started" | ||
| self._release(clock, ts) | ||
| elif kind in _RUN_HOLD_KINDS: | ||
| for clock in self._clocks.values(): | ||
| self._hold(clock, ts) | ||
| self._held = True | ||
| elif kind == "run-resume": | ||
| if not self._held and self._last_ts is not None: | ||
| for clock in self._clocks.values(): | ||
| self._hold(clock, self._last_ts) | ||
|
Comment on lines
+531
to
+533
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After an unrecorded engine death followed by a carry-on resume, root-identity reconciliation can defeat the downtime exclusion. In Useful? React with 👍 / 👎.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 52dd57e: |
||
| self._held = False | ||
| for clock in self._clocks.values(): | ||
| # A quota wait still open here belonged to a session of the engine | ||
| # that stopped; it never writes its `quota-wait-ended`, and a wait | ||
| # the resumed engine meets is journaled afresh. | ||
| clock.quota_wait = False | ||
| self._release(clock, ts) | ||
|
|
||
|
|
||
| # Pane geometry mirrors adapters.generic PANE_COLUMNS/PANE_LINES (not | ||
| # imported: that module drags in Policy/SignalWatcher, and this layer stays | ||
| # a pure observer). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a sweep resumes mid-triage,
SweepEngine._ensure_triage()emitsresume-restart, which creates a clock forsweep-triage. However,_accept_triage_plan()marks that task DONE and emitssweep-triage-result, not any of these story terminal events. The completed triage row therefore keeps accumulating time throughout subsequent bundle execution and reports the rest of the sweep as triage work. Handle the sweep task's actual completion signal and associate it with the corresponding triage key.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 52dd57e:
resume-restartnow only resets a clock a start row opened, so triage/migrate tasks get none (-).