fix(v4.0.0): step 6d after its review -- no error in the middle of the messages waiting, no offer left standing

Ruled 2026-10-08: A, B, C, D and the guard for a half message.  Each with
a scene in test_host_mesh.c that failed first.

A. The words of a message after its first are written from the passes
   over the messages waiting by (!W): an offer and a wait for that offer
   only (a new engine address).  A reader removed in mid-message makes no
   error; the rest is let go and counted.  Before, the error left the
   messages waiting in pieces and the node going round for ever.
B. A store to the wait withdraws every offer; (GATE1) and (PAY-SET) do it
   first.  Before, text begun after a node went round without sleeping
   could go to the port of an older offer: text for one node was done by
   another.
C. What a finished text printed is put with the messages waiting, as how
   it ended is.  With no room either is let go and counted; neither is
   begun as a message from (FINISH) any more, where a stuck node on the
   way held the whole node.
D. Only what a sender is owed from an earlier text -- its output, how it
   ended -- holds that sender's next text back; a GONE does not; and what
   cannot be noted holds nothing.  A node's own messages keep the order
   they were made in.
-  A message half taken in when its writer is removed is let go
   ((MQ-MEND)), not kept as if whole.
-  Smaller: a refused line no longer ends a waiting text 'Interrupted';
   a node's own queued messages may be passed on by 16 nodes, not 15; no
   value is left on the stack when a port goes in mid-refusal.

make -C v4 test and sanitize at both widths, hosted-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-08 06:34:15 -04:00
co-authored by Claude Opus 5.5
parent 380f1cc6ec
commit 2cf37aab4f
9 changed files with 289 additions and 62 deletions
+108
View File
@@ -121,6 +121,28 @@ static int waiting(unsigned id)
return n->reading && !n->given && n->read_port == V4_PORT_ANY;
}
/* Three nodes in a row once more, 10 at the console, 11, 12: a new fabric, each
* told who it is and the way to the others. For the scenes at the end. */
static unsigned starforth_node(unsigned k);
static void row_again(unsigned *hera, unsigned *mid, unsigned *far)
{
unsigned i;
v4_fabric_init(&f, places, 3);
v4_fabric_gone_error(&f, V4_ERROR_NO_ONE);
*hera = starforth_node(0); *mid = starforth_node(1); *far = starforth_node(2);
(void)v4_fabric_wire_device(&f, *hera, 1, &console);
(void)v4_fabric_wire(&f, *hera, 2, *mid, 2); (void)v4_fabric_wire(&f, *mid, 3, *far, 2);
going.count = 0; going_at = 0;
step_cap = 20000000;
for (i = 0; i < 20; i++) (void)v4_fabric_step(&f);
(void)tell(0, "10 (ME) ! 1 (CONSOLE) ! 1 1 ROUTE 0 2 ROUTE");
(void)tell(0, "11 (ME) ! 1 (CONSOLE) ! 2 DEFAULT-ROUTE 0 3 ROUTE");
(void)tell(0, "12 (ME) ! 1 (CONSOLE) ! 2 DEFAULT-ROUTE");
(void)tell(10, "11 2 ROUTE 12 2 ROUTE 11 2 NEIGHBOUR");
(void)tell(11, "12 3 ROUTE 10 2 NEIGHBOUR");
(void)tell(12, "11 2 NEIGHBOUR");
}
int main(void)
{
unsigned hera, mid, far, i;
@@ -487,6 +509,92 @@ int main(void)
CHECK(v4_fabric_remove(&f, far) == &pool[2], "node 12 is removed");
CHECK(strcmp(said(10, "1 2 + ."), "3 ") == 0 && pool[0].n.mem[OWED_COUNT] == 0 && waiting(hera) && !v4_node_in_wait(&pool[0].n), "node 10 lets the refusal go and is at rest: \"%s\"", printed);
/* ==== what the review of step 6d found: each scene on a row of three, begun again ==== */
/* a node is removed while a message is being passed on to it */
{
static char line[240];
unsigned steps = 0, k;
unsigned depth;
row_again(&hera, &mid, &far);
CHECK(strcmp(tell(12, "7 8 * ."), "56 ") == 0, "three nodes in a row again");
depth = pool[1].n.ds.depth;
memset(line, ' ', 200); memcpy(line, "1 DROP", 6); line[200] = 0;
printed_len = 0; printed[0] = 0; ended = 0;
(void)v4_message_text(&going, 12, CONSOLE_ID, V4_MSG_TEXT, line, 200); going_at = 0;
while (steps < 2000000 && !(pool[1].n.mem[MQ_COUNT] > 0 && pool[1].n.mem[MQ_COUNT] < 40 && pool[2].n.reading && pool[2].n.read_port == 2)) { (void)v4_fabric_step(&f); steps++; }
CHECK(steps < 2000000, "long text for node 12 is on its way through node 11, part written: %ld cells of it still with node 11", (long)pool[1].n.mem[MQ_COUNT]);
CHECK(v4_fabric_remove(&f, far) == &pool[2], "node 12 is removed");
for (k = 0; k < 3000000 && v4_fabric_step(&f) != 0; k++) { }
CHECK(k < 3000000 && pool[1].n.mem[MQ_COUNT] == 0 && waiting(mid) && pool[1].n.ds.depth == depth, "node 11 comes to rest: it has let the rest go, keeps nothing, and its stack is as it was (%ld cells kept)", (long)pool[1].n.mem[MQ_COUNT]);
CHECK(strcmp(tell(11, "20 22 + ."), "42 ") == 0 && strcmp(tell(10, "1 2 + ."), "3 ") == 0, "and it and node 10 go on");
}
/* a node is removed while it is writing a message to its neighbour: the half that came is not kept */
{
static char line[240];
unsigned steps = 0, k;
row_again(&hera, &mid, &far);
memset(line, ' ', 200); memcpy(line, "1 DROP", 6); line[200] = 0;
printed_len = 0; printed[0] = 0; ended = 0;
(void)v4_message_text(&going, 12, CONSOLE_ID, V4_MSG_TEXT, line, 200); going_at = 0;
while (steps < 2000000 && !(pool[2].n.mem[MQ_COUNT] > 8 && pool[2].n.reading && pool[2].n.read_port == 2)) { (void)v4_fabric_step(&f); steps++; }
CHECK(steps < 2000000, "node 12 has taken in part of a long text from node 11: %ld cells", (long)pool[2].n.mem[MQ_COUNT]);
CHECK(v4_fabric_remove(&f, mid) == &pool[1], "node 11 is removed");
for (k = 0; k < 3000000 && v4_fabric_step(&f) != 0; k++) { }
CHECK(k < 3000000 && pool[2].n.mem[MQ_COUNT] == 0 && waiting(far), "node 12 comes to rest, and has not kept the half: %ld cells", (long)pool[2].n.mem[MQ_COUNT]);
CHECK(v4_fabric_wire(&f, hera, 3, far, 3) && is_empty(tell(10, "12 NO-ROUTE 12 3 ROUTE")), "node 12 is wired to node 10 instead");
(void)tell(12, "NO-ROUTES 1 3 ROUTE 10 3 ROUTE");
CHECK(strcmp(tell(12, "7 8 * ."), "56 ") == 0, "and does what it is sent");
}
/* what a finished text printed, with the way to the console through a stuck node */
row_again(&hera, &mid, &far);
CHECK(v4_fabric_wire(&f, hera, 3, far, 3) && is_empty(tell(10, "NO-ROUTES 1 1 ROUTE 11 2 ROUTE 12 3 ROUTE")) && strcmp(tell(12, "3 4 + ."), "7 ") == 0,
"node 12 is reached straight from node 10; what it prints still goes back by node 11");
step_cap = 400000;
CHECK(strcmp(tell(11, ": ST BEGIN 0 UNTIL ; ST"), "(still running)") == 0, "node 11 is stuck in a loop");
(void)said(10, ": P S\" 65 EMIT\" 12 SEND ; P");
CHECK(v4_node_in_wait(&pool[2].n) && pool[2].n.mem[MQ_COUNT] > 0, "node 10 sends node 12 text that prints: what it printed, and how it ended, wait with node 12, offered, and it sleeps");
(void)said(10, ": Q S\" 9 (REFUSED) !\" 12 SEND ; Q");
(void)said(12, "8 (REFUSED) !");
CHECK(pool[2].n.mem[REFUSED] == 0 && v4_node_in_wait(&pool[2].n),
"the next text from node 10, and text typed at the console for it, are kept back: what it owes each from the last has not gone (MESH.md 7c.3). It sleeps in the wait");
{ v4_cell kept = pool[2].n.mem[MQ_COUNT];
(void)said(10, ": R S\" 7 (REFUSED) !\" 12 SEND ; R");
CHECK(pool[2].n.mem[MQ_COUNT] > kept && v4_node_in_wait(&pool[2].n), "it is not held: it takes in what it is sent, and sleeps again"); }
CHECK(v4_fabric_remove(&f, mid) == &pool[1], "node 11 is removed");
{ unsigned k; for (k = 0; k < 3000000 && v4_fabric_step(&f) != 0; k++) { }
CHECK(k < 3000000 && pool[2].n.mem[REFUSED] == 7 && pool[2].n.mem[MQ_COUNT] == 0 && waiting(far), "what could not go is let go, the texts kept back are done in the order they came, and node 12 is at rest: %ld", (long)pool[2].n.mem[REFUSED]); }
/* offers left standing when a node goes round to begin text */
row_again(&hera, &mid, &far);
CHECK(v4_fabric_wire(&f, hera, 3, far, 3) && v4_fabric_wire(&f, hera, 4, far, 4), "nodes 10 and 12 are wired to each other twice over");
(void)tell(10, "NO-ROUTES 1 1 ROUTE 11 2 ROUTE 12 3 ROUTE 77 3 ROUTE");
(void)tell(10, ": SLOW 400000 0 DO LOOP ; : Z S\" 1 DROP\" 77 SEND SLOW ;");
(void)tell(12, ": FWD99 S\" 67 EMIT\" 99 SEND ;");
(void)tell(12, "NO-ROUTES 10 3 ROUTE 11 2 ROUTE 1 4 ROUTE 99 4 ROUTE");
CHECK(strcmp(tell(12, "3 4 + ."), "7 ") == 0, "node 12's way to the console, and to 99, is by its other wire to node 10");
step_cap = 300000;
CHECK(strcmp(tell(11, ": C S\" 1 DROP\" 12 SEND S\" FWD99\" 12 SEND BEGIN 0 UNTIL ; C"), "(still running)") == 0, "node 11 sends node 12 two texts and is stuck");
step_cap = 30000;
(void)said(10, "Z");
CHECK(pool[2].n.mem[OWED_COUNT] == 1, "node 10 sends 77 a message by node 12, which has no way, and is then busy: node 12 owes it a refusal, offered on its first wire");
CHECK(v4_fabric_remove(&f, mid) == &pool[1], "node 11 is removed: node 12 lets its answer go, and begins the text it kept back");
printed_len = 0; printed[0] = 0; printed_from = -1;
{ unsigned k; for (k = 0; k < 20000000 && v4_fabric_step(&f) != 0; k++) { }
CHECK(k < 20000000, "all come to rest"); }
CHECK(strchr(printed, 'C') == NULL, "the text node 12 sent to 99 was not done by node 10: \"%s\" from %ld", printed, (long)printed_from);
CHECK(pool[0].n.mem[REFUSED] == 1 && pool[2].n.mem[OWED_COUNT] == 0, "node 10 was told its message to 77 was refused: %ld", (long)pool[0].n.mem[REFUSED]);
/* many of a node's own messages waiting for a stuck node */
row_again(&hera, &mid, &far);
step_cap = 300000;
CHECK(strcmp(tell(11, ": ST BEGIN 0 UNTIL ; ST"), "(still running)") == 0, "node 11 is stuck in a loop");
{ int k, good = 0;
for (k = 1; k <= 12; k++) { (void)said(10, "12 11 GONE"); if (strcmp(said(10, "1 2 + ."), "3 ") == 0) good++; }
CHECK(good == 12 && pool[0].n.mem[MQ_COUNT] == 108, "node 10 is told twelve times to tell it a node is gone, and after each still does what is typed: %d of 12, %ld cells kept", good, (long)pool[0].n.mem[MQ_COUNT]); }
printf(" %d checks, %d failures\n", checks, failures);
return failures != 0;
}