Skip to content

feat: Show import progress, skip live sessions before the read, mark imports with (*) - #1893

Merged
huang195 merged 3 commits into
rossoctl:mainfrom
huang195:perf/import-skip-before-read
Nov 17, 2026
Merged

huang195 merged 3 commits into
rossoctl:mainfrom
huang195:perf/import-skip-before-read

Conversation

@huang195

@huang195 huang195 commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Problem

  • agentop import showed only a spinner. A large history takes 30 s or more, and the user cannot see how far the import is.
  • The import was slow. The Claude Code source read every line of every transcript before the skip check. So it read the live and expired sessions in full and then dropped them.
  • The imp prefix on imported sessions was not clear.

Changes

Progress bar

  • POST /v1/import accepts "progress": true. The body is then NDJSON: progress lines {"progress":{"agent","done","total"}}, at most 4 a second, and then the report line.
  • Source.Sessions gets a progress(done, total) function. importer.Options.Progress passes it through.
  • On a terminal, agentop shows importing claude-code [█████████░░░░░░░░░░░] 45% 837/1851 sessions. Not on a terminal, it asks for no progress.
  • Compatibility: an older proxy ignores the field and sends only the report. Then agentop shows the spinner. An older agentop does not send the field and gets the same body as before.

Skip before the read

  • The Claude Code source calls skip with the newest file mtime before it reads the files. No line is newer than its file, so the Sessions contract ("a time not before Updated") still holds.
  • The live check needs only the id, and the expired check is correct with the mtime. So the source reads neither type of session now.
  • Report change: an old transcript with no turns now counts as skippedExpired. Before, the importer read it and dropped it without a count.

Marker

  • An imported session shows (*) before its title, or before its id when TITLE does not fit. The search finds it with (*).

Measurements

Dry run with importer.Run on a copy of the archive and real ~/.claude (2.8 GB, about 1,800 sessions). The versions ran one after the other:

Version Time Imported / live / expired
main 28.4 s 395 / 1292 / 110
skip before the read 13.1 s 395 / 1292 / 113
1 MiB read buffer only (not in this PR) 25.9 s 395 / 1292 / 110

The remaining 13 s is the full parse of the sessions to import.

Tests

  • New: TestSessions_SkipBeforeTheRead (it fails on main), TestImport_ProgressLinesBeforeTheReport, TestClientImport_ProgressLines, TestProgressBar.
  • go test -race on core/session/..., core/sessionapi/..., all cmd/agentop subpackages, and scripts/dev/go-test-shards.sh -race cmd/agentop (1,098 tests) pass. go vet is clean on both modules.
  • End to end: the new agentop ran in a pty against the import route on a test port, with the archive copy. It showed the spinner, then the bar, then the report line.
  • Not tested: a run against a restarted laptop proxy.

Bob source

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Deferred from review

  • nit, core/session/importer/claude/claude.go:80: the early skip uses the file mtime. A transcript that is copied or restored with an mtime older than its newest line is skipped as current, and its new turns are not imported.
  • nit, cmd/agentop/cmd_import.go:170: the progress bar wraps on a narrow terminal (open review thread).

@huang195
huang195 requested a review from a team as a code owner November 16, 2026 20:26
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 10 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7c8b7305-b5f7-48d8-b884-d4e60856d567
Commits

Reviewing files that changed from the base of the PR and between 3141333 and 8924af2.

Files selected for processing: 20

  • cmd/agentop/README.md
  • cmd/agentop/apiclient/import.go
  • cmd/agentop/apiclient/import_test.go
  • cmd/agentop/cmd_import.go
  • cmd/agentop/cmd_import_test.go
  • cmd/agentop/tui/imported_test.go
  • cmd/agentop/tui/sessions_context.go
  • cmd/agentop/tui/sessions_pane.go
  • core/session/importer/bob/bob.go
  • core/session/importer/bob/bob_test.go
  • core/session/importer/claude/claude.go
  • core/session/importer/claude/claude_test.go
  • core/session/importer/claude/heap_bench_test.go
  • core/session/importer/importer.go
  • core/session/importer/importer_test.go
  • core/session/importer/types.go
  • core/sessionapi/import.go
  • core/sessionapi/import_test.go
  • docs/laptop-service.md
  • docs/session-api.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 16, 2026

@clawgenti clawgenti left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Reviewed the import progress bar, the skip-before-the-read change in the Claude Code source, and the (*) marker. The wire compatibility story checks out on both sides (old proxy → report only; old agentop → no progress field), the NDJSON reader is bounded like every other body this client reads, and the skip-before-the-read change preserves the documented Sessions contract (a file's mtime is not older than its newest line, so skip still receives a time not before the parsed Updated). The rate limit (250 ms) matches the documented "at most 4 a second", and the progress tests are deterministic on that boundary (first line passes on the zero last, last line passes on done == total). No findings — the diff, the tests, and both docs pages agree with each other.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (agentop client/cmd, TUI, importer, sessionapi), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing

All checks pass. Ready for human review.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The changes look correct. Calling skip with the newest file mtime before the read keeps the Sessions contract: an mtime is never older than the lines in its file, so a Rule 1 or expired skip on the mtime is sound. A Rule 2 "current" skip on the mtime only fires when the archive copy is at least that new, and the existing newestAt re-check still catches a file that was only touched. The counters cannot double-count, because the first skip either drops the session or returns false. The NDJSON progress stream works with older peers in both directions: an old proxy sends one report line, which the scanner reads as the report, and an old client never sets progress. Two small, non-blocking comments are inline.

What I checked locally on bcd14d5 (merge base ef574d4):

  • go vet is clean on core/session/..., core/sessionapi/... and cmd/agentop/....
  • go test -race passes on core/session/importer/..., core/sessionapi/..., cmd/agentop/apiclient and the tui imported-marker and title tests.
  • I ran TestImport_ProgressLinesBeforeTheReport 200 times under -race, and it passed every time.
  • cmd/agentop: only TestReportSessionInterruption/names_the_cost_when_connections_are_attached fails, and it fails the same way on the base. It is environmental and not related to this PR.
  • I sent progress with the wrong JSON type to head and base. {"progress":"yes"} and {"progress":1} get 400 bad JSON body on head, and base ignored them. This field is new and only agentop sends it, so I don't consider it a regression.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (importer, session API, agentop client/CLI/TUI), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (CodeRabbit and Spellcheck skipped)

Comment thread core/sessionapi/import_test.go Outdated
}
got = append(got, p.Progress)
}
want := []importer.Progress{{Agent: "claude-code", Done: 0, Total: 2}, {Agent: "claude-code", Done: 2, Total: 2}}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This exact want depends on timing. The {done:1,total:2} line is dropped only while the archive write of s1 takes less than importProgressEvery (250 ms). On a slow, -race CI runner a stalled fsync can take longer than that. The handler then sends a third line, and slices.Equal fails. It passed 200 times for me under -race, so the risk is low. You could make it deterministic in either of two ways: make importProgressEvery a package var and set it very high in the test, or assert only the first line (done == 0) and the last line (done == total).

Comment thread cmd/agentop/cmd_import.go
if last == nil {
fmt.Fprintf(w, "\rimporting %c", frames[i%len(frames)])
} else {
fmt.Fprintf(w, "\r\033[K%s", progressBar(*last))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The bar line has about 70 columns at four-digit counts, and its width does not change. On a terminal narrower than the line, it wraps. \r\033[K then clears only the last physical row, so each 150 ms tick leaves another wrapped row behind. The spinner was too short to have this problem. You could cut the line to the terminal width, which term.GetSize gives for the *os.File, or drop the bar cells below a minimum width.

…orts with (*)

- agentop import shows a progress bar on a terminal, not only a spinner.
  POST /v1/import with "progress": true sends NDJSON progress lines before
  the report. An older proxy ignores the field and sends only the report.
  The Claude Code and Bob sources report progress.
- The Claude Code source calls skip with the file mtime before it reads
  the files. A live or expired session is not read now. A dry run on 2.8 GB
  of transcripts took 28.4 s before and 13.1 s after.
- An imported session shows "(*)" before its title, not "imp".

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
@huang195
huang195 force-pushed the perf/import-skip-before-read branch from 1905569 to a5eb2fd Compare November 17, 2026 00:30

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Since the approval of bcd14d5, the PR was rebased onto 31413332 (the #1892 Bob merge). The Bob source now takes the new progress parameter, TestSource_Progress covers it, and the docs say that the before-the-read skip belongs to the Claude Code source. The code changes are fine. The Bob source calls progress(i, len(all)) before each tree and progress(len(all), len(all)) after the loop, which meets the Source contract. Bob already calls skip before s.read, so the doc wording holds. The only Source implementers are bob and claude, so no other implementation breaks.

There is one blocking problem. Resolving the rebase conflict in docs/laptop-service.md deleted the text that #1892 and the forget-record PRs added on main: the 90% max_bytes stop, the forget-record and re-import counting rules, and the Flags and output: lead-in. It also leaves the paragraph ending in the fragment The import followed by a link. If this merges, those docs on main are reverted. See the inline comment.

The two earlier inline comments on bcd14d5 still apply to this head: the timing-dependent exact want in TestImport_ProgressLinesBeforeTheReport, and bar wrap on narrow terminals. Neither one blocks the merge.

What I checked locally on a5eb2fd (merge base 31413332):

  • The range-diff against bcd14d5 shows changes only in bob.go, bob_test.go, the docs and the commit message.
  • go build and go vet are clean on core/..., cmd/agentop/... and cmd/cortex/....
  • go test -race passes on core/session/importer/... (bob, claude, sqlitecli), core/sessionapi/..., cmd/agentop/apiclient, cmd/agentop/tui, and cmd/agentop -run 'Import|Progress'.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (importer incl. Bob source, sessionapi, agentop client/CLI/TUI), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: pending (DCO and CodeQL pass so far; the rest is still running)

Comment thread docs/laptop-service.md Outdated
project near it that the proxy wrote live or that an earlier import wrote. Flags
and output:
Each imported session is marked `(*)` in agentop. A Claude Code turn is priced
at today's rates. A Bob turn keeps Bob's own cost. LAST 1H shows imported turns only after the next restart. The import

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: The rebase conflict resolution here dropped the main text that follows the marker sentence. On 31413332, the paragraph continues: "The import stops at 90% of max_bytes. A session that you erased, or that a limit removed, comes back in full on the next import. Its forget record tells the import which turns the cost ledger already holds. The turns inside that span are not counted again, and the turns after it are. A turn before the span is counted only when the cost ledger has no row of the same project near it that the proxy wrote live or that an earlier import wrote. Flags and output:". At this head the paragraph ends in ...only after the next restart. The import and goes straight into the link. Merging this would revert the forget-record docs from #1892 and the earlier forget-record PRs, and would leave a broken sentence. The intended change is only imp → (*). Please restore the rest of the paragraph:

Suggested change
at today's rates. A Bob turn keeps Bob's own cost. LAST 1H shows imported turns only after the next restart. The import
at today's rates. A Bob turn keeps Bob's own cost. LAST 1H shows imported turns
only after the next restart. The import stops at 90% of `max_bytes`. A session
that you erased, or that a limit removed, comes back in full on the next import.
Its forget record tells the import which turns the cost ledger already holds.
The turns inside that span are not counted again, and the turns after it are. A
turn before the span is counted only when the cost ledger has no row of the same
project near it that the proxy wrote live or that an earlier import wrote. Flags
and output:

…timing-safe

Fixes review: docs/laptop-service.md lost the rossoctl#1892 import text in the merge and cut a sentence in two
Fixes review: TestImport_ProgressLinesBeforeTheReport expected an exact line list that depends on the 250 ms limit
Files:
- core/sessionapi/import_test.go
- docs/laptop-service.md

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
Fixes review: the timing-safe progress test no longer checked that the limit drops a middle line
Files:
- core/sessionapi/import.go
- core/sessionapi/import_test.go

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review — feat: Show import progress, skip live sessions before the read, mark imports with (*)

All checks pass. Ready for human review.

Summary: Clean PR. The progress protocol (NDJSON with a progress field, report as last line) is backward-compatible in both directions, and the pre-read skip in the Claude Code source preserves the Sessions contract (file mtime ≥ newest line, so the skip time is not before the parsed Updated). The changed accounting for unreadable/expired transcripts is documented in both the PR body and docs/session-api.md.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (importer, sessionapi, apiclient, TUI), docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed-off: yes
CI status: passing (some jobs still pending at review time; Pre-commit, DCO, CodeQL, YAML lint, build-and-push all green)

Verified on head a5eb2fd:

  • go test -race -count=1 on ./core/session/importer/..., ./core/sessionapi/..., ./cmd/agentop/apiclient/... — all pass (new tests TestSessions_SkipBeforeTheRead, TestImport_ProgressLinesBeforeTheReport, TestClientImport_ProgressLines, TestSource_Progress included)
  • go vet clean on ./cmd/agentop/... ./core/session/... ./core/sessionapi/...
  • gofmt -l clean on all touched Go dirs
  • TestProgressBar table cases (including the 0/0 and 9/4 clamp cases) pass
  • Note: TestReportSessionInterruption in cmd/agentop fails in this sandbox, but it fails identically on main, so it is pre-existing and environment-specific, not introduced by this PR
  • The local clone was checked out on the PR head for the probes and returned to main afterwards; no files were modified

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review — follow-up on new commits c124454 and 8924af2

Two commits were pushed after my review of a5eb2fd. Reviewed the delta: no issues.

  • c124454 restores the import paragraph in docs/laptop-service.md that the first revision had dropped, with the line wrapping fixed — good catch, that was a gap in the original diff.
  • 8924af2 makes importProgressEvery a settable var and pins the rate-limit test to it. The timing-safety concern was real (the original TestImport_ProgressLinesBeforeTheReport relied on the two progress lines passing the rate limit by ordering alone).

Verified on head 8924af2: go test -race -count=1 ./core/sessionapi/ passes, go vet and gofmt -l clean on core/sessionapi.

Ready for human review.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review marker for the cycle's queued head a5eb2fd; the full reviews (including the follow-up covering c124454 and 8924af2) are posted above.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Clean, well-tested change. The NDJSON progress protocol is backward-compatible in both directions (older proxy → spinner fallback; older agentop → plain report), the skip-before-the-read optimization is measured (28.4 s → 13.1 s) and its mtime assumption ("no line is newer than its file") is sound and documented. Tests cover the new rate limit, the client stream parsing, the bar rendering, and the pre-read skip (with a root-safety guard). No must-fix findings; the two deferred nits in the PR body (mtime-on-restore, narrow-terminal bar wrap) are reasonable to leave to their open threads.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (importer, sessionapi, agentop client/TUI), docs, tests
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes
CI status: passing (several Go CI jobs still pending at review time)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

mod = f.mod
}
}
if skip(id, mod) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: each imported session now calls skip twice — once pre-read with the file mtime (here) and again post-parse with newest. Both are needed for correctness (the mtime is only an upper bound on Updated, so the post-parse check can still drop a session the pre-read passed), but it doubles the store/ledger lookups for every session that is actually imported. With ~400 imported sessions that's negligible next to the ~1,400 reads you saved, so fine to leave — just noting it in case a future profile shows the skip closure getting expensive.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review tracking marker for the automation state machine (full review posted above):

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review at 8924af2. The must-fix from the a5eb2fd review is resolved, and the progress test is now deterministic. I found no new issues. Approving.

Resolved since the last review

  • docs/laptop-service.md (was must-fix): The import paragraph now matches main's text exactly, from "only after the next restart." to "Flags and output:". The dangling "The import" fragment is gone. git diff origin/main pr -- docs/laptop-service.md shows one changed line, the intended imp → (*). I diffed the PR's other .md files against main too, and every removed line is an intended imp → (*) edit. No other main text is reverted. Main has moved by 7 commits since this PR's merge base (dependency bumps only). None of them touch the PR's files, and the PR still merges into current main without conflicts.
  • TestImport_ProgressLinesBeforeTheReport (was a timing nit at bcd14d5): importProgressEvery is now a package var. The test sets it per subtest and restores it with a defer. The case with every=1h and gap=0 always drops the middle line. The case with every=50ms and gap=100ms always sends it, because the sleep happens before each progress(i, …) call. Each case asserts the line count, the first and last lines, and that Done grows. There is no data race: the write happens before httptest serves the request, the handler goroutine reads the var after that, and the package has no t.Parallel tests. go test -race -count=20 -run TestImport_ProgressLinesBeforeTheReport passed.

Still open (non-blocking, not reposted): The progress bar at cmd/agentop/cmd_import.go can still wrap on terminals narrower than the line, about 70 columns.

Checks run

  • go build and go vet passed on ./core/..., ./cmd/agentop/... and ./cmd/cortex/.... Only bob and claude implement the changed Source interface, and both are updated.
  • go test -race passed on core/session/importer/..., core/sessionapi/... and every cmd/agentop subpackage. In cmd/agentop, TestServiceInstall_RefusesABrokenConfig and TestReportSessionInterruption fail in my sandbox, which has no systemd user bus. They fail the same way on main, so this PR does not cause them.
  • Version skew: a new client against an old proxy gets only the report line, which still decodes. progress is omitempty and the server's decoder doesn't reject unknown fields, so an old proxy ignores the field.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (importer, sessionapi, agentop client/CLI/TUI), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 3 commits, all signed-off: yes (DCO check passes)
CI status: 22 passed, 0 failed so far. Go CI and some other jobs were still running or queued when I posted.

@huang195
huang195 merged commit 6537224 into rossoctl:main Nov 17, 2026
39 checks passed
@huang195
huang195 deleted the perf/import-skip-before-read branch November 17, 2026 01:28
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants