Skip to content

fix(grok): preserve unknown usage for malformed billing tags - #3357

Merged
steipete merged 2 commits into
mainfrom
codex/grok-protobuf-tag-validation
Sep 1, 2026
Merged

fix(grok): preserve unknown usage for malformed billing tags#3357
steipete merged 2 commits into
mainfrom
codex/grok-protobuf-tag-validation

Conversation

@steipete

@steipete steipete commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

Prevent a Grok fallback response with invalid protobuf field numbers or overflowing varints from qualifying as a complete implicit-zero reading. This keeps an omitted percentage from incorrectly replacing unknown proxy usage with 0%. It follows up the completeness check in #3325 without changing valid zero-usage behavior, wire-published percentages, request bytes, authentication, or authoritative proxy plan/reset metadata.

The scanner previously checked only whether the encoded key was nonzero. Field zero with a fixed64 or empty length-delimited value passed that check and left the response marked complete. Oversized field numbers did the same; an overflowing varint could also truncate into a valid-looking key.

The repair follows the existing Antigravity reader's validation pattern: enforce the protobuf field-number range and reject overflow in the tenth varint byte. Review caught an important boundary: length-delimited fields can contain opaque bytes, not just nested protobuf messages. The scanner now descends only into the 16 message paths declared by Grok's billing descriptor and charger types, freshly checked September 1. Unknown byte fields are skipped entirely after validating their outer length, so they cannot invalidate a valid response or invent percentages/reset dates. Errors in known nested messages still propagate. Changelog and provider documentation are updated.

Verification

  • Baseline regression: four malformed cases produce eight failing assertions because they incorrectly qualify for implicit zero and replace unknown proxy usage. The highest legal field number and a valid UInt64.max scalar pass as positive controls.
  • Review regression: six opaque-byte cases at root/config levels produce 14 failing assertions before the schema-boundary repair. All six now pass, including fake percentages and reset timestamps. All 16 known message paths retain malformed-message rejection, and historical timestamps remain readable.
  • Repaired decoder: the serial Grok/architecture run passes 191 tests across 15 suites on the first run, including flat legacy and captured billing fixtures.
  • An earlier candidate's broader run encountered initialization timeouts in two unchanged synthetic RPC-process tests; an unchanged serial rerun passed. No deadlines or assertions were relaxed. Fixture construction was moved into a typed helper after Swift's test macro hit a type-checking limit.
  • Independent Codex autoreview is scoped-clean at its configured P0 threshold on the repaired candidate; maintainer review also checked tag/varint boundaries, the schema descriptor, and related decoder behavior. The valid inline P2 finding is fixed, not waived.
  • make check passes with zero violations across 2,082 Swift files and all 95 process-cleanup checks (one expected Linux-only skip on macOS).
  • Full make test passes on the repaired commit: 988 selections across 83 groups, all first-pass successful, zero failures/retries/timeouts (937.1 seconds).
  • Exact-head CI run 33500594291 succeeds on c9832713f4901ed551722665efbc6326b8723c5d: both macOS shards, all three Linux jobs, lint, the aggregate check, and GitGuardian are green.

All verification is offline with synthetic responses, credential/session-file isolation, and Keychain access suppressed. No real-account probe or production occurrence is claimed. This is independent of the live-request proof still pending on #3336.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@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: 8af4494ccc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

while index < bytes.count {
let fieldStart = index
guard let key = Self.readVarint(bytes, index: &index), key != 0 else {
guard let key = Self.readVarint(bytes, index: &index), key >> 3 > 0, key >> 3 <= 536_870_911 else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid rejecting opaque bytes as invalid nested tags

When a valid response contains an unknown length-delimited string or bytes field, the unconditional recursion at lines 501–507 applies this new field-number validation to its opaque contents. For example, an unknown bytes field containing 0x01 followed by eight zero bytes is valid protobuf wire data, but this guard interprets that payload as nested field zero, marks the entire scan incomplete, and prevents an otherwise validated active period from supplying its implicit 0% usage. Restrict completeness validation to paths known to contain submessages, or avoid propagating nested malformedness from opaque unknown fields.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in c983271. The scanner now recurses only into the message paths declared by the official billing schema. Unknown length-delimited payloads are skipped entirely after checking their outer length; their bytes contribute neither completeness failures nor invented percentages/reset dates.

The six root/config opaque-payload regressions fail with 14 assertions before the repair and pass afterward. Tests also verify that malformed messages still block implicit zero at all 16 known message paths, and historical nested timestamps remain readable. The broader Grok/architecture run passes 191 tests; full-suite and exact-head CI verification are still running before merge.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 7:23 AM ET / 11:23 UTC.

ClawSweeper review

What this changes

The PR validates malformed protobuf tags and varints in Grok billing fallback responses while treating undeclared length-delimited fields as opaque bytes.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for normal maintainer review: this owner-authored parser hardening is not on fetched main, the earlier opaque-byte concern is resolved, and captured exact-head macOS CI was still running.

Priority: P2
Reviewed head: c9832713f4901ed551722665efbc6326b8723c5d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused parser repair has appropriate regression coverage and no remaining source-level finding; exact-head macOS CI completion remains the final normal merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This owner-authored internal parser repair is exempt from the external-contributor proof gate; supplied synthetic parser/resolver tests are relevant supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This owner-authored internal parser repair is exempt from the external-contributor proof gate; supplied synthetic parser/resolver tests are relevant supplemental evidence.
Evidence reviewed 5 items Malformed-response guard: The introduced scanner marks field number zero, field numbers beyond protobuf’s 29-bit range, and overflowing varints incomplete before the implicit-zero gate can use the response.
Prior review concern resolved: The current head recurses only through listed billing-message paths, so unknown length-delimited fields are outer-length-validated but their opaque contents cannot manufacture a field or invalidate a valid response.
Regression coverage: The added cases cover malformed tags, legal boundary values, opaque bytes at both levels, and malformed declared nested messages through parsing and resolution.
Findings None None.
Security None None.

How this fits together

CodexBar reads Grok billing gRPC-web fallback data when proxy usage is unavailable, then resolves it into the menu bar usage snapshot. The parser’s completeness result determines whether an omitted usage scalar may safely appear as 0% or must remain unavailable.

flowchart LR
    A[Grok billing response] --> B[Protobuf scanner]
    B --> C[Validate tags and varints]
    C --> D{Declared billing message?}
    D -->|Yes| E[Decode nested fields]
    D -->|No| F[Skip opaque bytes]
    E --> G[Usage snapshot resolver]
    F --> G
    G --> H[Menu bar usage display]
Loading

Before merge

  • Resolve merge risk (P1) - The captured exact-head CI state still had both macOS test shards in progress; merge should wait for those results.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +21/-2, tests +82/-5, 4 files affected The small parser/docs change is paired with substantially expanded focused regression coverage.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge after the exact-head macOS test shards succeed, retaining schema-bounded recursion and the malformed/opaque-frame regression coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge after the exact-head macOS test shards succeed, retaining schema-bounded recursion and the malformed/opaque-frame regression coverage.

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

Yes: the added synthetic response fixtures exercise the parser-to-resolver path where malformed data could otherwise qualify for implicit 0% usage.

Is this the best way to solve the issue?

Yes: bounds validation plus descriptor-bounded recursive decoding is the narrowest repair that preserves valid unknown fields and existing implicit-zero semantics.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded incorrect fallback usage-display case without evidence of data loss, a security bypass, or availability loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This owner-authored internal parser repair is exempt from the external-contributor proof gate; supplied synthetic parser/resolver tests are relevant supplemental evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • sf-jin-ku: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • olddonkey: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Confirm both exact-head macOS test shards finish successfully before merge.

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 (1 earlier review cycle)
  • reviewed 2026-09-01T11:08:26.044Z sha c983271 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit c3a25fd into main Sep 1, 2026
9 checks passed
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

Landed as c3a25fd. The merged main tree exactly matches the tested head c983271, and the main checkout is clean after a fast-forward pull.

The original malformed-tag cases reproduced eight failing assertions before repair. Review then exposed a real opaque-byte boundary issue: six root/config cases reproduced 14 failing assertions before schema-bounded recursion was added. Both sets now pass, along with valid boundary scalars, malformed messages at all 16 known nested paths, historical timestamps, and existing flat/captured billing fixtures.

Verification on the final candidate:

  • swift test --no-parallel --filter 'Grok|ProviderArchitectureGatekeeperTests': 191 tests across 15 suites pass on the first run.
  • make test: all 988 selections across 83 groups pass first time, with zero failures, retries, or timeouts (937.1 seconds).
  • make check: zero violations across 2,082 Swift files; all 95 process-cleanup checks pass, with one expected Linux-only skip on macOS.
  • Codex autoreview found no actionable P0 findings in its configured scope; maintainer review and the updated PR review confirm the opaque-byte finding is fixed.
  • CI run 33500594291: both macOS shards, all three Linux jobs, lint, aggregate, and GitGuardian succeed on the exact tested head.

Tests used the same local Swift toolchain via the native SwiftPM backend, with credential/session-file isolation and Keychain access suppressed. An earlier candidate had two synthetic RPC-fixture initialization timeouts; its unchanged rerun and the final candidate both pass without relaxed deadlines or assertions. No live-account probe or production occurrence is claimed. Request bytes and authentication are unchanged; #3336 remains independent. Changelog and provider documentation are updated. No release was published.

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. 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