Skip to content

Keep Muse token coverage with newer session journals - #5068

Open
jslabxyz wants to merge 1 commit into
steipete:mainfrom
jslabxyz:fix/muse-retained-journal-metadata
Open

jslabxyz wants to merge 1 commit into
steipete:mainfrom
jslabxyz:fix/muse-retained-journal-metadata

Conversation

@jslabxyz

@jslabxyz jslabxyz commented Nov 12, 2026 •

Copy link
Copy Markdown

Newer Muse Code journals can contain session bookkeeping records that the local reader rejects as unknown, even when the journal contains no inference. This marks coverage unavailable and prevents Usage & Spend from publishing the result.

Recognise the observed non-inference envelopes and permission transaction frame while preserving the existing token parser. Unknown versions, unknown inference records and bookkeeping with token fields still mark coverage incomplete.

Validation: swift build --product CodexBarCLI passed. A focused Swift harness verified a complete metadata-only journal, preservation of a supported inference record, and incomplete coverage for unsupported inference or malformed transaction data. Both changed files passed SwiftFormat. The app test target requires Xcode’s asset compiler and was not run locally.

Muse journal compatibility proof

Compared the installed signed app’s bundled CLI (CodexBar 0.84.0) with the product CLI built using
swift build --product CodexBarCLI at PR head a9f32e5f4457bbd51276de446a3c1c84a45503ef (CodexBar). Both ran the same cost command
on two synthetic journals in the supported date-partitioned directory layout. The fixtures contain no user data.

Both journals contain a retained permission transaction with its two metadata children, session metadata, a
schema v2 agent_tree_initialized record, task lifecycle metadata and a session-end record. The second also
contains a supported v1 model_completed event with 100 input and 25 output tokens, including 20 cached input
and 5 reasoning output tokens. The cache and reasoning counters are subsets, so the expected total is 125.

MUSE_SESSIONS_DIR="$fixture" XDG_CACHE_HOME="$isolated_cache" \
  "$cli" cost --provider muse --days 30 --json
# Repeat with the cache already populated and add --refresh for the force-refresh rows.

Actual output below contains selected CLI JSON fields plus fixture, stage, refresh flag and prior cache presence.
Each cold run starts with an empty cache. head-reuses-base-cache runs without --refresh against the incomplete
cache written by the installed CLI. The capture also checked that the file cache was written and its completeness
matched the reported coverage after each run.

