Skip to content

Codex parser panics on truncated type fields #2033

Closed

Description

@bvolpato

What happened?

ccusage aborts when a Codex JSONL record ends in a truncated "type" field. I reproduced this with my local logs on 20.0.45 and 20.0.48:

range start index 227 out of range for slice of length 226
Aborted (core dumped)

codex_line_type_flags can advance start to line.len() + 1 after a missing value or opening quote, then index line[start..] on its next iteration. This happens before the JSON parser can skip the malformed record. The release profile uses panic = "abort", so one record terminates the whole report.

I have implemented a small bounds check and a fixture regression test: patch 8c8cd6a. The regression failed before the fix and passes afterward, preserving valid usage around malformed records. Full Rust workspace tests, Node tests, Rust formatting, and Codex Clippy passed. Nix and oxlint are unavailable locally, so just fmt and just typecheck could not run.

The patched release binary also completed the full report against the unchanged local logs. The original trigger was a persisted 226-byte record ending in "type": followed by a newline, with more records after it.

I attempted to open the PR, but GitHub returned GraphQL: bvolpato does not have the correct permissions to execute CreatePullRequest. The signed patch above is ready for review or application by a maintainer.

Steps to reproduce

fixture=$(mktemp -d)
mkdir "$fixture/sessions"
printf '%s' '{"type" :' > "$fixture/sessions/rollout.jsonl"
CODEX_HOME="$fixture" npx [email protected] codex daily --offline --json

This synthetic input reproduces the same failure with range start index 10 out of range for slice of length 9 and exit status 134. No private session content is needed.

Expected behavior

Skip malformed records and continue reporting valid usage without panicking.

Version

20.0.45 and 20.0.48 on Linux x86_64. Also reproduced in current main at cde65fb before the patch.

Activity

  1. pullfrog commented on Nov 6, 2026

    @pullfrog
    Contributor
  2. added
    bugSomething isn't working
    priority:highHigh user impact or an important regression.
    triage:maintainableFits the repository's maintainable scope and needs review.
    on Nov 6, 2026
  3. github-actions commented on Nov 6, 2026

    @github-actions
    Contributor

    Pullfrog triage: priority:high
    Kind: bug
    Maintenance fit: maintainable
    Confidence: high

    Confirmed crash: truncated type field makes start exceed line length and the next slice panics, aborting the whole report. Code matches reproducer. Fix is a bounded bounds check preserving core reporting.

    Decision: kept open; Pullfrog will attempt a focused implementation PR.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:highHigh user impact or an important regression.triage:maintainableFits the repository's maintainable scope and needs review.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions