refactor: retain decision state instead of full logs
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import gzip
|
||||
import tempfile
|
||||
import unittest
|
||||
from datetime import datetime, timezone
|
||||
@@ -17,7 +16,7 @@ MODULE_ROOT = ROOT / "modelhub_submmit_api"
|
||||
if str(MODULE_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(MODULE_ROOT))
|
||||
|
||||
from common import read_jsonl, write_json, write_jsonl # noqa: E402
|
||||
from common import read_json, read_jsonl, write_json, write_jsonl # noqa: E402
|
||||
from config_optimizer import SafeConfigOptimizer # noqa: E402
|
||||
from hf_discovery import HuggingFaceDiscovery, parse_model_card_front_matter # noqa: E402
|
||||
from official_capabilities import OfficialCapabilityRegistry # noqa: E402
|
||||
@@ -47,7 +46,7 @@ class OfficialClient:
|
||||
|
||||
|
||||
class SuperAgentTests(unittest.TestCase):
|
||||
def test_outcome_history_compacts_to_checkpoint_recent_window_and_gzip_archive(self) -> None:
|
||||
def test_outcome_history_compacts_to_decision_checkpoint_without_raw_archive(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary_dir:
|
||||
root = Path(temporary_dir)
|
||||
outcomes = root / "outcomes.jsonl"
|
||||
@@ -82,7 +81,6 @@ class SuperAgentTests(unittest.TestCase):
|
||||
outcomes,
|
||||
checkpoint_path=checkpoint,
|
||||
recent_path=recent,
|
||||
archive_pending_dir=archive,
|
||||
)
|
||||
self.assertTrue(tracker.has_durable_checkpoint)
|
||||
self.assertEqual([], read_jsonl(outcomes))
|
||||
@@ -90,19 +88,14 @@ class SuperAgentTests(unittest.TestCase):
|
||||
report = tracker.get_stats_report()
|
||||
self.assertEqual(600, report["terminalRecords"])
|
||||
self.assertEqual(300, report["totals"]["successCount"])
|
||||
shard = next(archive.rglob("*.jsonl.gz"))
|
||||
import gzip
|
||||
|
||||
with gzip.open(shard, "rt", encoding="utf-8") as handle:
|
||||
archived_text = handle.read()
|
||||
self.assertNotIn("logCosUrl", archived_text)
|
||||
self.assertNotIn("token=hidden", archived_text)
|
||||
self.assertFalse(archive.exists())
|
||||
self.assertNotIn("logCosUrl", read_jsonl(recent)[0])
|
||||
self.assertEqual("decision_state_only", read_json(checkpoint)["storageMode"])
|
||||
|
||||
restored = OutcomeTracker(
|
||||
outcomes,
|
||||
checkpoint_path=checkpoint,
|
||||
recent_path=recent,
|
||||
archive_pending_dir=archive,
|
||||
)
|
||||
self.assertEqual(600, restored.get_stats_report()["terminalRecords"])
|
||||
|
||||
@@ -127,7 +120,6 @@ class SuperAgentTests(unittest.TestCase):
|
||||
outcomes,
|
||||
checkpoint_path=checkpoint,
|
||||
recent_path=recent,
|
||||
archive_pending_dir=archive,
|
||||
)
|
||||
self.assertEqual(601, restarted.get_stats_report()["terminalRecords"])
|
||||
self.assertIn("599", restarted._by_task_id)
|
||||
@@ -294,17 +286,6 @@ class SuperAgentTests(unittest.TestCase):
|
||||
restored_project / ".modelhub_state" / "worker_crashes.jsonl",
|
||||
[{"at": "2026-08-21T01:00:00+00:00", "exitCode": 1}],
|
||||
)
|
||||
pending_archive = (
|
||||
project
|
||||
/ ".modelhub_state"
|
||||
/ "archive_pending"
|
||||
/ "outcomes"
|
||||
/ "2026-08"
|
||||
/ "shard.jsonl.gz"
|
||||
)
|
||||
pending_archive.parent.mkdir(parents=True, exist_ok=True)
|
||||
with gzip.open(pending_archive, "wt", encoding="utf-8") as handle:
|
||||
handle.write('{"taskId":"archived"}\n')
|
||||
credentials = {"username": "tester", "email": "tester@example.com", "password": "secret-value"}
|
||||
manager = StateGitSync(
|
||||
project_root=project,
|
||||
@@ -332,9 +313,8 @@ class SuperAgentTests(unittest.TestCase):
|
||||
self.assertTrue(manager.sync("unchanged_cycle"))
|
||||
self.assertEqual(generation, manager.generation)
|
||||
self.assertEqual(remote_head, manager._remote_oid())
|
||||
self.assertFalse(pending_archive.exists())
|
||||
archive_refs = porcelain.ls_remote(str(remote)).refs
|
||||
self.assertIn(b"refs/heads/agent-archive-2026-08", archive_refs)
|
||||
self.assertNotIn(b"refs/heads/agent-archive-2026-08", archive_refs)
|
||||
manager.close()
|
||||
|
||||
restored = StateGitSync(
|
||||
@@ -384,7 +364,7 @@ class SuperAgentTests(unittest.TestCase):
|
||||
self.assertEqual(pending_oid, manager._remote_oid())
|
||||
manager.close()
|
||||
|
||||
def test_terminal_intents_are_bounded_and_archived(self) -> None:
|
||||
def test_terminal_intents_are_bounded_and_reduced_to_decision_fields(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary_dir:
|
||||
root = Path(temporary_dir)
|
||||
intent_path = root / ".modelhub_state" / "recovery_intents.jsonl"
|
||||
@@ -397,7 +377,7 @@ class SuperAgentTests(unittest.TestCase):
|
||||
"createdAt": f"2026-08-01T00:{index % 60:02d}:00+00:00",
|
||||
"completedAt": f"2026-08-02T00:{index % 60:02d}:00+00:00",
|
||||
}
|
||||
for index in range(250)
|
||||
for index in range(350)
|
||||
]
|
||||
+ [{"intentId": "pending", "status": "pending"}],
|
||||
)
|
||||
@@ -409,11 +389,9 @@ class SuperAgentTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(50, manager._compact_intents())
|
||||
retained = read_jsonl(intent_path)
|
||||
self.assertEqual(201, len(retained))
|
||||
self.assertEqual(301, len(retained))
|
||||
self.assertEqual(1, sum(row.get("status") == "pending" for row in retained))
|
||||
shard = next((root / ".modelhub_state" / "archive_pending" / "attempts").rglob("*.jsonl.gz"))
|
||||
with gzip.open(shard, "rt", encoding="utf-8") as handle:
|
||||
self.assertEqual(50, len(handle.readlines()))
|
||||
self.assertFalse((root / ".modelhub_state" / "archive_pending").exists())
|
||||
|
||||
def test_failed_intent_push_returns_no_batch_id(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary_dir:
|
||||
|
||||
Reference in New Issue
Block a user