From 8462afa56fe52377e96a497d596072425d0d696d Mon Sep 17 00:00:00 2001 From: Gahow Wang Date: Fri, 24 Jul 2026 00:40:15 +0800 Subject: [PATCH] Encode zero cacheable blocks explicitly --- runs/frontier-s3-real-v0/remap_hash_blocks.py | 9 +++- .../test_remap_hash_blocks.py | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/runs/frontier-s3-real-v0/remap_hash_blocks.py b/runs/frontier-s3-real-v0/remap_hash_blocks.py index a52973b..0628cc8 100644 --- a/runs/frontier-s3-real-v0/remap_hash_blocks.py +++ b/runs/frontier-s3-real-v0/remap_hash_blocks.py @@ -325,8 +325,13 @@ def materialize(args: argparse.Namespace, *, tokenizer: Any | None = None) -> di "num_prefill_tokens": isl, "num_decode_tokens": osl, "session_id": sid, - "block_hash_ids": "|".join( - str(value) for value in cacheable_block_ids + # "[]" is the explicit no-cacheable-block encoding accepted + # by Frontier. An empty CSV field is treated as missing + # metadata and rejected before scheduling. + "block_hash_ids": ( + "|".join(str(value) for value in cacheable_block_ids) + if cacheable_block_ids + else "[]" ), } ) diff --git a/runs/frontier-s3-real-v0/test_remap_hash_blocks.py b/runs/frontier-s3-real-v0/test_remap_hash_blocks.py index 55e8f50..510c14f 100644 --- a/runs/frontier-s3-real-v0/test_remap_hash_blocks.py +++ b/runs/frontier-s3-real-v0/test_remap_hash_blocks.py @@ -141,6 +141,49 @@ class StrictRemapTest(unittest.TestCase): len(frontier_row["block_hash_ids"].split("|")), math.floor(513 / 16) ) + def test_sub_block_prompt_uses_explicit_empty_cache_sequence(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + trace = root / "short.jsonl" + trace.write_text( + json.dumps( + { + "chat_id": "short", + "parent_chat_id": -1, + "timestamp": 1.0, + "input_length": 7, + "output_length": 1, + "hash_ids": [101], + "sampling_u": 0.1, + } + ) + + "\n" + ) + output = root / "mapped" + args = SimpleNamespace( + input=trace, + prompt=None, + tokenizer=None, + input_is_remapped=False, + output_root=output, + rho=1.0, + start_timestamp=None, + duration_s=None, + vocab_size=151936, + token_offset=1024, + served_model="test-model", + source_block_size=512, + workload_mode="prefill_decode", + validate_parents=False, + max_total_tokens=None, + frontier_only=True, + ) + materialize(args) + with (output / "frontier.csv").open(newline="") as stream: + frontier_row = next(csv.DictReader(stream)) + + self.assertEqual(frontier_row["block_hash_ids"], "[]") + def test_real_prompt_tokens_preserve_parent_and_four_to_one_contract(self) -> None: tokenizer = CharacterTokenizer() parent_prompt = "A" * 64