Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2777d8c
Fix durable constructor task-template creation
Oleksii-debug Sep 29, 2026
9572c51
Add restart regression for constructor task templates
Oleksii-debug Sep 29, 2026
77fa555
Cover constructor template persistence through app restart
Oleksii-debug Sep 29, 2026
9bcaa4b
Run constructor template restart regressions in qualification
Oleksii-debug Sep 29, 2026
ac98de1
Reconverge constructor persistence repair onto current package
Oleksii-debug Sep 29, 2026
604fb4c
Make constructor canonical forks restart-atomic
Oleksii-debug Sep 29, 2026
25176d6
Add crash-boundary regression for constructor forks
Oleksii-debug Sep 29, 2026
7a22c7f
Qualify restart-atomic constructor forks
Oleksii-debug Sep 29, 2026
0007d0b
Preserve fork update timestamp semantics
Oleksii-debug Sep 29, 2026
c36b688
Lock constructor fork timestamp compatibility
Oleksii-debug Sep 29, 2026
7d3c819
R06: bind QA67 to exact PR head and coalesce stale runs
Oleksii-debug Sep 29, 2026
6893892
Bind runtime checkpoint save to canonical current node
Oleksii-debug Sep 29, 2026
651083c
Project checkpoint identity only from runtime save truth
Oleksii-debug Sep 29, 2026
d232d2c
Lock runtime-owned checkpoint save projection
Oleksii-debug Sep 29, 2026
8c5a8e6
Prove checkpoint save cannot spoof runtime authority
Oleksii-debug Sep 29, 2026
8e01ae8
Preserve runtime save semantics before task load
Oleksii-debug Sep 29, 2026
5fa235d
Cover runtime checkpoint save before task load
Oleksii-debug Sep 29, 2026
01790ea
fix: fail closed on invalid runtime checkpoint identity
Oleksii-debug Sep 29, 2026
700bc8d
test: reject unknown runtime checkpoint nodes
Oleksii-debug Sep 29, 2026
f32207b
fix: require runtime checkpoint persistence acknowledgements
Oleksii-debug Sep 29, 2026
ed9f0b5
test: fail closed on unacknowledged checkpoint persistence
Oleksii-debug Sep 29, 2026
4a1202e
Merge PR #265: persist constructor task templates across restart
Oleksii-debug Sep 29, 2026
d20910f
fix: validate runtime checkpoint response contracts
Oleksii-debug Sep 29, 2026
5d47114
test: enforce checkpoint response contract at adapter
Oleksii-debug Sep 29, 2026
bcf0e26
merge: reconverge checkpoint runtime authority on current packaged head
Oleksii-debug Sep 29, 2026
7b2ff7a
Merge PR #267: bind checkpoint persistence to runtime truth
Oleksii-debug Sep 29, 2026
d3fc984
merge: reconverge QA67 exact-head qualification on current package
Oleksii-debug Sep 29, 2026
a458c7c
Merge PR #266: make QA67 exact-head and coalesce stale runs
Oleksii-debug Sep 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/qa67-runtime-gradeability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ on:
- 'lanes/dev1/repair_overlay/tests/test_constructor_runtime_gradeability.py'
- '.github/workflows/qa67-runtime-gradeability.yml'

permissions:
contents: read

env:
EXPECTED_HEAD: ${{ github.event.pull_request.head.sha || github.sha }}

concurrency:
group: qa67-constructor-runtime-${{ github.ref }}
cancel-in-progress: true

jobs:
constructor-runtime-contract:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.EXPECTED_HEAD }}
- name: Confirm exact source checkout
shell: bash
run: test "$(git rev-parse HEAD)" = "$EXPECTED_HEAD"
- uses: actions/setup-python@v5
with:
python-version: '3.13'
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/r06-constructor-v2-direct-qualification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
- 'lanes/dev1/repair_overlay/scripture_archive_platform/authoring/**'
- 'lanes/dev1/repair_overlay/scripture_archive_platform/transport/contracts.py'
- 'lanes/dev1/repair_overlay/tests/test_authoring_transport.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_fork_recovery.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_template_persistence.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_template_transport_restart.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_v2_frontend.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_v2_lifecycle.py'
- 'lanes/dev1/repair_overlay/tests/test_constructor_v2_recovery_atomicity.py'
Expand Down Expand Up @@ -111,9 +114,18 @@ jobs:
r06_platform/scripture_archive_platform/authoring
r06_platform/scripture_archive_platform/application/service.py
r06_platform/scripture_archive_platform/transport/contracts.py
r06_platform/tests/test_constructor_fork_recovery.py
r06_platform/tests/test_constructor_template_persistence.py
r06_platform/tests/test_constructor_template_transport_restart.py
r06_platform/tests/test_constructor_v2_lifecycle.py
r06_platform/tests/test_constructor_v2_recovery_atomicity.py
r06_platform/tests/test_authoring_transport.py
- name: Run Constructor fork crash-recovery regression
run: python r06_platform/tests/test_constructor_fork_recovery.py
- name: Run Constructor template persistence regression
run: python r06_platform/tests/test_constructor_template_persistence.py
- name: Run Constructor transport restart regression
run: python r06_platform/tests/test_constructor_template_transport_restart.py
- name: Run Constructor V2 lifecycle regression
run: python r06_platform/tests/test_constructor_v2_lifecycle.py
- name: Run Constructor V2 crash-recovery regression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ def invoke(self, command: str, payload: Mapping[str, Any] | None = None, *, requ
with self._runtime_lock:
if command == "player.next":
self._validate_next_context(request_id)
response = self.adapter.invoke_runtime(self._request(command, payload or {}, request_id))
return dict(response)
response = dict(self.adapter.invoke_runtime(self._request(command, payload or {}, request_id)))
if command == "player.save_checkpoint" and self._current_node_getter is not None:
# Runtime save deliberately accepts no caller checkpoint payload.
# Capture the canonical node under the same lock as persistence so
# the platform cannot label caller-supplied metadata as D5 truth.
response["current_node_id"] = self._current_node_getter()
return response

def get_daily_case(self) -> dict[str, Any]:
"""Project Daily Case from one atomic snapshot of canonical runtime state."""
Expand Down Expand Up @@ -348,4 +353,4 @@ def build_runtime_gateway(repo_root: Path, platform_store_root: Path) -> Runtime
runtime_application=runtime,
loader=loader,
subject_catalog=evidence_bundle.subject_catalog,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,35 @@ def _daily_case(self):
def _chronology_lab(self):
if not self.player_gateway:raise ValueError('Chronology Lab requires canonical runtime')
return self.player_gateway.get_chronology_lab()
def _checkpoint_from_runtime_node(self,nid):
if nid is None:return None
if not isinstance(nid,str) or not nid:raise ValueError('runtime checkpoint exposed invalid current_node_id')
try: mission=self.loader.mission_for_node(nid)
except (KeyError,ContentLoadError) as exc: raise ValueError('runtime checkpoint references unknown canonical node') from exc
campaign_id=mission.get('campaign_id'); mission_id=mission.get('mission_id')
if not isinstance(campaign_id,str) or not campaign_id or not isinstance(mission_id,str) or not mission_id:
raise ValueError('runtime checkpoint canonical mission metadata is invalid')
return {'campaign_id':campaign_id,'mission_id':mission_id,'node_id':nid,'checkpoint_schema':'scripture.player.checkpoint.v1'}
@staticmethod
def _require_runtime_checkpoint_ack(response,operation):
expected='saved' if operation=='save' else 'restored'
if response.get(expected) is not True:
raise ValueError(f'runtime checkpoint {operation} was not acknowledged')
if operation=='restore':
schema_version=response.get('schema_version')
if isinstance(schema_version,bool) or not isinstance(schema_version,int) or schema_version < 1:
raise ValueError('runtime checkpoint restore exposed invalid schema_version')
def _save_checkpoint(self,p):
if self.player_gateway:
rr=self.player_gateway.invoke('player.save_checkpoint',{},request_id='save-player')
self._require_runtime_checkpoint_ack(rr,'save')
return {'checkpoint':self._checkpoint_from_runtime_node(rr.get('current_node_id')),'truth_owner':'D5/runtime'}
checkpoint={'campaign_id':p.get('campaign_id'),'mission_id':p.get('mission_id'),'node_id':p.get('node_id'),'saved_at':int(time.time()),'checkpoint_schema':'scripture.player.checkpoint.v1'}
if self.player_gateway:self.player_gateway.invoke('player.save_checkpoint',{},request_id='save-'+str(p.get('node_id') or 'current'))
self.store.put_json('player','checkpoint',checkpoint);return {'checkpoint':checkpoint,'truth_owner':'D5/runtime' if self.player_gateway else 'REFERENCE_TEST_ONLY'}
self.store.put_json('player','checkpoint',checkpoint);return {'checkpoint':checkpoint,'truth_owner':'REFERENCE_TEST_ONLY'}
def _restore_checkpoint(self):
if self.player_gateway:
rr=self.player_gateway.invoke('player.restore_checkpoint',{},request_id='restore-player'); nid=rr.get('current_node_id'); checkpoint=None
if nid:
try: mission=self.loader.mission_for_node(str(nid));checkpoint={'campaign_id':mission.get('campaign_id'),'mission_id':mission.get('mission_id'),'node_id':str(nid),'checkpoint_schema':'scripture.player.checkpoint.v1'}
except Exception:checkpoint={'node_id':str(nid),'checkpoint_schema':'scripture.player.checkpoint.v1'}
rr=self.player_gateway.invoke('player.restore_checkpoint',{},request_id='restore-player')
self._require_runtime_checkpoint_ack(rr,'restore'); checkpoint=self._checkpoint_from_runtime_node(rr.get('current_node_id'))
return {'checkpoint':checkpoint,'runtime_schema_version':rr.get('schema_version'),'truth_owner':'D5/runtime'}
return {'checkpoint':self.store.get_json('player','checkpoint'),'truth_owner':'REFERENCE_TEST_ONLY'}
def _progress(self,nid):
Expand All @@ -253,4 +272,4 @@ def build_default_application(repo_root:Path|None=None,store_root:Path|None=None
if runtime_application.exists():
from scripture_archive_platform.application.runtime_gateway import build_runtime_gateway
gateway=build_runtime_gateway(repo_root,effective_store.root); return PlatformApplication(repo_root,store=effective_store,player_gateway=gateway)
return PlatformApplication(repo_root,store=effective_store)
return PlatformApplication(repo_root,store=effective_store)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
SNAPSHOT_SCHEMA,
AuthoringService,
)
from .validation import identity


TRANSACTION_SCHEMA = "scripture.authoring-transaction.v1"
Expand Down Expand Up @@ -68,6 +69,43 @@ def save_draft(self, draft: Any) -> dict[str, Any]:
self._commit_mutation(out["draft_id"], out, history=history)
return copy.deepcopy(out)

def fork_record(self, kind: str, record: dict[str, Any], title: str | None = None) -> dict[str, Any]:
"""Create a canonical fork without first exposing a durable blank draft.

Preserve the historical observable fork shape (revision 2 plus an undo
entry for the initial blank draft), but publish draft + history through
the recoverable write-ahead transaction as one restart-safe mutation.
"""
kind = self._kind(kind)
if not isinstance(record, dict):
raise ValueError("record must be an object")
stable_id = identity(kind, record)
blank = self._new_draft_record(title or stable_id or f"Edit {kind}", kind)
now = int(self.clock())
out = copy.deepcopy(blank)
out[kind] = self._json_copy(record)
out.update({
"status": "DRAFT",
"created_at": int(blank.get("created_at", now)),
"updated_at": now,
"revision": 2,
"base_identity": {kind: stable_id},
})
out.setdefault("change_record", []).append({
"timestamp": now,
"action": "save_draft",
"revision": 2,
})
self._protect_identity(out)
history = {
"schema": HISTORY_SCHEMA,
"draft_id": out["draft_id"],
"undo": [self._json_copy(blank)],
"redo": [],
}
self._commit_mutation(out["draft_id"], out, history=history)
return copy.deepcopy(out)

def restore_snapshot(self, draft_id: str, snapshot_id: str) -> dict[str, Any]:
current = self.load_draft(draft_id)
snapshot = self._load_snapshot(draft_id, snapshot_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,32 @@ def list_drafts(self) -> list[dict[str, Any]]:
})
return sorted(out, key=lambda x: (-(int(x.get("updated_at") or 0)), x["draft_id"]))

