Skip to content

Fix min_per_apply_amount zero-status checks in applyOrder#26

Draft
Copilot wants to merge 3 commits into
feature/add-order-min-max-per-apply-amountfrom
copilot/check-for-potential-issues
Draft

Fix min_per_apply_amount zero-status checks in applyOrder#26
Copilot wants to merge 3 commits into
feature/add-order-min-max-per-apply-amountfrom
copilot/check-for-potential-issues

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 5, 2026

Two bugs in applyOrder caused incorrect order zero-status transitions after a transaction, both introduced with the min_per_apply_amount / max_per_apply_amount feature.

Bug 1 — orderRow zeroed against the wrong constraint

orderRow was being set to 'zero' when its post-transaction left fell below applyingOrderRow's min_per_apply_amount. Each order should be evaluated against its own constraint.

// Before — wrong: uses applyingOrderRow's min constraint to zero orderRow
if (orderNewLeft.lt(applyingOrderMinPerApplyAmount ?? 0)) {
    await Order.update({ status: 'zero' }, { where: { id: orderRow.id } });
}

// After — correct: uses orderRow's own min constraint
if (orderRowMinPerApplyAmount !== null && orderNewLeft.lt(orderRowMinPerApplyAmount)) {
    await Order.update({ status: 'zero' }, { where: { id: orderRow.id } });
}

Bug 2 — Pre-transaction left used for applyingOrderRow zero check

applyingOrderLeft (the value before the transaction) was checked against min_per_apply_amount instead of applyOrderNewLeft (the value after). The pre-transaction check is vacuously always false — if applyingOrderLeft were already below the minimum, the applyInvalid gate above would have rejected the request before reaching this point.

// Before — wrong: applyingOrderLeft is the pre-transaction value
if (applyingOrderLeft.lt(applyingOrderMinPerApplyAmount ?? 0)) { ... }

// After — correct: applyOrderNewLeft is the post-transaction value
if (applyingOrderMinPerApplyAmount !== null && applyOrderNewLeft.lt(applyingOrderMinPerApplyAmount)) { ... }

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 5, 2026 11:25
Co-authored-by: jejolare <85789854+jejolare@users.noreply.github.com>
Co-authored-by: jejolare <85789854+jejolare@users.noreply.github.com>
Copilot AI changed the title [WIP] Double check potential issues in branch update Fix min_per_apply_amount zero-status checks in applyOrder Mar 5, 2026
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.

2 participants