Skip to content

mAIner: cap submittedResponses, remove dead stable lists, fix postupgrade penalty, guard pullNextChallenge#143

Merged
icppWorld merged 6 commits intomainfrom
removeStableMemory
Apr 24, 2026
Merged

mAIner: cap submittedResponses, remove dead stable lists, fix postupgrade penalty, guard pullNextChallenge#143
icppWorld merged 6 commits intomainfrom
removeStableMemory

Conversation

@icppWorld
Copy link
Copy Markdown
Contributor

@icppWorld icppWorld commented Apr 18, 2026

Summary

Implements Required Actions 1–6 (item 5 skipped per source) from funnAI/scripts/logs-mainer-analysis/mAIner-memory-remediation-plan.md to halt the mAIner freeze wave.

  • Cap submittedResponses at 5. putSubmittedResponse now List.takes after every push (mirrors challengeQueue cap pattern). Stops the primary unbounded-growth source.
  • Remove generatedResponses entirely. Declaration + 4 accessors + the putGeneratedResponse call site are gone — get/getAll/remove were never called anywhere; put produced a write-only sink. Pure dead code.
  • Remove officialCycleTopUpsStorage entirely. Write-only dead code (no reader anywhere in PoAIW). officialCyclesBalance accounting in addCycles() is preserved — still needed for unofficial-topup detection.
  • Reset officialCyclesBalance := Cycles.balance() in postupgrade(). Treats cycles delivered during upgrade (dfx wallet send) as official, fixing the 9× penalty that immediately froze 36 mAIners after the last upgrade. Reinstall path already correct via the line-108 initializer.
  • Guard pullNextChallenge entry with PAUSED_DUE_TO_LOW_CYCLE_BALANCE early-return + Cycles.balance() < CYCLE_BALANCE_MINIMUM early-return. Prevents the wasteful GameState call when the canister has already paused itself.

Diffstat: 2 files, 135 insertions, 143 deletions.

Test plan

  • moc --check clean (only pre-existing warnings)
  • make smoketest — 116 passed, 4 skipped (the 4 are GameState integration tests)
  • test__getSubmittedResponsesAdmin extended with entry_count <= 5 invariant assertion
  • Reinstall a single mAIner on local via scripts/upgrade_mainers.sh --reinstall --mainer <id> (companion PR in funnAI repo) and confirm memory drops to baseline
  • Roll out reinstall in batches; confirm zero post-deploy penalty freezes via scripts/check_mAIner_status.py

…cleTopUpsStorage; reset officialCyclesBalance in postupgrade; add cycle-balance and PAUSED guards to pullNextChallenge
@icppWorld icppWorld requested a review from patnorris April 18, 2026 00:38
Port the previously off-chain daily cleanup job directly into the canister. The challenge queue is now automatically reset if it reaches the length threshold or if all entries are older than 24 hours, ensuring stale work is cleared before pulling new challenges.
Add documentation for deploying the pre-built WASM to `mainer_ctrlb_canister_0` and include references to the `smoketest` Makefile target for both the controller and the main service.
… more forensic history; still a strict bound)
…ieval

Wrap cross-canister calls and timer operations in try-catch blocks to prevent silent failures and log cycle balances on error. Inlining the GameState call avoids unnecessary Motoko self-calls that can fail when the canister balance is near the freezing reserve.
@patnorris
Copy link
Copy Markdown
Contributor

looks good. Just one comment on the Summary above: it should be "Cap submittedResponses at 100" (MAX_SUBMITTED_RESPONSES : Nat = 100;)

Compensate for the IC's upfront instruction-cost deduction during install_code by adding a 1T cycle buffer to the official balance tracking. This prevents false triggers of the unofficial-topup penalty immediately after installation or upgrade. The minimum balance threshold is also increased to ensure the canister stays above the freezing reserve during the prepay/refund cycle. Includes a new diagnostic query and extensive logging to trace cycle balance drift.
@icppWorld icppWorld merged commit ab6d33c into main Apr 24, 2026
9 checks passed
@icppWorld icppWorld deleted the removeStableMemory branch April 24, 2026 13:22
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