Repository navigation
Show active (compute) time alongside wall-clock in Status (#147) - #164
Conversation
anilmurty
left a comment
There was a problem hiding this comment.
Review: ✅ Approve pending rebase + CI
Implementation is sound. Please rebase first — PR #163 merged a few minutes ago and touched both ui/index.html and tests/unit/test_lens_ui_regression.py, the same files this PR edits. CI hasn't run yet because of the conflict state; once rebased and re-pushed, CI should go green and this is ready to merge.
Strengths
Honest semantic split. Active = compute work (Σ span durations); Elapsed = wall-clock. The UI tooltip copy explicitly explains "Resumed Claude Code sessions span days, so this can be far larger than Active time." That's exactly the framing #147 (and #141's finding #18) asked for — no more "3087m" reading as a runaway session.
None not 0 when there are no spans. session_active_seconds() returns None for the missing-data case so callers can omit the field rather than display a misleading zero. The docstring explicitly justifies this — good honesty discipline.
Layered test coverage — every layer doing a different job, no redundancy:
tests/unit/test_db_helpers.py(NEW) — the SQL helper itself, including "no spans" and "unknown session_id" branchestests/integration/test_api.py— API contract (active_secondsin payload, distinct fromduration_seconds)tests/integration/test_cli.py— CLI JSON shape carries both fieldstests/unit/test_lens_ui_regression.py— locksActive/Elapsedlabels in, asserts the misleading bareDurationlabel is gone
fmtDurLong coarse formatter does its job. 2d 3h instead of 3087m for resumed sessions. The threshold (≥1h shows hours-up; otherwise minutes-and-seconds) means a real 12-minute Active span still renders fine-grained while a 51-hour Elapsed span reads naturally.
MCP was correctly left out of scope. get_status proxies the API and reads explicit fields — the new active_seconds field passes through transparently. Good situational awareness.
Built in an isolated worktree (/tmp/tj-147-wt). CLAUDE.md Rule 20 / Working-with-Concurrent-Agents guidance followed.
Two non-blocking nits
-
CLI label could read
Time:for parity. The CLI now rendersDuration: active 12m 3s · elapsed 2d 3h. Both are durations of different kinds, so the label is technically fine — butTime:would be slightly more honest given the line shows two semantically-distinct measures. Pure copy nit. -
JS
fmtDurLongvs Python_fmt_dur(coarse=True). Two helpers doing the same conceptual job. JS could mirror the Python pattern (fmtDur(ms, { coarse: true })instead of a separate function). Minor symmetry thing, not blocking.
To merge
- Rebase / merge
maininto the branch (#163'sui/index.htmlandtest_lens_ui_regression.pychanges are now in main and will overlap) - Re-push, wait for CI
- The conflict resolution should be mechanical — both PRs only add new functions/tests to those files, not modify existing lines
Ready when CI's green.
The Status surfaces showed only wall-clock `Duration` (ended_at − started_at), so a resumed Claude Code session read as a 51h runaway. Active time (Σ span duration_ms) already lives in the data — now surfaced everywhere Status renders. - core/db.py: `session_active_seconds(conn, session_id)` — sum of span durations in seconds; None when the session has no timed spans. - /api/v1/status: payload carries `active_seconds` next to `duration_seconds`. - UI status tile: new "Active" row (compute time) + the wall-clock row relabeled "Elapsed", each with an explanatory tooltip. Added `fmtDurLong` so multi-day spans render "2d 3h" instead of "3087m". - CLI `tj status`: replaced the misleading inline "(3087m 0s)" with a "Duration: active 12m 3s · elapsed 2d 3h" row; both fields in --json. Tests: core helper unit tests, /api/v1/status active_seconds, CLI --json fields, and a Lens UI regression pinning the Active/Elapsed labels + fmtDurLong. ruff + mypy clean; full suite 768 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TAC3wG18qq93ec7NFHCeRM
29485b2 to
efe4648
Compare
|
Rebased onto latest The only conflict was in ruff clean; full suite 772 passed (includes #163's tests). Branch now sits directly on top of (Left the non-blocking JS/Python helper-symmetry nit as-is per your "not blocking".) |
TokenJam v0.4.1 — concurrency + cycle-aware run-rate + Reuse HTTP fallback + quality follow-ups across the Lens UI. ## What's in 0.4.1 Six issues closed, all branched off main as separate PRs that landed cleanly: | Issue | PR | What | |---|---|---| | Metabuilder-Labs#138 | Metabuilder-Labs#158 | Run-rate honors `[budget.<provider>] cycle_start_day` (per-tier `cycle_bounds` extracted into `core/cycle.py`, shared with `budget_projection`) | | Metabuilder-Labs#124 | Metabuilder-Labs#161 | Daemon DB concurrency: `DuckDBBackend.conn` is now a per-thread DuckDB cursor (`threading.local`) over one shared database. Cursors are independent connections safe for concurrent use, so the Overview fan-out + sync read routes in Starlette's threadpool no longer crash under load. | | Metabuilder-Labs#139 | Metabuilder-Labs#163 | `buildCostSeries` coarsens up an `hour → day → week` ladder instead of silently emptying long windows (closed-form bucket count, never allocates an oversized array). Same PR reverts the Overview's sequential-fetch workaround to `Promise.all` with deliberately-asymmetric error handling (`/cost` no-catch; the other five panels carry per-call fallbacks). | | Metabuilder-Labs#147 | Metabuilder-Labs#164 | `tj status` shows active (compute) time alongside wall-clock elapsed (`session_active_seconds` = Σ span durations). Both CLI and Lens Status tile rendered, plus `--json` carries both fields. `fmtDurLong` reads multi-day spans as `2d 3h` instead of `3087m`. | | Metabuilder-Labs#154 | Metabuilder-Labs#165 | New `GET /api/v1/reuse/clusters` endpoint + `ApiBackend.fetch_reuse_clusters` lets `tj report --reuse` work when the daemon holds the DB lock. Dedicated endpoint (not bolted onto `/optimize`) so per-cluster planning text isn't paid for on every 30s Overview poll. | | Metabuilder-Labs#162 | Metabuilder-Labs#166 | Recoverable Waste tile consistency: title-cased fallback for unknown analyzer names (`reuse` now renders as `Reuse`), em-dash dropped from the not-ready content line, regression guard locks all three states so the bold-title issue can't recur. | ## Pre-release verification Walked the focused 10-step v0.4.1 checklist via a sub-agent (`tests/agent-pre-release-v0.4.1.md`). Result: **10/10 PASS, 0 FAIL, 0 UNCLEAR**. Full log committed at `tests/results/agent-pre-release-v0.4.1-20260620T002546Z.md`. Validated end-to-end against the live daemon: - 90 concurrent reads against the Overview endpoint set: no SIGABRT, no 500s (was the Metabuilder-Labs#124 reproduction) - `tj cost` cache columns show non-zero values with daemon up (was 0 pre-Metabuilder-Labs#153) - `/api/v1/cost` returns a `cycle` block; UI consumes it - `tj status` shows `active 12m 3s · elapsed 2d 3h`; JSON carries both fields - `tj report --reuse` writes HTML + Markdown with the daemon running (was the Metabuilder-Labs#154 error) - Recoverable Waste tile titles render uniformly and "Reuse" is title-cased ## What's in this commit - `pyproject.toml`: `version = "0.4.1"` - `sdk-ts/package.json`: `"version": "0.4.1"` - `tests/agent-pre-release-v0.4.1.md`: the focused 10-step checklist used to validate this release - `tests/results/agent-pre-release-v0.4.1-20260620T002546Z.md`: the agent-run log proving 10/10 PASS Tests: 689 pass locally; mypy + ruff clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #147.
Problem
The Status tile showed only wall-clock
Duration(ended_at − started_at). Claude Code sessions resume across days, so a tile readingDuration: 3087m(~51h) looks like a runaway session when the agent was actually active for minutes. Active time (Σ spanduration_ms) already exists in the data — it just wasn't surfaced.Fix
Surface active (compute) time alongside the wall-clock value across every Status surface:
core/db.py—session_active_seconds(conn, session_id): sum of span durations in seconds; returnsNonewhen the session has no timed spans (so callers omit rather than show a misleading0)./api/v1/status— payload now carriesactive_secondsnext toduration_seconds.ui/index.html) — new Active row (compute time) + the wall-clock row relabeled Elapsed, each with an explanatory tooltip. AddedfmtDurLongso multi-day spans render2d 3hinstead of3087m.tj status— replaced the misleading inline(3087m 0s)with aDuration: active 12m 3s · elapsed 2d 3hrow; both fields included in--json.Example CLI output for a resumed session (12m active, 51h elapsed):
Scope note
The issue scoped UI + API; I also applied it to
tj status(CLI) since it had the identical defect. MCPget_statusproxies the API and maps explicit fields, so it's unaffected (the new field is simply not mapped) — left out of scope.Verification
ruff check tokenjam/✅ ·mypy✅ · full suite 768 passed ✅/api/v1/statusactive_seconds, CLI--jsonfields, and a Lens UI regression pinning the Active/Elapsed labels +fmtDurLong(and asserting the bare "Duration" label is gone).test_ui_offline.py) still green — no external loads added.🤖 Generated with Claude Code