Guard Git file updates with the reader-observed blob SHA
Merged
SI
1mo ago+726+726+012345678901234567890123456789-89-89-01234567890123456789
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.- Successful uploads return new SHAs. All-failed conflict-only batches return 409 with
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. - Omitting the new fields retains legacy raw reads/default-branch create/update behavior. Both legacy and guarded paths now reject noncanonical relative paths (dot/traversal/backslash/control/empty segments and malformed Unicode) before provider access. Empty root upload directory remains allowed. Legacy raw paths encode literal percent/query/hash characters. These are intentional input-validation repairs; legacy Git error strings are also sanitized while retaining server-side diagnostics and existing response shapes.
Owning work: recoupable/app#2116 / recoupable/app#2140, tracked through https://github.com/recoupable/mono/issues/361. Route JSDoc and lib/sandbox/guarded-git-files.md document the contract, migration requirements and remaining decisions.
Validation:
- 177 affected tests across 27 suites pass locally. Actual route exports/validators/handlers/Git helpers are exercised against synthetic auth/snapshot/submodule/blob/GitHub boundaries: two readers, successful first update/new SHA, stale second conflict with preserved content, unchanged conditions, no update-time GET, invalid guard rejection, per-file forwarding, partial/mixed conflicts, unsafe names/paths/Unicode, binary handling, encoding and generic errors/server diagnostics.
- Repository lint, formatting, scoped changed-code/test typecheck and diff checks pass. Full local TypeScript output is byte-identical to an untouched archive of main e4d9b690 under the same dependencies (226 existing diagnostics); no clean full-repository typecheck is claimed.
- Records' existing private stale-sandbox fixture was executed unchanged against this branch: ordinary control passes, stale-overwrite acceptance still fails. Its temporary test copy was removed; the regression was not weakened or added as a failing product test.
- At exact head b0e0fa932c6b0b8b1d091cf12d2ceb43459bad79, all six checks pass. Full CI reports 1,213 suites / 6,581 tests passed; 11 suites / 13 tests skipped, including response-contract types. Incremental review reports zero new issues. Earlier findings are implemented and all review threads resolved; the final stale missing-test thread links the actual POST cases. This is not human merge approval.
Remaining boundaries and release prerequisites:
- This is the Git-backed portion of checkpoint D, not full D closure.
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. - No client is silently migrated: guarded clients must always carry their observed condition. Git commits do not synchronize already running sandboxes or accept Context facts. Draft-origin path/version linkage, rights and financial authority remain separate.
- Existing repository/submodule authorization policy remains an independent boundary. Before public release, canonical Marketing OpenAPI and its pinned Docs copy must adopt this approved contract. Hosted acceptance requires an explicitly authorized isolated repository/account.
- No customer/runtime file writes, provider actions, imports, new storage, migrations, permission/credential changes, merge or manual deployment were performed. Normal source push/automatic PR preview is distinct from hosted business-flow acceptance.