fix(history): preserve chronological replay ownership

This commit is contained in:
冰朔 2026-08-01 18:52:28 +08:00
commit efec80bc0e
2 changed files with 18 additions and 0 deletions

View file

@ -30,6 +30,11 @@ PERSONAS = {
PRIVATE_MARKERS = ("email", "token", "password", "secret", "api_key", "private_key") PRIVATE_MARKERS = ("email", "token", "password", "secret", "api_key", "private_key")
STREAM_BUFFER_BYTES = 1024 * 1024 STREAM_BUFFER_BYTES = 1024 * 1024
GPT_METADATA_SAMPLE_BYTES = 128 * 1024 GPT_METADATA_SAMPLE_BYTES = 128 * 1024
SOURCE_WAITING_STATUSES = {
"PENDING",
"WAITING_FOR_SOURCE",
"WAITING_FOR_SOURCE_ACCEPTANCE",
}
def now_iso() -> str: def now_iso() -> str:
@ -62,6 +67,11 @@ def classify_personas(text: str) -> list[str]:
] ]
def blocks_later_history(status: str) -> bool:
"""An available active/error source owns the chronological replay lane."""
return status != "COMPLETE" and status not in SOURCE_WAITING_STATUSES
def iter_top_level_json_objects( def iter_top_level_json_objects(
handle: BinaryIO, start_offset: int = 0 handle: BinaryIO, start_offset: int = 0
) -> Iterator[tuple[bytes, int]]: ) -> Iterator[tuple[bytes, int]]:
@ -753,6 +763,8 @@ class Runtime:
self.process_source(source) self.process_source(source)
if self.stop.is_set(): if self.stop.is_set():
break break
if blocks_later_history(self.store.state(source["id"])["status"]):
break
return self.write_public() return self.write_public()
def run(self) -> None: def run(self) -> None:

View file

@ -41,6 +41,12 @@ class RuntimeTests(unittest.TestCase):
labels = runtime.classify_personas("曜冥宝宝和霜砚不是铸渊,也不是凝渊") labels = runtime.classify_personas("曜冥宝宝和霜砚不是铸渊,也不是凝渊")
self.assertEqual(labels, ["YAOMING-BABY", "SHUANGYAN", "ZHUYUAN", "NINGYUAN"]) self.assertEqual(labels, ["YAOMING-BABY", "SHUANGYAN", "ZHUYUAN", "NINGYUAN"])
def test_available_active_source_blocks_later_history(self):
self.assertTrue(runtime.blocks_later_history("ACTIVE"))
self.assertTrue(runtime.blocks_later_history("ERROR_RETRYABLE"))
self.assertFalse(runtime.blocks_later_history("COMPLETE"))
self.assertFalse(runtime.blocks_later_history("WAITING_FOR_SOURCE_ACCEPTANCE"))
def test_public_snapshot_excludes_private_locators(self): def test_public_snapshot_excludes_private_locators(self):
with tempfile.TemporaryDirectory() as directory: with tempfile.TemporaryDirectory() as directory:
root = pathlib.Path(directory) root = pathlib.Path(directory)