fix: scale FM window in _apply_fidelity to match real API pressure
_apply_fidelity checked fm.current_pressure() which uses internal object tokens (tiny) / 200k window = always NORMAL. Now scales window_size using last_effective token count so FM pressure matches real context usage, enabling L0->L1->L2 degradations.
This commit is contained in:
parent
2a71014535
commit
225b9b30f1
1 changed files with 16 additions and 2 deletions
|
|
@ -1414,8 +1414,22 @@ def _apply_fidelity(payload: dict, session: "Session") -> None:
|
|||
obj_id = fm.register_object(obj)
|
||||
content_map[key] = obj_id
|
||||
|
||||
# Check pressure and log
|
||||
pressure = fm.current_pressure()
|
||||
# Check pressure and log.
|
||||
# Scale window_size so FM's internal pressure matches real API pressure.
|
||||
# (Same fix as _update_fidelity_pressure — FM's total_tokens() is only
|
||||
# a fraction of the real context, so internal pressure is always NORMAL.)
|
||||
obj_tokens = fm.total_tokens()
|
||||
if obj_tokens > 0 and fm.window_size > 0:
|
||||
real_pressure_ratio = session.token_state.get("last_effective", 0) / fm.window_size
|
||||
if real_pressure_ratio > 0:
|
||||
saved_ws = fm.window_size
|
||||
fm.window_size = max(1, int(obj_tokens / real_pressure_ratio))
|
||||
pressure = fm.current_pressure()
|
||||
fm.window_size = saved_ws
|
||||
else:
|
||||
pressure = fm.current_pressure()
|
||||
else:
|
||||
pressure = fm.current_pressure()
|
||||
if pressure > PressureZone.NORMAL:
|
||||
transitions = fm.degrade(turn)
|
||||
for obj_id, old_level, new_level in transitions:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue