Trace preloop's local-workspace snapshot flow end-to-end and explain why remote-server submissions fail with null-sha checkouts while loopback works, then propose ranked minimal fixes.
Assistant
The failure is caused by a deliberate security gate in the preloop client that prevents sending local filesystem paths to remote servers.
1. Failure Chain Diagram
mermaid
graph TD
A[Client: preloop run] -->|`should_send_local_workspace_header`| B{URL check}
B -->|Remote URL| C[Header Omitted]
B -->|Loopback/Default| D[Send X-Preloop-Workspace-Path]
C --> E[Remote Server]
D --> F[Local Engine]
E -->|No local_workspace| G[Server logic: submit_run_inner]
G -->|Result| H[sha: "", no snapshot, checkout fails]
F -->|Received path| I[Server logic: submit_run_inner]
I -->|`create_workspace_snapshot`| J[Snapshot created & payload rewritten]
J -->|Result| K[Success: checkout resolves]
2. Root Cause Analysis
Client Side (crates/preloop-cli/src/main.rs): The function should_send_local_workspace_header (line 31) returns false for any URL that is not a local loopback address or default transport. This prevents the client from leaking the local workspace path to the aksh.preloop.dev production server.
Server Side (crates/preloop-runner-server/src/runs.rs): In submit_run_inner (line 528), the server checks for the local_workspace property in the incoming submission or the header. Because the header is stripped, local_workspace is None. The server then skips create_workspace_snapshot (lines 528–533).
Checkout Propagation: Since no snapshot is created, the run.submission.after (the commit hash) is left at its default empty state (or fails to be rewritten to the snapshot hash). When the runner's actions/checkout executes, it attempts to fetch a 000... ref, triggering the Git error.
3. Fix Options (Ranked)
Client-side Bundle Upload (Recommended): Instead of passing a path, change the client to bundle the workspace (or just the .git objects) and POST it to the server as a binary blob or via a multi-part upload, similar to how the dirty-tree CI-gate flow handles unsaved files.
Files:crates/preloop-cli/src/main.rs (to implement bundling), crates/preloop-runner-server/src/runs.rs (to accept the bundle).
Risk: Higher bandwidth; requires new API endpoint or payload expansion.
Explicit Opt-in Flag: Add a --allow-remote-snapshot flag for preloop run. If passed, the client bypasses the URL security gate.
Files:crates/preloop-cli/src/main.rs (add flag handling).
Risk: User error leads to leaking local paths to malicious servers; requires documenting security trade-offs.
Push-first Documentation: Document a workflow where users must git push their branch to a remote origin that the production server can access before running. The server then ignores local workspace paths entirely.
Files:CONTEXT.md (no code changes).
Risk: Clutters user's remote branches with experimental/WIP code.
4. Remote Submission Feasibility
Could remote submission work without code changes? No. Even if you manually crafted a JSON payload with a sha that exists on the remote server, the server-side logic in crates/preloop-runner-server/src/runs.rs expects to perform a specific create_workspace_snapshot dance if it is to reconcile a local workspace. Without the server processing the local_workspace path (or receiving a payload it can uniquely identify as a snapshot), it will continue to treat the checkout as a standard ref fetch against a potentially empty repository state.
ts
result: {
data: {
summary: "The client purposefully omits the workspace header for remote URLs to protect local filesystem paths. The server requires this path to create a snapshot; without it, the run is submitted without a valid commit, causing checkout failures.",
files: [
{ path: "crates/preloop-cli/src/main.rs", description: "Contains the should_send_local_workspace_header security gate." },
{ path: "crates/preloop-runner-server/src/runs.rs", description: "Contains submit_run_inner which relies on local_workspace to trigger snapshot creation." }
],
architecture: "Client-side path suppression prevents server-side snapshot creation, breaking runner checkout."
}
}