MiniMax-AI / MiniMax-AI/minimax-code
[Bug]: POST /api/file/save cannot create new files — existing-path resolver 404s before the write
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 141
- Avg merge
- 2h 45m
- Merged PRs (30d)
- 46
Description
Description
POST /api/file/save can never create a new file. Any save request whose target path does not already exist returns 404 File not found before the write happens. Only overwriting existing files works.
Source evidence
Audited against the 0.4.12 source preview (release/extraction.json sourceRevision 9b9885e42a3cf1a3df1cfa52a46e4fdb034cfcee); line numbers refer to that revision.
- The save route passes
resolveBodyPathto the handler:packages/local-runtime/src/files/api.ts:557-559. resolveBodyPathcallsresolveExistingWorkspacePath:packages/local-runtime/src/files/api.ts:1950-1960.resolveExistingWorkspacePathrunsrealpath(target)and maps the resultingENOENTto a 404File not foundresponse:packages/local-runtime/src/files/api.ts:1997-2002.- The handler itself clearly intends to create files:
packages/local-runtime/src/files/save.ts:23-25doesmkdir(dirname(target.absolute), { recursive: true })followed bywriteFile(...)— both dead code for new files because the 404 short-circuits first.
So the mkdir + writeFile creation path is unreachable for any nonexistent target.
Expected behavior
Saving to a new path creates the file (that is what the recursive mkdir in the handler is for).
Actual behavior
Saving to a new path returns 404 {"error":"File not found"}.
Suggested fix
Give the save route a resolver that allows a non-existing leaf: resolve the parent directory with realpath, validate containment against the workspace root, then append the leaf name. resolveExistingWorkspacePath is the right resolver for read/open/reveal routes, but not for a write that is expected to create.
Environment
Found by source audit; not runtime-reproduced yet. The relevant code paths are small and self-contained, so the trace above should be quick to confirm.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the save route in packages/local-runtime/src/files/api.ts:557-559 through resolveBodyPath and resolveExistingWorkspacePath at 1950-1960 and 1997-2002, then inspect packages/local-runtime/src/files/save.ts:23-25. Confirm that a nonexistent target can reach the mkdir and writeFile path while preserving workspace containment checks; done means saving to a new nested path creates the file and existing-file saves still work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100