From 5ccb25e643c78a8c8d41e553e9ddf1daad4b7709 Mon Sep 17 00:00:00 2001
From: Z8MB1E
Date: Tue, 24 Nov 2026 15:00:30 -0500
Subject: [PATCH] fix(ai): bound the structured path too, and stop the dialog
overpromising
The timeout from the previous commit only covered the plain-text fetch, so
the default drafting path was still unbounded: `streamObject` for
json_schema had no abort signal, which is what `generateDialogueDraft` and
the probe's structured half use. A provider that answers the plain probe
and then stalls could still hold the Generate modal and the Test button
open, while the docs claimed every request was bounded. Both
`streamObject` calls (the shared structured path and Compose's fallback)
now carry the same ceiling.
Dialog copy told the author the branch continues into the successor even
after they cleared the return box, which is when it does not. It now says
that step becomes unreachable until wired by hand. When the node cannot
take a return at all the checkbox used to vanish without explanation; the
reason is now stated where the toggle would be.
A choice node marked as the start could receive the return hop, drawing an
edge into the start node that `connectHop` and the drop handler both
refuse. It no longer returns, and its open end stays free like the other
cases.
Also: the two misplaced doc comments now sit above the declarations they
describe, and the whole-conversation caveat moved into the shared preview
component so the global settings tab carries it too.
---
src/collections/game/NpcDialogues.ts | 2 +-
.../npc-dialogue/GenerateDraftDialog.tsx | 11 +++++++-
.../admin/npc-dialogue/PromptPreview.tsx | 3 ++-
src/lib/ai/generate.ts | 8 ++++--
src/lib/npc-dialogue/fragmentInsert.ts | 14 ++++++++--
src/lib/npc-dialogue/normalize.ts | 8 +++---
src/payload.config.ts | 4 +++
tests/int/npc-dialogue-fragment.int.spec.ts | 26 +++++++++++++++++++
8 files changed, 65 insertions(+), 11 deletions(-)
diff --git a/src/collections/game/NpcDialogues.ts b/src/collections/game/NpcDialogues.ts
index e6057f44..63242c51 100644
--- a/src/collections/game/NpcDialogues.ts
+++ b/src/collections/game/NpcDialogues.ts
@@ -112,7 +112,7 @@ export const NpcDialogues: CollectionConfig = {
{
label: "AI Drafting",
description:
- "How the drafting tools should sound for this conversation. The preview shows the assembled instruction for a whole-conversation draft; a generated branch swaps only the structure section.",
+ "How the drafting tools should sound for this conversation. The preview shows the exact instruction the model receives.",
fields: [
{
name: "voiceOverride",
diff --git a/src/components/admin/npc-dialogue/GenerateDraftDialog.tsx b/src/components/admin/npc-dialogue/GenerateDraftDialog.tsx
index f83c71a0..03603f02 100644
--- a/src/components/admin/npc-dialogue/GenerateDraftDialog.tsx
+++ b/src/components/admin/npc-dialogue/GenerateDraftDialog.tsx
@@ -399,13 +399,22 @@ export function GenerateDraftDialog({
{effectivePlacement === "attach" && attachTarget
? `The branch is wired in from ${attachTarget.label} and lands beside it, unsaved.${
attachTarget.returnsTo === "successor"
- ? " This replaces that node's current next step, and the branch continues into it at the end."
+ ? returnToCaller
+ ? " This replaces that node's current next step, and the branch continues into it at the end."
+ : " This replaces that node's current next step, and nothing continues into it, so it becomes unreachable until you wire it by hand."
: ""
}`
: "The branch lands beside the conversation and you drag the line to wire it."}
+ This node cannot take a return hop, so the branch's open end stays free for you
+ to wire. A condition would retake the same branch, a start node accepts nothing
+ pointing at it, and a node with nothing after it has nowhere to go.
+