def new_draft(self, title: str = "Нова чернетка", kind: str = "node") -> dict[str, Any]:
def _new_draft_record(self, title: str, kind: str) -> dict[str, Any]:
kind = self._kind(kind)
title = self._title(title)
now = int(self.clock())
draft = {
return {
"draft_schema": DRAFT_SCHEMA, "draft_id": "draft-" + self.id_factory(),
"kind": kind, "title": title, "status": "DRAFT", "revision": 1,
"created_at": now, "updated_at": now, "base_identity": None,
"campaign": blank_campaign(), "mission": blank_mission(), "node": blank_node(),
"change_record": [],
}

def new_draft(self, title: str = "Нова чернетка", kind: str = "node") -> dict[str, Any]:
draft = self._new_draft_record(title, kind)
self.store.put_json("drafts", draft["draft_id"], draft)
return copy.deepcopy(draft)

def new_node_from_task_type(self, title: str, task_type: str) -> dict[str, Any]:
task_type = str(task_type).upper()
if task_type not in self.task_registry:
raise ValueError("Unknown task_type")
draft = self.new_draft(title, "node")
draft = self._new_draft_record(title, "node")
draft["node"]["task_type"] = task_type
draft["node"]["response_mode"] = task_type.lower()
return draft
self.store.put_json("drafts", draft["draft_id"], draft)
return copy.deepcopy(draft)

def load_draft(self, draft_id: str) -> dict[str, Any]:
self._validate_id(draft_id, "draft id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def invoke_runtime(self,request:Mapping[str,Any])->dict[str,Any]:
if not isinstance(normalized,dict):raise RuntimeContractError('runtime response must be an object')
if normalized.get('api_version')!=RUNTIME_API_VERSION:raise RuntimeContractError('Unexpected runtime api_version')
if normalized.get('request_id') not in {None,runtime_request['request_id']}:raise RuntimeContractError('runtime request_id mismatch')
if runtime_request['command']=='save':
if normalized.get('saved') is not True:
raise RuntimeContractError('runtime save response must acknowledge saved=true')
if runtime_request['command']=='restore':
if normalized.get('restored') is not True:
raise RuntimeContractError('runtime restore response must acknowledge restored=true')
schema_version=normalized.get('schema_version')
if isinstance(schema_version,bool) or not isinstance(schema_version,int) or schema_version < 1:
raise RuntimeContractError('runtime restore response has invalid schema_version')
current_node_id=normalized.get('current_node_id')
if current_node_id is not None and (not isinstance(current_node_id,str) or not current_node_id):
raise RuntimeContractError('runtime restore response has invalid current_node_id')
if runtime_request['command']=='get_review_queue':
try:validate_review_queue_projection(normalized.get('review_queue'))
except ValueError as exc:raise RuntimeContractError(str(exc)) from exc
Expand Down
122 changes: 122 additions & 0 deletions lanes/dev1/repair_overlay/tests/test_constructor_fork_recovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import itertools
import tempfile
import unittest
from pathlib import Path
import sys

for _parent in Path(__file__).resolve().parents:
_runtime_root = _parent / "runtime_engine"
if (_runtime_root / "scripture_archive_runtime").is_dir():
sys.path.insert(0, str(_runtime_root))
break

from scripture_archive_platform.authoring.recoverable import (
RecoverableAuthoringService,
TRANSACTION_CATEGORY,
)
from scripture_archive_platform.content.loader import TaskPresentationMapper
from scripture_archive_platform.domain.registries import build_task_registries
from scripture_archive_platform.persistence.store import JsonFileStore


class SimulatedCrash(RuntimeError):
pass


class FailAfterWriteStore:
def __init__(self, inner, fail_category):
self.inner = inner
self.fail_category = fail_category

def put_json(self, category, key, value):
self.inner.put_json(category, key, value)
if self.fail_category == category:
self.fail_category = None
raise SimulatedCrash(f"crash after {category} write")

def __getattr__(self, name):
return getattr(self.inner, name)


class ConstructorForkRecoveryTests(unittest.TestCase):
def setUp(self):
self.registry = build_task_registries()[0]

def _service(self, store, ids, *, clock=None):
if clock is None:
clock = lambda: 1700000000
return RecoverableAuthoringService(
store,
self.registry,
TaskPresentationMapper(),
clock=clock,
id_factory=lambda: f"{next(ids):012d}",
)

def test_fork_preserves_existing_revision_history_and_timestamp_semantics(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
ticks = iter((1700000000, 1700000001))
service = self._service(
JsonFileStore(root),
itertools.count(1),
clock=lambda: next(ticks),
)
record = {
"campaign_id": "ZZ-CAMPAIGN",
"title_ua": "Canonical fixture",
}

forked = service.fork_record("campaign", record, "Edit canonical fixture")

self.assertEqual(1_700_000_000, forked["created_at"])
self.assertEqual(1_700_000_001, forked["updated_at"])
self.assertEqual(2, forked["revision"])
self.assertEqual(
{"timestamp": 1_700_000_001, "action": "save_draft", "revision": 2},
forked["change_record"][-1],
)
history = service.history(forked["draft_id"])
self.assertTrue(history["can_undo"])
self.assertFalse(history["can_redo"])

def test_fork_is_recovered_from_every_durable_write_boundary_without_blank_prewrite(self):
record = {
"campaign_id": "ZZ-CAMPAIGN",
"title_ua": "Canonical fixture",
}
for fail_category in (TRANSACTION_CATEGORY, "authoring_history", "drafts"):
with self.subTest(fail_category=fail_category), tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
ids = itertools.count(1)
base_store = JsonFileStore(root)
service = self._service(
FailAfterWriteStore(base_store, fail_category),
ids,
)

with self.assertRaises(SimulatedCrash):
service.fork_record("campaign", record, "Edit canonical fixture")

if fail_category == TRANSACTION_CATEGORY:
self.assertEqual([], base_store.list_keys("drafts"))
self.assertEqual(1, len(base_store.list_keys(TRANSACTION_CATEGORY)))

restarted = self._service(JsonFileStore(root), ids)
self.assertEqual([], restarted.store.list_keys(TRANSACTION_CATEGORY))
drafts = restarted.list_drafts()
self.assertEqual(1, len(drafts))
recovered = restarted.load_draft(drafts[0]["draft_id"])
self.assertEqual(record, recovered["campaign"])
self.assertEqual(
{"campaign": "ZZ-CAMPAIGN"},
recovered["base_identity"],
)
self.assertEqual(2, recovered["revision"])
history = restarted.history(recovered["draft_id"])
self.assertTrue(history["can_undo"])
self.assertFalse(history["can_redo"])


if __name__ == "__main__":
unittest.main()
Loading
Loading