Conversation
The stamp ownership registry and pool state were written with a plain open(path, 'w'), which truncates the target immediately. A crash mid-write (OOM, deploy restart, SIGKILL) left a truncated/corrupt file; on load both managers discard corrupt state and start fresh, silently losing the wallet ownership registry. Add app/core/atomic_io.atomic_write_json() — writes to a temp file in the same directory, fsyncs, then os.replace() to atomically swap it in. Readers always see a complete file. Wire it into both _save_state() methods. Closes #212
There is no CI test gate (deploy.yml only deploys), so passing the full suite locally is a manual development-process requirement before opening or merging any PR into dev or main. Documents the gap that let the x402 async test breakage go unnoticed (see #215).
Write JSON state files atomically to prevent corruption on crash
51 tests across 5 files had been failing since the x402 async migration (commit 4c22909) converted the pricing, balance, and preflight functions to async without updating the tests, which still called them synchronously and got coroutine objects back ('coroutine' object is not subscriptable). For each affected test: - mark @pytest.mark.asyncio, make it async, and await the call - upgrade the relevant @patch targets to AsyncMock where the patched function is itself awaited (get_chainstate, get_wallet_info, check_* helpers, _get_eth_balance_from_rpc, read_root deps) test_poll_updates_gauges was failing for a different reason: the #208 'keep last known value' refactor moved _poll_balances to call preflight's check_* helpers, which bind get_wallet_info/get_chequebook_info at their own module level. Patch those on app.x402.preflight (not swarm_api) so the test is deterministic regardless of run order. Full suite now green: 844 passed, 7 skipped. Addresses #215.
Repair 51 stale tests broken by x402 async migration
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.
Promotes
dev→main. Validated on staging (provenance-gateway.dev.datafund.io) and full local suite green (844 passed, 7 skipped).Contains exactly today's two merged PRs:
pytest tests/before merging todev/main. Closes Use atomic writes for JSON state files (ownership registry, stamp pool) #212.Staging smoke tests after these merges:
/health,/api/v1/pool/status,/api/v1/stamps/,/api/v1/notary/status,/metricsall 200 and healthy.