Skip to content

Fix dataset sidecar write race condition, duplicate app init, and missing status/priority persistence#40

Draft
ShockaHolmes with Copilot wants to merge 2 commits into
mainfrom
copilot/test-app-for-bugs
Draft

Fix dataset sidecar write race condition, duplicate app init, and missing status/priority persistence#40
ShockaHolmes with Copilot wants to merge 2 commits into
mainfrom
copilot/test-app-for-bugs

Conversation

Copilot AI commented Apr 30, 2026

Copy link
Copy Markdown

Running the app under test revealed three bugs in the dataset pipeline: a race condition causing random 404s, a duplicate FastAPI app instantiation, and status/priority fields being silently dropped on every save.

Race condition in sidecar writes

_PROFILE_EXECUTOR background threads rewrote sidecar files via Path.write_text(), which truncates before writing. A concurrent read between truncation and completion would see an empty file, causing parse_sidecar("") → id "untitled"get_by_id returning None → HTTP 404. Failures were non-deterministic and affected different tests each run.

Fixed by adding _write_text_atomic() — writes to a temp file in the same directory then os.replace() (atomic on POSIX) — applied to all three sidecar write sites: save(), save_with_file(), and save_profile().

@staticmethod
def _write_text_atomic(path: Path, text: str, encoding: str = "utf-8") -> None:
    fd, tmp_name = tempfile.mkstemp(dir=path.parent, suffix=".tmp")
    try:
        with os.fdopen(fd, "w", encoding=encoding) as fh:
            fh.write(text)
        os.replace(tmp_name, path)
    except Exception:
        try:
            os.unlink(tmp_name)
        except OSError:
            pass
        raise

Duplicate app = create_app() in app.py

Module-level create_app() was called twice, discarding the first instance. Removed the duplicate.

DatasetMetadata missing status and priority

DatasetMetadata (the YAML serialization layer) omitted these fields, silently dropping them on every save(). A PATCH updating status/priority would appear successful but return stale values on the next GET. Added both fields to DatasetMetadata.from_dataset(), to_dataset(), to_dict(), and from_dict().

Copilot AI linked an issue Apr 30, 2026 that may be closed by this pull request
…sing status/priority persistence

Agent-Logs-Url: https://github.com/ShockaHolmes/NoteForge/sessions/e9ec2f6f-5fda-4cc1-bf20-6305c085016a

Co-authored-by: ShockaHolmes <78627489+ShockaHolmes@users.noreply.github.com>
Copilot AI changed the title [WIP] Test app functionality and fix identified bugs Fix dataset sidecar write race condition, duplicate app init, and missing status/priority persistence Apr 30, 2026
Copilot AI requested a review from ShockaHolmes April 30, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test app to find bugs

2 participants