fix(perps): implement the TPSL false failure fix - #9995
Open
geositta wants to merge 3 commits into
Open
Conversation
Accepts HyperLiquid’s waitingForTrigger as successful Reconciles missing order IDs during mixed failure cleanup
restrict reconciliation and cancellation to waitingForTrigger restore old protection for unknown/incomplete responses
geositta
marked this pull request as ready for review
August 28, 2026 02:52
Contributor
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
4 tasks
Associate the unreleased TPSL changelog entry with its pull request so automated changelog checks can verify it. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Explanation
@metamask/perps-controllerv13 treated HyperLiquid's validwaitingForTriggerTP/SL acknowledgement as a failure because it has no order ID. The trigger was created, but Mobile displayedTPSL_UPDATE_FAILED.This change accepts
waitingForTriggerand reconciles its order ID only when needed to clean up a mixed-result batch. It reuses existing REST/cache order IDs to avoid an extra happy-path request, while preserving rollback for rejected, unknown, and incomplete responses. No dependencies or other packages changed, and there are no breaking changes.References
Checklist
Note
Medium Risk
Changes failure/rollback paths for
updatePositionTPSLand open-order reconciliation; incorrect matching could mis-cancel triggers or mis-report protection loss, though matching requires a single unambiguous candidate.Overview
Fixes false
TPSL_UPDATE_FAILEDwhen HyperLiquid accepts position TP/SL with a barewaitingForTriggeracknowledgement (no order ID in the response).updatePositionTPSLnow classifies TP/SL placement via#readTpslOrderPlacementOutcome, treatingwaitingForTriggeras success alongside resting and filled. On the happy path it returns success without requiring an order ID for every leg. When a mixed batch fails,#reconcileTpslOrderPlacementOutcomescan match new trigger orders fromfrontendOpenOrders(size, trigger price, side, TP vs SL) using a pre-placement order ID snapshot so cleanup can cancel reconciled legs; unreconciledwaitingForTriggerlegs surfaceTPSL_PROTECTION_LOSTinstead of a generic update failure. Restoration after partial failure uses the same TP/SL outcome logic. Tests cover combined/mixed statuses, replacement with cancel, reconciliation before mixed-failure cleanup, and restore-on-unknown/incomplete responses.Reviewed by Cursor Bugbot for commit d3cffda. Bugbot is set up for automated code reviews on this repo. Configure here.