HKUDS/Vibe-Trading · warning · ValueError
max_bytes must be positive, got {max_bytes}
Error message
max_bytes must be positive, got {max_bytes} What it means
rotate_if_needed validates its size threshold; max_bytes <= 0 (zero or negative) is rejected because rotation would either never trigger or loop.
Source
Thrown at agent/src/governance/ledger.py:649
sealed segment's final ``record_hash`` -- so a deletion of an entire segment
is as detectable as an edit within one. Use
:func:`verify_chain_with_archives` to check the whole history.
Args:
path: Active ledger path.
max_bytes: Size at or above which the active file is sealed.
fsync: Whether to fsync the directory after the rename.
Returns:
The archive path when a rotation happened, else None.
Raises:
ValueError: If ``max_bytes`` is not positive.
LedgerCorruptionError: If the active chain is broken -- a corrupt
ledger is sealed by nobody; fix or quarantine it deliberately.
"""
if max_bytes <= 0:
raise ValueError(f"max_bytes must be positive, got {max_bytes}")
if not path.exists() or path.stat().st_size < max_bytes:
return None
result = verify_chain(path)
if not result.ok:
raise LedgerCorruptionError(result.first_break)
counter = len(archive_segments(path)) + 1
archive = path.with_name(f"{path.stem}.{counter:0{ARCHIVE_SUFFIX_WIDTH}d}{path.suffix}")
path.rename(archive)
if fsync:
_fsync_dir(path.parent)
return archive
def verify_chain_with_archives(path: Path) -> ChainVerificationResult:
"""Verify a ledger's whole history, sealed segments included.
View on GitHub (pinned to 80ffdda44c)
Solutions
- Default the config to a sane positive size (e.g. 10 * 1024 * 1024) when unset/0
- Validate max_bytes > 0 at config load time with a clear error
- Treat 0/negative as 'rotation disabled' in your wrapper and skip the call
Example fix
# before
rotate_if_needed(path, max_bytes=config.max_bytes) # config.max_bytes == 0
# after
if config.max_bytes and config.max_bytes > 0:
rotate_if_needed(path, max_bytes=config.max_bytes) Defensive patterns
Strategy: validation
Validate before calling
if max_bytes is None or max_bytes <= 0:
max_bytes = 10 * 1024 * 1024 # or skip rotation Type guard
def is_valid_max_bytes(max_bytes: int) -> bool:
return isinstance(max_bytes, int) and max_bytes > 0 Try / catch
except ValueError as e: if 'max_bytes' in str(e): fall back to the default threshold and retry
Prevention
- Validate rotation config at load time
- Use a positive sentinel default, not 0, for 'unset'
- Cover config parsing with unit tests
When it happens
Trigger: Calling rotate_if_needed(path, max_bytes=0) or a negative value, often from a config default of 0 meaning 'unset'.
Common situations: Config reads max_bytes from an env var that defaults to 0; unit under test passes -1 as a sentinel; CLI arg parsed as int with missing validation.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- {result.first_break}
- payload must not set reserved chain fields: {sorted(reserved
- {verification.first_break}
- display_currency must be USD or CNY
- sources must be a list
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/7316d25ddc685d94.
Report an issue: GitHub.