Repository navigation
Guard Git file updates with the reader-observed blob SHA - #1044
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
All reported issues were addressed across 12 files
Architecture diagram
sequenceDiagram
participant Client as API Client
participant Route as Sandbox Routes
participant Auth as Auth Validator
participant Resolver as Submodule Resolver
participant GitHub as GitHub API
participant Blob as Blob Storage
Note over Client,Blob: Guarded Git File Flow
Client->>Route: GET /api/sandboxes/file?path=draft.txt&include_revision=true
Route->>Auth: validateAuthContext()
Auth-->>Route: accountId
alt Include revision requested
Route->>Resolver: resolveSubmodulePath()
Resolver-->>Route: githubRepo + path
Route->>GitHub: GET contents/{path}?ref=main
GitHub-->>Route: content + sha (same response)
Route-->>Client: 200 { content, sha }
else Raw read (no include_revision)
Route->>GitHub: GET raw file
GitHub-->>Route: raw content
Route-->>Client: 200 { content }
end
Note over Client,Blob: Guarded Write Flow
Client->>Route: POST /api/sandboxes/files
Route->>Auth: validateAuthContext()
Auth-->>Route: accountId
Route->>Blob: Fetch uploaded blob
Blob-->>Route: file content
alt expected_sha provided (guarded)
Route->>GitHub: PUT contents/{path} (sha + branch: main)
GitHub-->>Route: New blob sha
Route-->>Client: 200 { uploaded: [{sha}] }
alt Conflict (stale sha)
Route->>GitHub: PUT contents/{path} (stale sha)
GitHub-->>Route: 409 Conflict
Route-->>Client: 409 { conflicts: [file] }
end
alt Partial success
Route->>GitHub: PUT file A (valid sha)
GitHub-->>Route: sha A
Route->>GitHub: PUT file B (stale sha)
GitHub-->>Route: 409 Conflict
Route-->>Client: 200 { uploaded: [A], conflicts: [B] }
end
else No expected_sha (legacy)
Route->>GitHub: GET contents/{path} (fetch latest sha)
GitHub-->>Route: current sha
Route->>GitHub: PUT contents/{path} (sha, default branch)
GitHub-->>Route: New blob sha
Route-->>Client: 200 { uploaded: [{sha}] }
end
Note over Route,Blob: Temporary blob deletion occurs after every write attempt
Note over Client,GitHub: Authorization: x-api-key or Bearer token required
Note over Client,GitHub: Access: Account snapshots + submodule resolution before GitHub calls
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
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. Comment |
There was a problem hiding this comment.
All reported issues were addressed across 17 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 9 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
Stale Git-backed draft uploads can overwrite a newer edit because the existing helper replaces the reader's revision with a freshly fetched SHA. Add an opt-in condition that keeps the reader's SHA unchanged through GitHub's atomic commit boundary.
GET /api/sandboxes/file?include_revision=truereturns content and blobshafrom one response onmain. It supports regular files with inline base64 content, preserves known binary encodings, and rejects invalid UTF-8 rather than returning corrupted editable text.POST /api/sandboxes/filesacceptsfiles[].expected_sha. Guarded updates use that SHA onmain, with no fresh-SHA lookup or automatic conflict retry. The commit helper independently fails closed if a guarded update has no valid condition.conflicts; all-failed mixed failures return 500 with conflicts preserved; partial successes retain 200 and their successful receipts/errors/conflicts. Existing temporary-blob cleanup remains unchanged.Owning work: recoupable/app#2116 / recoupable/app#2140, tracked through recoupable/mono#361. Route JSDoc and
lib/sandbox/guarded-git-files.mddocument the contract, migration requirements and remaining decisions.Validation:
Remaining boundaries and release prerequisites:
editFileTool→Sandbox.writeFile→ SDKwriteFilesremains unconditional. The guide names the required atomic comparison/replacement, writer participation, crash/path/creation and adoption decisions. A second read, rename alone or per-process mutex is not presented as a fix.