Make backend Vercel-safe (no import-time writes)#29
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7950196d63
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "path": path_str, | ||
| "under_tmp": path_str.startswith("/tmp"), | ||
| "exists": path.exists(), | ||
| "writable": path.is_dir(), |
There was a problem hiding this comment.
Check actual write permission in storage health checks
run_runtime_storage_check() marks a directory as writable using path.is_dir(), which only confirms existence/type and will still be true for read-only mounts. In deployments that set DATA_DIR, STORAGE_DIR, or WORKING_STORAGE_DIR to an existing but non-writable directory, /health/storage and health_info can report healthy storage even though uploads will fail later with permission errors. This should validate real write access (for example via os.access(..., os.W_OK) or a temp-file probe) before reporting writable: true.
Useful? React with 👍 / 👎.
Motivation
/tmpis writable./tmpby default while still allowing env-var overrides.Description
backend/app/config.pyby addingensure_dir,_resolve_writable_dir,get_storage_dir, andget_working_storage_path, and defaulting non-overridden paths to/tmp/*while keeping env-var overrides (DATA_DIR,STORAGE_DIR,WORKING_STORAGE_DIR).WORKING_STORAGE_DIR = (BACKEND_ROOT / "storage" / "projects")and itsensure_working_storage_dir()with runtime resolution viaget_working_storage_path()in upload handlers so directory creation only happens during request/startup.run_runtime_storage_check()and a new endpointGET /health/storage, and addedstorage_checkstoGET /health/info; these checks are run at startup (not at import).appdirectly frombackend/index.pyfor predictable serverless mounting.backend/tests/test_import_safety.pyto assert noPath.mkdircalls during import and to verify storage helpers default to/tmp; updatedbackend/tests/test_health.pyto validate new storage endpoint and payload.Fixed import-time write locations and changes made
backend/app/config.py: removed import-time directory creation logic and centralized helper functions so nomkdir()or filesystem writes occur during module import; directory creation is done viaensure_dir()only when runtime helpers are called.backend/app/routers/projects.py: removed module-levelWORKING_STORAGE_DIRandensure_working_storage_dir()that performed repo-root writes at import time, and switched upload logic to write intoget_working_storage_path()resolved at request time.Testing
cd backend && pytest -qand all tests passed:20 passed.backend/tests/test_import_safety.pywhich asserts that importingapp.maintriggers noPath.mkdircalls (import-time writes); this test passed as part of the suite.GET /health/storageendpoint andstorage_checksinGET /health/info, and these assertions passed in CI tests.Codex Task