Stravin Core ⟷ Stravin Review¶
This specification defines the contract between Stravin Core (bare Git storage engine) and Stravin Review (pull requests, stacked diffs, inline review, and repository browser).
1. Boundary & Ownership¶
| Concern | Source of Truth | Private Implementation Details (Never Crosses Boundary) |
|---|---|---|
Git objects, packs, refs, default_branch, object_format |
Stravin Core | S3 pack layout, DynamoDB RS#s/RH#s/MS#m sharding, stravin-node NVMe cache, stravin-pack compaction |
PR lifecycle, review comments, approvals, stacked-diff topology (base_ref -> parent head_ref), draft state |
Stravin Review | Review SQL/document database, inline comment anchoring heuristics, UI notification preferences |
PR synthetic/head refs (refs/stravin/pr/{pr_id}/head, refs/stravin/pr/{pr_id}/merge) |
Stravin Core (storage) / Stravin Review (lifecycle) | Core stores refs via Ref-CAS; Review decides when to create, update, retarget, or clean them up |
| Synchronous push guardrails (Tier 1 Wasm hooks) | Stravin Core (execution) | wazero module cache, bulkhead semaphore; Review surfaces hook rejection messages to web-editor commits |
2. Interaction Flow¶
sequenceDiagram
actor Dev as Developer / Agent
participant Edge as Stravin Core (stravin-edge)
participant Node as Stravin Core (stravin-node)
participant Relay as Stravin Core (stravin-relay)
participant NATS as NATS JetStream (STRAVIN_CORE)
participant Review as Stravin Review
Dev->>Edge: git push origin feature-branch (Smart HTTP/SSH)
Edge->>Node: gRPC stravin.core.v1.GitWire/Stream (Cilium eBPF, 0 proxy hop)
Node->>Node: Index pack + S3 PutObject || Wasm pre-receive
Node->>Node: DynamoDB TransactWriteItems (RS + RH + MS)
Node-->>Dev: Push ACK (new commit_oid)
Note over Node,Relay: DynamoDB Streams transactional outbox (RH#s INSERT)
Relay->>NATS: Publish stravin.core.<tenant>.<repo>.ref.updated (Nats-Msg-Id, traceparent) [vNext]
NATS-->>Review: Durable consumer delivery (review-core-refs)
Review->>Review: Match branch to open PRs / stacked diffs
Review->>Node: gRPC GitData.CompareDiff(base_oid, head_oid) [vNext]
Node-->>Review: Changed paths, hunks, merge_base_oid
Review->>Review: Re-anchor inline comments & update PR revision
opt Web UI Edit / PR Branch Update / Direct Merge (non-gated)
Review->>Edge: git-receive-pack or gRPC GitData.CreateCommitAndUpdateRef [vNext]
Edge-->>Review: Committed new_oid or REF_CONFLICT
end
3. Auth, Tenancy & Trust Boundary¶
- Cilium eBPF Transport & Network Policy: Internal gRPC and HTTP calls between Review and Core traverse Cilium (eBPF) transparent WireGuard/SPIFFE mTLS with
CiliumNetworkPolicyallowlists (zero sidecar proxy hop on Core's 256 MiB Git streams;stravin-edgeretains Go HRW(tenant_id, repo_id)pinning via headless Kubernetes Service). - Mandatory App-Level Tenancy Check: Cilium verifies workload identity, NOT
tenant_id. Every Core RPC/HTTP handler and every Review JetStream consumer MUST verifytenant_idin constant time in application code (matchingedge.AuthorizeTenantin Corev1.12.x). - Git Wire Operations (Implemented in Core v1.12.x): Review authenticates to
stravin-edgeover Smart HTTP (Authorization: Bearer <token>) or SSH. Corev1.12.xenforcesedge.AuthorizeTenantso a Review credential minted fortenant_id=acmecan never read or write another tenant's repo. - Scoped Service Tokens (Proposed Core Extension vNext): Review exchanges end-user session identity for short-lived (5-minute) Core tokens containing
tenant_id,repo_id,actor_id(original human/agent ID for audit and WasmPushContext.actor_id), andscopes(git:read,git:write:pr-refs,git:write). - Git Data Read API (Proposed Core Extension vNext): Service-to-service gRPC over Cilium eBPF mTLS (or app-level TLS 1.3 mTLS locally via
RequireAndVerifyClientCert, matchinginternal/rpc/auth.go), carrying signed service JWTs plus mandatory metadatax-stravin-tenant-id,x-stravin-repo-id,x-stravin-actor-id, andtraceparent. - Event Transport Auth: In Core
v1.12.x, direct HTTP webhooks are verified viaX-Stravin-Signature-256(async.VerifySignature). InvNext, Review consumes from NATS JetStream over Cilium mTLS + scoped NATS credentials (stravin.core.*.*.ref.updated) and verifies envelopetenant_idagainst the subject token.
4. Synchronous Interfaces¶
4.1 Git Wire Protocol — Implemented in Core v1.12.x¶
Review uses Smart HTTP/SSH on stravin-edge for web-editor commits, branch creation/deletion, and fallback cloning:
GET /{tenant_id}/{repo_id}.git/info/refs?service=git-upload-pack|git-receive-packPOST /{tenant_id}/{repo_id}.git/git-upload-pack(Git-Protocol: version=2)POST /{tenant_id}/{repo_id}.git/git-receive-pack(decompressed body cap256 MiB)- Internal
stravin-edge->stravin-nodetransport:/stravin.core.v1.GitWire/Streamwith codecstravin-gitwireand headersx-stravin-tenant-id,x-stravin-repo-id,x-stravin-operation,x-stravin-git-protocol,traceparent.
4.2 Read-Only Git Data & Diff API — Proposed Core Extension (vNext)¶
To render PR diffs, file browsers, blame, and stacked-diff base comparisons without cloning full repositories into Review pods, Core exposes a stateless gRPC service backed by stravin-node's warm NVMe cache and S3 pack plane:
syntax = "proto3";
package stravin.core.v1;
service GitData {
rpc GetRepoMeta(GetRepoMetaRequest) returns (RepoMetaResponse);
rpc ListRefs(ListRefsRequest) returns (ListRefsResponse);
rpc GetCommit(GetCommitRequest) returns (CommitResponse);
rpc ListTree(ListTreeRequest) returns (ListTreeResponse);
rpc GetBlob(GetBlobRequest) returns (stream BlobChunk);
rpc MergeBase(MergeBaseRequest) returns (MergeBaseResponse);
rpc CompareDiff(CompareDiffRequest) returns (stream DiffFileEntry);
rpc CreateCommitAndUpdateRef(CreateCommitRequest) returns (UpdateRefResponse);
}
message GetBlobRequest {
string tenant_id = 1;
string repo_id = 2;
string blob_oid = 3; // 40-hex (sha1) or 64-hex (sha256)
uint64 max_bytes = 4; // bounded streaming cap enforced by Core
}
message CompareDiffRequest {
string tenant_id = 1;
string repo_id = 2;
string base_oid = 3; // 40-hex (sha1) or 64-hex (sha256)
string head_oid = 4;
bool three_dot = 5; // true => diff(merge_base(base, head), head)
uint32 context_lines = 6; // default 3
uint32 max_files = 7; // pagination cap (default 500)
string page_token = 8;
}
message DiffFileEntry {
string path = 1;
string old_path = 2; // populated on rename
string change_kind = 3; // "add" | "modify" | "delete" | "rename"
string mime_type = 4; // detected MIME type (e.g. "text/x-go", "image/png")
bool is_binary = 5;
string old_blob_oid = 6;
string new_blob_oid = 7;
uint64 old_size_bytes = 8;
uint64 new_size_bytes = 9;
uint32 additions = 10;
uint32 deletions = 11;
repeated DiffHunk hunks = 12; // empty ([]) for binary / non-text files
bytes unified_patch = 13; // empty for binary files; truncated if > max_patch_bytes
bool patch_truncated = 14;
}
- Pluggable Diff Renderer Metadata: Every
DiffFileEntrycarriesmime_type,is_binary,old_blob_oid,new_blob_oid,old_size_bytes, andnew_size_bytesso Review'sDiffRendererregistry (Pull Requests UI, ADR-0004) can select code, image, binary fallback, or future renderers without extra metadata round-trips. - Bounded On-Demand Blob Streaming (
hunks: []+GetBlob): Binary and non-text files always returnhunks: [](and emptyunified_patch) in the diff JSON/gRPC response—diff responses never base64-inflate binary payloads. When a lazy-loaded renderer (for exampleImageDiffRenderer) needs file contents,stravin-webstreams rawold_blob_oid/new_blob_oidbytes on demand viaGitData.GetBlobwith a boundedmax_byteslimit and serves them withX-Content-Type-Options: nosniffand strict CSP.
4.3 Tier 1 Wasm Hook Rejection Surface — Implemented in Core v1.12.x¶
When Review submits a commit (e.g., applying a suggested change or resolving a conflict in the UI), Core executes configured Tier 1 wazero Wasm hooks (HookHostABI). A REJECT verdict returns the hook's message and per-ref ref_verdicts over Git side-band stderr (or structured FAILED_PRECONDITION details on CreateCommitAndUpdateRef) so Review can render the exact guardrail violation inline.
4.4 Stacked PR Branch Resolution, Base Retargeting & Fast-Forward Ref Advancement — Proposed Contract (vNext)¶
Stravin supports first-class branch-on-branch stacked pull requests without hidden metadata refs or custom Git wire extensions:
- Branch-on-Branch Stack Resolution: When a PR's
base_refequals another open PR'shead_ref(for examplePR #101 (feat/auth -> main)<-PR #102 (feat/auth-ui -> feat/auth)<-PR #103 (feat/auth-tests -> feat/auth-ui)), Stravin Review resolves the contiguous directed chain in its PR graph and computes each PR's incremental diff viaGitData.CompareDiff(base_oid=parent_head_oid, head_oid=child_head_oid, three_dot=true). Review rejects cyclicbase_refchains before persisting. - Automatic Base-Branch Retargeting (Bottom-Up Merge): When the bottom PR (
#101) lands onmainviaBOTTOM_UP_CASCADE, Core emitscore.ref.updatedforrefs/heads/main(and optional deletion ofrefs/heads/feat/auth). Review atomically updates#102'sbase_reffromrefs/heads/feat/authtorefs/heads/main, re-evaluatesGitData.MergeBase(main_oid, pr102_head_oid)andGitData.CompareDiff, and emitsreview.pr.base_retargeted(STRAVIN_REVIEW) without requiring manual retargeting by the author. - Fast-Forward Ref Advancement: For linear stacks and bottom-up merges, ref updates advance via fast-forward (
old_oidis an ancestor ofnew_oidverified throughGitData.MergeBase/CreateCommitAndUpdateRefwithfast_forward_only: trueand atomic DynamoDBRef-CAS). Because fast-forward preserves exact commit andtree_oididentities, downstream PRs in the stack remain cleanly descendant of the newmaintip with zero synthetic merge commits and maximumtree_oidCI verdict reuse.
5. Asynchronous Events & Streams¶
5.1 Core -> Review: Ref Update Event (STRAVIN_CORE JetStream)¶
- Implemented in Core v1.12.x (
internal/hooks/async/dispatcher.go):stravin-hookcurrently consumes DynamoDB StreamsINSERTonRH#sand POSTs flat HTTPWebhookPayload(tenant_id,repo_id,ref,oid,pack_id,timestamp) with headersX-Stravin-Event: push,X-Stravin-Signature-256: sha256=<hex>, andtraceparent. - Proposed Core Extension (vNext — NATS JetStream):
stravin-relay(renamed fromstravin-hookinvNext) publishes the Standard Async Event Envelope to streamSTRAVIN_COREon subjectstravin.core.<tenant_id>.<repo_id>.ref.updatedwith NATS headersNats-Msg-Id: <idempotency_key>,Stravin-Event-Type: core.ref.updated,Stravin-Schema-Version: 1.0, andtraceparent:
{
"event_id": "evt_01JDF8Z7Q2K9M4N6P8R0T2V4W6",
"event_type": "core.ref.updated",
"schema_version": "1.0",
"occurred_at": "2026-11-24T22:15:03.412Z",
"tenant_id": "acme",
"repo_id": "monorepo",
"traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
"idempotency_key": "acme:monorepo:refs/heads/feat/stack-1:01JDF8Z7Q2K9M4N6P8R0T2V4W6",
"data": {
"ref": "refs/heads/feat/stack-1",
"oid": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2",
"prev_oid": "9999999999999999999999999999999999999999",
"pack_id": "9c1185a5c5e9fc54612808977ee8f548b2258d31a1b2c3d4e5f60718293a4b5c",
"ulid": "01JDF8Z7Q2K9M4N6P8R0T2V4W6",
"epoch": 3,
"actor_id": "usr_alice",
"object_format": "sha1",
"is_force_push": false
}
}
- Consumer & Ordering: Review binds durable pull consumer
review-core-refsonSTRAVIN_COREfiltered tostravin.core.*.*.ref.updated. DynamoDB Streams guarantees per-shard ordering for a singleref_name(RH#{fnv64a(ref) % S}). JetStream deduplicates onNats-Msg-Id, and Review deduplicates on(tenant_id, repo_id, ref, ulid), ignoring out-of-order stale events whoseulidis older than the last applied revision for that ref.
6. Shared Data Contracts & Identifiers¶
- Repository Identity:
(tenant_id, repo_id)+ immutableobject_format(sha1|sha256) and mutabledefault_branch(from CoreMETA). - PR Reference Namespace: Review-managed refs live strictly under
refs/stravin/pr/{pr_id}/headandrefs/stravin/pr/{pr_id}/mergeso they never collide with user branches (refs/heads/*) or Gate refs (refs/stravin/gate/*). - Stacked Lineage: Stored in Review as
(pr_id, base_ref, head_ref, stack_group_id)resolved directly from user branch refs (refs/heads/*); Core remains unaware of PR groupings and enforces only atomic ref-CAS and fast-forward ancestry checks. - OID Encoding: Always lowercase hex matching
object_format(40 chars forsha1, 64 chars forsha256). Zero OID (ddb.ZeroOIDForFormat) represents ref creation (old_oid) or deletion (new_oid).
7. Failure Modes, Timeouts & Idempotency¶
| Failure Scenario | Behavior & Degradation | Timeout / Retry Policy |
|---|---|---|
stravin-node / GitData slow or unavailable |
Review serves cached PR metadata, comments, and approvals from its own DB; diff pane shows "Git diff temporarily unavailable" with manual retry. | GetCommit/ListTree: 2 s; CompareDiff: 10 s; 2 retries with jitter on UNAVAILABLE. |
| Review consumer down or lagging | Messages buffer durably in STRAVIN_CORE for the review-core-refs consumer; after MaxDeliver exhaustion, JetStream emits a DLQ advisory to STRAVIN_DLQ. |
Review resumes from its JetStream consumer offset and runs a ListRefs reconciliation sweep on PR view when head_oid looks stale. |
Concurrent push during UI edit (REF_CONFLICT) |
Core Ref-CAS rejects the write atomically; Review reloads latest head_oid and prompts the user to rebase or re-apply. |
Non-retryable (409 / FAILED_PRECONDITION). |
Core regional failover (failover_epoch advance / ref rewind) |
Core may rewind un-replicated refs during stravin-ctrl scrub. Review detects oid mismatch via core.ref.updated or ListRefs and marks affected PR revisions as rewound rather than crashing. |
Idempotent state convergence against Core's authoritative RefState. |
8. Meet-in-the-Middle Bridge Checklist¶
Side A: Stravin Core Build Checklist¶
- Preserve
stravin-hookper-refRH#sordering andtraceparentpropagation (Implemented in Core v1.12.x). - Rename
stravin-hooktostravin-relayand add NATS JetStream publisher targetingstravin.core.<tenant_id>.<repo_id>.ref.updatedwithNats-Msg-Id=idempotency_keyand additive fields (prev_oid,ulid,epoch,actor_id,object_format) (vNext). - Implement read-only
stravin.core.v1.GitDatagRPC service onstravin-nodewith constant-time app-leveltenant_idauthorization (vNext). - Support short-lived scoped tokens with
actor_idforwarding to WasmPushContext(vNext).
Side B: Stravin Review Build Checklist¶
- Bind durable JetStream consumer
review-core-refsonSTRAVIN_CORE(stravin.core.*.*.ref.updated), verifying envelopetenant_idmatches subjecttenant_id. - Store
(tenant_id, repo_id, object_format)on every PR; never hardcode 40-char SHA-1 assumptions. - Implement idempotent PR revision sync keyed by
(ref_name, ulid), branch-on-branch stack resolution (base_refmatching parenthead_ref), and automaticbase_refretargeting on bottom-up fast-forward merges. - Restrict all Review-managed refs to
refs/stravin/pr/{pr_id}/*.
Shared Contract-Test Fixtures¶
fixtures/core-review/webhook-push-v1.json— Legacy Core v1.12.x flat HTTP push webhook + expectedX-Stravin-Signature-256vector.fixtures/core-review/nats-ref-updated-vnext.json— NATS JetStreamstravin.core.<tenant>.<repo>.ref.updatedmessage, headers (Nats-Msg-Id,traceparent), and branch create / fast-forward / force-push / delete cases (sha1andsha256).fixtures/core-review/compare-diff-cases.json— Rename, binary file, truncated large diff, and 3-dot merge-base test vectors.