Conversations on the new loop (M2.5, PR A)
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 5m14s

- A top-level message that isn't a command is a conversation: an item in
  the `general` scope (L1), threaded under the operator's message, with
  `reply`, `ask_human` and `propose_work` and no workspace or execution.
  `general` is reserved as a project name.
- propose_work(project, title, summary) goes up as a revision for a
  go-ahead (or a plain yes). On go, under a file_issue intent (L8), the
  record issue is opened in that project, assigned to the agent and
  carrying the new item's ID; its item starts agreed, with the summary as
  its brief. Intake skips any issue carrying an ID (D1); boot adopts a
  filed issue or puts the proposal up again.
- A conversation closes after tuning.loop.general_idle_s (default a day);
  a reply in its thread then starts a new conversation that continues it.

Tests: conversation unit tests (threading, filing, the marker, an unknown
project, changes, idle close and continuation, a plain yes, both crash
cases, commands at top level); the walk with conversations, proposals and
idle time, and records_have_one_item / conversations_do_no_work; an e2e
conversation that becomes filed work.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPQ14L3LikyefCMFBqEbKE
This commit is contained in:
dongarandClaude Opus 5.5 committed 2026-10-06 04:26:40 +00:00
1 parent d70d43a8cc
commit 3f54896f65
14 files changed
+811 -35

No files matched your search

+8
View File
@@ -50,6 +50,14 @@ class FakeGitea:
self.closed: list[int] = []
self.deps: dict[int, list[int]] = {}
def create_issue(self, repo: str, title: str, body: str) -> int:
n = max([i.number for i in self.issues] + [0]) + 1
self.issues.append(Issue(n, title, body, "nisse-dev", ()))
return n
def assign_issue(self, repo: str, index: int, assignee: str) -> None:
pass
def open_dependencies(self, repo: str, index: int) -> list[str]:
return [f"{repo}#{n}" for n in self.deps.get(index, []) if n not in self.closed]
+239
View File
@@ -0,0 +1,239 @@
"""Conversations on the new loop (M2.5, PR A): the `general` scope, a
thread per conversation, idle close and continuation (L1, L5), and agreed
work filed as a record issue whose item starts as agreed (D1, L8). Real git
on the throwaway build host; a fake Gitea."""
import re
from typing import Any
from test_loop_milestones import DON, Forge, ScriptedModel, call, loop_agent
from test_loop_milestones import world as world # noqa: PLC0414 -- the fixture
from nisse_dev.canonical import Fact, ToolResult
from nisse_dev.gitea import Issue
from nisse_dev.loop.agent import FILE_ISSUE
from nisse_dev.loop.items import CHAT, GO_AHEAD, MERGE, WAITING, loop_of
PROPOSAL = call(
"propose_work",
project="sandbox",
title="Add count_lines",
summary="Add count_lines(text) to text.py, counting newline-separated lines, "
"with tests. First step: the function and its tests.",
)
def conversations(world: dict[str, Any]) -> list[Any]:
return [i for i in world["store"].work_items() if i.scope == "general"]
def facts(world: dict[str, Any], item: Any) -> list[str]:
return [
e.event.text
for e in world["store"].transcript(item.id, "orchestrator").read()
if isinstance(e.event, Fact)
]
def quiet(world: dict[str, Any]) -> None:
"""No assigned issue: only conversations in these tests."""
world["forge"].issues.clear()
def test_a_top_level_message_is_a_conversation_in_its_own_thread(
world: dict[str, Any],
) -> None:
quiet(world)
model = ScriptedModel(
[call("reply", text="A 4090 runs a 27B model at 4-bit comfortably.")],
[call("reply", text="Yes, with a smaller context.")],
)
agent, transport = loop_agent(world, model)
asked = transport.receive(DON, "Could a 4090 run a 27B model?")
[chat] = conversations(world)
loop = loop_of(chat)
assert loop.thread == asked # the thread is under the operator's message
assert (chat.position, loop.wait) == (WAITING, CHAT)
reply = transport.outbound[-1]
assert reply.thread == asked and "4-bit" in reply.text
assert 'conversation "Could a 4090 run a 27B model?": talking' in agent.status()
transport.receive(DON, "And a 32B?", thread=asked)
assert len(conversations(world)) == 1 # the same conversation
assert transport.outbound[-1].text == "Yes, with a smaller context."
def test_agreed_work_is_filed_and_starts_as_agreed(world: dict[str, Any]) -> None:
quiet(world)
forge: Forge = world["forge"]
model = ScriptedModel(
[PROPOSAL],
[ # the filed item's first run: straight to work, no restatement
call("start_milestone", name="count_lines"),
call("write_file", path="lines.py", content="L = 1\n"),
call("finish_milestone", summary="count_lines", final="yes"),
],
)
_, transport = loop_agent(world, model)
root = transport.receive(DON, "I'd like a line counter in the sandbox.")
assert transport.outbound[-1].text.startswith(
'rev-1: I\'d open an issue in don/sandbox, "Add count_lines"'
)
transport.receive(DON, "go", thread=root)
[filed] = forge.issues
marker = re.search(r"<!-- nisse-item: ([\w-]+) -->", filed.body)
assert (
marker and "count newline-separated lines" not in filed.body
) # it's the summary
assert "counting newline-separated lines" in filed.body
assert forge.assigned == [filed.number]
work = world["store"].work_item(marker.group(1))
assert work is not None and work.scope == "sandbox"
assert loop_of(work).issue == filed.number and loop_of(work).started
assert (work.position, loop_of(work).wait) == (WAITING, MERGE) # it worked
[pr] = forge.prs
assert f"Closes #{filed.number}" in forge.prs[pr]["body"]
# The conversation says where the work went and goes on.
[chat] = conversations(world)
assert loop_of(chat).became == (f"don/sandbox#{filed.number}",)
assert loop_of(chat).wait == CHAT
assert any("filed from the conversation" in f for f in facts(world, work))
def test_intake_never_takes_a_record_issue(world: dict[str, Any]) -> None:
quiet(world)
forge: Forge = world["forge"]
body = "brief\n\n<!-- nisse-item: sandbox-cabc123 -->"
forge.issues.append(Issue(30, "a record", body, "nisse-dev", ()))
agent, _ = loop_agent(world, ScriptedModel())
agent.intake()
assert world["store"].work_items() == []
def test_a_proposal_for_an_unknown_project_is_sent_back(world: dict[str, Any]) -> None:
quiet(world)
model = ScriptedModel(
[call("propose_work", project="nope", title="t", summary="s.")],
[call("reply", text="Which project should it go in?")],
)
_, transport = loop_agent(world, model)
transport.receive(DON, "Let's build a thing")
results = [
e.event.result
for e in world["store"].transcript(conversations(world)[0].id, "driver").read()
if isinstance(e.event, ToolResult)
]
assert any("no project 'nope': the projects are sandbox" in r for r in results)
assert loop_of(conversations(world)[0]).wait == CHAT
def test_changes_to_a_proposal_go_back_to_the_driver(world: dict[str, Any]) -> None:
quiet(world)
model = ScriptedModel([PROPOSAL], [PROPOSAL])
_, transport = loop_agent(world, model)
root = transport.receive(DON, "a line counter please")
transport.receive(DON, "call it line_count instead", thread=root)
loop = loop_of(conversations(world)[0])
assert (loop.wait, loop.rev) == (GO_AHEAD, 2)
assert world["forge"].issues == []
def test_an_idle_conversation_closes_and_a_reply_continues_it(
world: dict[str, Any],
) -> None:
quiet(world)
model = ScriptedModel(
[call("reply", text="Sure.")], [call("reply", text="Picking up again.")]
)
agent, transport = loop_agent(world, model)
clock = [1000.0]
agent._clock = lambda: clock[0]
agent._idle = 3600
root = transport.receive(DON, "thinking about a backup tool")
clock[0] += 3599
agent.intake()
assert conversations(world)[0].status == "open"
clock[0] += 1
agent.intake()
[old] = conversations(world)
assert (old.status, old.outcome) == ("closed", "idle")
transport.receive(DON, "back to that backup tool", thread=root)
new = [c for c in conversations(world) if c.status == "open"]
assert len(new) == 1 and loop_of(new[0]).follows == old.id
assert loop_of(new[0]).thread == root
assert any("this continues the conversation" in f for f in facts(world, new[0]))
def test_a_plain_yes_files_the_work(world: dict[str, Any]) -> None:
quiet(world)
class Reader:
def agrees(self, proposal: str, reply: str) -> bool:
return reply == "sounds right"
model = ScriptedModel([PROPOSAL], [call("ask_human", question="anything else?")])
agent, transport = loop_agent(world, model)
agent._reader = Reader()
root = transport.receive(DON, "a line counter please")
transport.receive(DON, "sounds right", thread=root)
assert len(world["forge"].issues) == 1
def test_a_filing_cut_off_by_a_crash_is_settled_at_boot(world: dict[str, Any]) -> None:
quiet(world)
forge: Forge = world["forge"]
model = ScriptedModel([PROPOSAL])
_, transport = loop_agent(world, model)
root = transport.receive(DON, "a line counter please")
chat = conversations(world)[0]
store = world["store"]
# The issue was opened, then the agent died before its item existed.
intent = store.begin_intent(
FILE_ISSUE,
{"repo": "don/sandbox", "item": "sandbox-cdead01", "title": "Add count_lines"},
cause="filing",
work_item=chat.id,
)
forge.issues.append(
Issue(
40, "Add count_lines", "b\n\n<!-- nisse-item: sandbox-cdead01 -->", "x", ()
)
)
agent2, _ = loop_agent(world, ScriptedModel([call("ask_human", question="ok?")]))
agent2.boot()
work = store.work_item("sandbox-cdead01")
assert work is not None and loop_of(work).issue == 40 and loop_of(work).started
assert not [i for i in store.pending_intents() if i.id == intent]
assert root # the conversation itself is untouched
def test_a_filing_that_never_reached_gitea_is_put_up_again(
world: dict[str, Any],
) -> None:
quiet(world)
_, transport = loop_agent(world, ScriptedModel([PROPOSAL]))
transport.receive(DON, "a line counter please")
chat = conversations(world)[0]
world["store"].begin_intent(
FILE_ISSUE,
{"repo": "don/sandbox", "item": "sandbox-cnever1", "title": "Add count_lines"},
cause="filing",
work_item=chat.id,
)
agent2, _ = loop_agent(world, ScriptedModel())
agent2.boot()
loop = loop_of(world["store"].work_item(chat.id))
assert loop.wait == GO_AHEAD and "cut off by a restart" in loop.note
assert world["store"].work_item("sandbox-cnever1") is None
def test_commands_alone_at_top_level_are_not_conversations(
world: dict[str, Any],
) -> None:
quiet(world)
_, transport = loop_agent(world, ScriptedModel())
transport.receive(DON, "status")
transport.receive(DON, "go")
assert conversations(world) == []
+9
View File
@@ -60,11 +60,20 @@ class Forge:
self.closed_issues: list[int] = []
self.issues = [Issue(14, "Add count_words", "count words", "don", ())]
self.deps: dict[int, list[int]] = {} # issue -> the issues it depends on
self.assigned: list[int] = [] # issues the agent assigned to itself
# intake
def assigned_issues(self, repo: str, assignee: str) -> list[Issue]:
return [i for i in self.issues if i.number not in self.closed_issues]
def create_issue(self, repo: str, title: str, body: str) -> int:
n = max([i.number for i in self.issues] + [0]) + 1
self.issues.append(Issue(n, title, body, "nisse-dev", ()))
return n
def assign_issue(self, repo: str, index: int, assignee: str) -> None:
self.assigned.append(index)
def open_dependencies(self, repo: str, index: int) -> list[str]:
return [
f"{repo}#{n}"
+72 -13
View File
@@ -9,6 +9,7 @@ the seed and the steps, so it replays exactly.
"""
import random
import re
import subprocess
from pathlib import Path
from typing import Any
@@ -28,6 +29,7 @@ from nisse_dev.loop.driver import Driver
from nisse_dev.loop.items import (
ANSWER,
BLOCKED,
CHAT,
GO_AHEAD,
MERGE,
RUNNING,
@@ -49,8 +51,9 @@ class PolicyModel:
after comments, close after a merge; sometimes asks a question or
replies in prose. Seeded, so a walk replays exactly."""
def __init__(self, rng: random.Random) -> None:
def __init__(self, rng: random.Random, projects: list[str]) -> None:
self.rng = rng
self.projects = projects
self.n = 0
def complete(self, events, tools, model, system=None) -> list[Any]:
@@ -63,6 +66,17 @@ class PolicyModel:
return [call("ask_human", question=f"question {self.n}?")]
if roll < 0.12:
return [ToolCall(call_id=f"p{self.n}", tool="nonsense", arguments={})]
if "reply" in offered: # a conversation: talk, or propose work
if self.rng.random() < 0.4:
return [
call(
"propose_work",
project=self.rng.choice(self.projects),
title=f"filed {self.n}",
summary=f"do thing {self.n}.",
)
]
return [call("reply", text=f"an answer {self.n}")]
if "restate" not in offered and "finish_milestone" not in offered:
return [call("ask_human", question=f"talk first {self.n}?")] # discuss
if "finish_milestone" not in offered:
@@ -101,7 +115,6 @@ class Walk:
self.seed = seed
self.steps: list[str] = []
self.shown_at_go: list[str] = [] # item:revision on screen at each go
self.next_issue = dict.fromkeys(worlds, 15) # numbers repeat across projects
self.now = 1000.0
self.agent, self.transport = self._agent()
@@ -132,7 +145,11 @@ class Walk:
account="nisse-dev",
operators={DON},
gitea_operators={"don"},
driver=Driver(PolicyModel(self.rng), "m", cancel=cancel), # type: ignore[arg-type]
driver=Driver(
PolicyModel(self.rng, list(self.worlds)), # type: ignore[arg-type]
"m",
cancel=cancel,
),
worker=InlineWorker(),
cancel=cancel,
oplog=OpLog("nisse-dev", _Null()),
@@ -158,15 +175,26 @@ class Walk:
open_items = [i for i in self.items() if i.status == "open"]
# Weighted towards what an item can actually do, so review paths
# are walked often, not drowned out by intake and crashes.
weights = {"intake": 2 if not open_items else 1, "crash": 1, "issue": 1}
weights = {
"intake": 2 if not open_items else 1,
"crash": 1,
"issue": 1,
"chat": 1,
}
item = self.rng.choice(open_items) if open_items else None
loop = loop_of(item) if item else None
# The forge an item's project lives on; a new issue picks one.
project = item.scope if item else self.rng.choice(list(self.worlds))
project = (
item.scope
if item and item.scope != "general"
else self.rng.choice(list(self.worlds))
)
forge: Forge = self.worlds[project]["forge"]
if item and loop:
weights.update({"go": 3, "answer": 2, "abandon": 1, "go-stale": 1})
weights.update({"first": 1, "plain-yes": 2, "named-go": 1, "wait": 2})
weights.update({"plain-yes": 2, "wait": 2})
if item.scope != "general": # conversations aren't named by number
weights.update({"first": 1, "named-go": 1})
if loop.pr:
weights.update(
{"comment": 4, "merge": 2, "close-pr": 1, "comment-merge": 2}
@@ -175,12 +203,15 @@ class Walk:
self.steps.append(f"{action}{self.name(item)}" if item else action)
if action == "intake":
self.agent.intake()
elif action == "chat":
# A top-level message: a conversation of its own (L1, L5).
self.transport.receive(DON, f"thinking aloud {len(self.steps)}")
elif action == "issue":
# A new issue, sometimes depending on one that is still open.
project = self.rng.choice(list(self.worlds))
forge = self.worlds[project]["forge"]
n = self.next_issue[project]
self.next_issue[project] += 1
# Numbered by the forge, as filed records are: never reused.
n = max([i.number for i in forge.issues] + [14]) + 1
labels = self.rng.choice([(), (), ("bug",), ("discuss",), ("design",)])
forge.issues.append(Issue(n, f"task {n}", f"do task {n}", "don", labels))
live = [i.number for i in forge.assigned_issues("", "") if i.number != n]
@@ -197,8 +228,8 @@ class Walk:
self.shown_at_go.append(f"{item.id}:{loop.rev}")
self.transport.receive(DON, f"go {self.name(item)}")
elif action == "wait":
# Time passes: bug countdowns may run out.
self.now += self.rng.choice([60, 700])
# Time passes: bug countdowns may run out, conversations idle.
self.now += self.rng.choice([60, 700, 90000])
for other in open_items:
o = loop_of(other)
if (
@@ -261,11 +292,10 @@ class Walk:
assert len(issues) == len(set(issues)), f"one_item_per_issue: {where}"
for item in items:
loop = loop_of(item)
forge = self.worlds[item.scope]["forge"]
repo = self.worlds[item.scope]["repo_name"]
if item.status == "open" and item.position == WAITING:
explained = (
(loop.wait == GO_AHEAD and loop.rev > 0)
(loop.wait == CHAT and item.scope == "general")
or (loop.wait == GO_AHEAD and loop.rev > 0)
or (loop.wait == ANSWER and bool(loop.note))
or (loop.wait == MERGE and loop.pr > 0)
)
@@ -281,6 +311,10 @@ class Walk:
assert all(f"{item.id}:{rev}" in self.shown_at_go for rev in gos), (
f"go_binds: {item.id} {gos} not in {self.shown_at_go}: {where}"
)
if item.scope == "general":
continue # no forge: nothing below applies
forge = self.worlds[item.scope]["forge"]
repo = self.worlds[item.scope]["repo_name"]
# Blocked comes from external truth (L1): an item whose issue
# had an open dependency from the start never ran before it closed.
if forge.open_dependencies(repo, loop.issue):
@@ -337,12 +371,37 @@ class Walk:
assert not [i for i in items if i.position == RUNNING], (
f"one_active (nothing left running): {where}"
)
for item in items:
if item.scope == "general":
loop = loop_of(item)
# L1: a conversation has no workspace, milestone or PR.
assert not (loop.prepared or loop.milestone or loop.pr), (
f"conversations_do_no_work: {item.id}: {where}"
)
for name, w in self.worlds.items():
self._records_have_one_item(name, w, where)
self._own_repository_only(name, w, where)
self._parked_work_safe(w, name, where)
self._milestones_start_fresh(w, where)
self._review_fixes_land(w, where)
def _records_have_one_item(self, name: str, world: Any, where: str) -> None:
"""D1: a record issue filed from a conversation is its item's, from
the moment it exists, and intake never takes it for another."""
store = self.world["store"]
for issue in world["forge"].issues:
found = re.search(r"<!-- nisse-item: ([\w-]+) -->", issue.body or "")
if not found:
continue
item = store.work_item(found.group(1))
assert item is not None and item.scope == name, (
f"records_have_one_item: {name}#{issue.number} has no item: {where}"
)
assert loop_of(item).issue == issue.number, (
f"records_have_one_item: {item.id} isn't #{issue.number}: {where}"
)
assert loop_of(item).started, f"filed work starts agreed: {where}"
def _own_repository_only(self, name: str, world: Any, where: str) -> None:
"""D8: an item's branches and PRs reach only its own project's
repository."""