Skip to content

⚙️ FEATURE-#252: Improve model_dump_json truncation strategy - #254

Merged
FernandoCelmer merged 6 commits into
developfrom
feature/252
Apr 12, 2026
Merged

FernandoCelmer merged 6 commits into
developfrom
feature/252

Conversation

@FernandoCelmer

Copy link
Copy Markdown
Member

Summary

  • Gradual context truncation — removes largest context first, stops when under limit
  • Fix max=0 falsy bug — not self.max → self.max is None
  • JSON structured message — {"message": "Context size exceeded"} instead of plain string
  • Remove size_message string sentinel, use dict field

Before vs After

Before: All 3 contexts replaced at once, even if only 1 is large

15MB payload → replace ALL contexts → clear errors → return

After: Contexts removed one at a time (largest first)

15MB payload → remove current_context (14MB) → 1MB → fits, return
                 ↑ initial and previous preserved

Changes

Issue Fix
All-or-nothing truncation Gradual: largest context first
max=0 skipped self.max is None check
String sentinel "Context size exceeded" JSON {"message": "Context size exceeded"}

Test plan

  • test_with_max_truncates_largest_context_first — only largest removed
  • test_with_max_truncates_all_contexts_if_needed — all removed when necessary
  • test_with_max_zero_truncates — max=0 works
  • test_with_max_clears_errors_if_still_over — errors cleared as last resort
  • All 19 serializer tests pass
  • ruff lint + format pass

Closes #252

@FernandoCelmer FernandoCelmer added enhancement New feature or request 0.15.0 Introduced in v0.15.0 labels Apr 12, 2026
Comment thread dotflow/core/serializers/task.py Resolved
@FernandoCelmer
FernandoCelmer merged commit 55937d9 into develop Apr 12, 2026
10 checks passed
@FernandoCelmer
FernandoCelmer deleted the feature/252 branch April 12, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.15.0 Introduced in v0.15.0 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant