Skip to content

Fix: live mode (and all non-chat content) falling back to chat-widget - #597

Merged
joelteply merged 1 commit into
mainfrom
fix/live-mode-chat-fallback
Mar 30, 2026
Merged

joelteply merged 1 commit into
mainfrom
fix/live-mode-chat-fallback

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Problem

Live mode tab showed general chat instead of live-widget. Same for logs, factory, grid, canvas — all content types were falling back to chat-widget.

Root Cause

getWidgetForType() checked the async recipe service FIRST. If it wasn't loaded yet (race condition on startup), it fell through to fallback = chat-widget. The generated config (compiled from recipe JSON, always available synchronously) was only checked SECOND.

Fix

Swap the order: check generated config first (always available), recipe service second (for runtime updates). No more race condition.

Test

  • npm run build:ts passes
  • Deploy and verify live mode opens live-widget, not chat
  • Verify grid overview still works
  • Verify factory room works

…service

Live mode, logs, factory, etc. were all falling back to chat-widget because
the recipe service wasn't loaded yet when switchContentView fired. Generated
config (compiled from recipe JSON files) is always available synchronously.
Check it first, recipe service second.
Copilot AI review requested due to automatic review settings March 30, 2026 02:25
@joelteply
joelteply merged commit 0166af4 into main Mar 30, 2026
4 of 6 checks passed
@joelteply
joelteply deleted the fix/live-mode-chat-fallback branch March 30, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix incorrect widget selection during early startup (before the async recipe layout service is loaded) by changing how getWidgetForType() resolves a widget for a given content type.

Changes:

  • Reordered getWidgetForType() to check CONTENT_TYPE_CONFIGS (generated config) before consulting RecipeLayoutService.
  • Updated inline comments around the lookup order and “unknown type” handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to 49
// 1. Generated config FIRST — always available, no async, no race conditions
// This is the compiled-in truth from recipe JSON files.
const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType];
if (generated) return generated.widget;

// 2. Recipe service — runtime data from DB (may have newer recipes)
const recipeService = getRecipeLayoutService();
if (recipeService.isLoaded()) {
const widget = recipeService.getWidget(contentType);
if (widget) return widget;
}

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getWidgetForType() now returns the generated config’s widget immediately, which means the RecipeLayoutService can no longer override widgets for known content types. This breaks cases where the generated config is out of sync with runtime layouts (e.g., live.json uses new layout.widgets with center live-widget, but CONTENT_TYPE_CONFIGS['live'].widget is currently chat-widget; same pattern for logs). As written, live/logs will still render chat-widget even after recipes load. Consider using the generated widget as a default but, when recipeService.isLoaded(), prefer recipeService.getWidget(contentType) if it returns a value; and/or update the generator to derive widget from the new layout.widgets format so the generated config is correct.

Suggested change
// 1. Generated config FIRST — always available, no async, no race conditions
// This is the compiled-in truth from recipe JSON files.
const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType];
if (generated) return generated.widget;
// 2. Recipe service — runtime data from DB (may have newer recipes)
const recipeService = getRecipeLayoutService();
if (recipeService.isLoaded()) {
const widget = recipeService.getWidget(contentType);
if (widget) return widget;
}
// 1. Recipe service — runtime data from DB (may have newer recipes)
const recipeService = getRecipeLayoutService();
if (recipeService.isLoaded()) {
const widget = recipeService.getWidget(contentType);
if (widget) return widget;
}
// 2. Generated config — compiled-in truth from recipe JSON files.
const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType];
if (generated) return generated.widget;

Copilot uses AI. Check for mistakes.
Comment on lines 34 to +41
* Get widget tag name for a content type.
* Recipe service (runtime) → generated config (build-time) → error.
*/
export function getWidgetForType(contentType: string): string {
// 1. Recipe service has the most up-to-date info (loaded from DB/files at runtime)
// 1. Generated config FIRST — always available, no async, no race conditions
// This is the compiled-in truth from recipe JSON files.
const generated = CONTENT_TYPE_CONFIGS[contentType as ContentType];
if (generated) return generated.widget;

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function docstring still states “Recipe service (runtime) → generated config (build-time) → error.”, but the implementation now checks generated config first and then falls back to chat-widget after logging an error. Please update the comment to reflect the actual resolution order and whether there is a fallback, so it doesn’t mislead future changes/debugging.

Copilot uses AI. Check for mistakes.

// 3. No fallback — unknown type is an error
// 3. No match — unknown type
console.error(`Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json`);

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error path logs “Unknown content type …” but then silently falls back to chat-widget. If fallback is intentional, the log message should explicitly say it’s falling back (and ideally be a warn), otherwise consider throwing/returning an explicit error to match the “unknown type is an error” behavior described elsewhere in this module.

Suggested change
console.error(`Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json`);
console.warn(
`Unknown content type: '${contentType}'. Add a recipe in system/recipes/${contentType}.json. Falling back to 'chat-widget'.`,
);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants