Skip to content

optimize: bound zero-edit low-worth savings estimate to a recovery fraction - #691

Merged
iamtoruk merged 1 commit into
getagentseal:mainfrom
avs-io:fix/640-zero-edit-savings
Jul 16, 2026
Merged

iamtoruk merged 1 commit into
getagentseal:mainfrom
avs-io:fix/640-zero-edit-savings

Conversation

@avs-io

@avs-io avs-io commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Problem

estimateLowWorthRecoverableTokens returns the entire session token total when editTurns === 0, and that number flows into the headline "Potential savings: X tokens ($Y, ~Z% of spend)" and the JSON potentialSavingsCostUSD / per-finding estimatedSavingsUSD. A zero-edit (exploration/reading) session claims 100% of its cost as recoverable — an upper bound presented as a point estimate. The retry path already applies a bounded fraction; only the no-edit branch claimed everything. (#640)

Note: the old behavior was documented as intentional in the comment above the function, so this is a deliberate behavior change, not a typo fix — the doc comment is rewritten accordingly.

Fix

New WORTH_IT_NO_EDIT_RECOVERY_FRACTION = 0.5 next to the other WORTH_IT_* constants (aligned with the existing CAPABILITY_RELIABILITY_RECOVERY_FRACTION = 0.5 precedent): the no-edit branch now returns round(tokens * 0.5). Retry branch untouched. The two existing tests pinning the old ceiling now pin the fraction.

Tuning note

0.5 is a judgment call — read-only sessions may still contain useful exploration, so claiming half is conservative in both directions. Easy to adjust in one place, guarded by tests.

Tests

  • New tests/optimize-zero-edit-savings.test.ts (written red-first: both cases failed with expected 10000 to be less than 10000 before the fix, pass after).
  • Updated pins in tests/optimize.test.ts (8K → 4K for the no-edit cases).
  • npx tsc --noEmit clean; full suite 1712 passed / 0 failed.

Closes #640

@iamtoruk
iamtoruk marked this pull request as ready for review July 16, 2026 18:07
@iamtoruk
iamtoruk merged commit 6cdbf56 into getagentseal:main Jul 16, 2026
3 checks passed
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.

optimize: low-worth sessions with zero edits claim the full session as recoverable savings

2 participants