[PR #6159] [MERGED] fix(browser): report zero decoded bytes for undecodable gRPC-web text #7173

Closed
opened 2026-11-01 21:45:54 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/6159
Author: @Abelo9996
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @morluto

Base: main ← Head: fix-5942-grpc-web-text-decoded-bytes


📝 Commits (1)

  • 3265c97 fix(browser): report zero decoded bytes for undecodable gRPC-web text

📊 Changes

2 files changed (+13 additions, -7 deletions)

View changed files

📝 src/browser/history/protobuf/ProtobufBody.ts (+1 -1)
📝 src/browser/history/protobuf/ProtobufWire.test.ts (+12 -6)

📄 Description

Summary

Fixes #5942.

When gRPC-web-text protocol text fails base64 preparation, inspect-web-network-capture reported the retained text length as decoded_bytes even though nothing was decoded. For AB== it said 4 decoded bytes, for !!!! also 4, and for a valid chunk followed by AB== it said 16. It now reports 0, which matches the absence of a decoded body. The partial status, error, zero examined bytes and the retained source descriptor are unchanged.

Problem and expected behavior

decodeProtobufBody in src/browser/history/protobuf/ProtobufBody.ts initialized decoded_bytes to body.length and only overwrote it with data.length after preparation succeeded. For gRPC-web-text, body is the retained base64 text, so the early data === undefined return left the encoded length in a field whose coordinates are documented as base64-decoded body bytes. Retained length already lives on the binary sidecar, so decoded_bytes should not fall back to it.

Change and scope

decoded_bytes now starts at 0 and is set from the prepared buffer once one exists. That is the only place the value is produced, so the fix is at the owner rather than in a projection. Successful bodies are unchanged because they still assign data.length. Raw, gRPC and gRPC-web bodies always have prepared data, so their counts are also unchanged.

Not included: recovering frames from a valid prefix before a later bad chunk, and any change to offset_basis. The issue explicitly does not ask for either.

Follow the contribution scope.
Scope decision: not applicable (ordinary fix within existing boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: decodeProtobufBody (protobuf body owner), at body result construction.
  • Contribution scope fit and linked maintainer decision: ordinary bug fix, not applicable.
  • CLI and MCP/tool-catalog contract: no schema change. decoded_bytes keeps its type and is now 0 on this failure path.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: decoded-byte accounting on failed gRPC-web-text preparation is corrected. Retained source bytes, hashes and sidecars are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact (CI generates and validates ignored catalogs and skills/; edit authored instructions in .agents/skills/reverse-engineer-anything/ and never commit build outputs): none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/browser/history/protobuf/ProtobufWire.test.ts. The existing base64 chunk test only checked status for AB==. It now checks AB==, !!!! and a valid chunk followed by AB==, and expects decoded_bytes: 0, status: "partial", examined_bytes: 0, no frames or fields, and an error at offset 0.

  • Base reproduction or other evidence (executed): with the test change and without the fix, the test fails on the first case:

    FAIL src/browser/history/protobuf/ProtobufWire.test.ts > decodes independently padded base64 chunks with explicit coordinates and rejects noncanonical text
    AssertionError: expected { …(13) } to match object { decoded_bytes: +0, …(5) }
    -   "decoded_bytes": 0,
    +   "decoded_bytes": 4,
    Tests  1 failed | 14 passed (15)
    

    With the fix: Tests 15 passed (15).

  • User-visible CLI/MCP output (if applicable): I ran the issue's five HAR 1.2 fixtures through node scripts/rea.mjs inspect-web-network-capture <file> har --record 0 --json on a build of base 2aadcf7d and on a build with this change, then read normalized_result.records[0].protobuf[0]. All runs exited 0.

    Protocol text decoded_bytes before decoded_bytes after status / examined
    AAAAAAIIAQ== (control) 7 7 complete / 7
    AB== 4 0 partial / 0
    !!!! 4 0 partial / 0
    AAAAAAIIAQ==AB== 16 0 partial / 0
    empty 0 0 complete / 0

    The error reason (gRPC-web text is not canonical base64 or independently padded base64 chunks) is the same before and after.

  • Remaining proof gaps: MCP transport and the separate protobuf body view command were not executed. The view projects the stored count, so I expect it to show the same change, but I did not run it.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

Run with the pinned Node 24.18.0 on macOS arm64.

  • npm run test:focused -- src/browser/history/protobuf/ProtobufWire.test.ts: 15 passed (fails 1 of 15 without the fix, shown above)
  • npm run test:focused -- src/browser/history/protobuf/ProtobufCapture.test.ts src/browser/history/protobuf/ProtobufBodyTrailer.test.ts: 7 passed
  • npm run check: exit 0 (typecheck, lint, format:check, knip, metadata:check, architecture guards)
  • CLI reproduction above, on builds from npm run build:cached with and without the fix

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Consumers that read decoded_bytes on this failure path now get 0 instead of the encoded text length.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable. Offline HAR inspection on macOS only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new inputs, execution or I/O.

Author readiness

Human owner: @Abelo9996

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/6159 **Author:** [@Abelo9996](https://github.com/Abelo9996) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix-5942-grpc-web-text-decoded-bytes` --- ### 📝 Commits (1) - [`3265c97`](https://github.com/morluto/rea/commit/3265c977ec8d49e78f4ff2f5a3c5a691618abcbf) fix(browser): report zero decoded bytes for undecodable gRPC-web text ### 📊 Changes **2 files changed** (+13 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/browser/history/protobuf/ProtobufBody.ts` (+1 -1) 📝 `src/browser/history/protobuf/ProtobufWire.test.ts` (+12 -6) </details> ### 📄 Description ## Summary Fixes #5942. When gRPC-web-text protocol text fails base64 preparation, `inspect-web-network-capture` reported the retained text length as `decoded_bytes` even though nothing was decoded. For `AB==` it said 4 decoded bytes, for `!!!!` also 4, and for a valid chunk followed by `AB==` it said 16. It now reports 0, which matches the absence of a decoded body. The partial status, error, zero examined bytes and the retained source descriptor are unchanged. ## Problem and expected behavior `decodeProtobufBody` in `src/browser/history/protobuf/ProtobufBody.ts` initialized `decoded_bytes` to `body.length` and only overwrote it with `data.length` after preparation succeeded. For gRPC-web-text, `body` is the retained base64 text, so the early `data === undefined` return left the encoded length in a field whose coordinates are documented as base64-decoded body bytes. Retained length already lives on the binary sidecar, so `decoded_bytes` should not fall back to it. ## Change and scope `decoded_bytes` now starts at 0 and is set from the prepared buffer once one exists. That is the only place the value is produced, so the fix is at the owner rather than in a projection. Successful bodies are unchanged because they still assign `data.length`. Raw, gRPC and gRPC-web bodies always have prepared data, so their counts are also unchanged. Not included: recovering frames from a valid prefix before a later bad chunk, and any change to `offset_basis`. The issue explicitly does not ask for either. Follow the [contribution scope](https://github.com/morluto/rea/blob/main/CONTRIBUTING.md#contribution-scope). Scope decision: not applicable (ordinary fix within existing boundaries). ## Contract and boundary impact - Semantic owner and earliest changed stage: `decodeProtobufBody` (protobuf body owner), at body result construction. - Contribution scope fit and linked maintainer decision: ordinary bug fix, not applicable. - CLI and MCP/tool-catalog contract: no schema change. `decoded_bytes` keeps its type and is now 0 on this failure path. - Provider, bridge, target-format, or platform compatibility: none. - Evidence, artifact, provenance, or reconstruction contract: decoded-byte accounting on failed gRPC-web-text preparation is corrected. Retained source bytes, hashes and sidecars are unchanged. - Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable. - Generated metadata (`docs/public/product-catalog.json`), package, or installation impact (CI generates and validates ignored catalogs and `skills/`; edit authored instructions in `.agents/skills/reverse-engineer-anything/` and never commit build outputs): none. Expected effects (check known effects; use documentation-only on its own). Unchecked items do not establish absence; leave uncertainties visible. - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added or updated: `src/browser/history/protobuf/ProtobufWire.test.ts`. The existing base64 chunk test only checked `status` for `AB==`. It now checks `AB==`, `!!!!` and a valid chunk followed by `AB==`, and expects `decoded_bytes: 0`, `status: "partial"`, `examined_bytes: 0`, no frames or fields, and an error at offset 0. - Base reproduction or other evidence (executed): with the test change and without the fix, the test fails on the first case: ``` FAIL src/browser/history/protobuf/ProtobufWire.test.ts > decodes independently padded base64 chunks with explicit coordinates and rejects noncanonical text AssertionError: expected { …(13) } to match object { decoded_bytes: +0, …(5) } - "decoded_bytes": 0, + "decoded_bytes": 4, Tests 1 failed | 14 passed (15) ``` With the fix: `Tests 15 passed (15)`. - User-visible CLI/MCP output (if applicable): I ran the issue's five HAR 1.2 fixtures through `node scripts/rea.mjs inspect-web-network-capture <file> har --record 0 --json` on a build of base `2aadcf7d` and on a build with this change, then read `normalized_result.records[0].protobuf[0]`. All runs exited 0. | Protocol text | `decoded_bytes` before | `decoded_bytes` after | status / examined | | --- | --- | --- | --- | | `AAAAAAIIAQ==` (control) | 7 | 7 | complete / 7 | | `AB==` | 4 | 0 | partial / 0 | | `!!!!` | 4 | 0 | partial / 0 | | `AAAAAAIIAQ==AB==` | 16 | 0 | partial / 0 | | empty | 0 | 0 | complete / 0 | The error reason (`gRPC-web text is not canonical base64 or independently padded base64 chunks`) is the same before and after. - Remaining proof gaps: MCP transport and the separate protobuf body view command were not executed. The view projects the stored count, so I expect it to show the same change, but I did not run it. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed Run with the pinned Node 24.18.0 on macOS arm64. - `npm run test:focused -- src/browser/history/protobuf/ProtobufWire.test.ts`: 15 passed (fails 1 of 15 without the fix, shown above) - `npm run test:focused -- src/browser/history/protobuf/ProtobufCapture.test.ts src/browser/history/protobuf/ProtobufBodyTrailer.test.ts`: 7 passed - `npm run check`: exit 0 (typecheck, lint, format:check, knip, metadata:check, architecture guards) - CLI reproduction above, on builds from `npm run build:cached` with and without the fix ## Compatibility, safety, and release - Breaking changes or migration steps: none. Consumers that read `decoded_bytes` on this failure path now get 0 instead of the encoded text length. - Real Hopper/Ghidra, browser, or OS coverage: not applicable. Offline HAR inspection on macOS only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new inputs, execution or I/O. ## Author readiness Human owner: @Abelo9996 - [x] I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] The PR has one focused outcome and the title follows `type(scope): outcome`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] Tests cover changed observable behavior and meaningful failure paths. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-01 21:45:54 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#7173
No description provided.