Skip to content

Surface server-side failures and receive errors in sync JSON output#41

Merged
andinux merged 5 commits intomainfrom
fix/sync-surface-receive-errors
Apr 16, 2026
Merged

Surface server-side failures and receive errors in sync JSON output#41
andinux merged 5 commits intomainfrom
fix/sync-surface-receive-errors

Conversation

@andinux
Copy link
Copy Markdown
Collaborator

@andinux andinux commented Apr 16, 2026

Summary

  • Forward the server's lastFailure object (jobId, code, message, retryable, failedAt) in the output of cloudsync_network_send_changes() and cloudsync_network_sync() so callers can see why the
    server rejected an apply job.
  • When cloudsync_payload_apply fails during the receive phase (e.g. unknown schema hash, invalid checksum), return structured JSON with a receive.error field instead of failing silently — applies
    to all three sync functions (cloudsync_network_send_changes, cloudsync_network_check_changes, cloudsync_network_sync).
  • Endpoint/network errors (server unreachable, auth failure) always raise a SQL error. Processing errors (cloudsync_payload_apply failures) are returned as structured JSON. If you get JSON back,
    the server was reachable.
  • Document the error-handling contract in API.md and as a code comment in network.c.

Test plan

  • CI integration tests pass (Init+Sync, Enable Disable, Peer tests)
  • Trigger a schema-hash mismatch and verify cloudsync_network_send_changes() includes send.lastFailure
  • Trigger an apply error during cloudsync_network_sync() and verify the output includes receive.error with the error message and send fields are still populated
  • Trigger an apply error during cloudsync_network_check_changes() and verify the output includes receive.error (not NULL, not a SQL error)
  • Verify endpoint errors (e.g. bad URL) raise a SQL error in all three functions
  • Verify normal sync cycles (no errors) produce the same JSON shape as before (no lastFailure or error fields)

andinux and others added 5 commits April 15, 2026 17:06
Propagate server-reported lastFailure through cloudsync_network_send_changes
and cloudsync_network_sync output. Capture receive-phase errors (including
cloudsync_payload_apply failures like unknown schema hash) and emit them as
a structured receive.error field in cloudsync_network_sync instead of
raising a SQL error that would hide the successful send result.
cloudsync_network_check_changes keeps the error-raising behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The err_out path in network_download_changes and
cloudsync_network_check_internal was treating all non-BUFFER responses
as errors, including CLOUDSYNC_NETWORK_OK which is the normal "no
changes ready yet" response. This caused the retry loop in
cloudsync_network_sync to break immediately on the first empty check
response instead of retrying, resulting in receive.rows always being 0.

Now only CLOUDSYNC_NETWORK_ERROR sets err_out; CLOUDSYNC_NETWORK_OK
returns rc=0 so the retry loop continues as expected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Refine the error-handling contract: endpoint/network errors (server
unreachable, auth failure) always raise a SQL error regardless of which
function is called. Only cloudsync_payload_apply failures are surfaced
as structured JSON via receive.error.

cloudsync_network_check_changes now also returns receive.error in JSON
for apply failures (consistent with sync), instead of raising a SQL
error for those.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@andinux andinux merged commit 61b9cea into main Apr 16, 2026
27 checks passed
@andinux andinux deleted the fix/sync-surface-receive-errors branch April 16, 2026 18:08
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.

1 participant