-
Notifications
You must be signed in to change notification settings - Fork 15
feat(perps): retry transient order cancellations #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kartojal
wants to merge
4
commits into
main
Choose a base branch
from
feature/dev-535-type-perps-cancel-rejections-and-add-bounded-retry-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2393b48
feat(perps): retry transient order cancellations
kartojal c7995b3
Merge branch 'main' into feature/dev-535-type-perps-cancel-rejections…
kartojal 8cd56f7
fix(perps): preserve cancel rejection outcomes
kartojal 694e37f
fix(perps): distinguish cancel request rejections
kartojal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@polymarket/bindings': minor | ||
| '@polymarket/client': minor | ||
| --- | ||
|
|
||
| Type known Perps cancellation rejections while preserving unrecognized identifiers, and retry transient `order_in_flight` results with configurable bounded backoff. |
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[blocking] Closing this field to five values turns any other rejection identifier into a thrown error that discards the rest of the batch.
The engine renders a code its build predates as a literal
unknown_error_code_<n>string —Error::Unknown(u16)carries#[strum(to_string = "unknown_error_code_{0}")](perpetuals engine/platform/src/errors.rs:207-209) — and the cancel ack goes straight through it viacancel_rejected_err(err) -> cancel_rejected(err.to_string(), ..)(apps/gateway/common/result.rs), whose own comment says why: "to_string()(notas_str()) so an unrecognized wire code surfaces asunknown_error_code_<n>".docs/getting-started/errors.mdxalso documents a WS request-level rejection ofcancel-orders/cancel-orders-coidas[{ "status": "err", "error": "invalid_request" }], and lists cancel-reachable identifiers outside this set (account_not_found,proxy_expired,account_liquidating).The damage isn't confined to the offending item.
cancelPerpsOrdersparses withz.array(PerpsCancelOrderResultSchema), so one non-member fails the whole array, andPerpsSession.#handleResponse(session.ts:1075-1083) routes a schema failure througherrorAckFrom, which recurses into the array and rejects the command withRequestRejectedError(<first err string>). So[{ "status": "ok", "oid": 1 }, { "status": "err", "error": "unknown_error_code_18", "oid": 2 }]used to return two results and now throws — the caller can't tell that order 1 was cancelled. That is the worst information to lose on a cancel path.
The repo already has the pattern for this:
PerpsWithdrawalStatus(perps/common.ts:224-239) pairs aPerpsKnown*enum with aKnown | (string & {})alias andz.string().transform(...), documenting that the service evolves the set independently of released clients. The same shape here keepsresult.error === PerpsCancelOrderErrorCode.OrderInFlightworking inretryPerpsOrderCancellationswhile letting new codes through.orders.test.ts:192codifies the strict behavior, so I read this as deliberate rather than an oversight — but I don't think the wire contract supports it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already addressed in
8cd56f7.PerpsCancelOrderErrorCode = PerpsKnownCancelOrderErrorCode | (string & {})withz.string().min(1)matches thePerpsWithdrawalStatusprecedent exactly, andorders.test.tsnow pinsunknown_error_code_18flowing through with itsoid. A mixed[ok, unknown_code]array no longer collapses the whole command.