Skip to content

Vercel: remove import-time mkdir#28

Merged
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-vercel-crash-due-to-import-time-writes
Feb 18, 2026
Merged

Vercel: remove import-time mkdir#28
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-vercel-crash-due-to-import-time-writes

Conversation

@gitgrahamdunn
Copy link
Copy Markdown
Owner

Motivation

  • Eliminate filesystem writes during module import to avoid crashes on serverless platforms (Vercel) where the filesystem is read-only except for /tmp.
  • Preserve existing behavior for determining the default data directory using the DATA_DIR environment variable or falling back to /tmp/gitplant-data.

Description

  • Replace import-time _default_data_dir() with a pure resolver get_data_dir() and add ensure_data_dir() to perform mkdir() only at runtime. (backend/app/config.py)
  • Stop creating DEFAULT_DATA_DIR at import time by assigning it to get_data_dir() instead of invoking a mkdir helper. (backend/app/config.py)
  • Add ensure_exists option to get_document_storage_path() and get_plant_storage_path() so callers can resolve paths without causing writes, and make these helpers create directories only when requested. (backend/app/config.py)
  • Move SQLite parent-directory creation out of module import and into init_db() so importing app.db no longer writes to disk. (backend/app/db.py)
  • Remove import-time mkdir() in projects router and introduce ensure_working_storage_dir() that is called only at upload time. (backend/app/routers/projects.py)
  • Update documents router to avoid import-time directory creation by using get_document_storage_path(ensure_exists=False) at module level and calling get_document_storage_path() at write time. (backend/app/routers/documents.py)

Testing

  • Ran unit tests with cd backend && pytest -q, which completed successfully with 18 passed.
  • Verified that modules import cleanly in a read-only environment with cd backend && python -c "import app.config, app.db, app.routers.documents, app.routers.projects; print('import-ok')", which printed import-ok.

Codex Task

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitplant Ready Ready Preview, Comment Feb 18, 2026 10:20pm
gitplant-backend Ready Ready Preview, Comment Feb 18, 2026 10:20pm
gitplant-oggy Ready Ready Preview, Comment Feb 18, 2026 10:20pm

Copy link
Copy Markdown

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

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: 8e66a4aec7

ℹ️ 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".

Comment thread backend/app/config.py

# Vercel serverless functions run on a read-only filesystem except for /tmp.
DEFAULT_DATA_DIR = _ensure_writable_data_dir(_default_data_dir())
DEFAULT_DATA_DIR = get_data_dir()
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 Keep writable fallback when deriving DEFAULT_DATABASE_URL

Assigning DEFAULT_DATA_DIR = get_data_dir() removes the previous writability fallback at config load, so when DATA_DIR points to a read-only or non-creatable path (e.g. serverless filesystems outside /tmp), settings.database_url is built with that unwritable location and startup now fails in init_db() when creating the SQLite parent directory. This is a regression from the prior behavior that transparently fell back to /tmp/gitplant-data; the default DB path should still be derived from a writable directory.

Useful? React with 👍 / 👎.

@gitgrahamdunn gitgrahamdunn merged commit d1f8147 into main Feb 18, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant