Skip to content

Snapshots fail for Locations opened through symlinked paths #54454

Closed

Description

@sdivyanshu90

Description

Snapshots are unavailable when a v2 Location is opened through a symlinked path. The Git worktree path is canonicalized, but the Location path is not, so snapshot capture incorrectly decides that the Location is outside the project and returns undefined.

Plugins

None

OpenCode version

v2 branch

Steps to reproduce

  1. Create a Git project at /tmp/real/project with one tracked file.
  2. Create /tmp/linked as a directory symlink to /tmp/real.
  3. Open the Location as /tmp/linked/project.
  4. Trigger a snapshot capture.

Observed: capture logs Location is outside the project and returns no snapshot.

Expected: the symlinked Location is recognized as the same project and a snapshot is created.

Operating System

Linux

Terminal

bash

Activity

  1. opencode-agent commented on Oct 11, 2026

    @opencode-agent
    Contributor

    Thanks for the clear report. I could reproduce this on the latest dev (e31136b).

    With a Git repo at <tmp>/real/project and <tmp>/linked symlinked to <tmp>/real:

    • a Location opened at <tmp>/real/project gets a snapshot ID from Snapshot.capture()
    • a Location opened at <tmp>/linked/project gets undefined

    The cause is in packages/core/src/snapshot.ts. The Git worktree path is resolved with realPath, but the Location directory is not, so the containment check in scope() fails with "Location is outside the project" and capture() swallows the error.

    The script below reproduces it as a packages/core Bun test.

    Related: #52224 (resolves symlinks before the external_directory boundary check, a similar fix in another component) and #40160.

    Reproduction script (snapshot-symlink-repro.test.ts)
    // Reproduction for https://github.com/anomalyco/opencode/issues/54454
    // Run from packages/core: bun test test/snapshot-symlink-repro.test.ts
    import { $ } from "bun"
    import { describe, expect } from "bun:test"
    import fs from "fs/promises"
    import path from "path"
    import { Effect, Layer } from "effect"
    import { AppNodeBuilder } from "@opencode/core/effect/app-node-builder"
    import { Global } from "@opencode/util/global"
    import { Location } from "@opencode/core/location"
    import { AbsolutePath } from "@opencode/core/schema"
    import { Snapshot } from "@opencode/core/snapshot"
    import { tmpdir } from "./fixture/tmpdir"
    import { testEffect } from "./lib/effect"
    
    function snapshotLayer(data: string, directory: string) {
      return AppNodeBuilder.build(Snapshot.node, [
        Location.node.replace(Location.boundNode(Location.Ref.make({ directory: AbsolutePath.make(directory) }))),
        Global.node.replace(Global.layerWith({ data, config: path.join(data, "config") })),
      ])
    }
    
    const capture = (data: string, directory: string) =>
      Effect.gen(function* () {
        const snapshot = yield* Snapshot.Service
        return yield* snapshot.capture()
      }).pipe(Effect.provide(snapshotLayer(data, directory)))
    
    describe("Snapshot via symlinked Location (#54454)", () => {
      testEffect(Layer.empty).live("real path vs symlinked path", () =>
        Effect.acquireUseRelease(
          Effect.promise(() => tmpdir()),
          (tmp) =>
            Effect.gen(function* () {
              const real = path.join(tmp.path, "real")
              const project = path.join(real, "project")
              const linked = path.join(tmp.path, "linked")
              yield* Effect.promise(async () => {
                await fs.mkdir(project, { recursive: true })
                await fs.writeFile(path.join(project, "tracked.txt"), "one\n")
                await $`git init -q`.cwd(project).quiet()
                await $`git add .`.cwd(project).quiet()
                await $`git -c user.email=t@t -c user.name=t commit -q --no-gpg-sign -m init`.cwd(project).quiet()
                await fs.symlink(real, linked, "dir")
              })
    
              const viaReal = yield* capture(path.join(tmp.path, "data-real"), project)
              const viaLink = yield* capture(path.join(tmp.path, "data-link"), path.join(linked, "project"))
              console.log("capture via real path:     ", viaReal)
              console.log("capture via symlinked path:", viaLink)
              expect(viaReal).toBeDefined()
              expect(viaLink).toBeDefined() // fails: undefined, "Location is outside the project"
            }),
          (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
        ),
      )
    })

    Run it: bun snapshot-symlink-repro.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions