Skip to content

fix: async adapter writes return 200 but silently fail to persist for TypeScript SDK#216

Merged
br-raia merged 1 commit into
mainfrom
fix/async-write-persistence
May 18, 2026
Merged

fix: async adapter writes return 200 but silently fail to persist for TypeScript SDK#216
br-raia merged 1 commit into
mainfrom
fix/async-write-persistence

Conversation

@br-raia

@br-raia br-raia commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Bug: Writes via the async psycopg adapter (POST /api/v1/entries) return HTTP 200 with a well-formed response, but the data doesn't persist properly when using the TypeScript SDK. Reads immediately return not_found, stats show unchanged entry counts. Confirmed with raw curl.
  • Root cause: The async adapter's write() method builds its response from input data (not a RETURNING clause), so even if the INSERT silently fails or the transaction doesn't commit, the client sees a perfect 200.
  • Impact: All writes through the HTTP API have been silently dropping since the async adapter was deployed (commit 92713fe, May 9). Existing bench data (1038 entries) is unaffected as it predates the async adapter.

Changes

  1. async_adapter.py: Add RETURNING id, account_id to the INSERT — verifies the row persisted and detects NULL account_id (which would make entries invisible to RLS reads). Raises RuntimeError if RETURNING yields nothing.

  2. server.py: Add sync adapter fallback in write_entry — if async write raises any exception, retry through the proven sync mem.write() path so writes still land while we investigate the async transaction issue.

…G verification and sync fallback

Writes via the async psycopg adapter (introduced in #215) return HTTP 200
with a well-formed response but the data never reaches the database.
The response was built from input data rather than DB output, masking
the silent failure completely.

Confirmed via curl: POST /api/v1/entries returns 200, immediate
GET returns not_found, stats show unchanged entry count.

Changes:
- Add RETURNING id, account_id to the async INSERT so we verify
  the row actually persisted and detect NULL account_id (RLS invisible)
- Raise RuntimeError if RETURNING yields nothing (no silent failures)
- Add sync adapter fallback in write_entry endpoint: if async write
  raises, retry through the proven sync path so writes still land
@br-raia br-raia self-assigned this May 18, 2026
@br-raia br-raia added the bug Something isn't working label May 18, 2026
@br-raia br-raia changed the title fix: async adapter writes return 200 but silently fail to persist fix: async adapter writes return 200 but silently fail to persist for TypeScript SDK May 18, 2026
@br-raia br-raia merged commit 0bbc597 into main May 18, 2026
3 checks passed
@br-raia br-raia deleted the fix/async-write-persistence branch May 18, 2026 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant