Skip to content

Add Codex Workspaces indexing foundation - #2456

Merged
steipete merged 9 commits into
steipete:mainfrom
AmrMohamad:codex/workspaces-foundation
Jul 29, 2026
Merged

Add Codex Workspaces indexing foundation#2456
steipete merged 9 commits into
steipete:mainfrom
AmrMohamad:codex/workspaces-foundation

Conversation

@AmrMohamad

@AmrMohamad AmrMohamad commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

This is the non-UI foundation extracted from #2453 so the compatibility-sensitive scanner, cache, catalog, sidecar, and analytics behavior can be reviewed and proven independently.

The remaining menu, inspector, Settings, UsageStore, AppKit/SwiftUI, accessibility, and localization work stays in draft PR #2453 and will be rebased/merged onto this foundation after it lands.

Scope

  • Keep CostUsageScanner authoritative for parsing, cumulative-token deltas, fork/subagent accounting, pricing, and incremental cursors.
  • Persist Codex session/project attribution in the v11 local cost cache.
  • Read the Codex catalog without mutating it, with scope isolation and explicit missing/locked/corrupt/incompatible states.
  • Add the first-release schema-5 SQLite Workspaces sidecar with payload format 3, transactional publication, current-schema validation, invalidation fingerprints, changed/deleted rollout handling, and last-complete retention.
  • Add core Models aggregation, known/unknown cost semantics, parity diagnostics, performance telemetry, and CSV serialization.
  • Stabilize the pre-existing time-sensitive Spend Dashboard fixtures without changing dashboard production behavior.
  • Document v10→v11 rebuild behavior, the first-release schema-5 contract, last-good retention, partial catalog behavior, and the local-only privacy boundary.

No remote API, provider authentication, billing interface, public CLI JSON contract, product enablement, or UI is introduced here.

Maintainer-approved cleanup

The accepted landing scope drops migrations for unreleased sidecar schemas 2–4 and removes the unreleased legacy JSON snapshot reader. Public Workspaces snapshot loads now require an explicit personal-information-hiding choice; hidden snapshots remove persisted workspace paths, working directories, workspace names, and session titles before presentation.

Compatibility contract

  • codex-v10.json is not treated as a v11 cursor or migrated in place.
  • The first post-upgrade scan rebuilds v11 while leaving v10 byte-identical and recoverable.
  • v11 is atomically published only after a successful scan.
  • A failed sidecar transaction preserves the previous complete snapshot.
  • Schema 5 is the first supported Workspaces sidecar schema; any other schema is rejected without modification.
  • The pre-sidecar development JSON snapshot path is intentionally unsupported.
  • The internal UI boundary is:
    • CostUsageFetcher.loadCachedCodexLocalProjectUsageSnapshot
    • CostUsageFetcher.loadCodexLocalProjectUsageSnapshot
    • CostUsageFetcher.clearCachedCodexLocalProjectUsageSnapshot
    • CodexLocalProjectUsageSnapshot
    • CodexLocalProjectUsageIndexProgress

Commit structure

  1. Stabilize spend dashboard fixtures
  2. Persist Codex session metadata
  3. Add Codex Workspaces index
  4. Add workspace models analytics
  5. Test and document workspace indexing

Each intermediate source layer was built before the next layer was added.

Regression history

The 13 reported Spend Dashboard issues were not introduced by Workspaces:

Checkout Focused result
Exact base cc8da27c 37 tests, 13 issues
Pre-fix feature head a29ca876 Same 37 tests, same 13 issues
This foundation 5c571d71 37 tests, 0 issues

The repair gives the synthetic token snapshots an explicit USD currency and injects fixed request/model clocks into July fixtures. Production grouping, completeness, pricing, and cache behavior are unchanged.

Contributor verification before maintainer cleanup

All commands below ran from a detached worktree at 5c571d71ed6c557a217b7c457cb15f605f13d9b4.

Gate Result
Spend Dashboard focused suites 37 tests / 4 suites passed
Scanner/cache/catalog/sidecar/Models focused suites 173 tests / 8 suites passed
make test 727/727 selections in 61/61 groups; 0 failures, retries, or timeouts
make check 0 SwiftFormat changes; 0 SwiftLint violations
git diff --check Passed

The automated gates used deterministic fixtures/stores and did not perform Keychain reads, cookie imports, browser imports, real provider/account probes, or provider network requests.

Redacted real-workspace proof

The proof used three real local Codex session files copied into an isolated CODEX_HOME, a task-specific CFFIXED_USER_HOME, a task-specific cache root, and an outer macOS sandbox policy denying all network access.

cold: status=complete projects=2 sessions=3 indexed=3 skipped=0 duration_ms=1615
phases: scanning -> indexing 0/3 -> indexing 1/3 -> indexing 3/3 -> saving
warm: scope_match=true totals_match=true indexed=3 skipped=0 duration_ms=68
warm phases: scanning only (v11 cursor reused; no reindex/save)

cache_empty_before_v10_seed=true
v10_checksum_unchanged=true
v11_created=true
sidecar_created=true
sidecar_user_version=5
payload_format=3
tables=catalog_threads,index_state,schema_meta,snapshot_payloads,usage_daily,usage_events,usage_rollouts
rows: catalog_threads=2801 index_state=1 schema_meta=0 snapshot_payloads=1
rows: usage_daily=7 usage_events=737 usage_rollouts=3

missing_catalog: status=catalogMissing totals_retained=true projects_retained=true
corrupt_catalog: status=catalogCorrupt totals_retained=true projects_retained=true

A full-resolution sanitized screenshot of the same evidence is attached in this PR discussion.

Privacy review

The published transcript and screenshot were manually inspected at full resolution and scanned for home paths, identities, emails, UUID/session IDs, API-key/token patterns, auth headers, and IP addresses.

They do not contain raw paths, chat titles, session IDs, database rows, token or cost values, account identities, API keys, auth headers, hostnames, or IP addresses. Raw captures remain outside the repository and will be deleted after verification.

Follow-up

After this foundation merges, #2453 will be updated onto main and its current diff will be limited to the Workspaces preference/inheritance rule, UsageStore integration, native menu/progress rows, inspector presentation, display-only projections, accessibility/localization, CSV action, and UI tests/evidence.

The proposed product decision remains: a missing dedicated Workspaces preference inherits existing local cost usage, while an explicit Workspaces setting overrides it. That default is not introduced by this foundation PR and still requires maintainer approval in #2453.

@AmrMohamad

Copy link
Copy Markdown
Contributor Author

Redacted real-workspace proof

Sanitized Codex Workspaces foundation runtime proof

Inspect the sanitized runtime log.

These sanitized artifacts are pinned to evidence commit 504f355ef2f80908e8621054381fd4808c171fe5 on a non-merge evidence branch, so the reviewed foundation head remains exactly 5c571d71ed6c557a217b7c457cb15f605f13d9b4.

The screenshot was rendered and captured with @Computer, inspected at full resolution, and checked against the same redaction scan described in the PR body.

@AmrMohamad
AmrMohamad marked this pull request as ready for review July 25, 2026 23:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c571d71ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Sources/CodexBarCore/CodexLocalProjectUsageIndexer.swift
Comment thread Sources/CodexBarCore/CodexThreadCatalogReader.swift Outdated
Comment thread Sources/CodexBarCore/CodexWorkspaceUsageSidecar.swift
@AmrMohamad

Copy link
Copy Markdown
Contributor Author

Ready-run CI closure

Exact head 5c571d71ed6c557a217b7c457cb15f605f13d9b4 completed the Ready-for-Review workflow successfully: Linux x64, Linux arm64, Linux musl, lint, both required macOS shards, and the aggregate lint-build-test gate all passed. The macOS jobs ran; they were not deferred or skipped.

Run: https://github.com/steipete/CodexBar/actions/runs/30180152648

For the paired draft contract proof, #2453 at ca5b1f3a deferred macOS and its aggregate gate correctly failed: https://github.com/steipete/CodexBar/actions/runs/30180210214

The task-specific raw session/catalog copy and temporary instrumented runtime worktree have now been permanently removed after verification. Only the inspected sanitized screenshot and transcript linked above remain published.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 26, 2026
@clawsweeper

clawsweeper Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 26, 2026, 3:39 AM ET / 07:39 UTC.

ClawSweeper review

What this changes

Adds a local Codex Workspaces indexing foundation that scans existing Codex data, attributes usage to projects, sessions, models, and days, and stores derived results in a v11 cache plus a SQLite sidecar.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

This PR has addressed the prior catalog/sidecar correctness findings and provides strong real-workspace proof, but it still needs a maintainer decision before merge because it introduces a new persistent local-data contract for existing installations.

Priority: P2
Reviewed head: 7bf6a49a58032f2c9e19b43936b70a1937fea44a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The PR has strong real-workspace proof, focused regression coverage, and no remaining discrete correctness finding; merge readiness is gated by product ownership of the new persistence contract.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Sanitized terminal evidence shows after-fix cold and warm indexing, v10 preservation, v11/sidecar creation, and degraded catalog retention; private values were intentionally redacted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Sanitized terminal evidence shows after-fix cold and warm indexing, v10 preservation, v11/sidecar creation, and degraded catalog retention; private values were intentionally redacted.
Evidence reviewed 4 items Prior findings resolved: The contributor’s follow-up states that cached reads now project current catalog degradation, legacy timestamps normalize to milliseconds, and complete catalog generations prune absent rows; these correspond to all three prior P2 review findings.
Persisted upgrade boundary: The branch changes the Codex cache artifact from v10 to v11 and adds a schema-versioned SQLite Workspaces sidecar, with documented rebuild and retention behavior.
Real behavior proof: The PR provides a sanitized terminal proof of cold creation, v10 preservation, v11 and sidecar creation, warm cache reuse, and missing/corrupt catalog retention behavior; the review context marks the proof sufficient.
Findings None None.
Security None None.

How this fits together

CodexBar’s local usage system reads Codex rollout logs and caches token/cost data for usage reporting. The new Workspaces layer combines those scanned records with a read-only Codex thread catalog, then publishes project/session/model aggregates for a later UI PR.

flowchart LR
  A[Local Codex rollout logs] --> B[Usage scanner]
  C[Codex thread catalog] --> D[Catalog reader]
  B --> E[Workspace index]
  D --> E
  E --> F[Versioned cache and SQLite sidecar]
  F --> G[Project session model aggregates]
  G --> H[Future CodexBar views]
Loading

Decision needed

Question Recommendation
Should CodexBar adopt and support the new v11 local cost cache plus schema-5 Workspaces sidecar, including its rebuild, migration, and last-good-retention contract, as the foundation for future Workspaces UI? Accept the persistent foundation: Merge the documented v11 cache and schema-5 sidecar contract, then let the UI follow-up build on this stable foundation.

Why: The patch can be technically correct while still committing the product to durable local artifacts, compatibility behavior, and an internal presentation boundary that need maintainer ownership.

Before merge

  • Resolve merge risk (P1) - Merging begins writing codex-v11.json and a schema-5 SQLite sidecar for existing users; the cache rebuild, retention, and rollback contract needs explicit maintainer acceptance before the project owns it as a supported upgrade path.
  • Resolve merge risk (P1) - The linked UI follow-up at feat: Add local Codex Workspaces analytics #2453 depends on this foundation, so the persistence API and behavior should be accepted as a stable boundary before that UI is rebased onto it.
  • Complete next step (P2) - No mechanical repair remains; a maintainer needs to accept or reject the persistent upgrade contract before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Persistence surface 2 persistent artifacts introduced or versioned Existing users will receive a new v11 JSON cache and a new SQLite sidecar.
Patch scope 29 files affected; 8,281 added, 67 removed The feature spans scanner parsing, cache semantics, persistence, aggregation, tests, and docs.
Focused regression coverage 3 prior P2 findings addressed The follow-up commit adds targeted handling for catalog freshness, legacy timestamps, and complete-generation pruning.

Root-cause cluster

Relationship: canonical
Canonical: #2456
Summary: This is the extracted foundation for the separate Workspaces UI follow-up.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept the upgrade contract (recommended)
    Merge after a maintainer explicitly accepts the v10-to-v11 rebuild, schema-5 migration, and last-good retention semantics for existing users.
  2. Narrow the durable surface
    Reduce or redesign the cache and sidecar contract before merge if maintainers do not want to support these persistent artifacts long term.
  3. Pause the foundation
    Hold this PR if the planned Workspaces UI is not yet a supported product direction.

Technical review

Best possible solution:

Accept or narrow the durable cache/sidecar contract after a maintainer confirms that CodexBar should own the documented v10-to-v11 rebuild, schema migration, and last-good retention behavior; then land this foundation before reviewing the UI follow-up.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR introduces a new local indexing capability rather than fixing a current-main bug. Its supplied real-workspace run provides strong behavior evidence for the proposed feature.

Is this the best way to solve the issue?

Unclear: the implementation is internally staged and well-tested, but a maintainer must decide whether the new durable cache and sidecar contract is the right long-term product boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against cc8da27cec92.

Labels

Label justifications:

  • P2: This is a substantial but non-emergency local-usage feature whose compatibility contract needs normal maintainer review.
  • merge-risk: 🚨 compatibility: The PR changes the on-disk Codex cache version and adds a versioned SQLite sidecar with migration and retention semantics.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Sanitized terminal evidence shows after-fix cold and warm indexing, v10 preservation, v11/sidecar creation, and degraded catalog retention; private values were intentionally redacted.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sanitized terminal evidence shows after-fix cold and warm indexing, v10 preservation, v11/sidecar creation, and degraded catalog retention; private values were intentionally redacted.

Evidence

What I checked:

  • Prior findings resolved: The contributor’s follow-up states that cached reads now project current catalog degradation, legacy timestamps normalize to milliseconds, and complete catalog generations prune absent rows; these correspond to all three prior P2 review findings. (Sources/CodexBarCore/CodexLocalProjectUsageIndexer.swift:24, 7bf6a49a5803)
  • Persisted upgrade boundary: The branch changes the Codex cache artifact from v10 to v11 and adds a schema-versioned SQLite Workspaces sidecar, with documented rebuild and retention behavior. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift:11, 7bf6a49a5803)
  • Real behavior proof: The PR provides a sanitized terminal proof of cold creation, v10 preservation, v11 and sidecar creation, warm cache reuse, and missing/corrupt catalog retention behavior; the review context marks the proof sufficient. (docs/codex-workspaces.md:1, 7bf6a49a5803)
  • Repository policy: The supplied target AGENTS.md requires care around provider data siloing, focused non-Keychain validation, and explicit validation of UI/runtime only when needed; this PR supplies focused persistence tests and avoids live provider reads in its stated validation. (AGENTS.md:1, cc8da27cec92)

Likely related people:

  • AmrMohamad: The PR’s six commits introduce the Workspaces scanner, cache, sidecar, models, tests, and documentation; no current-main provenance could be inspected because read-only shell access failed. (role: feature author; confidence: medium; commits: e541cab54ae4, 394431928810, ff58c48000f8; files: Sources/CodexBarCore/CodexLocalProjectUsageIndexer.swift, Sources/CodexBarCore/CodexWorkspaceUsageSidecar.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain explicit maintainer acceptance of the v11 cache and schema-5 sidecar upgrade contract.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-26T00:37:21.689Z sha 5c571d7 :: needs changes before merge. :: [P2] Surface degraded catalog state on a cached refresh | [P2] Convert legacy catalog timestamps to milliseconds | [P2] Prune catalog rows missing from a complete generation
  • reviewed 2026-07-26T07:12:01.527Z sha 7bf6a49 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-26T07:17:11.822Z sha 7bf6a49 :: needs maintainer review before merge. :: none

@AmrMohamad

Copy link
Copy Markdown
Contributor Author

Addressed the three catalog/sidecar correctness findings in 7bf6a49.

  • Cached sidecar and legacy snapshot reads now re-check the catalog and project the current source status, so a missing/corrupt/incompatible catalog is visible while last-good usage remains available.
  • Legacy created_at / updated_at seconds now normalize to Unix milliseconds, including the catalog fingerprint summary.
  • Catalog rows absent from a successful complete generation are pruned transactionally; degraded catalog reads pass catalogIsComplete: false and retain last-good metadata.

Regression coverage added:

  • catalog reader normalizes legacy seconds timestamps to milliseconds
  • cached refresh surfaces catalog degradation while retaining last good usage
  • sidecar prunes catalog metadata absent from a complete generation

Validated on the identical source tree:

  • swift test --filter CodexLocalProjectUsageTests — 35 passed
  • make test — 727 selections, 61/61 groups, zero retries/timeouts
  • make check — passed
  • git diff --check — passed

@AmrMohamad

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 26, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 26, 2026
@steipete
steipete merged commit ce0e1cb into steipete:main Jul 29, 2026
15 of 17 checks passed
@steipete

Copy link
Copy Markdown
Owner

Maintainer verification complete on exact head dc6fe7274f1853d07f30dd943f4d1c924ce82cfd.

The final hostile review found no blocking defect. This lands the owner-approved non-UI Workspaces indexing foundation while keeping CostUsageScanner authoritative, retaining read-only catalog access, and publishing the sidecar transactionally. Per the approved cleanup, schemas 2–4 and the pre-sidecar JSON snapshot reader were removed because those formats were never released; schema 5 is the first supported Workspaces schema. Public snapshot loads now require an explicit personal-information-hiding choice, and the hidden projection removes workspace paths, working directories, workspace names, and session titles before presentation.

Local focused proof passed 229 tests across 13 Workspaces, Models, cache, and scanner suites. Structured autoreview was clean after each current-main merge. Hosted CI is green on the final head: https://github.com/steipete/CodexBar/actions/runs/30418945708. One unrelated Kimi timing assertion exceeded its 250 ms budget by 10.96 ms on the first attempt; the authorized failed-job rerun passed, as did both macOS shards, all Linux builds, lint, the aggregate gate, and GitGuardian.

Thank you, @AmrMohamad, for the careful foundation work and thorough test coverage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants