Fix code execution failing on serverless read-only filesystem - #62
Open
umarjaved204 wants to merge 1 commit into
Open
umarjaved204 wants to merge 1 commit into
umarjaved204 wants to merge 1 commit into
Conversation
executeCppCode, executeJavaScriptCode and executeJavaCode created their temp directory at RUNTIME_TMP_PATH, which resolves inside the deployment bundle. On Vercel that path is read-only, so every request failed with "ENOENT: no such file or directory, mkdir '/var/task/src/runtime'" before a compiler was ever invoked. They now use the existing getWritableRuntimeDir() helper, which falls back to os.tmpdir() on serverless -- the same approach executeRubyCode already took. Also in this change: - Add executeCppViaPiston() so hosts without a local g++ can compile remotely, mirroring the existing executeRubyViaPiston(). Dormant unless PISTON_API_URL points at a reachable instance. - Replace the "install MinGW/g++" error, which is not actionable on a managed host, with one naming the actual configuration needed. - Delete the compiled binary when compilation fails; only the source was being cleaned up. - Tell nodemon to ignore src/runtime/tmp, so writing a temp file no longer restarts the dev server and kills the in-flight request. Note: C++ still cannot execute on Vercel after this change, because that runtime ships no C++ compiler. This fixes the crash and makes the failure report itself honestly; running C++ in production additionally requires a compiler, via PISTON_API_URL or a non-serverless host.
|
@umarjaved204 is attempting to deploy a commit to the seno-quantum-coder's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
C++ execution has never worked on the deployed backend.
POST /api/challenges/run-cppreturns HTTP 500 in production:{"stdout":"","stderr":"ENOENT: no such file or directory, mkdir '/var/task/src/runtime'","error":"...","exitCode":1}executeCppCodecreated its temp directory atRUNTIME_TMP_PATH, which resolves to/var/task/src/runtime/tmp— inside the deployment bundle, which Vercel mounts read-only. The request died atmkdir, before any compiler was invoked.executeJavaScriptCodeandexecuteJavaCodehad the identical bug.Fix
Use the existing
getWritableRuntimeDir()helper, which falls back toos.tmpdir()on serverless.executeRubyCodealready did this; the other three didn't.Also included:
executeCppViaPiston()— remote compile fallback for hosts with no localg++, mirroring the existingexecuteRubyViaPiston(). Dormant unlessPISTON_API_URLis configured.src/runtime/tmp— writing a temp file was restarting the dev server and killing the in-flight request. This is also why stalerun_*.cppfiles ended up committed undersrc/runtime/tmp/.Testing
Verified locally (PowerShell, where the MSYS2
g++resolves correctly):Ran 3× consecutively — no temp files left behind. Serverless code path verified separately with
VERCEL=1.What this does NOT fix
C++ still will not run on Vercel after this merges, because that runtime ships no C++ compiler and one cannot be installed there. This PR fixes the crash and makes the failure report itself honestly.
Making C++ actually execute in production additionally requires a compiler, via either:
PISTON_API_URLpointed at a self-hosted Piston instance (sandboxed; no code change needed — just the env var), org++can be installed.This needs a decision from whoever owns deployment.
Note: the public Piston API — the current default value — went whitelist-only on 2026-02-15, so the existing Ruby fallback is also non-functional for the same reason.
Security note
Code execution here is unsandboxed — a timeout is the only limit, with no memory, filesystem, or network restrictions. This PR neither introduces nor fixes that, but it's worth confirming the team is comfortable with it before C++ execution goes live, given the input is user-submitted. Self-hosted Piston would address it.
Related frontend issue (separate repo)
Why this went unnoticed for so long:
runCpp.jscatches the 500, keyword-matches it as "compiler unavailable" (the regex/g\+\+|compiler.*not|not installed|enoent/imatches ourENOENTtext), substitutes a browser simulation that only prints quoted string literals, and thenstripSimulationBanner()deletes the "simulation mode" warning before rendering the result as a successful run.Net effect:
cout << "Score: " << 100 << endl;displaysScore:— the literal survives, the variable silently vanishes, and nothing indicates it wasn't really executed.To be filed separately against
PolyCode-Frontend. The Playground already handles this correctly (playgroundExecutor.jsprepends a visible "simulation only" warning), and Java lessons rethrow properly — C++ is the outlier.