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."}
)}
+ {effectivePlacement === "attach" && attachTarget && !attachTarget.returnsTo && (
+
+ 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.
+
+ )}
{effectivePlacement === "attach" && attachTarget?.returnsTo && (
VOICE and HOUSE RULES follow the fields above. STRUCTURE, FIELDS, STATE and OUTPUT
- are fixed in code because the draft validator enforces them.
+ are fixed in code because the draft validator enforces them. This is the prompt for a
+ whole-conversation draft; a generated branch swaps only the STRUCTURE section.
{voice ? "" : ` No custom voice is set, so the built-in voice is used: ${DEFAULT_VOICE.length} characters.`}
diff --git a/src/lib/ai/generate.ts b/src/lib/ai/generate.ts
index 9acafc4c..0577224e 100644
--- a/src/lib/ai/generate.ts
+++ b/src/lib/ai/generate.ts
@@ -49,8 +49,8 @@ export const MODEL_LABEL =
//
// Only sent when the active connection allows it: a strict provider rejects
// unrecognised body fields with a 400.
-export /** Ceiling for one completion, including a slow local model. */
-const REQUEST_TIMEOUT_MS = 600_000;
+/** Ceiling for one completion, including a slow local model. */
+export const REQUEST_TIMEOUT_MS = 600_000;
const REASONING_DISABLED = { reasoning_effort: "none" } as const;
@@ -322,6 +322,10 @@ export async function generateStructured(
const result = streamObject({
maxOutputTokens: options.maxTokens ?? 5000,
+ // Same ceiling as the plain path. Without it a provider that answers the
+ // plain probe and then stalls leaves Generate busy forever, because the
+ // modal waits on `result.object` for as long as the stream dribbles.
+ abortSignal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
model: providerFor(connection)(connection?.modelId || options.model || resolveModel()),
onError: (error) => {
console.error("AI generateStructured: ", error);
diff --git a/src/lib/npc-dialogue/fragmentInsert.ts b/src/lib/npc-dialogue/fragmentInsert.ts
index afab1fae..97db9309 100644
--- a/src/lib/npc-dialogue/fragmentInsert.ts
+++ b/src/lib/npc-dialogue/fragmentInsert.ts
@@ -163,7 +163,12 @@ export function returnTargetOf(
source: DialogueNode,
sourceHandle?: string | null,
): { target: string; kind: "caller" | "successor" } | null {
- if (source.type === "choice") return { target: source.id, kind: "caller" };
+ // A hop into the start node is refused everywhere else (`connectHop`, the
+ // canvas drop handler), so a start menu is the one caller that cannot take a
+ // return. Its open end stays free instead of breaking that rule silently.
+ if (source.type === "choice") {
+ return source.data.isStart ? null : { target: source.id, kind: "caller" };
+ }
if (source.type === "condition") return null;
const successor = hopFromHandle(source, sourceHandle)?.target;
return successor ? { target: successor, kind: "successor" } : null;
@@ -367,7 +372,12 @@ export function describeAttachTarget(node: DialogueNode): {
};
}
if (node.type === "choice") {
- return { label, output: "a new choice button", canAttach: true, returnsTo: "caller" };
+ return {
+ label,
+ output: "a new choice button",
+ canAttach: true,
+ returnsTo: returnTargetOf(node, null)?.kind ?? null,
+ };
}
if (node.type === "condition") {
// A branch cannot rejoin a condition: re-entering re-evaluates the same flags
diff --git a/src/lib/npc-dialogue/normalize.ts b/src/lib/npc-dialogue/normalize.ts
index 58fe1c31..71171fc3 100644
--- a/src/lib/npc-dialogue/normalize.ts
+++ b/src/lib/npc-dialogue/normalize.ts
@@ -21,6 +21,10 @@ export function normalizeDashes(text: string): string {
.replace(/\u2013/g, "-");
}
+/** Length ceilings for admin-entered prompt text. Shared by every writer. */
+export const MAX_VOICE_CHARS = 4000;
+export const MAX_EXTRA_RULES_CHARS = 2000;
+
/**
* Clean an admin-entered prompt fragment: normalise dashes, trim, collapse an
* empty result to null (meaning "use the built-in"), and cap the length.
@@ -28,10 +32,6 @@ export function normalizeDashes(text: string): string {
* A cap rather than a rejection: an over-long paste should still save something
* usable instead of failing the whole settings form with no explanation.
*/
-/** Length ceilings for admin-entered prompt text. Shared by every writer. */
-export const MAX_VOICE_CHARS = 4000;
-export const MAX_EXTRA_RULES_CHARS = 2000;
-
export function cleanPromptText(value: unknown, maxLength: number): string | null {
if (typeof value !== "string") return null;
const normalised = normalizeDashes(value.trim());
diff --git a/src/payload.config.ts b/src/payload.config.ts
index 3a0f3e94..acebdee2 100644
--- a/src/payload.config.ts
+++ b/src/payload.config.ts
@@ -130,6 +130,7 @@ import {
generatePlainText,
MODEL_ID,
MODEL_LABEL,
+ REQUEST_TIMEOUT_MS,
reasoningOptionsFor,
} from "@/lib/ai/generate";
import { resolveConnection } from "@/lib/ai/connections";
@@ -782,6 +783,9 @@ export default buildConfig({
// structured path rather than guessing at a wrapper.
const streamResult = streamObject({
maxOutputTokens: options.maxTokens || 5000,
+ // Same ceiling as every other model call: Compose runs inside an
+ // admin request, and a stalled provider would hold it open.
+ abortSignal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
model: connectionProvider(connection)(model),
onError: (error) => {
console.error("Unsloth generateObject: ", error);
diff --git a/tests/int/npc-dialogue-fragment.int.spec.ts b/tests/int/npc-dialogue-fragment.int.spec.ts
index 8b6c5bd0..5c960b89 100644
--- a/tests/int/npc-dialogue-fragment.int.spec.ts
+++ b/tests/int/npc-dialogue-fragment.int.spec.ts
@@ -181,6 +181,32 @@ describe("insertGeneratedFragment", () => {
expect(result.nodes.some((n) => n.id === "end")).toBe(true);
});
+ it("does not point a branch at a start node, which the canvas refuses everywhere else", () => {
+ // A choice can be the start node. Returning to it would draw an edge into the
+ // start, the one thing `connectHop` and the drop handler both reject.
+ const base = existing().map((n) =>
+ n.id === "menu" ? { ...n, data: { ...n.data, isStart: true } } : n,
+ );
+
+ const described = describeAttachTarget(node("m2", "choice", { isStart: true }));
+ expect(described.canAttach).toBe(true);
+ expect(described.returnsTo).toBeNull();
+
+ const result = insertGeneratedFragment(base, fragment(), {
+ attachment: { sourceId: "menu", sourceHandle: null },
+ returnToCaller: true,
+ newId: ids("a1", "a2"),
+ });
+
+ expect(result.returnedFrom).toBeNull();
+ expect(result.returnKind).toBeNull();
+ // Only the inserted nodes matter: the existing start legitimately leads to it.
+ const insertedPointsAtStart = result.nodes
+ .filter((n) => n.id === "a1" || n.id === "a2")
+ .some((n) => n.data.next?.target === "menu");
+ expect(insertedPointsAtStart).toBe(false);
+ });
+
it("refuses to rejoin a condition, because re-entering retakes the same branch", () => {
const base = [
...existing(),