Skip to content

fix(contracts): preserve literal edge whitespace in UsageAccessRequest paths - #48342

Open
saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-676e105639
Open

saphid wants to merge 3 commits into
pingdotgg:mainfrom
saphid:hunter/c-676e105639

Conversation

@saphid

@saphid saphid commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Problem

UsageAccessRequest.paths in packages/contracts/src/usage.ts uses Schema.Array(TrimmedNonEmptyString) instead of Schema.Array(NonBlankString), unlike UsageBucket.sourcePath and UsageSourceFingerprint.resolvedHomePath in the same file. When an enabled, unasked provider resolves a transcript directory with leading or trailing whitespace (for example Pi with PI_CODING_AGENT_SESSION_DIR or --session-dir), UsageService.accessRequests populates the raw path, and server.getUsageSummary silently trims it during RPC wire encoding/decoding.

Deterministic repro on origin/main (6a4651b206788c3f21dafc7b950bcced57e05ee6)

Save prove-access-request-paths.mjs from the before/after runtime transcript outside the checkout, run vp i, then run node /path/to/prove-access-request-paths.mjs "$(mktemp -d)". It starts an isolated server with pi enabled (unasked) and PI_CODING_AGENT_SESSION_DIR="<tmp>/pi-sessions ", authenticates via t3 pair -> /api/auth/browser-session -> /api/auth/websocket-ticket/rpc, and calls server.getUsageSummary over /ws.

  • Observed: accessRequests[0].paths on the wire is ["<tmp>/pi-sessions"] (trailing space stripped, exit 1).
  • Expected: accessRequests[0].paths preserves ["<tmp>/pi-sessions "] while blank strings remain rejected (exit 0).

Change

Switch UsageAccessRequest.paths in packages/contracts/src/usage.ts from Schema.Array(TrimmedNonEmptyString) to Schema.Array(NonBlankString) so literal edge whitespace survives server.getUsageSummary wire encoding and decoding while still rejecting blank strings. Because the shared contract is used by the server and all clients (web, desktop, mobile), no server or client call-site changes are needed; current web/mobile access prompt UIs render driver descriptions rather than paths, while RPC callers receive the exact resolved directories.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Added a focused contract regression test in packages/contracts/src/rpc.test.ts (preserves literal edge whitespace in UsageAccessRequest paths over server.getUsageSummary):
    • Failed on origin/main (6a4651b206788c3f21dafc7b950bcced57e05ee6): AssertionError: expected [ '/tmp/pi-sessions', …(1) ] to deeply equal [ ' /tmp/pi-sessions', …(1) ].
    • Passed on head (706a29291372a92a637293f46ebb0ba5a78c525b).
  • Real-server WebSocket RPC before/after transcript (gist): Wire accessRequest.paths changed from ["/tmp/.../pi-sessions"] (base, exit 1) to ["/tmp/.../pi-sessions "] (head, exit 0).
  • vp run check:changed exited 0: format (0.6s), lint (1.3s), knip (14.9s), typecheck across 39 packages (41.3s), and 6 tests across 2 files (8.2s) all passed.
  • Not shown: Rendered web, desktop, or mobile screens (they do not display UsageAccessRequest.paths); relay/tunnel sessions; providers other than Pi; full CI.

Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • docs/internals/15_testing.md:48 — The standalone WebSocket repro is not a scenarios:prove scenario. State that explicitly in Not shown, or port the existing assertion to the scenario harness.
  • PR body:24 — The check:changed pass is reported, but the linked evidence does not include that run or tie its exit status to HEAD 706a29291372a92a637293f46ebb0ba5a78c525b. Attach the revision-stamped output or note that this result was not independently verified.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Dec 3, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Dec 3, 2026
@macroscopeapp

macroscopeapp Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at e27743f

Macroscope's review found this PR approvable — Usage-access requests now preserve literal whitespace at directory-path boundaries while still rejecting blank paths. This corrects path representation without changing consent or file-access permissions.

Notes:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The UsageAccessRequest schema now accepts non-blank paths without trimming surrounding whitespace. RPC tests check whitespace preservation during encoding and decoding, and rejection of whitespace-only paths.

Changes: Usage path validation

Layer / File(s) Summary
Path schema and RPC tests
packages/contracts/src/usage.ts, packages/contracts/src/rpc.test.ts
UsageAccessRequest.paths now uses NonBlankString. Tests check that leading and trailing whitespace survive encoding and decoding, and that whitespace-only paths fail decoding.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: aymankhan9

Merge Risk: Minimal · up to e2774

This change keeps leading and trailing whitespace in usage paths when they are sent over RPC, and still rejects blank paths. Tests cover the new behavior, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(contracts): preserve literal edge whitespace in UsageAccessRequest paths" matches the main change. The PR switches UsageAccessRequest.paths from TrimmedNonEmptyString to NonBlankString …
Description check Passed The description follows the repository template. It includes Problem, Change, Scope, and Verification sections. The Problem section names the file, the schema mismatch, and a reproduction path. The Ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(contracts): preserve literal edge whitespace in UsageAccessRequest paths" matches the main change. The PR switches UsageAccessRequest.paths from TrimmedNonEmptyString to NonBlankString so that leading and trailing whitespace survives RPC encoding and decoding. The title is specific, follows conventional commit form, and names the changed schema. It is 76 characters, which is within a reasonable length for a title.

Full details: Description check

Explanation

The description follows the repository template. It includes Problem, Change, Scope, and Verification sections. The Problem section names the file, the schema mismatch, and a reproduction path. The Change section explains the one-line schema switch and why no call-site changes are needed. The Scope section explains why no issue is linked. The Verification section gives a focused regression test, before/after results on the base and head revisions, and a check:changed run. It also lists what was not shown. Two gaps remain. First, the standalone WebSocket repro is not a scenarios:prove scenario, and the description does not say so. Second, the check:changed pass is not tied to HEAD 706a29291372a92a637293f46ebb0ba5a78c525b in linked evidence. These gaps are minor and do not make the description largely incomplete.

Resolution

Optional: state in the Not shown section that the standalone WebSocket repro is not a scenarios:prove scenario, or port the assertion to the scenario harness. Also attach the revision-stamped check:changed output, or note that this result was not independently verified.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9268c02 and e27743f.

Files selected for processing: 1

  • packages/contracts/src/rpc.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@saphid
saphid force-pushed the hunter/c-676e105639 branch from 9214e2a to 9268c02 Compare December 3, 2026 18:04
@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Dec 3, 2026
@macroscopeapp
macroscopeapp Bot dismissed their stale review December 3, 2026 21:18

Dismissing prior approval to re-evaluate e27743f

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

size:XS 0-9 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants