Repository navigation
fix(backend): Settlement and TransactionStatus update the existing transaction - #13
Merged
Merged
Conversation
…itted changes ci-local's conformance target failed on any git status output under the site mirror, so a correctly re-mirrored protocol edit could not pass the local gate before it was committed. Compare the mirror's file contents before and after aggregate-docs.sh instead: new, edited and deleted protocol files that were never re-mirrored still fail.
…ansaction POST /api/v1/transaction INSERTed every @type under its id, so a Settlement or TransactionStatus for an existing transaction always answered 409 and never changed its status, while one for an unknown id created an orphan completed transaction. They now lock and update the existing row, recording a transaction.settled / transaction.status_updated loop event and a status-updated evidence entry: 404 for an unknown transaction, 409 for leaving a terminal state or settling a terminal transaction again (SPECIFICATION.md §3.6). openapi.json documents the update semantics and the 400/404/409 responses; the site mirror is re-synced.
9 of 13 tasks
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
The bug.
POST /api/v1/transactioninserted a new row for every@type, using the id the payload names. So aSettlementorTransactionStatusfor an existing transaction always answered409 Transaction with this id already exists, and its status never changed. The code comment said "a recorded settlement marks the referenced transaction as settled", but that couldn't happen. For an unknown id, a Settlement instead created an orphan "completed" transaction that never had aMaterialTransaction.The fix (
apps/backend/src/db/loop.ts,src/routes/transactions.ts):MaterialTransactioncreates the transaction, as before. A duplicate id is still a 409.SettlementandTransactionStatuslock the existing row (SELECT … FOR UPDATE) and update its status. The stored payload stays the originalMaterialTransaction. The Settlement or TransactionStatus body is recorded in atransaction.settled/transaction.status_updatedloop event and astatus-updatedevidence entry, in the same database transaction.transaction_id:404 NOT_FOUND, withdetails.searched_id. Nothing is created.completed,cancelledanddisputed):409 CONFLICT. The spec says MUST NOT, and that nodes SHOULD answer 409.409 CONFLICT.protocol/openapi.jsonnow documents the update semantics and the400/404/409responses. Only201was listed before. The site mirror is re-synced.Also in this PR (separate commit): a gate fix. The mirror drift check I added in MycelAI/LocalLOOP#8 failed
scripts/ci-local.shon any uncommitted mirror change. A correctly re-mirrored protocol edit, like theopenapi.jsonchange here, therefore couldn't pass the local gate before it was committed. The check now compares the mirror's file contents before and afteraggregate-docs.sh. It still fails on new, edited or deleted protocol files that were never re-mirrored; I tested both drift cases.conformance.ymlkeeps its clean-checkoutgit statuscheck.Tree(s) touched
apps/backendapps/site(mirror re-sync only)protocol(openapi.json,CHANGELOG.md)ops/org-profileops/ledger,scripts/,.github/or root files (scripts/ci-local.sh,CHANGELOG.md)How was this tested?
bash scripts/ci-local.sh(all targets): pass.bun testagainst a scratchlocalloop_testdatabase: 378 pass, 0 fail.tests/transactions.routes.test.ts. All three fail on the old code:completed, with one loop event and one evidence entry;in_transitgives 409, a second Settlement gives 409, anddisputedgives 201.Checklist
bash scripts/ci-local.shpasses locally..env.protocol/changed: the site mirror was re-synced,check:conformancepasses, andgit status --shortshows no deletions.CHANGELOG.mdUnreleasedupdated in backend, protocol and root..envfiles, dumps orapps/backend/data/content included.Generated by Claude Code