Skip to content

Port upstream 0.68.0: name and rank Codex sessions in Usage & Spend - #673

Closed
Finesssee wants to merge 2 commits into
port/upstream-0.68.0from
port/micro-0.68.0-codex-session-names
Closed

Finesssee wants to merge 2 commits into
port/upstream-0.68.0from
port/micro-0.68.0-codex-session-names

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Codex sessions in Usage & Spend are now named from local Codex thread metadata and ranked by cost.

  • Names come from session_index.jsonl in the Codex home (one {"id","thread_name"} per line; blank names ignored, lines over 64 KiB skipped, latest line wins), then from threads.title in the newest state_<n>.sqlite (read-only, 100 ms busy timeout, SELECT title FROM threads WHERE id = ?1 LIMIT 1).
  • SQLite home resolution: absolute top-level sqlite_home in <CODEX_HOME>/config.toml (first 256 KiB only, top-level key only, project config never used), then CODEX_SQLITE_HOME (absolute, or relative to the rollout's original working directory), then the Codex home.
  • Untitled sessions show Session <short id>.
  • Ranking: cost descending with unpriced last, then tokens descending, then latest activity descending, then session id ascending. Each project's conversation list shows the rank, the top 8, and expands up to 50.
  • Hide personal information replaces the title with the short-id label; project names and paths were already removed, and tooltips only carry the masked title.
  • Naming and ranking do not change daily totals, the ledger, project totals or per-session costs (covered by a test).

Upstream reference

steipete/CodexBar v0.68.0, PR steipete#4020. Tag-pinned files read: CodexThreadMetadataReader.swift, CostUsageFetcher.swift, SpendDashboardModel.swift, CostHistoryIdentity.swift, CostHistoryChartMenuView.swift, SpendDashboardSessionRowTests.swift.

Ported / Deferred

Ported: thread-name lookup, SQLite home resolution, short-id label, ranking, top-8 / expand-to-50 UI, privacy masking.

Deferred or different:

  • config.toml is parsed with the existing toml crate (full parse, with a retry on the text before the first table header) instead of upstream's hand-written scanner. No new dependency.
  • The catalog status still reads state_5.sqlite.
  • top_sessions stays at 5; the UI uses contract.conversations.
  • Cached snapshots receive names on the next scan.
  • The panel is grouped per project, so rank is per project rather than one flat list.
  • The CLI --group-by session output is unchanged.
  • The "Session " label is a backend English string, consistent with the existing backend labels; no new locale keys.

Validation

  • cargo +1.98.0 fmt --all: clean
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: clean
  • cargo +1.98.0 test -p codexbar -- --test-threads=4: 2176 passed, 0 failed, 1 ignored (includes 10 new thread-name tests, ranking tests, and 4 end-to-end workspace tests)
  • pnpm test for ProjectConversations.test.tsx: 2 passed
  • pnpm run build: succeeded; pnpm run lint: only pre-existing warnings

Affected areas

rust/src/codex_workspaces/ (new thread_names.rs, indexer.rs, types.rs), rust/src/cli/cost.rs (shared short-id helper), and the Usage & Spend settings tab (ProjectConversations.tsx, UsageSpendTab.tsx).

UI proof

Pending: the coordinator will capture CUA proof on a fresh build.

Overlay Codex thread names from session_index.jsonl and state_<n>.sqlite threads.title, rank sessions by cost/tokens/activity/id, show the top 8 with expand to 50, and mask names with the short session id under Hide personal information.
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

  • High, indexer.rs:149: cached snapshots bypassed session naming and ranking, so existing users kept old labels and ordering. Fix: one projection applies to cached and fresh snapshots; each project's top five is rebuilt from ranked sessions.
  • Medium, indexer.rs:43: CODEX_SQLITE_HOME could be taken as the Codex home when CODEX_HOME was unset, redirecting rollout and session-index lookup. Fix: home resolves from CODEX_HOME or ~/.codex; the SQLite override only feeds thread-metadata lookup.
  • Medium, thread_names.rs:51: SQLite fallback also queried sessions already named in session_index.jsonl. Fix: skip the database when all names are found; query only missing ones.
  • Low, thread_names.rs:282: invalid state_*.sqlite names counted as version 0 and directories could be picked. Fix: only numeric versions pointing to files are accepted.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Fixes landed at 52c4219 ("Address thermo review"). All four findings above are fixed; none left open.

Claude also removed a now-unneeded mut in indexer.rs that clippy flagged after Codex's change.

Commands run (Rust 1.98.0, E-core wrappers): cargo fmt --all --check, cargo clippy --all-targets -- -D warnings on both rust/ and apps/desktop-tauri/src-tauri, cargo test codex_workspaces (23 passed). No frontend change, so vitest was not run.

@Finesssee

Finesssee commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

CUA proof

Build commit: 52c4219b04076aed981096acbd9a1fc6308ff0a8 (PR head). Debug desktop build (pnpm run tauri:build:debug), driven with cua-driver in background mode only (UIA element invoke, window screenshots; no focus, keyboard or mouse taken). Window kept on the second monitor.

Proof-only patches (never committed, restored after build): root Cargo.toml [patch.crates-io] dirs = ...proof-shim/dirs (redirects home/config/data dirs under CODEXBAR_PROOF_HOME) plus the resulting Cargo.lock lines. No source files patched, no TLS/URL changes, no mock server.

Data path: the real get_codex_workspaces_snapshot reading a synthetic CODEX_HOME (fake projects atlas-web and billing-api, 16 sessions, one with an unpriced model, session names from session_index.jsonl and state_5.sqlite). Isolated profile; settings: codex only, theme auto.

Surface: CODEXBAR_PROOF_MODE=settings:usageSpend, Settings > Usage & Spend > Projects.

# Assertion Result
0 No real email/account/personal data visible PASS
1 Usage & Spend loads; project list shows atlas-web and billing-api PASS
2 atlas-web rows ranked #1.. by descending cost; names: index name first (latest index line wins, index beats DB title), DB titles next, untitled as Session aaaa...0000000N PASS
3 8 rows initially plus Show all (13); expands to 13 rows, #13 is the unpriced session shown as ~$0.00; Show less returns to 8 rows PASS
4 Untitled sessions read Session <short id>, never "Local Codex chat" PASS
4b Long-title ellipsis and hover title Not exercised (no long title in fixture; hover is not possible without moving the pointer). Covered by the PR's vitest test only
5 billing-api: #1 Add webhook retry backoff $0.90, #2 Rotate API keys $0.51, #3 Session bbbb...00000003 $0.20, no expand button PASS
6 Costs monotonic non-increasing down each list, unpriced last (2.02, 1.89, 1.75, 1.62, 1.49, 1.35, 1.22, 1.08, 0.94, 0.81, 0.68, 0.54, ~0.00) PASS
7 Dark theme under auto, no overflow or clipped text PASS

Minor observation (not a failure): the rank column is not fixed width, so titles for #10..#13 start about 1-2 px to the right of #1..#9 rows.

Screenshots (local, not committed), in %LOCALAPPDATA%\Win-CodexBar\port-audit\proof\673\shots\: 03-tall.png (8 rows), 04-show-all.png (13 rows), 05-billing.png (both projects expanded).

Commands: bash launch.sh settings:usageSpend; cua-driver call get_window_state | click (element_token) | set_window_frame; instance stopped afterwards.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Adversarial validation (lane-B review)

Head validated: 52c4219b ("Address thermo review"). Spec: 0.68.0.md PR 8 (item #10, Codex session names).

Verdict: no blocking defects. All spec points verified in the source at head:

  • Naming order matches the spec: session_index.jsonl in the Codex home first (latest line wins, blank names ignored, lines over 64 KiB skipped — SESSION_INDEX_MAX_LINE_BYTES), then threads.title in the newest state_<n>.sqlite (read-only, 100 ms busy timeout).
  • SQLite home resolution: absolute top-level sqlite_home in <CODEX_HOME>/config.toml (head 256 KiB only, top-level key only), else CODEX_SQLITE_HOME (absolute or relative to the rollout's original working directory), else the Codex home.
  • Untitled sessions render Session <8 chars> (untitled_session_label) instead of a generic label.
  • Ranking/ordering applied to the conversation list and top_sessions (Windows groups conversations under projects; no flat ranked list required — matches the spec's Windows note). ProjectConversations.tsx renders the ordered list; truncation via PROJECT_TOP_SESSION_LIMIT.
  • Privacy: redact_for_privacy covers the new title fields (types.rs +82, tests included).

Validation re-run at head (pinned 1.98.0, E-cores): cargo +1.98.0 fmt --all -- --check clean; cargo +1.98.0 clippy --workspace --all-targets -- -D warnings clean; cargo +1.98.0 test -p codexbar --lib 2176 passed / 0 failed (focused codex_workspaces 23/23: session names, redaction, indexer overlays); cargo +1.98.0 test -p codexbar-desktop-tauri 461 passed / 1 failed (the documented #684 bootstrap_payload_exposes_every_provider_variant baseline, untouched by this diff); frontend: pnpm test 68 files / 404 tests passed (ProjectConversations 2/2); pnpm run check-locale OK (879 keys); pnpm run build OK.

UI proof: waived per user 2026-10-02 directive (fast-track); component tests + build cover the rendering.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

UI proof (browser-use)

Combined build of integrate/v0.70.0-ports at ddd85594 (all 40 port PRs and the follow-ups). Debug desktop build in proof mode, isolated config/data dirs, driven by browser-use over the WebView2 DevTools protocol with DOM events only (no mouse or keyboard input, no focus changes). All data is synthetic: local mock servers for L1, a seeded usage snapshot plus synthetic local logs for L2.

Scenario Check Result
L2 seeded snapshot + synthetic local logs #673 atlas-web: 13 conversations, ranked by cost; names from the latest session_index entry, then state_5.sqlite PASS

Every surface also passed the privacy check (no email-like text, account e-mail nodes or profile paths in the DOM) and theme auto rendered dark on the tray flyout, float bar and settings windows.

Validation at ddd85594: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p codexbar (3567 passed, 0 failed) and cargo test -p codexbar-desktop-tauri (606 passed, 0 failed). Screenshots were captured for each scenario and kept with the local proof kit.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
…ons in Usage & Spend

Conflict in UsageSpendTab.tsx imports only: the release CostPeriodControl
import and the ProjectConversations import are both kept. The ranked,
named conversation list renders inside the release period-aware Projects
panel; the native spend contract passes snapshot.sessions through, so the
backend ranking reaches the UI unchanged. The CLI session listing now uses
the shared codex_workspaces short-id helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant