Skip to content

fix(server): keep Gitea PR diffs consistent after branch updates - #77

Merged
kalvenschraut merged 1 commit into
rtvisionfrom
t3code/fix-pr-viewed-files
Oct 2, 2026
Merged

kalvenschraut merged 1 commit into
rtvisionfrom
t3code/fix-pr-viewed-files

Conversation

@kalvenschraut

Copy link
Copy Markdown
Member

Problem

Updating a Gitea PR branch can temporarily leave its saved merge base behind the current branch. T3 then displays incoming base-branch files that Gitea excludes from its current PR diff, and marking those files viewed fails with HTTP 422.

Change

Use the fork's raw comparison API with the current base commit and mirrored PR head. Keep historical diffs for closed and merged PRs and existing behavior on hosts without raw comparisons.

Carry the rendered patch's blob IDs into full-file context requests and their cache keys. Gitea accepts only contents matching those IDs, including a bounded fallback to the updated base commit. Context expansion returns an error when the patch lacks required IDs or matching contents are unavailable, so it cannot mix a fresh patch with stale lines. This includes pure renames and mode-only patches that omit index hashes.

Scope and approval

Requested maintainer fix for the RTVision fork, targeting rtvision. The adapter, contract, and hydration changes address the same comparison mismatch. Web and desktop use the shared loader; other providers retain their existing content requests, and the new wire fields are optional.

Verification

  • vp test run apps/server/src/pullRequest/GiteaPullRequestApi.test.ts apps/web/src/lib/diffFileContents.test.ts packages/client-runtime/src/state/pullRequests.test.ts: 171 tests passed. Coverage includes stale merge bases, source heads ahead of mirrored heads, exact context blobs, missing revision identities, historical/commit diffs, and concurrent expansion requests.
  • Scoped server, web, and client-runtime typechecks passed. Targeted lint, formatting, and diff checks passed.
  • Read-only requests against rtvision/monorepo PR Fix project deletion being blocked by archived threads pingdotgg/t3code#2039 returned a raw comparison with exactly the same 17 files and head as the native viewed-file API. No live viewed marks were changed.
  • GPT-6 Astra independently reviewed the final source and returned GO after its findings were addressed.
  • No browser verification was performed; the branch-update timing window is covered by regression fixtures.

Implemented with GPT-6.1 Sol through the Codex harness.

@kalvenschraut

Copy link
Copy Markdown
Member Author

@coderabbitai review

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.5 KiB 13.5 KiB +1 B (+0.0%) 15.1 KiB ✅
Codex Thread snapshot wire 7.1 KiB 7.1 KiB +6 B (+0.1%) 7.3 KiB ✅
Codex Live turn WebSocket wire 6.5 KiB 6.5 KiB −5 B (−0.1%) 7.8 KiB ✅
Codex Live turn WebSocket decoded 56.3 KiB 56.3 KiB 0 B (0.0%) 66.4 KiB ✅
Codex Live turn messages 10 10 0 (0.0%) 21 ✅
Claude Total thread wire 13.5 KiB 13.5 KiB −28 B (−0.2%) 15.1 KiB ✅
Claude Thread snapshot wire 7.1 KiB 7.1 KiB −3 B (−0.0%) 7.3 KiB ✅
Claude Live turn WebSocket wire 6.5 KiB 6.4 KiB −25 B (−0.4%) 7.8 KiB ✅
Claude Live turn WebSocket decoded 57.0 KiB 57.0 KiB 0 B (0.0%) 66.4 KiB ✅
Claude Live turn messages 9 9 0 (0.0%) 21 ✅

Baseline: d0136d6 · PR result: aafff8e · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 113.9 KiB
  • Claude decoded thread snapshot: 114.6 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: RTVision/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 0b6928e0-06ef-41ec-86fa-f44f2640997e

📥 Commits

Reviewing files that changed from the base of the PR and between d0136d6 and aafff8e.

📒 Files selected for processing (10)
  • apps/server/src/pullRequest/GiteaPullRequestApi.test.ts
  • apps/server/src/pullRequest/GiteaPullRequestApi.ts
  • apps/server/src/pullRequest/GiteaPullRequestProvider.ts
  • apps/server/src/pullRequest/PullRequestProvider.ts
  • apps/server/src/pullRequest/PullRequestService.ts
  • apps/web/src/lib/diffFileContents.test.ts
  • apps/web/src/lib/diffFileContents.ts
  • packages/client-runtime/src/state/pullRequests.test.ts
  • packages/client-runtime/src/state/pullRequests.ts
  • packages/contracts/src/pullRequest.ts

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


📝 Walkthrough

Walkthrough

Open pull-request diffs can use recorded base and current head revisions. Diff-file loading now carries blob IDs through content requests and cache keys. Gitea verifies returned file contents against those IDs and can try the pull-request base ref for old contents.

Changes

Gitea pull-request diffs

Layer / File(s) Summary
Select immutable pull-request diffs
apps/server/src/pullRequest/GiteaPullRequestApi.ts, apps/server/src/pullRequest/GiteaPullRequestApi.test.ts
Open pull requests use a base-to-head comparison when feature discovery reports pull-revert. Other pull-request diffs retain the pull-request endpoint, and explicit commit diffs retain the commit endpoint. Tests cover these paths and missing base revisions.
Carry blob IDs through diff loading
packages/contracts/src/pullRequest.ts, apps/web/src/lib/diffFileContents.ts, apps/web/src/lib/diffFileContents.test.ts, packages/client-runtime/src/state/pullRequests.ts, packages/client-runtime/src/state/pullRequests.test.ts, apps/server/src/pullRequest/PullRequestProvider.ts, apps/server/src/pullRequest/PullRequestService.ts, apps/server/src/pullRequest/GiteaPullRequestProvider.ts
The input contract accepts optional old and new blob IDs. Web loading forwards them and includes them in cache keys. Runtime single-flight keys distinguish requests with different blob IDs. Server provider calls forward the IDs.
Verify file contents against blob IDs
apps/server/src/pullRequest/GiteaPullRequestApi.ts, apps/server/src/pullRequest/GiteaPullRequestApi.test.ts
Gitea content lookup checks returned SHAs against supplied blob IDs. Old-content lookup can try the pull-request base ref. Tests cover updated branches, mismatches, missing IDs, and files absent at the saved merge base.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: bil0000

Merge Risk: ⚪ Minimal · up to aafff

The change keeps Gitea pull-request diffs and context expansion tied to the revisions shown to the reviewer. Fallbacks to the existing endpoints are preserved, and tests cover them. No concrete merge-blocking risk was found.

Security Architecture Review

Security architecture risk: 🔵 Low · up to aafff

The change strengthens consistency between displayed diffs and expanded file contents without showing an increase in write privileges or repository access. Older clients and patches without revision identifiers can receive expansion errors. Remaining uncertainty prevents an unconditional minimal-risk assessment.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed operations affect repository content read under the existing Gitea credential authority and the integrity of reviewer-visible context. Inspected new requests remain within the selected host and repository; they do not introduce a cross-host, cross-repository, or write-authority path.

Trust Boundaries and Controls

  • observed — The existing request boundary validates the configured or approved host and owner/name repository format. File paths reject traversal and are component-encoded; query values are encoded. The content RPC remains assigned read scope and wrapped with the pull-request viewer context.
  • inferred — An empty-string ID would bypass truthiness-based checks in the internal API, but it is invalid under the declared RPC payload schema. The inspected public route therefore does not substantiate that bypass as an externally reachable PR-introduced concern.

Resilience and Maintainability Implications

  • observed — Unavailable capability metadata causes open-PR expansion to require blob identities rather than silently weakening verification. Missing required IDs, missing revisions, and nonmatching contents terminate with errors. New and deleted files synthesize an empty string only for the absent side.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title is concise, uses the conventional commit format, and clearly identifies the main Gitea pull-request diff consistency fix.
Description check ✅ Passed The description includes all required sections. It clearly explains the problem, the cross-component change, scope, and detailed verification results, including tests and known limitations.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kalvenschraut
kalvenschraut merged commit 9dc9d59 into rtvision Oct 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant