Skip to content

test(pi): pin before_agent_start run without prompt - #7387

Merged
kunchenguid merged 1 commit into
kunchenguid:mainfrom
thelad-dev:fm/fm-pi-prompt-regressionstest-20261016
Oct 16, 2026
Merged

kunchenguid merged 1 commit into
kunchenguid:mainfrom
thelad-dev:fm/fm-pi-prompt-regressionstest-20261016

Conversation

@thelad-dev

Copy link
Copy Markdown
Contributor

Intent

Der Regressionstest zum Aufsichtsfehler geht als Beitrag nach oben.

Der gemeldete Abbruch ist im Standardzweig seit 8c9c67d behoben; was oben fehlt, ist die Absicherung. Der Test ist fertig: data/branch-prompt-trim-20261015/regressionstest-0547e084.patch, 13 Zeilen in tests/fm-pi-branch-extension.test.sh. Diese eine Veroeffentlichung nach github.com/kunchenguid/firstmate ist ausdruecklich genehmigt.

Inhalt des genannten Patches, damit diese Absicht ohne ihn lesbar bleibt (Commit "test(pi): Lauf ohne prompt in before_agent_start festnageln"): Ein Lauf, den sendCustomMessage startet, traegt eine Custom-Nachricht und keinen prompt. Das Lesen des prompt an dieser Stelle warf, womit jeder solche Lauf mit einem Fehler auftauchte statt zu starten. Die Verengung dagegen steht seit 8c9c67d im Zweig, ein Test, der sie benennt, fehlte: die einzige Abdeckung lag beilaeufig in einem Abbruch-Fall der Abwesenheits-Haltung und verschwindet mit ihm. Der neue Fall erweitert den bestehenden Mirror-Test in tests/fm-pi-branch-extension.test.sh (test_branch_mirror_filters_order_and_cursor) und prueft, dass ein solcher Lauf weder wirft noch als Dialog gespiegelt wird. Gegenprobe: ohne die Verengung wirft genau dieser Fall mit "Cannot read properties of undefined (reading 'trim')".

What Changed

  • Extended test_branch_mirror_filters_order_and_cursor in tests/fm-pi-branch-extension.test.sh with a before_agent_start case for a sendCustomMessage-style run that has a custom message and no prompt.
  • Asserts that path neither throws nor mirrors the custom-message run as captain dialog.

Risk Assessment

✅ Low: Test-only change that exercises the already-landed custom-message narrowing via the public fire path, matches the stated intent, and introduces no production behavior.

Testing

Ran the targeted mirror test including the new sendCustomMessage-style custom/no-prompt case; it passed under the 8c9c67d narrowing. Removing only that narrowing in a fixture reproduced Cannot read properties of undefined (reading 'trim'), matching the stated Gegenprobe. No product failure found.

Evidence: Pass with fix: test_branch_mirror_filters_order_and_cursor

Source: Pass with fix: test_branch_mirror_filters_order_and_cursor

ok - dialog mirror filters tool and operational traffic, lands before wakes, and keeps a durable cursor === exit: 0 ===

=== focused regression: test_branch_mirror_filters_order_and_cursor ===
=== branch: HEAD @ 45c50545 ===
=== includes custom before_agent_start case (no prompt) ===
ok - dialog mirror filters tool and operational traffic, lands before wakes, and keeps a durable cursor
=== exit: 0 ===
Evidence: Counterproof without narrowing reproduces trim crash

Source: Counterproof without narrowing reproduces trim crash

COUNTERPROOF_ERROR=Cannot read properties of undefined (reading 'trim') ok - counterproof: without narrowing, custom before_agent_start throws on prompt.trim

mutated-ok
COUNTERPROOF_ERROR=Cannot read properties of undefined (reading 'trim')
ok - counterproof: without narrowing, custom before_agent_start throws on prompt.trim
Evidence: Combined regression e2e transcript (fix site, new test, pass, counterproof)

Source: Combined regression e2e transcript (fix site, new test, pass, counterproof)

=== NEW TEST BLOCK (tests/fm-pi-branch-extension.test.sh) ===
commit 45c505455000c7f84cdc5d7dcf699e667ea33a93
Author: thelad-dev <[email protected]>
Date:   Fri Oct 16 06:49:04 2026 +0200

    test(pi): Lauf ohne prompt in before_agent_start festnageln
    
    Ein Lauf, den sendCustomMessage startet, traegt eine Custom-Nachricht und
    keinen prompt. Das Lesen des prompt an dieser Stelle warf, womit jeder
    solche Lauf mit einem Fehler auftauchte statt zu starten.
    
    Die Verengung dagegen steht seit 8c9c67de im Zweig, ein Test, der sie
    benennt, fehlte: die einzige Abdeckung lag beilaeufig in einem
    Abbruch-Fall der Abwesenheits-Haltung und verschwindet mit ihm. Der neue
    Fall erweitert den bestehenden Mirror-Test und prueft, dass ein solcher
    Lauf weder wirft noch als Dialog gespiegelt wird.
    
    Gegenprobe: ohne die Verengung wirft genau dieser Fall mit
    "Cannot read properties of undefined (reading 'trim')".

diff --git a/tests/fm-pi-branch-extension.test.sh b/tests/fm-pi-branch-extension.test.sh
index 4a6f8efe..615c897a 100644
--- a/tests/fm-pi-branch-extension.test.sh
+++ b/tests/fm-pi-branch-extension.test.sh
@@ -3216,6 +3216,19 @@ if (mirrored.some((m) => m.content.includes("operational injection") || m.conten
   throw new Error("mirror leaked operational, tool, or merge-note traffic");
 }
 
+// A run that pi.sendCustomMessage starts carries a custom message and no
+// prompt, so reading the prompt here threw and every such run surfaced the
+// failure instead of starting. It is not captain input either, so nothing of
+// it reaches the mirror.
+const mirroredBeforeCustomRun = session.ops.filter((op) => op.kind === "custom").length;
+await fire("before_agent_start", {
+  messageType: "custom",
+  message: { role: "custom", customType: "fm-branch-merge", content: "merge note that starts its own run" },
+}, ctx);
+if (session.ops.filter((op) => op.kind === "custom").length !== mirroredBeforeCustomRun) {
+  throw new Error("a custom-message run was mirrored as captain dialog");
+}
+
 // The durable cursor advances: a second turn_end mirrors only NEW dialog.
 entries.push({ type: "message", message: { role: "user", content: "actually, task-7 may merge when green" } });
 await fire("turn_end", {}, ctx);

=== FIX SITE still present (8c9c67de narrowing) ===
    // SessionManager still contains only the preceding dialog, so relying on
    // getEntries() here loses the captain request that the next wake may answer.
    // Stage it verbatim and remember the future persisted index for turn_end's
    // duplicate suppression. Operational extension injections are not dialog.
    if (event.messageType === "custom") {
      processingOpenedThisRun = isProcessingCustomMessage(event.message) &&
        queuedProcessingContent !== null && event.message.content === queuedProcessingContent;
      return;
    }
    const prompt = event.prompt;
    processingOpenedThisRun = queuedProcessingContent !== null && prompt === queuedProcessingContent;
    const trimmed = prompt.trim();
    if (!trimmed || isOperationalUserText(trimmed)) return;
    const file = currentMainSession.getSessionFile() ?? "";
    const index = mirrorCollection.collectAnchor?.index ?? currentMainSession.getEntries().length;
    pendingMirror.push({ tag: "captain", text: trimmed });

=== COUNTERPROOF (same custom event, narrowing removed in fixture only) ===
mutated-ok
COUNTERPROOF_ERROR=Cannot read properties of undefined (reading 'trim')
ok - counterproof: without narrowing, custom before_agent_start throws on prompt.trim

=== PASS WITH FIX ===
=== focused regression: test_branch_mirror_filters_order_and_cursor ===
=== branch: HEAD @ 45c50545 ===
=== includes custom before_agent_start case (no prompt) ===
ok - dialog mirror filters tool and operational traffic, lands before wakes, and keeps a durable cursor
=== exit: 0 ===
Evidence: Evidence index for reviewers

Source: Evidence index for reviewers

Evidence for: test(pi) custom before_agent_start without prompt

User intent: publish the regression that a sendCustomMessage-started run
(custom message, no prompt) must neither throw nor mirror as captain dialog.
Fix already landed in 8c9c67de; this change only adds the named test coverage.

1) pass-with-fix.txt
   Ran tests/fm-pi-branch-extension.test.sh :: test_branch_mirror_filters_order_and_cursor
   including the new before_agent_start custom/no-prompt case. Result: ok.

2) counterproof-without-narrowing.txt
   Same executable path with the custom early-return removed from a fixture
   copy of fm-branch-supervision.ts only. Result:
   COUNTERPROOF_ERROR=Cannot read properties of undefined (reading 'trim')
   Matches the intent's stated Gegenprobe.

3) regression-e2e-transcript.txt
   Combined transcript of fix site, new test block, pass, and counterproof.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash focused runner of tests/fm-pi-branch-extension.test.sh → test_branch_mirror_filters_order_and_cursor (includes new custom/no-prompt before_agent_start case)
  • Manual counterproof: same custom before_agent_start path against a fixture copy of .pi/extensions/fm-branch-supervision.ts with the messageType === &#34;custom&#34; early-return removed
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Ein Lauf, den sendCustomMessage startet, traegt eine Custom-Nachricht und
keinen prompt. Das Lesen des prompt an dieser Stelle warf, womit jeder
solche Lauf mit einem Fehler auftauchte statt zu starten.

Die Verengung dagegen steht seit 8c9c67d im Zweig, ein Test, der sie
benennt, fehlte: die einzige Abdeckung lag beilaeufig in einem
Abbruch-Fall der Abwesenheits-Haltung und verschwindet mit ihm. Der neue
Fall erweitert den bestehenden Mirror-Test und prueft, dass ein solcher
Lauf weder wirft noch als Dialog gespiegelt wird.

Gegenprobe: ohne die Verengung wirft genau dieser Fall mit
"Cannot read properties of undefined (reading 'trim')".
@thelad-dev

Copy link
Copy Markdown
Contributor Author

The red check here isn't a test failure: Behavior portable serial 2 was cancelled by the runner after about 30 minutes - conclusion cancelled, not failed. The other 18 checks are green, and the diff is 13 lines in one test file. Could someone re-run that one shard? I can't trigger it from my side.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @thelad-dev, you're right. Behavior portable serial 2 was cancelled at the runner's 30-minute ceiling (a known flake class), not a test failure. I've re-run just that shard.

I reviewed the tip against main 1a6714f2. It's 13 test-only lines in tests/fm-pi-branch-extension.test.sh that pin the messageType === "custom" early return, which is still on main in .pi/extensions/fm-branch-supervision.ts. The new case already passed in serial 4, and Require no-mistakes is green. Once the serial 2 re-run comes back green this merges, and there's nothing you need to do.

@kunchenguid
kunchenguid merged commit 5f2b81b into kunchenguid:main Oct 16, 2026
36 of 37 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @thelad-dev — really appreciate you taking the time on this.