T2 drain at stop: finish the calls in flight within the drain bound, cut and say past it

Once told to stop, the tool runner makes no new ask of a bundle (a call after the stop is refused),
waits for the asks in flight within the drain bound (30 s by default), cuts each still in flight at
the bound with a journal line naming the bundle, the verb and the call's age, leaves its caller
unanswered (a transport fault), and only then stops its bundles itself.

Builds: design 47 H2 §813 (12), H-A-342 (2), H-A-353
This commit is contained in:
2026-11-21 23:11:38 +01:00
parent 02675a43ea
commit f7269d9812
7 changed files with 374 additions and 13 deletions
+15 -3
View File
@@ -1,11 +1,16 @@
#!/usr/bin/env python3
# A tools bundle for the tool runner's whole test (design 47 H §774): MCP over stdio, no SDK. A tool `who`, the seat node-desk's verbs
# `who` (answers at once) and `slow` (answers after three seconds), and a tool `reach` that asks the seat verb node-desk.fresh as the
# bundle does, through the runtime's `mesh/ask`, and says what came back.
import json, sys, time
# bundle does, through the runtime's `mesh/ask`, and says what came back; a tool `hold`, which answers after the seconds it is given,
# beside other calls (design 47 H2 §813 (12)).
import json, os, sys, threading, time
LOCK = threading.Lock()
def say(m):
m["jsonrpc"] = "2.0"; sys.stdout.write(json.dumps(m) + "\n"); sys.stdout.flush()
m["jsonrpc"] = "2.0"
with LOCK:
sys.stdout.write(json.dumps(m) + "\n"); sys.stdout.flush()
def text(rid, value):
say({"id": rid, "result": {"content": [{"type": "text", "text": json.dumps(value)}]}})
@@ -13,6 +18,7 @@ def text(rid, value):
TOOLS = [
{"name": "who", "description": "the module's own tool", "inputSchema": {"type": "object", "properties": {}}},
{"name": "reach", "description": "asks the seat verb node-desk.fresh", "inputSchema": {"type": "object", "properties": {}}},
{"name": "hold", "description": "answers after the seconds it is given, beside other calls", "inputSchema": {"type": "object", "properties": {"seconds": {"type": "number"}}}},
{"name": "node-desk.who", "description": "the seat's verb", "inputSchema": {"type": "object", "properties": {}}},
{"name": "node-desk.slow", "description": "the seat's verb that answers late", "inputSchema": {"type": "object", "properties": {}}},
]
@@ -24,6 +30,12 @@ for line in sys.stdin:
say({"id": rid, "result": {"tools": TOOLS}})
elif m == "tools/call":
name = p.get("name")
if name == "hold":
seconds = (p.get("arguments") or {}).get("seconds", 0)
with open(os.environ["HELD_FILE"], "a") as noted:
noted.write("hold %s\n" % seconds)
threading.Thread(target=lambda r=rid, n=seconds: (time.sleep(n), text(r, {"held": n})), daemon=True).start()
continue
if name == "node-desk.slow":
time.sleep(3)
if name == "reach":