Skip to content

Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.

fix(v0.32.7): the discuss misroute — a write request must never need a provider to be classified

Ashiq Hussain Mir196c50208981
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66d15f6..4b5dd72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
recovery e2e (mocked route, real editor); the live benchmark spec
(CANVIX_BENCH_LIVE=1, real provider) writes docs/BENCHMARK-v0.32.7.md.
Fixed: the panel crashed on a partial brief event.
+- **Fixed: the discuss misroute during provider outages** (router.ts).
+ The entire fix/improve family — "fix it", "fix the design", "improve
+ this poster", "make it look cool", "it looks like shit", "redesign
+ the poster" — fell through the heuristic lists to the model router,
+ and when the provider was down (429/502, exactly when users retry a
+ broken design) the catch kept the catch-all: DISCUSS. A write request
+ became a product chat that touched nothing. The fix/improve family
+ now classifies deterministically: whole-artifact fixes route to
+ improve, element-level fixes ("fix the title", "change the app
+ icon") stay edits, product talk ("improve the app", "fix the Canvix
+ agent tool loop") stays discuss, interrogatives never create, and a
+ new fallbackMode() classifies remaining design vocabulary by canvas
+ state (empty → create, populated → edit) whenever the model router
+ fails or answers garbage. +5 regressions from the live JNV Baramula
+ poster session (26 Nov 2026).
### Changed — v0.32.6: ONE agent, ZERO selectors + the canvas map
diff --git a/src/app/api/ai/agent/route.ts b/src/app/api/ai/agent/route.ts
index 09ecd77..a168c7a 100644
--- a/src/app/api/ai/agent/route.ts
+++ b/src/app/api/ai/agent/route.ts
@@ -10,7 +10,7 @@ import {
} from '@/lib/agent/protocol'
import { fontFamilies } from '@/lib/agent/tools'
import { serializeDesignContext, type AgentDesignCtx } from '@/lib/agent/context'
-import { heuristicMode, parseMode, ROUTER_SYSTEM, modeAllowsWrites, MODE_TOOL_RISK } from '@/lib/agent/router'
+import { heuristicMode, parseMode, ROUTER_SYSTEM, modeAllowsWrites, MODE_TOOL_RISK, fallbackMode } from '@/lib/agent/router'
import { runAgentLoop, toolsForMode } from '@/lib/agent/loop'
import { auditDesign as runDesignAudit } from '@/lib/agent/audit'
import { selectSkills } from '@/lib/agent/skills'
@@ -350,6 +350,14 @@ async function __canvix_post(req: NextRequest) {
const h = heuristicMode(message)
mode = h.mode
if (h.confidence === 'low') {
+ // v0.32.7 (production report): a WRITE request must never
+ // depend on a provider to be classified. When the heuristic
+ // recognized no pattern and the model router call fails
+ // (429/502/network — exactly when users retry a broken
+ // design) or answers unparseable garbage, the old catch kept
+ // the heuristic catch-all: DISCUSS — "fix my poster" became
+ // a product chat that touched nothing. fallbackMode classifies
+ // deterministically: design vocabulary + canvas state.
try {
const modelMode = parseMode(
await chat([
@@ -357,9 +365,10 @@ async function __canvix_post(req: NextRequest) {
{ role: 'user', content: message.slice(0, 500) },
]),
)
- if (modelMode) mode = modelMode
+ mode = modelMode ?? fallbackMode(message, (design.elements?.length ?? 0) > 0)
} catch {
- /* provider hiccup — the heuristic answer stands */
+ /* provider hiccup — the deterministic fallback stands */
+ mode = fallbackMode(message, (design.elements?.length ?? 0) > 0)
}
}
}
diff --git a/src/lib/agent/harness.test.ts b/src/lib/agent/harness.test.ts
index 851fe94..fcf3a7a 100644
--- a/src/lib/agent/harness.test.ts
+++ b/src/lib/agent/harness.test.ts
@@ -26,7 +26,7 @@ import { parseAgentTurn, sseLine, AGENT_GUARDS, AGENT_PROTOCOL_VERSION, type Age
import { AGENT_TOOL_MAP, AGENT_TOOLS, type ToolContext, type SanitizeResult } from './tools'
import { runAgentLoop, toolsForMode, loopSystemPrompt } from './loop'
import { auditDesign, contrastBetween } from './audit'
-import { heuristicMode, parseMode, modeAllowsWrites, MODE_TOOL_RISK } from './router'
+import { heuristicMode, parseMode, modeAllowsWrites, MODE_TOOL_RISK, fallbackMode } from './router'
import { DESIGN_SKILLS, selectSkills, skillsPromptSection } from './skills'
import { extractBrief, validateBrief, briefPromptSection, FORMAT_PRESETS, type DesignBrief } from './brief'
import { serializeDesignContext, contextValidIds, type AgentDesignCtx } from './context'
@@ -1689,6 +1689,94 @@ describe('v0.32.2 · router: the Instagram-post misroute (defect A)', () => {
})
})
+describe('v0.32.7 · router: the fix-family misroute (write requests must never depend on a provider)', () => {
+ // Production report (26 Nov 2026, the JNV Baramula session): every
+ // fix/improve phrasing fell through the heuristic lists to the model
+ // router — and during a provider outage (429/502, exactly when users
+ // retry a broken design) the catch kept the catch-all: DISCUSS. The
+ // user asked to fix a design and got product conversation.
+ it('the EXACT messages from the production session are deterministic write modes', () => {
+ expect(heuristicMode('create a poster for my school basket ball competetion. school name : JNV Baramula')).toEqual({ mode: 'create', confidence: 'high' })
+ expect(heuristicMode("it doesn't look cool add desings images stickers and better fonts etc").mode).toBe('improve')
+ expect(heuristicMode('fix it')).toEqual({ mode: 'improve', confidence: 'high' })
+ expect(heuristicMode("don;t stop until you fix the design it looks like shit")).toEqual({ mode: 'improve', confidence: 'high' })
+ })
+
+ it('the fix/improve family classifies high — never the model router, never discuss', () => {
+ for (const msg of [
+ 'fix it',
+ 'fix this',
+ 'fix them',
+ 'fix everything',
+ 'fix the design',
+ 'fix my poster',
+ 'fix the layout',
+ 'improve it',
+ 'improve this',
+ 'improve this poster',
+ 'improve the design',
+ 'redo it',
+ 'revamp this design',
+ 'make it look cool',
+ 'make it look better',
+ 'make this look professional',
+ "it doesn't look good",
+ 'this does not look nice',
+ 'it looks bad',
+ 'it looks like shit',
+ 'the design looks terrible',
+ 'redesign the poster',
+ ]) {
+ expect(heuristicMode(msg), msg).toEqual({ mode: 'improve', confidence: 'high' })
+ }
+ })
+
+ it('element-level fixes stay surgical edits (the intent classifier refines inside the run)', () => {
+ for (const msg of [
+ 'fix the title',
+ 'fix the typos',
+ 'fix the logo',
+ 'update the design',
+ 'update the poster',
+ 'adjust the spacing',
+ 'tweak the colors',
+ 'change the app icon on the poster',
+ ]) {
+ expect(heuristicMode(msg).mode, msg).toBe('edit')
+ }
+ })
+
+ it('conversations, product talk and questions keep their old modes — the write verbs hijack nothing', () => {
+ expect(heuristicMode('hi')).toEqual({ mode: 'discuss', confidence: 'high' })
+ expect(heuristicMode('how was your day').mode).toBe('discuss')
+ expect(heuristicMode('Why is the Canvix agent broken?').mode).toBe('discuss')
+ expect(heuristicMode('improve the app').mode).toBe('discuss')
+ expect(heuristicMode('fix your code').mode).toBe('discuss')
+ expect(heuristicMode('How does the poster feature work?').mode).not.toBe('create')
+ expect(heuristicMode('What is wrong with this design?').mode).toBe('review')
+ expect(heuristicMode('make it bolder').mode).toBe('edit')
+ // interrogatives are questions about the artifact, not create briefs
+ expect(heuristicMode('why is my poster broken?').mode).not.toBe('create')
+ // polite question FORMS still create
+ expect(heuristicMode('can you make me a poster for my coffee shop?').mode).toBe('create')
+ expect(heuristicMode('make a poster that looks cool').mode).toBe('create')
+ expect(heuristicMode('Design a bold Instagram post for a coffee launch')).toEqual({ mode: 'create', confidence: 'high' })
+ })
+
+ it('fallbackMode — the provider-outage escape hatch classifies by vocabulary + canvas state', () => {
+ // design vocabulary on a POPULATED canvas → surgical edit
+ expect(fallbackMode('fix my poster please', true)).toBe('edit')
+ expect(fallbackMode('fix the posetr on it', true)).toBe('edit') // artifact typo survives on the verb
+ // design vocabulary on an EMPTY canvas → create (nothing to damage)
+ expect(fallbackMode('make me a cool posetr', false)).toBe('create')
+ expect(fallbackMode('add some stikcers', false)).toBe('create')
+ // NO design vocabulary → it really was conversation
+ expect(fallbackMode('how was your day', true)).toBe('discuss')
+ expect(fallbackMode('nice weather today', false)).toBe('discuss')
+ expect(fallbackMode('', true)).toBe('discuss')
+ })
+})
+
describe('v0.32.2 · loop: the original request reaches the model (defect B)', () => {
const emptyDesign: AgentDesignCtx = {
name: 'Untitled',
diff --git a/src/lib/agent/router.ts b/src/lib/agent/router.ts
index 6252364..006e307 100644
--- a/src/lib/agent/router.ts
+++ b/src/lib/agent/router.ts
@@ -97,23 +97,47 @@ export function heuristicMode(message: string): { mode: AgentMode; confidence: '
/\b(poster|flyer|menu|logo|banner|thumbnail|deck|presentation|slide|campaign|invitation|infographic|card|graphic|advert|ad|cover|header|brochure|certificate|resume|newsletter|posts?|stor(ies|y)|reels?|story)\b|\b(instagram|insta|tiktok|pinterest|linkedin|facebook|twitter|threads|snapchat|youtube|social[- ]media)\b/
const buildVerb = /\b(design|create|make|build|generate|add|produce)\b/
const asksQuestion = /\?\s*$/.test(m) || /^(how|why|what|when|which|who)\b/i.test(m)
+ // v0.32.7: an interrogative OPENER ("why is my poster broken?")
+ // is a question about the artifact, not a create brief — polite
+ // question FORMS ("can you make me a poster?") still create.
+ const interrogative = /^(how|why|what|when|where|which|who)\b/i.test(m)
// v0.32.2 (defect A): an artifact noun + build verb normally means
// create — but "make the poster title bold" is an EDIT of an
// existing thing. Exempt messages that pair an edit verb with a
// reference to an EXISTING element ("the title", "this logo",
// "existing headline") from the create-first guard.
- const editVerb = /\b(make|set|change|turn|swap|move|align|center|centre|delete|remove|add|resize|rename|duplicate|rotate|flip|recolor|recolour)\b/
- const elementRef = /\b(the|this|that|these|those|existing|current|selected)\s+(\w+\s+){0,2}(title|headline|subtitle|texts?|logo|icon|image|images?|photo|picture|shape|element|background|border|caption|body|copy|button|card|badge|label|grid|rows?|columns?|lines?|boxes?|circles?|cup|price|prices|tagline)\b/
+ // v0.32.7 (production report: "ask him something to design and he
+ // only talks"): the fix/improve/update verb family sat in NONE of
+ // these lists — "fix it", "improve it", "update the design" fell to
+ // the model router, and a provider outage (429/502 — exactly when
+ // users retry) let the catch keep the catch-all: DISCUSS. Every
+ // write verb is listed here so write requests classify free.
+ const editVerb = /\b(make|set|change|turn|swap|move|align|center|centre|delete|remove|add|resize|rename|duplicate|rotate|flip|recolor|recolour|fix|improve|update|adjust|tweak|edit|redo|rework|revamp|restyle|rearrange|reorder)\b/
+ // v0.32.7: the artifact family joins the element references —
+ // "update the poster" references the EXISTING artifact, it is not a
+ // create brief ("i want a poster" still creates: no the/this/…).
+ const elementRef = /\b(the|this|that|these|those|existing|current|selected)\s+(\w+\s+){0,2}(title|headline|subtitle|texts?|logo|icon|image|images?|photo|picture|shape|element|background|border|caption|body|copy|button|card|badge|label|grid|rows?|columns?|lines?|boxes?|circles?|cup|price|prices|tagline|posters?|flyers?|menus?|banners?|thumbnails?|decks?|presentations?|slides?|infographics?|graphics?|newsletters?|brochures?|covers?|headers?|posts?|stories|story|reels?|design|layout)\b/
const editingExisting = editVerb.test(lower) && elementRef.test(lower)
if (artifactNoun.test(lower) && buildVerb.test(lower) && !asksQuestion && !editingExisting) {
return { mode: 'create', confidence: 'high' }
}
// discuss: about the tool/product itself, not the user's design
- const productWords = /\b(canvix|the (app|editor|product|repo|codebase)|your (architecture|agent|tools?)|this project|github)\b/
+ // v0.32.7: the product guard's verb set grows with the write-verb
+ // family — "improve the app" / "update your code" are product
+ // requests and must stay conversations even though improve/update
+ // are now first-class write verbs for DESIGNS. Product nouns and
+ // artifact nouns never overlap (app/code/repo vs poster/logo…),
+ // the brand may sit between article and noun ("fix the Canvix
+ // agent"), and a product noun followed by a DESIGN noun ("change
+ // the app icon") is an element edit, not product talk.
+ const productWords = /\b(canvix|the (app|editor|product|repo|codebase)|your (architecture|agent|tools?|code)|this project|github)\b/
const asksAboutProduct = productWords.test(lower) && /\b(how (does|do|is|are)|why|bug|broken|error|architecture|implemented|feature|work)s?\b/.test(lower)
- const fixTheProduct = /\bfix (the|your) (agent|editor|app|code|bug)|\bagent'?s (tool|loop|architecture)\b/.test(lower)
+ const fixTheProduct =
+ /\b(fix|improve|update|redo|rework|revamp|change) (the|your|my|this|that) (canvix )?(agent|editor|app|code|codebase|bug|repo|product|backend|frontend|server|api|site)(?! (icon|image|images?|logo|title|titles?|texts?|elements?|buttons?|cards?|photos?|pictures?|shapes?|stickers?|badges?|labels?|backgrounds?|banners?|headers?|illustrations?))\b/.test(lower) ||
+ /\bfix (the|your) (canvix )?(agent|editor|app|code|bug)\b/.test(lower) ||
+ /\bagent'?s? (tool|loop|architecture)\b/.test(lower)
if (asksAboutProduct || fixTheProduct) return { mode: 'discuss', confidence: 'high' }
// review: critique/feedback asks — never modify
@@ -139,7 +163,25 @@ export function heuristicMode(message: string): { mode: AgentMode; confidence: '
}
// improve: polish/make-professional requests on an existing design
- if (/\b(make (this|it) (more )?(professional|better|prettier|nicer|polished)|polish|clean up|refine|jazz|spice|tighten)\b/.test(lower)) {
+ // v0.32.7 (production report, the JNV Baramula session): "fix it",
+ // "fix the design it looks like shit", "improve it", "make it look
+ // cool", "it doesn't look cool …" — the ENTIRE fix-family routed
+ // nowhere deterministically. It reached the model router, and on a
+ // provider outage the catch kept the catch-all: DISCUSS. A user who
+ // watches a broken design and asks for a fix during an outage got a
+ // product chat that touched nothing. The fix-family improves the
+ // WHOLE artifact (the intent classifier decides the per-message
+ // intent — add/refine/restyle — inside the run):
+ if (
+ /\b(make (this|it|that) (more )?(professional|better|prettier|nicer|polished|cooler|cool|good|great|awesome)|polish|clean up|refine|jazz|spice|tighten)\b/.test(lower) ||
+ /\b(fix|improve|redo|rework|revamp) (it|this|that|them|everything|up)\b/.test(lower) ||
+ /\b(fix|improve|redo|rework|revamp) (the|my|our|this|that) (design|poster|flyer|banner|menu|deck|presentation|slides?|infographic|cards?|graphics?|layout|page|canvas|look|feel|branding)\b/.test(lower) ||
+ /\bfix (the )?(design|poster|flyer|layout)\b/.test(lower) ||
+ /\bmake (this|it|that) look (better|cooler|nicer|good|great|cool|professional|prettier)\b/.test(lower) ||
+ /\b(doesn'?t|does not|don'?t|didn'?t|not) look (good|great|cool|nice|professional|right|appealing)\b/.test(lower) ||
+ /\blooks? (bad|terrible|awful|boring|plain|ugly|horrible|like (shit|crap|garbage|ass))\b/.test(lower) ||
+ /\bredesign\b/.test(lower)
+ ) {
return { mode: 'improve', confidence: 'high' }
}
@@ -150,7 +192,7 @@ export function heuristicMode(message: string): { mode: AgentMode; confidence: '
// v0.32.2: editingExisting ("make the poster title bold") is exempt
// here too — an artifact noun inside an existing-element reference
// is still an edit.
- if (artifactNoun.test(lower) && m.split(/\s+/).length >= 2 && !editingExisting) {
+ if (artifactNoun.test(lower) && m.split(/\s+/).length >= 2 && !editingExisting && !interrogative) {
return { mode: 'create', confidence: 'high' }
}
const createSignals = [
@@ -178,6 +220,37 @@ export function heuristicMode(message: string): { mode: AgentMode; confidence: '
return { mode: 'discuss', confidence: 'low' }
}
+/** Design-domain vocabulary for the outage fallback below. Broad by
+ * design: a typo'd artifact noun ("posetr") must still count as a
+ * design request — none of these words belong in small talk. */
+const DESIGN_DOMAIN_WORDS =
+ /\b(designs?|designing|designed|posters?|flyers?|menus?|logos?|banners?|thumbnails?|decks?|presentations?|slides?|infographics?|cards?|graphics?|brochures?|newsletters?|stories|story|reels?|campaigns?|invitations?|adverts?|instagram|insta|tiktok|pinterest|linkedin|facebook|twitter|youtube|social[- ]media|canvas|pages?|elements?|texts?|titles?|headlines?|headings?|subtitles?|captions?|images?|photos?|pictures?|icons?|shapes?|stickers?|backgrounds?|colou?rs?|fonts?|typography|layouts?|spacing|margins?|borders?|buttons?|badges?|labels?|grids?|rows?|columns?|brands?|themes?|styles?|make|makes|made|create|creates|created|build|builds|built|add|adds|added|remove|removes|removed|delete|deletes|deleted|move|moves|moved|change|changes|changed|fix|fixes|fixed|fixing|improve|improves|improved|edit|edits|edited|update|updates|updated|adjust|adjusts|adjusted|tweak|tweaks|tweaked|redesign|redesigns|redesigned|polish|polished|refine|refines|refined|restyle|restyles|restyled|draw|draws|drawing|illustrations?|look|looks|looking)\b/
+
+/** v0.32.7 · the provider-outage escape hatch. When the heuristic
+ * could not classify (confidence 'low' — it recognized no pattern)
+ * and the model router call FAILED (429/502/network, or unparseable
+ * output), the old code kept the heuristic catch-all: DISCUSS. So
+ * "fix my poster" during an outage became a product chat that
+ * touched nothing — the user watches a broken design and asks for
+ * a fix, the provider is down BECAUSE everyone is retrying, and
+ * the agent answers in paragraphs.
+ *
+ * This deterministic fallback classifies by vocabulary + canvas
+ * state — no provider, no latency, no failure mode:
+ * · design-domain vocabulary + empty canvas → create
+ * (nothing to damage; the plan-first gate governs the build)
+ * · design-domain vocabulary + elements exist → edit
+ * (surgical: "touch only what the request implies" — the edit
+ * prompt degrades honestly on an empty canvas)
+ * · no design vocabulary → discuss
+ * (it really was conversation)
+ */
+export function fallbackMode(message: string, canvasHasElements: boolean): AgentMode {
+ const m = message.trim()
+ if (!m) return 'discuss'
+ return DESIGN_DOMAIN_WORDS.test(m.toLowerCase()) ? (canvasHasElements ? 'edit' : 'create') : 'discuss'
+}
+
/** System prompt for the model classifier (used when heuristics are
* unsure). Reply JSON {"mode": "…"}. */
export const ROUTER_SYSTEM =