Commit 3ba6af8
committed
fix(roi): split-write checkpoint; scan-range cap; try/except sum
Complete the split-storage pattern for the offchain-deposit
checkpoint. round-4 added ``read_offchain_deposits_from_disk`` for
the read side of ``_save_agent_performance_summary``; this commit
adds the matching ``write_offchain_deposits_to_disk`` on
``SharedState`` and rewires ``_fetch_offchain_prepaid_wei`` to use
both.
``_fetch_offchain_prepaid_wei`` now sources ``state`` from
``read_offchain_deposits_from_disk`` (raw JSON, lenient on siblings)
and persists via ``write_offchain_deposits_to_disk`` (raw JSON,
sibling-preserving). It no longer touches
``read_existing_performance_summary`` or
``overwrite_performance_summary``, so a nested-field ``__post_init__``
raise elsewhere on disk can neither cause a spurious re-seed
(sourcing) nor cascade into wiping sibling fields at write time
(persistence). Split-write mirrors the split-read and closes both
sides of the corruption cascade class.
Scan-range cap. Added ``OFFCHAIN_MAX_SCAN_RANGE = 5000`` and clamped
``to_block = min(head_block, from_block + OFFCHAIN_MAX_SCAN_RANGE
- 1)``. An agent offline for longer than the provider's
``eth_getLogs`` block-range cap (~14h+ of Gnosis blocks — a Pearl
laptop closed over a weekend) previously scanned
``[checkpoint+1, head]`` which exceeded common public-provider caps
(Alchemy / Infura ~10k), got rejected every cycle with ERROR
performative, and the checkpoint froze. Now each cycle marches the
checkpoint forward at most one chunk until it reaches head.
Exception guard on the entries sum. Wrapped
``sum(int(entry["amount"]) for entry in entries)`` in
``try/except (KeyError, TypeError, ValueError)`` and routed to the
malformed-response branch. Previously a shape drift on the entries
wire format raised uncaught, and with ``skill_exception_policy:
stop_and_exit`` in aea-config.yaml that terminated the whole agent —
harder failure mode than freezing the checkpoint. Reviewer flagged
my earlier "raise loudly, the ERROR performative arm catches it"
reasoning as wrong; the performative gate above the sum only
catches API performatives, not application exceptions inside the
sum.
Tests. Three model-level tests around ``write_offchain_deposits_to_disk``:
sibling-field preservation with a real file round-trip; minimal
file when nothing exists on disk; recovery from a truncated JSON
prefix. Two behaviour-level tests:
``test_scan_range_capped_at_offchain_max_scan_range`` (long offline
stretch, verify ``to_block`` clamped and checkpoint advances by
one chunk); ``test_malformed_entry_shape_returns_cached_total_no_raise``
(entries missing ``amount``, verify no raise and warning routing).
Existing ``TestFetchOffchainPrepaidWei`` helper reworked to mock the
disk helpers and assert (via ``AssertionError`` side-effects) that
the whole-summary read/write paths are NOT touched by this behaviour.1 parent e65d64d commit 3ba6af8
14 files changed
Lines changed: 443 additions & 68 deletions
File tree
- packages
- valory
- agents/trader
- services
- polymarket_trader
- trader_pearl
- skills
- agent_performance_summary_abci
- tests
- chatui_abci
- check_stop_trading_abci
- decision_maker_abci
- trader_abci
- tx_settlement_multiplexer_abci
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | | - | |
76 | | - | |
| 75 | + | |
| 76 | + | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 74 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
417 | 426 | | |
418 | 427 | | |
419 | 428 | | |
420 | | - | |
421 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
422 | 445 | | |
423 | 446 | | |
424 | 447 | | |
| |||
484 | 507 | | |
485 | 508 | | |
486 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
487 | 515 | | |
488 | | - | |
489 | | - | |
490 | | - | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
491 | 521 | | |
492 | | - | |
493 | | - | |
494 | 522 | | |
495 | 523 | | |
496 | 524 | | |
| |||
504 | 532 | | |
505 | 533 | | |
506 | 534 | | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
507 | 545 | | |
508 | 546 | | |
509 | 547 | | |
510 | 548 | | |
511 | 549 | | |
512 | 550 | | |
513 | 551 | | |
514 | | - | |
| 552 | + | |
515 | 553 | | |
516 | 554 | | |
517 | 555 | | |
| |||
535 | 573 | | |
536 | 574 | | |
537 | 575 | | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
555 | 598 | | |
556 | | - | |
557 | | - | |
558 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
559 | 604 | | |
560 | | - | |
561 | | - | |
562 | 605 | | |
563 | 606 | | |
564 | 607 | | |
565 | | - | |
| 608 | + | |
566 | 609 | | |
567 | 610 | | |
568 | 611 | | |
| |||
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
452 | 508 | | |
453 | 509 | | |
454 | 510 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
0 commit comments