mirror of
https://github.com/razzant/ouroboros.git
synced 2026-10-21 14:12:28 +00:00
Merge pull request #1774 from AkshatAag/fix/continue-title-stacking
fix: keep one Continue prefix across a chain of continuations (#1717)
This commit is contained in:
commit
c2880ca386
2 changed files with 59 additions and 2 deletions
|
|
@ -117,6 +117,7 @@ def _replay(q: Any, predecessor: str, nonce: str, successor: str) -> Optional[Di
|
|||
# writer census: the owner's Continue. Every other consumer (Pause, Resume,
|
||||
# money, sleep, restart) keeps the whole observation.
|
||||
CONTINUE_PURPOSE = "owner_continue"
|
||||
CONTINUE_TITLE_PREFIX = "Continue: "
|
||||
|
||||
|
||||
def conflicting_writers(q: Any, predecessor: str, *, drive_root: Any = None,
|
||||
|
|
@ -331,7 +332,10 @@ def _successor_task(q: Any, predecessor: str, result: Dict[str, Any], binding: D
|
|||
deadline_at = str(binding.get("deadline_at") or "")
|
||||
text = work_order_text(predecessor, verdict["cause"], sources, deadline_at=deadline_at,
|
||||
authority_source=authority_source, checkout=recorded_system_checkout(result))
|
||||
title = str(result.get("title") or result.get("suggested_name") or result.get("objective") or predecessor)[:80]
|
||||
title = str(result.get("title") or result.get("suggested_name") or result.get("objective") or predecessor)
|
||||
while title.startswith(CONTINUE_TITLE_PREFIX):
|
||||
title = title[len(CONTINUE_TITLE_PREFIX):]
|
||||
title = (title or predecessor)[:80]
|
||||
original = sources.get("original") or {}
|
||||
origin_ref = original.get("origin_message_ref")
|
||||
from ouroboros.settings_scales import EFFORT_SCALE
|
||||
|
|
@ -353,7 +357,7 @@ def _successor_task(q: Any, predecessor: str, result: Dict[str, Any], binding: D
|
|||
**({"context_requires_self_body_docs": self_body_docs} if isinstance(self_body_docs, bool) else {}),
|
||||
"id": binding["successor_task_id"], "type": "task", "chat_id": binding.get("chat_id"),
|
||||
"project_id": str(binding.get("project_id") or ""), "text": text, "objective": text,
|
||||
"title": f"Continue: {title}", "suggested_name": f"Continue: {title}",
|
||||
"title": f"{CONTINUE_TITLE_PREFIX}{title}", "suggested_name": f"{CONTINUE_TITLE_PREFIX}{title}",
|
||||
"root_task_id": binding["successor_task_id"], "depth": 0, "delegation_role": "root",
|
||||
**({"deadline_at": deadline_at} if deadline_at else {}),
|
||||
**{key: binding[key] for key in ("workspace_root", "workspace_mode") if binding.get(key)},
|
||||
|
|
|
|||
53
tests/test_continue_title.py
Normal file
53
tests/test_continue_title.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"""#1717: a chain of Continues keeps the work's own name under one prefix.
|
||||
|
||||
The link between links is ``metadata.continuation``; the title carries no
|
||||
second copy of it, so "Continue: Continue: …" never stacks and an 80-character
|
||||
name is not pushed out by its own prefixes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from tests._budget_pause_exact_helpers import _install_queue
|
||||
from tests.test_owner_continue import NONCE, _interrupted
|
||||
|
||||
SOURCES = {"original": {"content": "Write the Friday report"}, "later": []}
|
||||
|
||||
|
||||
def _successor(predecessor: str, result: dict, successor: str) -> dict:
|
||||
from supervisor.continuation_admission import _successor_task
|
||||
|
||||
return _successor_task(None, predecessor, result, {"successor_task_id": successor, "chat_id": 7},
|
||||
{"cause": "context_overflow"}, SOURCES, {})
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", [
|
||||
pytest.param("Friday report", id="short"),
|
||||
pytest.param("x" * 80, id="at-limit"),
|
||||
pytest.param("y" * 120, id="over-limit"),
|
||||
])
|
||||
def test_a_chain_of_continues_keeps_one_prefix_and_its_provenance(name):
|
||||
result, predecessor = {"title": name}, "pred-0"
|
||||
for link in range(1, 5):
|
||||
task = _successor(predecessor, result, f"succ-{link}")
|
||||
assert task["title"] == task["suggested_name"] == f"Continue: {name[:80]}"
|
||||
assert task["metadata"]["continuation"]["predecessor_task_id"] == predecessor
|
||||
result, predecessor = task, task["id"]
|
||||
|
||||
|
||||
def test_a_title_that_is_only_prefixes_falls_back_to_the_predecessor_id():
|
||||
task = _successor("pred-0", {"title": "Continue: Continue: "}, "succ-1")
|
||||
assert task["title"] == "Continue: pred-0"
|
||||
|
||||
|
||||
def test_admission_does_not_stack_a_predecessor_already_carrying_prefixes(tmp_path, monkeypatch):
|
||||
from supervisor.continuation_admission import admit_continuation
|
||||
|
||||
_queue, _state, workers = _install_queue(tmp_path, monkeypatch)
|
||||
_interrupted(tmp_path, title="Continue: Continue: Friday report")
|
||||
ack = admit_continuation("pred-1", action_nonce=NONCE)
|
||||
assert ack["ok"] is True, ack
|
||||
row = next(task for task in workers.PENDING if task["id"] == ack["successor_task_id"])
|
||||
assert row["title"] == row["suggested_name"] == "Continue: Friday report"
|
||||
assert row["metadata"]["continuation"]["predecessor_task_id"] == "pred-1"
|
||||
Loading…
Add table
Add a link
Reference in a new issue