Commit 6035fe6
committed
fix: handle BROADCAST_DEADLINE gracefully — deadlock fix, retry, configurable daemon attempts
The bot deadlocked after a BROADCAST_DEADLINE credential daemon response,
leaving the grid unreconciled and the process hung. Three interrelated
changes:
## Deadlock fix (fillLockAlreadyHeld:true)
File: modules/dexbot_class.ts:4242
- Problem: _reconcileAfterUncertainBroadcast tried to acquire
_fillProcessingLock, but it was already held by the fill-processing
call chain (fill loop → safe-rebalance → COW broadcast → catch).
AsyncLock is not reentrant, so the second acquire() queued forever.
- Impact: reconcile never ran, no log output after the error.
- Fix: pass fillLockAlreadyHeld:true from the catch block — the lock
is always held at this call site.
## Bot-level retry for BroadcastUncertainError
File: modules/dexbot_class.ts:2943-2972
- The daemon's broadcastWithRetry runs up to N attempts against a
single 25s inner deadline (CREDENTIAL_DAEMON_INNER_DEADLINE_MS).
If all expire, the error reaches the bot immediately.
- Fix: new _executeWithRetryOnUncertain wrapper retries the broadcast
once with a fresh 25s window before falling through to reconcile.
- Skips retry when err.partialOnChainState is true (pair-mode grouped
execution) — re-broadcasting would duplicate already-committed creates.
## Configurable daemon broadcast retries
File: modules/constants.ts:271, credential-daemon.ts:407,421
- Hardcoded `attempt <= 2` replaced by
CREDENTIAL_DAEMON_BROADCAST_RETRIES (default 3).
- Daemon reads constant via TIMING lookup with ??2 fallback.
## Test coverage
File: tests/test_uncertain_broadcast.ts
- UNC-012: drives _updateOrdersOnChainBatchCOW through the
BroadcastUncertainError path, asserts reconcile receives
fillLockAlreadyHeld:true (deadlock regression guard).
- UNC-013: asserts _executeWithRetryOnUncertain retries exactly
once then re-throws on second BroadcastUncertainError.
- UNC-014: asserts retry is skipped when partialOnChainState is
set (pair-mode double-publish guard).
- Also added missing stubs (lockOrders, unlockOrders, etc.) to
makeBot() to support the deeper method path.
## Risk/Edge-case Notes
- Bot-level retry adds up to ~25s per retry. Current config = 1 retry,
so worst-case broadcast stall is ~50s (2 × 25s) before reconcile.
- partialOnChainState skip only matters for pair-mode (outside-in
create groups). Non-pair batches (updates/cancels) always set it
false, so they always get the retry.
- Daemon's broadcastWithRetry now reads TIMING at call time, not
module-load time — consistent with the existing pattern used by
CREDENTIAL_DAEMON_INNER_DEADLINE_MS.
## Testing Notes
- npm test (uncertain broadcast suite) — all 24 tests pass.
- Also verified: cow_orchestration_fixes, cow_commit_guards,
main_loop_sync_fill_rebalance.1 parent 5a20dbd commit 6035fe6
4 files changed
Lines changed: 170 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| 407 | + | |
407 | 408 | | |
408 | | - | |
| 409 | + | |
409 | 410 | | |
410 | 411 | | |
411 | 412 | | |
| |||
417 | 418 | | |
418 | 419 | | |
419 | 420 | | |
420 | | - | |
| 421 | + | |
421 | 422 | | |
422 | 423 | | |
423 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
270 | 277 | | |
271 | 278 | | |
272 | 279 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2940 | 2940 | | |
2941 | 2941 | | |
2942 | 2942 | | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
2943 | 2974 | | |
2944 | 2975 | | |
2945 | 2976 | | |
| |||
4077 | 4108 | | |
4078 | 4109 | | |
4079 | 4110 | | |
4080 | | - | |
| 4111 | + | |
4081 | 4112 | | |
4082 | 4113 | | |
4083 | 4114 | | |
| |||
4211 | 4242 | | |
4212 | 4243 | | |
4213 | 4244 | | |
4214 | | - | |
| 4245 | + | |
4215 | 4246 | | |
4216 | 4247 | | |
4217 | 4248 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
885 | | - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
886 | 895 | | |
887 | 896 | | |
888 | 897 | | |
889 | 898 | | |
890 | 899 | | |
891 | 900 | | |
892 | 901 | | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
893 | 1015 | | |
894 | 1016 | | |
895 | 1017 | | |
| |||
915 | 1037 | | |
916 | 1038 | | |
917 | 1039 | | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
918 | 1043 | | |
919 | | - | |
| 1044 | + | |
920 | 1045 | | |
921 | 1046 | | |
922 | 1047 | | |
| |||
0 commit comments