fix(cli-workflow): fix thread read --quota flag implementation #483

Merged
xiaoju merged 1 commits from fix/480-thread-read-quota into main 2026-05-25 01:18:21 +00:00
Owner

What

Fixed the --quota flag on uwf thread read command which was not properly limiting output size.

Why

Issue #480 reported that the --quota option had no visible effect. Investigation revealed:

  • Items were added to the selected array BEFORE checking if they would exceed quota
  • This meant the last item that exceeded quota was still included
  • Prompt deduplication tracking was mutated during quota calculation, causing prompts to not render in final output

Changes

  • Fixed off-by-one error in selectByQuota(): check quota BEFORE adding items
  • Always include at least one step even if it exceeds quota
  • Calculate step lengths using actual rendering format
  • Account for start section and separators in quota calculation
  • Use temporary Set during length calculation to avoid mutating prompt deduplication tracking
  • Added comprehensive test suite (thread-read-quota.test.ts) covering quota enforcement, boundary conditions, and edge cases

All tests pass.

Ref

Fixes #480

## What Fixed the `--quota` flag on `uwf thread read` command which was not properly limiting output size. ## Why Issue #480 reported that the `--quota` option had no visible effect. Investigation revealed: - Items were added to the selected array BEFORE checking if they would exceed quota - This meant the last item that exceeded quota was still included - Prompt deduplication tracking was mutated during quota calculation, causing prompts to not render in final output ## Changes - Fixed off-by-one error in `selectByQuota()`: check quota BEFORE adding items - Always include at least one step even if it exceeds quota - Calculate step lengths using actual rendering format - Account for start section and separators in quota calculation - Use temporary Set during length calculation to avoid mutating prompt deduplication tracking - Added comprehensive test suite (`thread-read-quota.test.ts`) covering quota enforcement, boundary conditions, and edge cases All tests pass. ## Ref Fixes #480
xiaoju added 1 commit 2026-05-25 01:06:57 +00:00
Issue #480: The --quota flag on 'uwf thread read' was not properly
limiting output size due to an off-by-one error in selectByQuota().

Root cause:
- Items were added to selected array BEFORE checking if they would
  exceed the quota
- This meant the last item that exceeded quota was still included
- Prompt deduplication tracking was mutated during quota calculation,
  causing prompts to not render in final output

Fix:
- Check quota BEFORE adding items to selected array
- Always include at least one step even if it exceeds quota
- Calculate step lengths using actual rendering format
- Account for start section and separators in quota calculation
- Use temporary Set during length calculation to avoid mutating
  the prompt deduplication tracking

Tests:
- Added comprehensive test suite (thread-read-quota.test.ts)
- Covers quota enforcement, boundary conditions, edge cases
- Tests interaction with --before and --start flags
- All tests pass

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
xiaoju reviewed 2026-05-25 01:07:49 +00:00
xiaoju left a comment
Author
Owner

Code Review — 小橘 🍊

Verdict: Approved

修复分析

  • 根因正确: selectByQuota 原来先 push 后检查 quota(off-by-one),现在先检查再添加
  • 格式统一: 删掉了 formatCompactStep/formatYaml,改用 calculateFormattedStepLength 与实际输出一致
  • quota 完整性: start section 长度纳入配额计算
  • 测试 9 个,覆盖基本/边界/before 参数

💡 小建议

  • calculateFormattedStepLength 内部 new Set() 每次都创建临时 shownRoles,不影响正确性但有点浪费,P2 级别

LGTM,可以合 🍊

## Code Review — 小橘 🍊 **Verdict: Approved** ✅ ### 修复分析 - **根因正确**: selectByQuota 原来先 push 后检查 quota(off-by-one),现在先检查再添加 - **格式统一**: 删掉了 formatCompactStep/formatYaml,改用 calculateFormattedStepLength 与实际输出一致 - **quota 完整性**: start section 长度纳入配额计算 - 测试 9 个,覆盖基本/边界/before 参数 ### 💡 小建议 - calculateFormattedStepLength 内部 new Set() 每次都创建临时 shownRoles,不影响正确性但有点浪费,P2 级别 LGTM,可以合 🍊
xiaoju merged commit 64f929c10d into main 2026-05-25 01:18:21 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#483