Investigate why there are sometimes 0 steps indications in the @frontend/src/domains/platform/checkpoints/components/CommitList.tsx
Assistant
I'll investigate the source of session.steps to understand when it can be 0. Let me look at the relevant API/types and how steps is computed.
Assistant
The frontend just renders session.steps verbatim. The "0 steps" must originate in the API. Let me trace where steps is computed on the backend.
Assistant
Let me look at the specific code paths that feed the commits/checkpoints list rendered by CommitList.
Assistant
Now let me trace which path actually feeds CommitList — the commits endpoint — and how it builds each session's steps.
Assistant
Let me check what checkpoints_count represents in the committed metadata and confirm the 0 path.
Assistant
Let me verify against real data to confirm the source of 0 values.
Assistant
The checkpoint-level steps column is 0 in ~16% of rows, but no sessions JSON contains "steps":0. This points to the fallback path. Let me confirm.
Assistant
The per-session JSON itself stores steps: 0. So this is not the fallback path — it's the stored value. Let me check the time distribution to see whether it's a legacy issue or ongoing.
Assistant
I have the complete picture, confirmed against production data. Here's what's happening.
Why "0 steps" appears in CommitList.tsx
The frontend isn't computing anything wrong — line 228 renders session.steps verbatim:
Those sessions come from mapCheckpointToInfo → parseSessionsFromRow (api/src/lib/checkpoint-mapper.ts:25-35), which just deserializes the repo_checkpoints.sessions JSON column. The per-session steps is whatever was stored there.
That value was written by parseSessionMetadata (api/src/lib/github.ts:647):
ts
steps: parsed.checkpoints_count ?? 1,
The bug is the ?? 1. Nullish coalescing only substitutes 1 for null/undefined — it does not catch 0. So whenever a session's committed metadata.json has checkpoints_count: 0, it's persisted as steps: 0 and renders as "0 steps". (checkpoints_count is what the CLI calls the per-session checkpoint count; the UI relabels it "steps".)
Confirmed in production (entire-io DB)
54,237 of 341,847 checkpoints (~16%) have steps = 0.
All 54,237 have the zero stored inside the sessions JSON ("steps":0), not via the legacy fallback — e.g. checkpoint 1900c8c6134b has a real session with tokens, attribution, a full summary, prompt "brainstorm:", and steps: 0. So these are genuine sessions that simply recorded checkpoints_count: 0.
It's not legacy and it's growing:
Month
% steps=0
User
Is the steps count coming from the CLI?
Assistant
Let me verify rather than assert — I'll check whether the API ever computescheckpoints_count/steps itself, or only ever reads it from the committed metadata.
Assistant
Yes — confirmed. The steps count originates entirely from the CLI. The API never computes it; it only reads it.
The evidence:
checkpoints_count appears in exactly one non-type, non-test place in the whole API: api/src/lib/github.ts:647, and there it's read (parsed.checkpoints_count), never assigned. There is no code anywhere in api/ that calculates or sets it.
Where parsed comes from (github.ts:639): JSON.parse(metadataText) — and metadataText is the raw contents of a per-session metadata.json blob fetched straight from the checkpoint git repo via GitHub's GraphQL API (github.ts:850-953, expressions like …/0/metadata.json).
Those metadata.json files are committed into the repo by the entire CLI when it creates a checkpoint. The CLI is the producer of checkpoints_count; the API is purely a consumer.
So the full provenance of the number on screen is:
code
entire CLI → writes checkpoints_count into per-session metadata.json → git commit
↓ (GitHub GraphQL fetch)
API github.ts:639 JSON.parse(metadataText)
API github.ts:647 steps = parsed.checkpoints_count ?? 1 ← only transform; doesn't catch 0
↓ stored in repo_checkpoints.sessions JSON
API checkpoint-mapper.ts → SessionInfo.steps
↓
frontend CommitList.tsx:228 renders "{steps} steps"
The two ways the value goes wrong are therefore both attributable to the CLI side:
The CLI writes checkpoints_count: 0 for ~16% of sessions (rising to ~23% recently) — that's the actual source of the zeros. We saw real, fully-populated sessions (tokens, attribution, summaries) carrying checkpoints_count: 0.
The API's only contribution is the ?? 1 guard, which fails to normalize that 0 (nullish coalescing passes 0 through). A || 1 there would have masked it.
So if you want the count to actually be correct (not just non-zero), the fix belongs in the CLI — figure out why it emits checkpoints_count: 0. The API/frontend can only clamp the symptom.
Want me to dig into the CLI to find where checkpoints_count is set? That code isn't in this repo (this is entire.io-3 — the API/frontend), so I'd need a pointer to the CLI repo.
User
Instead of taking the count from the CLI we could also just count the user prompts between the checkpoint and the checkpoint before? With the only edge case that it could be "start of session".
Assistant
Good idea — let me check feasibility against the actual data model before forming an opinion. The key questions: where would we count prompts (write-time vs read-time), do we have transcript boundaries per checkpoint, and what counts as a "user prompt."
Assistant
Yes, that works, and it's arguably a better metric than what we show today — but there's one real constraint that decides where it has to live. Let me lay it out.
Your boundary model is already encoded in the data
You don't actually need to look back at the previous checkpoint explicitly. Every checkpoint's metadata already carries where its transcript slice starts:
checkpoint_transcript_start (offset) and/or transcript_identifier_at_start (UUID of the last message before this checkpoint began).
resolveTranscript() (api/src/lib/transcript-parsers/resolve.ts:28) already slices a transcript to "just this checkpoint's portion" using those fields.
That slice runs from the previous checkpoint's boundary to the end of the transcript at commit time — i.e. exactly "between this checkpoint and the one before." So:
isToolResultOnlyMessage (checkpoint-analysis-transcript.ts:211) already exists to exclude tool-result user messages, and the parser strips system reminders / command messages. So "real user prompts" is a clean, available signal — the analysis pipeline already groups on exactly this predicate (checkpoint-analysis-pipeline.ts:210).
Your "start of session" edge case is handled for free: the first checkpoint has start offset 0 / null identifier, so the slice is from the beginning and the count is correct.
The constraint: this can't be a read-time computation on the list
This is the important part. The /commits and /checkpoints list endpoints that feed CommitListdo not load transcripts — they read repo_checkpoints and map rows. Transcripts are fetched lazily (transcript endpoint, search indexing, detail hydration), and each fetch is a GitHub/R2 read + JSONL parse. Counting prompts in mapCheckpointToInfo would mean loading and parsing one transcript per checkpoint per page — not viable.
So the count has to be computed once where the transcript is already parsed, then persisted to a column the list reads cheaply. Concretely:
Compute + store during the paths that already parse transcripts — search indexing / analysis hydration (checkpoint-payload-hydrator.ts, checkpoint-analysis-pipeline.ts). Write into (overwrite) or a new column.
User
Investigate in the CLI why the steps count is wrong in the first place.
Assistant
The CLI is a separate Go repo (I saw cmd/entire/cli/... paths in the session data). Let me find it on this machine.
Assistant
The CLI is at /Users/dip/Repositories/cli. Let me dispatch a focused investigation into how checkpoints_count is computed there.
Assistant
Let me verify the core claims directly — the two write sites and the counter increment.
Assistant
Let me confirm the team's own acknowledgment and the reset behavior to round out the picture.
Assistant
Let me read the fallback comment for the team's own framing.
Assistant
I've traced it to the root cause in the CLI and verified every load-bearing line directly. Here's the answer.
Why the steps count is 0 in the CLI
The number shown as "steps" is the CLI's state.StepCount — a counter in the per-session local state file under .entire, written verbatim into metadata.json as checkpoints_count. It is not derived from commits, turns, or the transcript. It's incremented in exactly one place:
cmd/entire/cli/strategy/manual_commit_git.go:113
go
state.StepCount++ // inside SaveStep — runs when a hook records a checkpoint step + shadow-branch commit
The bug: a checkpoint can be written before SaveStep ever ran, so StepCount is still its zero value. There are two such paths, and both are growing in usage — which matches the rising 0% trend you saw (11% → 23%).
Cause 1 — mid-turn / "commit-only" sessions (the dominant one)
When a commit happens before any SaveStep step is recorded (agent commits mid-turn, no-TTY subprocess, or commit_linking="always"), the agent-commit fast path still stamps the checkpoint trailer and triggers condensation. Its skip gate (manual_commit_hooks.go:2054) only bails when all three are empty:
So a session with a live transcript but StepCount == 0 passes through, condenses via the live-transcript branch, and writes CheckpointsCount: 0. None of the condense gates ever check StepCount > 0. The team already knows about this case — manual_commit_hooks.go:1075:
// Sessions with checkpoints_count == 0 (e.g., commit-only sessions) use a fallback…
Cause 2 — entire attach never sets the field
attach.go:297-308 builds WriteCommittedOptions and simply omits , so it takes Go's zero value. attach checkpoint is by construction.
User
Let's ignore what's already broken for now and focus on the root cause instead. So there are 3 problems:
written before save step
entire attach ignores it entirely
condensation
Anything I missed?
Assistant
Good instinct to separate the structural causes from the historical mess. Before I confirm your three, let me check one thing that determines whether the list is complete: every code path that writes checkpoint metadata, not just the two we've looked at. If there's a third strategy/write path that also omits or mis-sets the field, it belongs on the list.
Assistant
No third write path — production checkpoint metadata is written from exactly two places (manual_commit_condensation.go:222 and attach.go:297; benchutil is a bench harness, and resume.go/explain_export.go/common.go only copy an existing value forward). So the write surface is fully enumerated. Let me verify one ordering question that determines whether there's a hidden fourth cause.
Assistant
Confirmed the ordering: the resets to 0 (condensation.go:1195/1287/1309) all happen in the callers, afterCondenseSession has already written the metadata — so there's no "reset-before-write" fourth bug. Good.
But having traced it fully, I'd push back on the framing slightly. You've got the symptoms right, but a couple of things are worth correcting/adding:
Your #1 and #3 are the same defect
Both flow through one line — CondenseSession (manual_commit_condensation.go:230) writes state.StepCountunconditionally, with no guard that a SaveStep ran in this window. StepCount is a per-condensation-window counter: SaveStep increments it (manual_commit_git.go:113), condensation reads it, then resets it to 0 for the next window. So it reads 0 in two situations:
new commit-only / mid-turn session — no SaveStep has run yet (your #1), and
a window that the previous condensation just reset — condensation fires again before any new SaveStep (your #3, "condensation").
Same code reading the same counter that happens to be 0. So it's really 2 root causes, not 3 (one condensation-counter defect with two triggers, plus attach) — unless you specifically want to track the two triggers separately, which is reasonable.
What you're actually missing (the deeper one)
The value is the wrong primitive, and it's already partly synthetic. Even when StepCount is non-zero it doesn't mean "steps" in any stable sense — it's "SaveStep hook firings since the last condensation reset." Two tells:
The carry-forward path hard-codes state.StepCount = 1 (manual_commit_hooks.go:2933) — the code already fabricates the value when it doesn't have a real one.
It resets every condensation, so it's a per-window count, not per-checkpoint or per-session — yet the API sums per-session steps as if they're stable counts.
So flooring 0 → max(1, …) at the two write sites fixes the zeros, but the number still won't be trustworthy. If "steps" is meant to convey how much work happened, this counter is structurally shaky no matter how many holes you plug — which is exactly why the transcript-turn approach we discussed is the durable answer.
One structural observation
Both write paths funnel through a single chokepoint — writeSessionToSubdirectory / WriteCommitted (, ). There's . A defensive floor at that one spot would catch both the condensation-counter case attach simultaneously, which is arguably the cleanest framing of the root cause:
User
Ok, but the counter is actually correct? Like the steps are counting prompts between checkpoints, with exception for first checkpoint in a session?
Assistant
Good question — let me verify what a "step" actually is rather than assume. I need to see what triggers SaveStep (the only incrementer) and whether each increment corresponds to one user prompt/turn.
Assistant
SaveStep has a single caller — lifecycle.go:746. Let me see what lifecycle event drives it (which hook), which tells us whether one step = one prompt/turn.
Assistant
Let me find which hook event drives this and confirm the one-per-turn semantics.
Assistant
SaveStep fires on agent.TurnEnd — once per turn. But there's a guard above it I need to check, plus a separate turn counter at line 1102. Let me read both.
Assistant
Now I can answer precisely — and the answer is no, not quite. There are actually two counters, and the one shipped as "steps" isn't counting prompts.
What StepCount (→ checkpoints_count → "steps") actually counts
SaveStep fires on agent.TurnEnd (once per turn), but only after a guard that skips turns with no file changes:
lifecycle.go:693-702
go
totalChanges := len(relModifiedFiles) + len(relNewFiles) + len(relDeletedFiles)
if totalChanges == 0 {
logging.Info(logCtx, "no files modified during session, skipping checkpoint")
transitionSessionTurnEnd(...)
return nil // ← returns BEFORE SaveStep, so StepCount does NOT increment
}
...
strat.SaveStep(ctx, stepCtx) // StepCount++ only reached here
So StepCount = number of file-modifying turns since the last condensation, not prompts between checkpoints. A turn where the agent only discusses, plans, investigates read-only, or answers a question increments nothing. A checkpoint that took 5 prompts of back-and-forth but changed files in only 2 of them shows "2 steps."
There's a separate counter that is turns
Right next to it, persistEventMetadataToState keeps SessionTurnCount:
lifecycle.go:1101-1109
go
// Use hook-reported turn count if available (take max); otherwise
// increment on each TurnEnd event to count turns ourselves.
if event.TurnCount > 0 {
if event.TurnCount > state.SessionTurnCount { state.SessionTurnCount = event.TurnCount }
} else if event.Type == agent.TurnEnd {
state.SessionTurnCount++
}
This counts every turn (or trusts the agent's reported turn count) — that's the thing closest to "prompts." But it's session-cumulative, and it's not what gets written into checkpoints_count. The field the UI shows is the file-modifying-turn counter.
User
Yeah, but we need prompts, not "file-modifications". Also if there are two checkpoints directly after another, instead of actually counting 0 for the second one, we count up until there are prompts in between checkpoints again. So basically the second checkpoint would have the same number of steps as the first.
So, we need to fix the two bugs + the counting.
Assistant
Got it — clear requirements. Let me restate to make sure we're aligned, then I'll map the remaining pieces I need before proposing the fix:
Target semantics: a checkpoint's "steps" = number of user prompts since the previous checkpoint that had prompts before it. Counting is prompt-driven (not file-change-driven), and the reset is deferred: a checkpoint doesn't zero the counter — the counter only restarts when the next prompt arrives. So two checkpoints with no prompt in between both report the same count.
Let me map the prompt lifecycle and state fields so the fix is grounded.
Assistant
This is a real implementation task with subtle state-machine semantics. Let me look at the TurnStart handler (the natural "a prompt arrived" signal) and the condensation reset sites before proposing the design.
Assistant
Two more checks to make the plan accurate: where persistEventMetadataToState runs relative to the file-change gate, and what prompts is in attach.
Assistant
I now have the full picture. Two key confirmations:
SessionTurnCount already counts every turn/prompt (not file-gated): both the no-change path (lifecycle.go:696) and the checkpoint path (:768) call transitionSessionTurnEnd → persistEventMetadataToState → the turn increment (:1107). It also has an exec-mode fallback via the hook-reported event.TurnCount (:1103) — important because some agents (Factory AI, etc.) never fire UserPromptSubmit/TurnStart.
attach only ever has [meta.FirstPrompt] (attach.go:282-285) — so at most 1 prompt is known there.
This is a substantive change to the CLI's counting state machine with real edge cases, so let me lay out the design for approval before editing.
Assistant
I've already traced the full code path during investigation, so Phase 1 understanding is solid. Let me launch a Plan agent to nail down the trickiest part — the cross-hook ordering (prompts counted on TurnEnd, checkpoints written on a separate commit/condensation hook) and how the deferred-reset flag persists across those hooks.
Assistant
This is a strong plan. It surfaced two non-obvious things I want to verify before finalizing: the cumulative nature of event.TurnCount, and the CheckpointsCount == 0 attribution sentinel that flooring would break.
Assistant
Both verified:
manual_commit_hooks.go:1083 — if metadata.CheckpointsCount == 0 { continue } is a real attribution gate. Flooring CheckpointsCount to ≥1 would silently break it, so the fix must decouple that sentinel.
The CondenseSession write succeeds at :256-261 and returns at :280, so the ResetPending=true flag has a clean home right after the successful write.
The design is well-grounded and the requirements were precise, so I'll finalize the plan. Let me write it.
Assistant
Let me fix a stray markdown artifact at the end of the plan file.
Assistant
The plan is ready.
Assistant
Plan approved. Let me set up task tracking and read the exact regions I'll edit.
Assistant
Now let me read the exact regions I'll edit across the files.
Assistant
Now let me find the CommittedMetadata struct, the write site at committed.go:443, and check for maxInt.
Assistant
Go 1.26 has builtin max(), so no helper needed. I have everything. Let me start implementing.
Assistant
Now the deferred-reset logic in persistEventMetadataToState:
Assistant
Now the CondenseSession changes. Let me read the full write block and function signature first.
Assistant
Now set the deferred flag after the successful write, and update the CondenseResult mirror:
Assistant
Now add the checkpointStepCount helper. Let me find the CondenseSession function header to place it just before.
Assistant
Now wire it through the metadata build in committed.go:
Assistant
Now switch the attribution sentinel to the new field:
Assistant
Now let me verify it compiles before touching tests.
Assistant
Build passes. Let me look at the existing test the plan flagged will break (manual_commit_test.go:3560) and run the affected package tests to see the current state.
Assistant
The assertion CheckpointsCount == 2 is incidental to this token-usage test, but now the count is driven by SessionTurnCount. Let me set that so the test reflects the new model.
Assistant
Now let me run the affected package tests to find any other breakage before adding new tests.
Assistant
All existing tests pass. Let me check the lifecycle package tests too, then add new tests for the worked examples.
Assistant
All green. Now let me add focused tests. First, let me find the function containing the attribution sentinel and check existing coverage, and confirm the test package names.
Assistant
Let me read the full updateCombinedAttributionForCheckpoint to assess a focused sentinel test.
Assistant
Writing a full git-backed test for updateCombinedAttributionForCheckpoint is heavy, and my change is a behavior-preserving field rename (SaveStepCount carries the same state.StepCount value that gated this path before), covered by the passing multi-session test. I'll focus the new tests on the genuinely new logic. Let me check the target test files.
Assistant
lifecycle_test.go is package cli (can call persistEventMetadataToState) and imports strategy. Let me check the condensation test package and confirm field access, then write the tests.
Assistant
Now let me add the strategy-package test for checkpointStepCount:
Assistant
I'll append the checkpointStepCount test to the condensation test file:
Assistant
Now the deferred-reset + exec-mode state-machine tests in the cli package. Let me append to lifecycle_test.go:
Assistant
All new tests pass. Now let me run the full affected-package suites, plus lint and format, per the plan's verification.
Assistant
attach.go needs reformatting (struct alignment). Let me format it and run the full affected suites + lint.
Assistant
Formatted. Now run the full affected suites and lint.
Assistant
Lint flagged runAttach maintainability index at 19 (threshold 20) — I'm right at the boundary. Let me check whether this is pre-existing or my change tipped it over.
Assistant
Confirmed — my change tipped runAttach (already a 515-line function at the limit) from MI 20→19. Let me minimize the footprint inside runAttach by moving the comment and logic to a small helper outside it.
Assistant
Now define the attachStepCount helper outside runAttach:
Assistant
Lint passes (0 issues). Let me do a final verification: gofmt check on all edited files + the affected test suites including attach.
Assistant
All green. Let me do a final whole-module build to make sure nothing else references the changed structs.
Assistant
Build clean, vet clean, lint passes, all tests green. Here's the summary.
What I changed (CLI, /Users/dip/Repositories/cli)
The "steps" count now means user prompts since the previous checkpoint that had prompts before it, prompt-driven with a deferred reset — instead of the old file-modifying-turn counter that read 0 whenever no SaveStep ran.
Counting model — derived from the existing prompt-accurate, exec-mode-safe SessionTurnCount:
code
steps = SessionTurnCount − PromptWindowBase (floored at 1)
session/state.go — added PromptWindowBase + PromptWindowResetPending (both omitempty, zero-value-safe for in-flight sessions on old state files).
lifecycle.gopersistEventMetadataToState — when a turn is counted and a reset is pending, re-anchor PromptWindowBase to the pre-turn count and clear the flag. This is the deferred reset: the window only restarts on the next prompt, so back-to-back checkpoints report the same count.
manual_commit_condensation.go — new checkpointStepCount() helper; used at the write site and the CondenseResult mirror; sets PromptWindowResetPending=true after a successful write (does not zero the window).
attach.go — CheckpointsCount: attachStepCount(prompts) (floored at 1), extracted to a helper to keep runAttach under the maintainability-index limit.
Attribution sentinel decouple — flooring checkpoints_count to ≥1 would have broken the == 0 gate at manual_commit_hooks.go:1083. Added a separate honest signal SaveStepCount (= old StepCount) to CommittedMetadata/WriteCommittedOptions, wired through committed.go, and switched the gate to it. Behavior-preserving (same value that gated before).
Tests — TestCheckpointStepCount (window math + floor), TestPromptWindowDeferredReset (the two worked examples + back-to-back + re-anchor), TestPromptWindowExecModeCumulativeTurnCount (cumulative hook TurnCount); updated the existing condensation test that asserted the old StepCount semantics.
User
Create a new branch, commit the changes and create a PR. In the description, you add a simple, human readible explanation of the problems and the solutions. Two bugs and change of the turn count including the scenarios. Stay concise!
Assistant
I'll create a branch, commit, and open a PR in the cli repo. Let me check state and stage everything.
Assistant
Current branch is review-pi-reviewer (a feature branch), and there's an unrelated untracked .pi/extensions/entire.ts I'll leave out. Let me check how this branch relates to main to pick the right base for a clean PR.
Assistant
review-pi-reviewer is far ahead of main with unrelated review-profile work, so a clean PR to main must branch off main. Of my files, only lifecycle.go/lifecycle_test.go differ between the branch and main. Let me verify my lifecycle.go edit region exists identically on main so it applies cleanly.
Assistant
Confirmed — main has the identical persistEventMetadataToState block and the same lifecycle_test.go tail, so my edits apply cleanly. The other 8 files match main exactly. I'll branch off main, carry my changes over, and verify.
Assistant
Applied cleanly onto main. Let me verify the changes are intact and build + run the new tests on the main base.
Assistant
All 10 files intact, builds on main base. Let me confirm both test packages pass cleanly, then commit.
Assistant
Now let me stage the 10 files (excluding the unrelated untracked .pi file) and commit.
Branch:fix/checkpoint-step-count-prompts, based off main (kept clean — the unrelated review-pi-reviewer work and the untracked .pi/extensions/entire.ts are not included).
Commit: the 10 changed files, building/testing/linting green on the main base.
The PR description is human-readable and concise: the two bugs (written-before-a-step-was-recorded, entire attach ignoring it), the counting change (prompts via SessionTurnCount with a deferred reset, floored at 1), and a scenarios table showing A=3,B=2 / back-to-back A=3,B=3 / floor =1.
User
Address the review comments
Assistant
I'll check the PR for review comments.
Assistant
Three actionable comments: one real bug (Cursor) and two comment fixes (Copilot). Let me address them. First, let me re-read the relevant regions.
Assistant
The Cursor bug is real — a stale Stop hook (same cumulative TurnCount) leaves SessionTurnCount unchanged but still clears the flag, re-anchoring early. The fix is to gate on whether the count actually advanced:
Assistant
Now the two comment fixes. First, checkpointStepCount — remove the inaccurate "attach" reference:
Assistant
Now the WriteCommittedOptions.CheckpointsCount field comment:
Assistant
Now let me add a regression test for the stale-hook case the Cursor bug described, and verify everything builds + passes.
Assistant
All pass, including the new regression test. Let me run lint and the affected suites, then commit and push.
Assistant
Lint clean, all suites pass. Let me commit and push.
Assistant
Pushed to the PR. Here's what I addressed:
1. Real bug (Cursor, lifecycle.go) — stale hook resetting the window early.
The deferred reset was cleared on any TurnEnd/TurnCount > 0 event, even when SessionTurnCount didn't actually advance. A repeated Cursor Stop hook with the same cumulative count would re-anchor the window prematurely, making a later back-to-back checkpoint report 1 instead of matching the prior count. Now gated on a genuine advance (SessionTurnCount > prevTurnCount), which is also semantically cleaner. Added TestPromptWindowStaleHookDoesNotResetEarly as a regression guard.
2. Comment fix (Copilot, manual_commit_condensation.go).checkpointStepCount doc no longer claims to "cover attach" — attach uses its own attachStepCount and doesn't go through this path.
3. Comment fix (Copilot, checkpoint.go).WriteCommittedOptions.CheckpointsCount comment updated to say it's the displayed prompt/"steps" count (floored at 1), not a count of checkpoints.
Verification: go build, mise run lint (clean), and the cli / strategy / checkpoint suites all pass, including the three prompt-window tests. Commit cd76a7340 is on fix/checkpoint-step-count-prompts (PR #1347).
The remaining bot notes were just the summary/no-op comments (Cursor Bugbot's footer, Copilot's overview) — nothing else actionable.
User
I installed the state of the CLI of this branch. So you could now use "entire attach" to validate that it's not broken anymore?
Assistant
Good idea — let me validate end-to-end. First let me confirm the installed entire is from this branch and see how attach resolves a session.
Assistant
Confirmed — installed binary is commit cd76a734081b, matching my latest push. Now I need a real session transcript to attach. Let me see how attach resolves transcripts (so I can set up a clean, non-polluting validation).
Assistant
There's a searchTranscriptInProjectDirs fallback that finds a transcript by session id across all project dirs — so I can validate in a throwaway repo without polluting anything. Let me pick a real session id and set up a temp repo.
Assistant
Attach succeeded — checkpoint 099392f84c70. Now let me read back the written metadata and confirm checkpoints_count.
Assistant
Confirmed fixed. Let me clean up the temp repo.
Assistant
Validated end-to-end with the branch's CLI (confirmed binary commit cd76a734081b).
Test: created a throwaway git repo, ran entire attach <real-session-id> --force (the session lived in a different project — the searchTranscriptInProjectDirs fallback located it), then read back the written checkpoint metadata.
Result:
Per-session metadata.json → checkpoints_count = 1 (previously this path wrote 0) ✅
Root summary → checkpoints_count = 1 ✅
save_step_count is absent (omitempty → 0), which is correct: attach runs no SaveStep, so the combined-attribution gate stays conservative for it ✅
So Bug 2 (entire attach writing 0) is genuinely fixed — it now floors to 1 via attachStepCount. No real repos were touched; the temp repo is cleaned up.
One caveat on coverage: this validates the attach floor. The mid-turn/commit-only bug and the prompt-window counting + deferred reset are covered by the unit tests rather than this manual run, since reproducing them live requires driving real agent turn/commit hooks. If you want, I can set up a scripted local session (prompt → prompt → commit, then an immediate second commit) to eyeball the A=3, B=3 back-to-back scenario in real metadata too — just a bit more involved to orchestrate.
User
If you attached it, then you can look it up in the database now.
Assistant
That checkpoint won't have reached the database — let me confirm by querying, then explain why.
Assistant
Confirmed: 0 rows — the checkpoint isn't in the database, as expected.
The reason: I deliberately validated in a throwaway /tmp git repo with no GitHub remote, then deleted it. The DB is only populated when checkpoints are pushed to a GitHub repo that has the Entire app installed → webhook → API → repo_checkpoints. A local-only repo never triggers that path. So the local metadata.json I read back (checkpoints_count = 1) is the ground truth for what the CLI wrote, but it never synced.
To get a DB-level confirmation, I'd need to attach in a real connected repo and push — which has side effects (it amends/links a real commit and pushes a checkpoint ref to GitHub). I don't want to do that to one of your active repos without checking.
How would you like to proceed?
Assistant
Understood — attach this session to my CLI branch commits, push so it syncs, then look it up in the DB. Let me first inspect the cli repo state and find the session id.
Assistant
The cli repo uses a checkpoint remote (cli-checkpoints), and HEAD has no checkpoint trailer yet. Attaching with --force will amend HEAD with the trailer + write checkpoint metadata, which I then push (force-push the branch, and the v1 ref to the checkpoint remote) to sync to the DB.
Let me find this session's id (most recently active transcript), then attach.
So roughly 1 in 5 recent checkpoints show "0 steps".
Root cause vs. symptom
The deepest cause is upstream: the entire CLI is writing checkpoints_count: 0 into committed session metadata for a large and rising fraction of checkpoints (likely the first/only checkpoint of a session being counted as 0 rather than 1). That's outside this repo, but it's where the real fix belongs.
Within this repo there are three places that would each independently surface or mask it:
api/src/lib/github.ts:647 — parsed.checkpoints_count ?? 1 should be || 1 (or Math.max(1, …)) if 0 is never a valid display value. This is the write-time guard; it only affects new ingests.
api/src/lib/checkpoint-mapper.ts:34,75 and api/src/lib/planetscale/sessions.ts:183 — note these are inconsistent: the mapper aggregates with s.steps ?? 1 while the materialized session aggregation uses entry.steps ?? 0. None coerce a stored 0.
frontend/.../CommitList.tsx:228 — could clamp (Math.max(1, session.steps)) or hide the indicator when 0, but that only hides the symptom.
The 54k existing rows already have 0 baked in, so any code fix would also need a backfill (or read-time clamping) to clean up historical data.
Do you want me to (a) fix the write-path coalescing + frontend clamp, (b) just clamp in the frontend as a quick display fix, or (c) leave it as investigation and pass the checkpoints_count: 0 finding to whoever owns the CLI?
repo_checkpoints.steps
prompt_count
Backfill the ~54k existing rows (and really all rows, if we want consistency) with a one-off job, since the transcript isn't loaded at webhook ingestion time.
Transitional state: a brand-new checkpoint won't have a transcript yet at ingest, so it'd show the old value (or null) until the transcript is first loaded. Need to decide the placeholder.
Edge cases beyond "start of session"
Off-by-one at the boundary — does the prompt that triggered the commit belong to this checkpoint or the next? Whatever we pick, apply it consistently or you get a systematic ±1.
Multi-session checkpoints (v1) — each session has its own start offset; count per session and sum (matches current totalSteps aggregation).
Sub-agent / Task sessions (is_task, tool_use_id) — separate transcripts; decide whether their prompts count toward the parent.
Dead/missing transcripts (dead_session_indices, parse fallback) — no transcript → count would be 0, which is the exact problem we're trying to fix. Need a fallback (e.g. keep CLI value, or max(1, …)).
Semantic shift — note this changes what "steps" means: from "git checkpoints in the session" (checkpoints_count) to "user turns in this checkpoint." Probably what users actually expect from "steps," but worth being deliberate — maybe even rename the label.
My recommendation
Go with it, but as a new prompt_count column (don't overload steps), computed in the transcript-parsing hydration path + a backfill, with max(1, count) as the floor so we never show 0 again. Keep the CLI steps around as a fallback for not-yet-hydrated rows.
Want me to:
Spike the countUserPrompts(checkpoint) helper on top of resolveTranscript and validate it against a few real checkpoints (I can pull transcripts and eyeball the counts), before committing to schema changes?
Or go straight to a plan (schema + hydration write + backfill + frontend)?
I'd suggest (1) first — cheap to verify the count matches intuition on real data before we touch the schema.
CheckpointsCount
Every
checkpoints_count: 0
Why it's getting worse, not legacy
StepCount resets to 0 after each condensation (manual_commit_hooks.go:1385, manual_commit_condensation.go:1287/1309), so any subsequent commit-only/mid-turn condensation re-hits the zero. The fast path that creates these (no-TTY agent commits + the commit_linking="always" opt-in) is recent and increasingly used — consistent with the climbing percentage.
Fix belongs here (CLI), and it's small
Both sites have an unambiguous correct value — a session being condensed produced at least one checkpoint, and attach produces exactly one:
manual_commit_condensation.go:230 (and the CondenseResult echo at ~:283): floor it — CheckpointsCount: max(state.StepCount, 1) when there's condensable content.
attach.go:297: set CheckpointsCount: 1.
That fixes the source going forward. Note it still leaves two things on the table, which connect back to our earlier discussion:
max(1, …) only restores "≥1," it doesn't make the number meaningful.StepCount counts SaveStep-recorded checkpoint steps, which for commit-only/attach sessions is genuinely ~1 regardless of how much work happened. If you want "steps" to reflect actual user turns, the count-user-prompts-from-transcript approach we discussed is the real metric — but that lives in the API/backfill, not the CLI.
The 54k existing rows stay 0 — a CLI fix is forward-only, so a backfill is still needed either way.
Want me to put together the CLI patch (the two one-line fixes + tests), or hold while you decide between "just floor it in the CLI" vs. "compute real steps from prompts in the API"? These aren't mutually exclusive — the CLI floor is a cheap correctness fix regardless of which metric you ultimately want to display.
committed.go:443
CheckpointsCount: opts.CheckpointsCount
no invariant there
and
nothing enforces a sane value at the write boundary; the two callers just expose it differently.
So, net:
Not missing a write path — verified only condensation + attach in production.
#1 and #3 collapse into one condensation-counter defect (two triggers).
Missing: the value is already synthetic (carry-forward =1) and is the wrong shape (resettable per-window counter labeled "steps") — so this is fundamentally a what-are-we-counting problem, not just a handle-the-zeros problem.
Want me to write this up as a short root-cause doc / Linear-ready summary, or start sketching the durable fix (transcript-turn count) vs. the cheap CLI floor?
So, correcting the mental model
It's not "prompts between checkpoints" — it's "file-modifying turns in the current condensation window." Close in spirit, off in practice (drops no-op/discussion turns).
The zeros aren't a "first checkpoint" exception. A normal first checkpoint born from a file-modifying turn is 1, not 0. It's 0 only when the checkpoint is created by a path that bypasses the TurnEnd→SaveStep flow entirely — mid-turn raw git commit (fast-path) or entire attach. Those produce a checkpoint with zero recorded file-modifying turns even though work happened.
A turn-accurate counter already exists (SessionTurnCount) — it's just not wired into the metadata, and it's session-scoped rather than per-window.
This actually sharpens the earlier conclusion: even with the zero-bugs fixed, "steps" would still mean "file-modifying turns," which is a defensible metric but not what the label implies and not what you hypothesized. If you want "prompts between checkpoints," the cleanest source is per-window turn counting (SessionTurnCount-style, scoped to the condensation window) or the transcript-derived prompt count we discussed on the API side — the file-change-gated StepCount is the wrong primitive either way.
Want me to check whether SessionTurnCount is already persisted into the committed metadata anywhere (it might give you a per-checkpoint turn count for free), before deciding on a fix?
Verification:go build ./..., go vet, mise run lint (0 issues), and the affected suites (cli, strategy, checkpoint, session) all pass.
Two things to flag
Scope was CLI-only and forward-only, per your call to ignore what's already broken. The ~54k existing rows keep their stored 0s; no backfill. The API/frontend pass the value through unchanged, so new checkpoints stop showing "0 steps" once produced by an updated CLI.
Attribution-sentinel regression test: I relied on behavior-preservation (the gate now reads SaveStepCount, which carries the identical state.StepCount value the old CheckpointsCount gate used) plus the existing passing multi-session test, rather than building a heavy git-backed test for updateCombinedAttributionForCheckpoint. If you want belt-and-suspenders, I can add that integration test.
Nothing is committed — let me know if you want a branch + commit/PR in the cli repo.