{"fixture":"metadata-only","stage":"base-cold","cacheBefore":false,"forceRefresh":false,"historyCoverageIsEstablished":false,"dailyRows":0,"last30DaysTokens":null,"last30DaysCostUSD":null}
{"fixture":"metadata-only","stage":"base-warm-refresh","cacheBefore":true,"forceRefresh":true,"historyCoverageIsEstablished":false,"dailyRows":0,"last30DaysTokens":null,"last30DaysCostUSD":null}
{"fixture":"metadata-only","stage":"head-cold","cacheBefore":false,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":0,"last30DaysTokens":0,"last30DaysCostUSD":null}
{"fixture":"metadata-only","stage":"head-warm","cacheBefore":true,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":0,"last30DaysTokens":0,"last30DaysCostUSD":null}
{"fixture":"metadata-only","stage":"head-warm-refresh","cacheBefore":true,"forceRefresh":true,"historyCoverageIsEstablished":true,"dailyRows":0,"last30DaysTokens":0,"last30DaysCostUSD":null}
{"fixture":"metadata-only","stage":"head-reuses-base-cache","cacheBefore":true,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":0,"last30DaysTokens":0,"last30DaysCostUSD":null}
{"fixture":"with-supported-turn","stage":"base-cold","cacheBefore":false,"forceRefresh":false,"historyCoverageIsEstablished":false,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}
{"fixture":"with-supported-turn","stage":"base-warm-refresh","cacheBefore":true,"forceRefresh":true,"historyCoverageIsEstablished":false,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}
{"fixture":"with-supported-turn","stage":"head-cold","cacheBefore":false,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}
{"fixture":"with-supported-turn","stage":"head-warm","cacheBefore":true,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}
{"fixture":"with-supported-turn","stage":"head-warm-refresh","cacheBefore":true,"forceRefresh":true,"historyCoverageIsEstablished":true,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}
{"fixture":"with-supported-turn","stage":"head-reuses-base-cache","cacheBefore":true,"forceRefresh":false,"historyCoverageIsEstablished":true,"dailyRows":1,"last30DaysTokens":125,"last30DaysCostUSD":null,"dailyTokenMix":{"inputTokens":100,"outputTokens":25,"cacheReadTokens":20,"reasoningTokens":5}}

The installed CLI reports incomplete coverage for both journals. At the PR head, the metadata-only journal has
complete coverage with zero tokens and no daily rows, and the second has one daily row with 125 tokens. Normal
warm scans, explicit refresh and reuse of the previous incomplete cache preserve both results. Muse leaves dollar
cost unavailable in every case.

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T12:05:19.424184Z a9f32e5 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

Recognizes newer Muse bookkeeping envelopes and permission transactions without counting them as inference.

Example: A Muse journal contains session metadata, a permission transaction, and a turn with 100 input and 25 output tokens.

  • Before: The reader retains 125 tokens but reports incomplete coverage.
  • After: The reader reports complete coverage and the same 125 tokens, with monetary cost unavailable.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful, focused, and demonstrated through the shipped CLI, including existing-cache compatibility; validation otherwise consists of the reported focused harness and build rather than the full app suite.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The updated body exercises MuseLocalUsageReader through the built cost CLI at the reviewed head against isolated date-partitioned journals, recording complete coverage with zero or 125 tokens across cold, warm, refresh, and v0.84.0-cache reuse scenarios; this resolves the previous review's proof gap.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Valid newer Muse journals report incomplete token-history coverage, and metadata-only journals cannot establish an empty history.
Reason: The change restores the documented local-history behavior without adding configuration, changing inference totals, or touching credential access.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current Muse journal compatibility bug with a focused parser change; no actionable defects remain after reviewing the updated evidence.

Priority: P2
Reviewed head: a9f32e5f4457bbd51276de446a3c1c84a45503ef

Before merge

None.

Findings

None.

Agent review details

How this fits together

Muse session JSONL files enter the local history reader, which produces cached daily token totals and coverage status for the cost CLI and Usage & Spend.

flowchart LR
  A[Muse session journals] --> B[Envelope classification]
  B --> C[Inference token parser]
  B --> D[Coverage status]
  C --> E[Daily totals and file cache]
  D --> F[Token snapshot]
  E --> F
  F --> G[Cost CLI and Usage and Spend]
Loading

Technical review

Best possible solution:

Land the focused compatibility extension while preserving inference accounting, conservative unknown-record handling, and unavailable monetary values.

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

Current main rejects the newly recognized envelopes before inference parsing; contributor-supplied v0.84.0 CLI output demonstrates the resulting incomplete coverage, and head output demonstrates recovery.

Is this the best way to solve the issue?

Extending the existing reader's explicit format recognition is the smallest complete fix for the shown journals and preserves the established token-counting contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7447bc77c249.

Provenance checked

  • Muse journal schema recognition keeps the original intent (e926758: The original feature accepted verified inference formats and deliberately degraded coverage for unsupported records rather than inventing zero usage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The pinned diff adds explicit bookkeeping classification and permission-frame validation while retaining the existing inference parser and token arithmetic. (Sources/CodexBarCore/Providers/Muse/MuseLocalUsageReader.swift:524, a9f32e5f4457)
  • Shipped CLI and upgrade evidence: The updated PR body records installed v0.84.0 versus head CLI output for metadata-only and supported-inference journals, including cold, warm, explicit-refresh, and reuse-of-old-cache runs; coverage becomes complete while totals remain zero or 125 as appropriate. (a9f32e5f4457)
  • Existing cache compatibility: Only complete, valid cached files are reused; incomplete entries from the older reader are reparsed, supporting the reported upgrade result without a stored-format migration. (Sources/CodexBarCore/Providers/Muse/MuseLocalUsageReader.swift:287, a9f32e5f4457)
  • Original product contract and ownership: The merged local-history implementation preserves valid token subtotals, distinguishes unavailable history from zero, and leaves monetary values unavailable; this PR follows that intent. The feature history credits sanjay3290 and Srimi1, with steipete recorded as merger. Local rename-following history stops at an unavailable creation-era object; the supplied provenance and merged PR establish the relevant origin. (Sources/CodexBarCore/Providers/Muse/MuseLocalUsageReader.swift:520, e92675860899)
  • Targeted regression coverage: Added tests exercise metadata-only and mixed journals, preserve inference totals, and reject unsupported versions, unknown task kinds, and token-bearing bookkeeping. (TestsLinux/MuseLocalUsageReaderTests.swift:104, a9f32e5f4457)
  • Exact-head check scope: The reported check on the reviewed head is a successful GitGuardian security check; it does not establish Swift test-suite coverage. (a9f32e5f4457)

Likely related people:

  • Sanjay Ramadugu: Raw commit e926758 adds Sources/CodexBarCore/Providers/Muse/MuseLocalUsageReader.swift:497 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e92675860899; files: Sources/CodexBarCore/Providers/Muse/MuseLocalUsageReader.swift)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Newer Muse journals can lose established local-history coverage, with impact limited to that provider's token-history reporting.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-12T12:12:14.726Z sha a9f32e5 :: needs real behavior proof before merge. :: none

Reviewed November 12, 2026, 7:36 AM ET / 12:36 UTC (Revision 2).

@jslabxyz

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 12, 2026

This branch has not been deployed

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

Labels

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.

1 participant