Skip to content

fix(inference): make pruning bounded and retry-safe - #1773

Open
Ryanchen911 wants to merge 3 commits into
gonka-ai:upgrade-v0.2.16from
Ryanchen911:ryan/fix-pruner-prunedcount
Open

Ryanchen911 wants to merge 3 commits into
gonka-ai:upgrade-v0.2.16from
Ryanchen911:ryan/fix-pruner-prunedcount

Conversation

@Ryanchen911

@Ryanchen911 Ryanchen911 commented Sep 15, 2026

Copy link
Copy Markdown

Summary

  • enforce each pruner's PruningMax across all eligible epochs in a block
  • stop immediately after a partial pruning failure so later epochs and markers cannot skip unfinished data
  • defer VOTING/STARTED inferences to the current epoch instead of orphaning them
  • reject non-positive pruning limits in parameter validation and skip safely if a legacy value reaches EndBlock
  • restore non-zero inference and PoC pruning defaults
  • backfill legacy non-positive stored limits during the v0.2.16 upgrade before full parameter validation

Tests

  • multi-epoch 12,600-item backlog stays within 1,000 removals per block and fully drains
  • active inferences survive, transition to FINISHED, and are removed on a later retry without stale indexes
  • zero/negative limits do not mutate state and fail parameter validation
  • v0.2.16 upgrades replace legacy zero/negative limits while preserving positive custom values
  • injected partial failures do not process later epochs or advance the marker
  • go test ./x/inference/keeper ./x/inference/types ./app/upgrades/...

This is the prerequisite for the InferenceValidationDetails pruner in #1499.

Refs #1223 and #1499.

Copilot AI lite review requested due to automatic review settings September 15, 2026 04:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved pruning-index retention, budget accounting, and non-positive-limit handling issues remain.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR fixes pruning budget handling, restores default pruning limits, and preserves active inferences.

Changes:

  • Adds default inference and PoC pruning limits.
  • Accumulates pruning counts across epochs.
  • Adds active-status preservation and regression tests.
File summaries
File Summary
inference-chain/x/inference/types/params.go Adds default pruning limits; non-positive limits still require validation or guarding.
inference-chain/x/inference/keeper/pruning.go Updates budget accounting and status handling; retains unresolved index, error-accounting, logging, and zero-limit concerns.
inference-chain/x/inference/keeper/pruning_test.go Adds backlog and status-preservation regression coverage.
Review details

Suppressed comments (2)

inference-chain/x/inference/keeper/pruning.go:367

  • PruneEpoch runs from EndBlock, and Prune invokes it for each pruner, so this adds an Info log for every epoch-pruner invocation on normal blocks with eligible data. That creates sustained log volume during routine operation; this diagnostic should be Debug-level.
	p.Logger.LogInfo("PruneEpoch called", types.Pruning, "epoch", currentEpochIndex, "prunesLeft", prunesLeft, "list", p.List.GetName())

inference-chain/x/inference/types/params.go:228

  • These limits are still accepted as zero or negative by EpochParams.Validate (only the threshold is checked), and PruneEpoch compares the budget only after removing an item. A governance update or legacy params record with InferencePruningMax == 0 therefore still removes one item per call, violating the advertised maximum; the new defaults do not protect those configurations. Reject non-positive limits or guard before entering PruneEpoch.
		InferencePruningEpochThreshold: 2,    // Number of epochs after which inferences can be pruned
		InferencePruningMax:            1000, // Maximum number of inferences to prune per block
		PocPruningMax:                  1000, // Maximum number of PoC items to prune per block
  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread inference-chain/x/inference/keeper/pruning.go Outdated
Comment thread inference-chain/x/inference/keeper/pruning.go
Comment thread inference-chain/x/inference/keeper/pruning.go Outdated
@Ryanchen911 Ryanchen911 changed the title fix(inference): fix pruner prunedCount accumulation and status preservation fix(inference): make pruning bounded and retry-safe Sep 15, 2026
@Ryanchen911

Copy link
Copy Markdown
Author

@copilot review

@tcharchian tcharchian added this to the v0.2.18 milestone Sep 15, 2026
Ryanchen911 and others added 2 commits September 17, 2026 14:48
…vation

This commit fixes three critical issues in the generic Pruner implementation
that were blocking issue gonka-ai#1499 and causing pruning failures:

1. **Missing prunedCount accumulation (lines 413-421 in pruning.go)**
   - Root cause: prunedCount was declared but never accumulated across epochs
   - Impact: Every epoch received full PruningMax budget instead of sharing it
   - Result: First block deleted all items (batch delete), and smaller epochs
     were skipped over by the marker, leaving data permanently orphaned
   - Fix: Added 'prunedCount += prunedForEpoch' and early return when limit hit
   - Verification: TestPrunerMultiEpochBacklogBudget now passes, properly
     spreading 12,600 deletions across 13 blocks at 1000/block

2. **Missing default pruning limits (params.go lines 226-227)**
   - Root cause: InferencePruningMax and PocPruningMax were absent from
     DefaultEpochParams(), causing them to default to 0
   - Impact: No pruning occurred at all (0 items per block = infinite backlog)
   - Fix: Added both fields with value 1000 to default params
   - This was the primary blocker preventing any pruning from working

3. **Missing status-based pruning exemption (pruning.go lines 205-212)**
   - Root cause: Remover function directly deleted inferences without checking
     their status field
   - Impact: VOTING and STARTED status inferences were pruned when they should
     have been preserved (active validation state)
   - Fix: Added status check in Remover - skip deletion for VOTING/STARTED
     but still remove from pruning index to avoid infinite re-checks
   - Verification: TestPruningStatusPreservation now passes

Additional changes:
- Added TestPrunerMultiEpochBacklogBudget based on bonujel's 2026-07-30
  reproduction case (6 epochs, 12,600 items, varying sizes)
- Added debug logging in PruneEpoch to track per-epoch pruning progress

These fixes unblock PR gonka-ai#1499 (InferenceValidationDetails gradual pruning)
and address the core pruning infrastructure issues identified in issue gonka-ai#1223.

Refs: gonka-ai#1223, gonka-ai#1499

Co-Authored-By: Claude <noreply@anthropic.com>
@Ryanchen911
Ryanchen911 force-pushed the ryan/fix-pruner-prunedcount branch 2 times, most recently from 17c1544 to 269445f Compare September 17, 2026 06:48
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.

3 participants