@@ -46,8 +46,8 @@ def serving() -> bool:
4646
4747
4848def comparison_mode () -> str :
49- return ( "legacy_noise" if get_settings (). archive_comparison_mode . strip (). lower ()
50- == "legacy_noise" else " strict")
49+ # Retain the settings name for deploy compatibility; the legacy heuristic is retired.
50+ return " strict"
5151
5252
5353def serve_endpoints () -> set [str ]:
@@ -623,9 +623,6 @@ async def _store_locked(
623623 decisive = next_state in ("found" , "empty" ) and origin != "async_terminal"
624624 if decisive and baseline is not None and (previous_state , next_state ) != ("empty" , "empty" ):
625625 stable = previous_state == next_state == "found" and baseline .content_hash == ch
626- if (not stable and previous_state == next_state == "found"
627- and comparison_mode () == "legacy_noise" ):
628- stable = _noise_only (await _snapshot_body (s , baseline ), body , key )
629626 if stable :
630627 key .stable_seen += 1
631628 else :
@@ -1002,74 +999,13 @@ async def _touch_write(key_hash: str) -> None:
1002999TTL_CEILING_S = 30 * 86400
10031000TTL_NEVER = - 1 # the key marked itself never-cache: changes on every fetch
10041001_NEVER_AFTER = 4 # consecutive changed refetches (no stables) before self-marking
1005- _NOISE_MAX_LEAF_SHARE = 0.4 # a repeated identical diff-set is noise only if it is a MINOR
1006- _NOISE_MIN_LEAVES = 5 # corner of a body with at least this many leaves — a tiny body
1007- # whose one value moves (a price) must stay "changed", never noise.
1008-
1009-
1010- def _leaf_paths (node : Any , prefix : str = "$" , * , depth : int = 0 , out : list | None = None ) -> list [str ]:
1011- """Dotted leaf paths of a JSON tree; list items collapse to `[]` so per-row ids do not
1012- explode one logical path into hundreds. Bounded by depth and count — comparison machinery
1013- must never be the expensive part of a recording."""
1014- if out is None :
1015- out = []
1016- if len (out ) >= 400 or depth > 6 :
1017- return out
1018- if isinstance (node , dict ):
1019- for k , v in node .items ():
1020- _leaf_paths (v , f"{ prefix } .{ k } " , depth = depth + 1 , out = out )
1021- elif isinstance (node , list ):
1022- for v in node [:50 ]:
1023- _leaf_paths (v , f"{ prefix } []" , depth = depth + 1 , out = out )
1024- else :
1025- out .append (prefix )
1026- return out
10271002
10281003
1029- def _changed_paths (old : Any , new : Any , prefix : str = "$" , * , depth : int = 0 ,
1030- out : set | None = None ) -> set [str ]:
1031- """Leaf paths whose values differ between two JSON trees (same collapse rules as above)."""
1032- if out is None :
1033- out = set ()
1034- if len (out ) >= 400 or depth > 6 :
1035- return out
1036- if isinstance (old , dict ) and isinstance (new , dict ):
1037- for k in set (old ) | set (new ):
1038- _changed_paths (old .get (k ), new .get (k ), f"{ prefix } .{ k } " , depth = depth + 1 , out = out )
1039- elif isinstance (old , list ) and isinstance (new , list ):
1040- for a , b in zip (old [:50 ], new [:50 ]):
1041- _changed_paths (a , b , f"{ prefix } []" , depth = depth + 1 , out = out )
1042- if len (old ) != len (new ):
1043- out .add (f"{ prefix } []" )
1044- elif old != new :
1045- out .add (prefix )
1046- return out
10471004
10481005
1049- def _noise_only (old_body : bytes | None , new_body : bytes , key ) -> bool :
1050- """True when this refetch's difference is the SAME small diff-set as last time — learned
1051- request ids and server timestamps, not data. Two guards keep a real signal out of the noise
1052- bin: the identical set must repeat (first occurrence always counts as changed, and gets
1053- remembered as the candidate), and it must be a minor share (< 40%) of a body with at least
1054- 5 leaves — a tiny body whose one value moves every fetch is a PRICE, not noise."""
1055- if not old_body :
1056- return False
1057- try :
1058- old_json , new_json = json .loads (old_body ), json .loads (new_body )
1059- except (ValueError , UnicodeDecodeError ):
1060- return False
1061- changed = _changed_paths (old_json , new_json )
1062- if not changed :
1063- return False
1064- known = set (key .volatile_paths or [])
1065- leaves = len (_leaf_paths (new_json ))
1066- is_noise = (changed <= known
1067- and leaves >= _NOISE_MIN_LEAVES
1068- and len (changed ) / leaves < _NOISE_MAX_LEAF_SHARE )
1069- # Remember this diff-set as the next candidate either way (bounded), so the SAME noise
1070- # repeating is recognized from its second occurrence on.
1071- key .volatile_paths = sorted (changed )[:50 ]
1072- return is_noise
1006+
1007+
1008+
10731009
10741010
10751011def learn (key , * , stable : bool , entry : dict [str , Any ] | None ) -> None :
0 commit comments