Skip to content

Prevent lost settings updates and partial configuration writes #14

Closed

Description

@cchacs

Problem

my-plugin/routes.py performs an unlocked read–merge–write in asyncio.to_thread and writes directly to the destination. Concurrent subset updates can overwrite each other; an interrupted write can leave invalid JSON. A template should demonstrate a dependable persistence pattern.

Acceptance criteria

  • Serialize the complete read–merge–persist operation for concurrent requests within the supported deployment model.
  • Write to a temporary file in the same directory and atomically replace the destination.
  • Preserve the last valid configuration if persistence fails.
  • Add a meaningful overlapping-request test showing that updates to different settings are retained, plus a failed-write test.
  • Document the concurrency guarantee and any multi-process limitation.

Keep the example small and retain bounded input validation and off-event-loop filesystem work.

Activity

  1. pullfrog commented on Oct 13, 2026

    @pullfrog
    Contributor
  2. pullfrog commented on Oct 16, 2026

    @pullfrog
    Contributor

    Implemented issue #14 in PR #17: #17

    my-plugin/routes.py now serializes the full read–merge–persist with an asyncio.Lock held across asyncio.to_thread, and persists via a temp file in the same directory + os.replace, so concurrent subset POSTs can't lose each other's updates and a failed write preserves the last valid config (temp file cleaned up, request returns 500). Added an overlapping-request test (a lock-disabled harness confirmed it fails 20/20 runs without the lock) and a failed-write test; documented the single-process guarantee, the multi-process limitation, and the 0600 file-mode side effect in my-plugin/README.md + AGENTS.md. The TestClient fixture now runs as a context manager so all requests share one event loop — required for the lock.

    All 21 tests pass plus the CI-equivalent manifest/JS/print checks. A pre-commit reviewfrog pass found no blocking issues; its two doc-level findings were addressed, its dir-fsync and test-hook suggestions were rejected as ceremony for a template.

    Task list (3/6 completed)
    • Read routes.py, tests, README, learnings
    • Create branch pullfrog/14-atomic-settings-persistence
    • Implement serialized atomic read-merge-persist in routes.py
    • Add overlapping-request and failed-write tests
    • Document concurrency guarantee in README/AGENTS
    • Run tests, self-review, commit, push, PR

    Pullfrog  | View workflow run | via Pullfrog | Using big-pickle (free) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions