fix: async adapter writes return 200 but silently fail to persist for TypeScript SDK#216
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 returnnot_found, stats show unchanged entry counts. Confirmed with raw curl.write()method builds its response from input data (not aRETURNINGclause), so even if the INSERT silently fails or the transaction doesn't commit, the client sees a perfect 200.92713fe, May 9). Existing bench data (1038 entries) is unaffected as it predates the async adapter.Changes
async_adapter.py: AddRETURNING id, account_idto the INSERT — verifies the row persisted and detects NULLaccount_id(which would make entries invisible to RLS reads). RaisesRuntimeErrorifRETURNINGyields nothing.server.py: Add sync adapter fallback inwrite_entry— if async write raises any exception, retry through the proven syncmem.write()path so writes still land while we investigate the async transaction issue.