Skip to content

Forking & merging

Create an isolated fork, review its changes, merge them back into the parent, and resolve conflicts with a rebase.

This guide walks through creating a fork, reviewing its changes, merging those changes back into the parent namespace, and resolving conflicts with a rebase.

When an agent, a background job, or a user needs to edit files without changing the main workspace until the work is reviewed, you can fork the workspace into a separate namespace. Both namespaces share the same pool (so forking doesn’t copy existing file bytes), and changes in the fork stay isolated until you merge them back into the parent.

The examples below use workspace as the parent namespace and session as the fork. Include your Authorization bearer token and the required headers on every request (writes require Loonfs-Actor, and all of these endpoints require either Loonfs-Principals or Loonfs-Context: service).

Call Fork namespace on the parent namespace:

HTTP
POST /v0/namespaces/workspace/forks
Content-Type: application/json
{
"new_namespace_id": "session"
}

By default, LoonFS forks the parent’s current head. To fork an earlier state instead, include a snapshot_id in the request body. The response includes the shared pool ID (pool_id) and the parent sequence number where the fork branched off (fork_basis.fork_point_seq). For example, if workspace is at sequence 40 when you create session, fork_basis.fork_point_seq is 40.

If you omit new_namespace_id, LoonFS generates a namespace ID, but picking the ID yourself makes timeout retries safe. Retrying the same fork request finishes creating a fork that was still initializing, or returns namespace_exists if the fork is already active (in that case, fetch session and check its fork_basis before writing to session).

Write changes to session using normal commits. Those commits apply to session and don’t affect workspace.

To inspect what changed in session after the fork, call List differences on session with from_seq set to fork_basis.fork_point_seq. Continuing the example above, if session forked at sequence 40 and committed sequences 41 through 45, calling list_diff with from_seq=40 summarizes the net changes from commits 41 through 45.

list_diff compares session against the state session started from, not against any new commits written to workspace after sequence 40. If the diff spans multiple pages, pass the to_seq returned by the first page on every later page (see Diffs).

Before running a merge, you can check whether session has unmerged commits and whether the required history is still available by calling Get next merge range:

HTTP
GET /v0/namespaces/workspace/merges?source_namespace_id=session&consistency=strong

When outcome is open, LoonFS still has the history needed for the next merge. The pending range runs from next_after_seq to source_head_seq, so if both fields are 45, session has no new commits to merge. (This check verifies history retention, not whether the merge will be conflict-free.)

To merge the fork’s changes into workspace, call Merge fork:

HTTP
POST /v0/namespaces/workspace/merges
Content-Type: application/json
{
"source_namespace_id": "session",
"commit_id": "merge_session_1",
"message": "Apply session changes"
}

LoonFS applies the fork’s net changes to workspace as one atomic commit. On the first merge, the range starts after the fork point (sequence 40 in our example). On any later merge of the same fork, the range starts after the previous merge’s end sequence. Include through_seq if you want to merge up to a specific sequence you already reviewed instead of the fork’s current head.

If a merge request times out, retry with the exact same commit_id, request body, actor header, and context header. Use a new commit_id for each new merge. See Committing with idempotency.

A fork merges back into its parent, not into a sibling fork in the same pool. If you fork session into experiment, merge experiment into session first, and then merge session into workspace.

If workspace modified the same file, directory name, move target, permissions, or attributes while session was open, the merge returns merge_conflict and commits nothing to workspace. LoonFS doesn’t try to combine conflicting file edits automatically.

Because session still starts from an older state of workspace, you resolve conflicts by creating a new fork from workspace’s latest head and replaying session’s unmerged changes onto that new fork:

  1. Create a rebase fork from workspace’s current head using Fork for rebase:

    HTTP
    POST /v0/namespaces/workspace/rebases
    Content-Type: application/json
    {
    "source_namespace_id": "session",
    "new_namespace_id": "session-rebased"
    }
  2. Replay the unmerged changes from session onto session-rebased with Replay fork:

    HTTP
    POST /v0/namespaces/session-rebased/replays
    Content-Type: application/json
    {
    "source_namespace_id": "session",
    "commit_id": "replay_session_1"
    }

    LoonFS commits every change that applies cleanly and returns a conflicts array listing the changes it skipped (along with any later changes that depended on a skipped change). Check conflicts even when the HTTP status is 200, because a successful replay response can still report skipped changes.

  3. Inspect each entry in conflicts and commit your resolutions to session-rebased using normal commits.

  4. Merge session-rebased into workspace. If workspace changed again while you were resolving conflicts, that merge can conflict too and require another rebase.

Your original session fork isn’t modified or deleted by the rebase.

A single merge commit has to fit within the server’s commit size limits. If a fork accumulated too many changes for one commit, Merge fork fails with merge_too_large and includes a split_at_seq hint.

Merge the first part by setting through_seq to split_at_seq, then merge the remaining commits with a new commit_id. Each chunk commits atomically on its own, though the full series isn’t a single transaction. If the error omits split_at_seq, even the next single commit in the fork exceeds the server’s merge limit.

Both merging and rebasing need commit history going back to the fork point (or the end of the previous merge). If the retention floor advances past that sequence, LoonFS returns fork_point_below_floor or range_start_below_floor, and rebasing won’t bypass that error because replay needs the same history. Configure a retention window longer than forks stay open.

Merging a fork doesn’t delete the fork or release the snapshots protecting its inherited metadata. Once you verify the merge in workspace, delete finished forks so namespace retirement can clean up their metadata and shared storage.