diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 45bc63aa..c2a1f066 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -391,6 +391,8 @@ retained for the next parking operation; growth appends storage without copying the existing pages. Rewinds refresh the affected pages, and running state and checkpoints are captured again. Retained active K/V counts against the same byte budget and is discarded before evicting parked entries under memory pressure. +If reserving space for growth would evict another conversation, parking uses a +full capture instead. Oldest parked entries are evicted first. Oversized snapshots or host allocation failures fall back to ordinary prompt processing. `--conversation-cache-min-free-mib N` (default 2560) additionally requires that diff --git a/tools/conversation_cache_growth.py b/tools/conversation_cache_growth.py index 9a455d4a..d28683a1 100644 --- a/tools/conversation_cache_growth.py +++ b/tools/conversation_cache_growth.py @@ -29,14 +29,16 @@ def verify(results): require(full['name'] == 'full' and incremental['name'] == 'incremental', 'incorrect comparison arms') requests = results['requests'] require([r['name'] for r in requests] == NAMES, 'incomplete growth/rewind requests') + require(all(r['ids'] and r['max_new'] > 0 for r in requests), 'empty growth request') digest = hashlib.sha256(json.dumps(requests, sort_keys=True).encode()).hexdigest() require(digest == results['request_digest'], 'request evidence changed') for arm in (full, incremental): require(arm['request_digest'] == digest and arm['args'] == full['args'], 'inputs or arguments differ') + require(arm['exe_sha256'] == full['exe_sha256'], 'executable changed between comparison arms') require([r['name'] for r in arm['records']] == NAMES, 'incomplete growth/rewind outputs') for key in (*SETTINGS, 'conversation_cache_mib', 'conversation_cache_slots'): require(key in arm['info'] and arm['info'][key] == full['info'][key], f'engine setting differs: {key}') - require(arm['info']['conversation_cache_mib'] > 0, 'cache is not enabled') + require(arm['info']['conversation_cache_mib'] == results['cache_mib'] > 0, 'cache budget differs') budget = arm['info']['conversation_cache_mib'] * 1024 * 1024 require(arm['parks'] and all(0 < p['snapshot_bytes'] <= p['bytes'] <= budget and 0 <= p['reused_kv_bytes'] <= p['snapshot_bytes'] for p in arm['parks']), 'invalid allocation/reuse evidence') @@ -99,7 +101,7 @@ def main(): env['STRATA_SNAPSHOT_VERIFY'] = '1' env['STRATA_MTP_BATCH'] = '1' a.output.mkdir(mode=0o700, parents=False, exist_ok=False) - results = {'requests': [], 'arms': [], 'spec': a.spec, 'paragraphs': a.paragraphs} + results = {'requests': [], 'arms': [], 'spec': a.spec, 'paragraphs': a.paragraphs, 'cache_mib': a.cache_mib} for name in ('full', 'incremental'): current_env = dict(env) if name == 'full': diff --git a/tools/test_conversation_cache_growth.py b/tools/test_conversation_cache_growth.py index 73b3d336..36423449 100644 --- a/tools/test_conversation_cache_growth.py +++ b/tools/test_conversation_cache_growth.py @@ -16,7 +16,7 @@ def fixture(): requests = [dict(name=name, ids=[1]*n, max_new=16, expected=name.startswith('A-')) for name, n in zip(NAMES, lengths)] digest = hashlib.sha256(json.dumps(requests, sort_keys=True).encode()).hexdigest() - full = dict(name='full', args=['--conversation-cache-mib','1'], request_digest=digest, + full = dict(name='full', exe_sha256='fixed', args=['--conversation-cache-mib','1'], request_digest=digest, info={key: 1 for key in SETTINGS}, draft_verifications=4, parks=[dict(bytes=100,snapshot_bytes=100,reused_kv_bytes=0) for _ in range(3)], records=[dict(name=name, ids=[1], text=SECRET, finish='stop', reused=1, @@ -26,7 +26,7 @@ def fixture(): incremental['name'] = 'incremental' for p in incremental['parks']: p['reused_kv_bytes'] = 50 - return dict(arms=[full,incremental],requests=requests,request_digest=digest) + return dict(arms=[full,incremental],requests=requests,request_digest=digest,cache_mib=1) class GrowthGate(unittest.TestCase): @@ -37,6 +37,8 @@ class GrowthGate(unittest.TestCase): mutations = [ lambda r:r['requests'].pop(), lambda r:r['requests'][0]['ids'].append(2), + lambda r:r['arms'][1].update(exe_sha256='different'), + lambda r:r.update(cache_mib=2), lambda r:r['arms'][1]['records'].pop(), lambda r:r['arms'][1]['records'][2].update(ids=[2]), lambda r:r['arms'][1]['records'][2].update(text='wrong'),