Skip to content

fix(execd): add literal path mode and symlink-follow option to files/info and files/download - #2968

Open
yjjnls wants to merge 2 commits into
opensandbox-group:mainfrom
yjjnls:fix/file-info-literal-and-symlinks
Open

yjjnls wants to merge 2 commits into
opensandbox-group:mainfrom
yjjnls:fix/file-info-literal-and-symlinks

Conversation

@yjjnls

@yjjnls yjjnls commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

/files/info and /files/download always expand $VAR, ${VAR}, and a leading ~ in path, and reject a request whose path references an undefined variable. A workspace file literally named e.g. report-$VERSION.txt is therefore addressable only by accident of matching an environment variable — otherwise the request fails. The reporter needs a non-expanding, workspace-scoped lookup (Exists / ReadFile while grading file assertions).

The two endpoints also disagree about symlinks: /files/info uses Lstat (a dangling link looks present), while /files/download opens the path with os.Open (the link is followed, so the same dangling link yields 404). The same existence assertion can pass on Docker and none runtimes and fail on OpenSandbox.

This adds two opt-in query parameters, leaving default behavior unchanged:

  • literal=true on GET /files/info and GET /files/download (and the /v1/filesystem/{uid}/{gid} variants, which share the handlers): the path is used exactly as written — no $VAR/${VAR}/~ expansion, and no undefined-variable rejection.
  • follow=true on GET /files/info: resolve symlinks the same way /files/download opens them — the target's metadata is reported and a dangling link returns 404 FILE_NOT_FOUND. The default keeps reporting the link itself, which docs/api/index.md describes and existing tests assert. The birth-time lookup follows the same semantics, so follow=true reports the target's created_at rather than falling back to its mutable change time.

SDK propagation

The options are threaded through the stable SDK surfaces and the contract outputs regenerated:

  • Python: get_files_info/download_file clients regenerated; async and sync FilesystemAdapter.get_file_info and read_file/read_bytes* accept literal/follow (omitted by default).
  • JavaScript: src/api/execd.ts regenerated; FilesystemAdapter.getFileInfo/readBytes*/readFile and the SandboxFiles facade accept the options.
  • Go: GetFileInfoOptions (variadic, existing calls unchanged), DownloadFileOptions.Literal, IdentityFilesystem updated.
  • C#: GetFileInfoOptions and ReadBytesOptions.Literal on the adapter and interfaces.

Call-outs (not verified here): the C# project was not compiled in this environment (no dotnet SDK); the Kotlin SDK is untouched — its client is generated by Gradle at build time and needs a regeneration pass when the options should be exposed there.

Testing

  • go build ./... and GOOS=windows go build ./... — both green
  • go vet clean; full go test ./pkg/... (execd suite) green
  • New Go regression tests: literal names with defined and undefined variables, follow=true symlink resolution, dangling-link 404, follow=true birth time of the target
  • Python: ruff, pyright, full pytest suite green; new mapping tests (tests/test_filesystem_literal_follow.py)
  • JavaScript: lint, typecheck, build, full node --test suite green; new mapping tests (tests/filesystem.literal-follow.test.mjs)
  • Go SDK: full go test ./... green; new query-mapping tests

Refs #2960

@github-actions github-actions Bot added component/execd documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T16:41:27.879363Z c7dc68a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7dc68ad52

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread specs/execd-api.yaml
Comment on lines +615 to +619
- name: literal
in: query
required: false
description: >
Treat each path exactly as written: skip "$VAR"/"${VAR}" and "~"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Propagate the path modes through SDK clients

The stable filesystem facades never send either new parameter: for example, sdks/sandbox/javascript/src/services/filesystem.ts exposes no literal/follow option, FilesystemAdapter.fetchDownload and getFileInfo send only the existing fields, and Go's GetFileInfo/DownloadFileOptions do the same; even the checked-in generated Python and JavaScript clients were not regenerated. SDK users hitting the literal $VAR filename or symlink case therefore still get the old behavior unless they bypass the SDK and hand-build HTTP. Regenerate the contract outputs and thread these options through the affected adapters and facades.

AGENTS.md reference: specs/AGENTS.md:L50-L52

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 36e78d8 — the options are threaded end to end and the contract outputs regenerated. Python: get_files_info/download_file kwargs regenerated, async and sync FilesystemAdapter.get_file_info and every read_bytes*/read_file path accept literal/follow (omitted by default via UNSET), with mapping tests in tests/test_filesystem_literal_follow.py. JavaScript: src/api/execd.ts regenerated; FilesystemAdapter.getFileInfo/readBytes*/readFile and the SandboxFiles facade accept the options, covered by tests/filesystem.literal-follow.test.mjs. Go: new GetFileInfoOptions (variadic, so existing calls keep compiling), DownloadFileOptions.Literal, and the IdentityFilesystem interface updated; query-mapping tests added. C#: GetFileInfoOptions and ReadBytesOptions.Literal on the adapter and interfaces — call-out: the C# project was not compiled here (no dotnet SDK in this environment). The Kotlin SDK is untouched; its client is generated by Gradle at build time and needs a regeneration pass.

Comment on lines +284 to +285
if follow {
statFn = os.Stat

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve target birth time when following symlinks

On Linux filesystems that report STATX_BTIME, a follow=true request enters this os.Stat branch, but buildFileInfo calls getFileCreateTime(absPath, fileInfo) and syscall_linux.go always performs Statx(..., AT_SYMLINK_NOFOLLOW, ...). For a symlink, that lookup sees the link while fileInfo describes the target, so the inode check fails and created_at becomes the target's mutable ctime instead of its birth time; after a chmod, the endpoint therefore violates the documented target-metadata behavior. Pass the follow semantics into the birth-time lookup and cover this case.

AGENTS.md reference: AGENTS.md:L46-L46

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 36e78d8 — getFileCreateTime now receives the follow semantics and drops AT_SYMLINK_NOFOLLOW when following, so the statx lookup sees the target and created_at reports the target's birth time instead of falling back to its mutable change time. Covered by TestFilesystemControllerGetFilesInfoFollowCreatedAtUsesTargetBirthTime, which chmods the target to expose any ctime fallback, plus the existing dangling-link and rename tests still assert the link-own semantics for the default.

…info and files/download

The metadata and download endpoints always expand $VAR/${VAR}/~ in path
and, when a referenced variable is undefined, reject the request. A file
literally named e.g. report-$VERSION.txt therefore cannot be addressed,
even though it sits in the workspace. Add an optional literal=true query
parameter to both routes (and their /v1/filesystem/{uid}/{gid} variants,
which share the handlers): the path is used exactly as written.

/files/info also reports a symlink's own metadata (Lstat) while
/files/download opens the target (os.Open), so a dangling symlink looks
present to a metadata/existence check but a download returns 404. Add an
optional follow=true parameter that stats through the link, matching the
download's open semantics; the default keeps the link's own metadata,
which the API docs describe and existing tests assert. follow=true
reports the target's metadata and returns 404 for dangling links.

Refs opensandbox-group#2960

Docs and the OpenAPI spec document both parameters; regression tests
cover literal names with defined and undefined variables, symlink-to-file
resolution, and dangling-link 404s.

Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
…low-aware birth time

Round-2 review (codex) findings:

- P1: propagate the new path modes through the stable SDK facades.
  Regenerate the Python and JavaScript contract outputs and thread
  literal/follow through the handwritten layers: Python async/sync
  adapters (get_file_info + read_bytes* + _build_download_request),
  JavaScript FilesystemAdapter and SandboxFiles facade (api/execd.ts
  regenerated), Go GetFileInfoOptions/DownloadFileOptions.Literal and
  the IdentityFilesystem interface, C# GetFileInfoOptions and
  ReadBytesOptions.Literal. Mapping regression tests added in Python,
  JavaScript, and Go.
- P2: follow=true must report the target's birth time. getFileCreateTime
  now drops AT_SYMLINK_NOFOLLOW when following, so the statx inode check
  matches the target instead of falling back to its mutable ctime.
  Covered by TestFilesystemControllerGetFilesInfoFollowCreatedAtUsesTargetBirthTime.

The C# project was not compiled in this environment (no dotnet SDK); the
Kotlin SDK needs a Gradle regeneration and is left untouched.

Signed-off-by: yjjnls <yjjnls@users.noreply.github.com>
@yjjnls
yjjnls force-pushed the fix/file-info-literal-and-symlinks branch from 36e78d8 to cae9599 Compare November 26, 2026 00:50
@yjjnls

yjjnls commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (5c42221) to resolve the conflict with #3010-style perf rework in filesystem.go's SearchFiles (fb33989).

What changed

Only the SearchFiles callback was affected: main now early-returns on non-matching entries and calls buildFileInfo(filePath, info) once, while this PR's Linux buildFileInfo takes a third follow argument. The rebased commit keeps main's structure and passes follow=false (Search keeps Lstat semantics — a symlink entry is reported as the link itself, matching ListDirectory). No behavioral change on the Windows side, where buildFileInfo stays 2-arg.

Everything else in the two commits is unchanged; the range-diff deltas are context-only (main's docs/api/index.md 416 wording, Python logger.debug).

Verification

  • go build ./... (execd) OK; go vet ./pkg/web/controller/ OK on linux and GOOS=windows cross-compile
  • go test ./pkg/web/controller/ -count=1 → ok
  • author/committer and Signed-off-by are both yjjnls <yjjnls@users.noreply.github.com>

This branch has not been deployed

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

Labels

component/execd documentation Improvements or additions to documentation sdk/c# sdk/go sdk/js sdk/python size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant