Repository navigation
Package preview: exact payload bytes and a labelled input-token range - #31
Merged
Merged
Conversation
The preview gives the size of the whole payload as Codex gets it, measured on the same rendering the run sends. Input tokens before a run are a range from the last 50 successful reviews in the local ledger (a straight line, widened by the largest miss among them), shown only from 20 such reviews and within the sizes they cover; otherwise unknown, with the reason. The ledger is opened read-only and the range is never recorded. After a run the reply puts the bytes sent beside the input, cached and uncached tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… locked ledger The run that starts Codex no longer computes the estimate or reads the ledger for it; it still measures payload_bytes and reports Codex's own counts after the run. The preview opens the ledger read-only with no busy wait, so a ledger another process holds locked reads as unknown (ledger_busy) at once instead of after about five seconds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The package preview (
review_package,modelquad review package) now says how big the payload is and, when the local record allows, roughly how many input tokens it will cost. Until now it said ModelQuad does not estimate tokens.payload_bytesis the byte length of the rendering the run sends: the task text, ModelQuad's instruction, the files as JSON with their line-number prefixes, and the completion-envelope instruction.noshell.render_suppliedrecords it in its report. The executor'sfile_auditcarries it as a bounded integer (closed_file_audit), and it is kept in the package manifest in the ledger. The package id does not change.review_ledger.input_token_estimate()fits a straight line through the last 50 successful reviews in the ledger: task-text bytes plus file bytes against the input tokens Codex reported. It widens the line by the largest relative miss among those reviews and rounds outward to the thousand. It returns unknown, with the reason, when there are fewer than 20 such reviews, when the package falls outside the sizes they cover, or when the ledger cannot be read. It opens the ledger read-only (mode=ro) and never creates it. The range is removed beforerun()records the package, so the ledger never stores it. No price is estimated.usagegainspayload_bytesanduncached_input_tokens(input minus cached, only when Codex reported both). The reply lines add "the whole payload was N bytes" and "Of the input tokens, C came from Codex's cache and U did not."Why this is honest (invariant 4)
The estimate is computed only from runs recorded on this computer, and it is never called a count. Evidence from the installed ledger on the maintainer's machine, read-only: 18 answered runs have both a package and token counts. A least-squares line gives about 17,700 tokens plus 0.33 tokens per byte, and no run is off the line by more than 4.3%. A near-empty package still costs about 18,300 input tokens: that part is Codex's own instructions, which ModelQuad cannot see. Older runs with no files, from earlier Codex releases, cost about 19,980, so that fixed part moves with the release. That is why the range uses only the latest 50 runs and needs at least 20 before it shows. With 18 runs, that machine reads "unknown" today. Cached tokens (0 / 7,296 / 15,744 seen) depend on timing and are not estimated.
The owner chose this approach (exact bytes plus a range from the record) over bytes alone.
Update after review (24ec29f)
package(..., estimate=True)fromreview_packageandmodelquad review package). The run that starts Codex skips it and the ledger read it needs;payload_bytesand Codex's reported counts are unchanged.timeout=0): a ledger another process holds locked now reads as unknown (ledger_busy) at once, where it used to wait about five seconds.input_token_estimateand still reports the bytes and the counts; with the ledger held byBEGIN EXCLUSIVE, the preview returns its bytes in under a second with the estimate unknown.check.py reviewPASS;check.py pythonPASS (3,276 passed, 39 skipped, 1 known xfail; serial timing 2 passed).Checks
python scripts/check.py review: PASSpython scripts/check.py python: PASS (3,274 passed, 39 skipped, 1 known xfail; serial timing 2 passed)tests/test_review_flow.py: exact payload size; unknown with no record (and the ledger file is not created); 19 vs 20 runs; range around the line, rounding, and width from the largest miss; outside the recorded sizes; failed runs and runs without counts are ignored; only the latest 50 runs count; an unreadable ledger is left untouched; the range is not in the reply or the record of a run; reply lines for the cached and uncached split; uncached stays unknown unless both counts are present.tests/test_attached_file_rules.py: the audit keepspayload_bytesonly as a bounded integer.Docs: README (not a cost estimator), SECURITY (where the range comes from and its limits), PRIVACY (the range is computed locally from the ledger; the manifest keeps the payload size), AGENTS.md current state, CHANGELOG Unreleased.
🤖 Generated with Claude Code