Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.

Normalize boolish persisted config flags#17

Open
Promansis wants to merge 3 commits into
Pasta-Devs:mainfrom
Promansis:fix/boolish-config-normalization
Open

Normalize boolish persisted config flags#17
Promansis wants to merge 3 commits into
Pasta-Devs:mainfrom
Promansis:fix/boolish-config-normalization

Conversation

@Promansis
Copy link
Copy Markdown
Collaborator

@Promansis Promansis commented May 19, 2026

Summary

  • Normalize persisted boolish reads for connection random-pool membership across connection UI, quick switchers, and dependent random/default connection resolvers.
  • Normalize prompt preset default reads so boolean defaults show the default badge and are found by default preset lookup.
  • Record local bug ownership/status for the two boolean configuration issues.

Root Cause

Some persisted configuration readers only treated string "true" as enabled, while current writers and engine contracts use boolean true. That made UI state and resolver state diverge for random-pool membership and prompt preset defaults.

Validation

  • pnpm typecheck
  • git diff --check
  • Searched for remaining strict useForRandom, isDefault, and default equality checks in src/features and src/engine.

Summary by CodeRabbit

  • Improvements
    • More robust interpretation of boolean-like flags across connection selection, quick switchers, random-pool behavior, and preset default selection—reduces mismatch between stored values and UI state.
  • Bug Fixes
    • Fixed cases where random-pool toggles and preset default badges displayed incorrectly for legacy or boolean-typed values.
  • Documentation
    • Updated notes documenting work, affected areas, and a suggested smoke-test.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

This PR standardizes boolean-flag interpretation using a shared boolish helper across engine connection resolution, UI components, hooks, and presets, widening accepted flag types (string | boolean | null) and preserving existing fallback behaviors.

Changes

Boolean Configuration Normalization

Layer / File(s) Summary
Backend Connection Resolution via Boolish
src/engine/generation/context.ts, src/engine/modes/chat/core/summaries/auto-summary.service.ts, src/engine/modes/chat/schedules/schedule.service.ts, src/engine/modes/roleplay/scene/scene-service.ts
Connection-selection functions import boolish and use it to interpret isDefault, default, and useForRandom flags instead of strict equality checks, preserving fallback-to-first-connection behavior while accepting both boolean and legacy string truth values.
UI Components: Random Pool and Default Selection
src/features/chats/components/QuickConnectionSwitcher.tsx, src/features/chats/components/QuickSwitcherMobile.tsx, src/features/connections/components/ConnectionsPanel.tsx, src/features/chats/components/ChatSettingsDrawer.tsx
Switcher and panel components widen useForRandom typing to `string
Hooks and Preset Panel: Default Selection and Display
src/features/chats/hooks/use-chats.ts, src/features/presets/hooks/use-presets.ts, src/features/presets/components/PresetsPanel.tsx
Summary and preset resolution hooks import boolish and apply it to isDefault/default fields for connection and preset matching; PresetsPanel updates default-badge rendering to use the helper instead of string comparison, maintaining consistent truthy interpretation across the feature.
Developer and Bug Documentation
updates/people/promansis.md
Current-work and owned-bugs sections document the boolean normalization initiative, fixed random-pool toggle state inversion, and fixed preset default-badge recognition, noting reads accept boolean true and legacy string truth values while writes remain boolean-native.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

"Ah, the beautiful precision of normalized flags—allow true and 'true' to tango, and I, Il Dottore, applaud the orderly chaos contained within." 🧪✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main objective of the PR: normalizing how persisted boolean-like configuration flags are interpreted across multiple connection and preset resolution paths.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Promansis
Copy link
Copy Markdown
Collaborator Author

• Findings

  • No blocking findings.

The patch looks internally consistent: it normalizes legacy truthy string values and booleans on the connection/default paths it touches, and the preset default UI now matches the storage shape it already writes.

Validation

  • gh pr view 17 --repo Pasta-Devs/Marinara-Engine-Refactor --json ...
  • gh pr diff 17 --repo Pasta-Devs/Marinara-Engine-Refactor
  • git diff --check clean

Residual risk

  • I didn’t smoke-test the app against an old string-backed database, so the remaining risk is legacy data outside the reviewed paths.

@Promansis Promansis changed the title [codex] Normalize boolish persisted config flags Normalize boolish persisted config flags May 19, 2026
@Promansis
Copy link
Copy Markdown
Collaborator Author

• Findings

  • No blocking findings.

The patch looks internally consistent: it normalizes legacy truthy string values and booleans on the connection/default paths it touches, and the preset default UI now matches the storage shape it already writes.

Validation

  • gh pr view 17 --repo Pasta-Devs/Marinara-Engine-Refactor --json ...
  • gh pr diff 17 --repo Pasta-Devs/Marinara-Engine-Refactor
  • git diff --check clean

Residual risk

  • I didn’t smoke-test the app against an old string-backed database, so the remaining risk is legacy data outside the reviewed paths.

@Promansis Promansis marked this pull request as ready for review May 19, 2026 16:40
@munimunigamer
Copy link
Copy Markdown
Collaborator

The bug fix here is valid: persisted config flags can come back as string-ish values like "true" / "1" instead of real booleans, so default connection, random pool, and default preset checks can fail.

The issue is the implementation shape. This PR copies the same local helper into many files:

function isStoredBooleanTrue(value: unknown): boolean {
  return value === true || value === "true" || value === "1";
}

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/presets/components/PresetsPanel.tsx`:
- Line 281: The badge logic only checks preset.isDefault while useDefaultPreset
uses both isDefault and default; update the badge determination in PresetsPanel
(the const isDefault assignment) to consider both fields consistently (e.g., use
the same OR/NULL-coalescing logic used in useDefaultPreset) by replacing the
single-field check with a combined check that passes the resulting value into
boolish so presets with default: true also render the default badge.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b8e5dae-2c37-4e93-a5f6-79d248d40c6c

📥 Commits

Reviewing files that changed from the base of the PR and between 422a858 and 58d988f.

📒 Files selected for processing (12)
  • src/engine/generation/context.ts
  • src/engine/modes/chat/core/summaries/auto-summary.service.ts
  • src/engine/modes/chat/schedules/schedule.service.ts
  • src/engine/modes/roleplay/scene/scene-service.ts
  • src/features/chats/components/ChatSettingsDrawer.tsx
  • src/features/chats/components/QuickConnectionSwitcher.tsx
  • src/features/chats/components/QuickSwitcherMobile.tsx
  • src/features/chats/hooks/use-chats.ts
  • src/features/connections/components/ConnectionsPanel.tsx
  • src/features/presets/components/PresetsPanel.tsx
  • src/features/presets/hooks/use-presets.ts
  • updates/people/promansis.md

const sectionCount = getSectionCount(preset);
const wrapFormat = (preset.wrapFormat ?? "xml") as string;
const isDefault = preset.isDefault === "true";
const isDefault = boolish(preset.isDefault, false);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Ah, a fascinating divergence in experimental protocol! The badge rendering examines only one specimen field.

The default-badge logic checks solely preset.isDefault, yet your useDefaultPreset hook in use-presets.ts (lines 129-130) examines both isDefault and default fields with OR logic. Should a preset possess default: true whilst isDefault remains falsy, the hook shall identify it as the default preset—yet the badge will fail to materialize!

This creates observable inconsistency: a preset may be selected as default but display no badge, contradicting the stated research objective: "normalize prompt preset default reads so boolean defaults show the default badge and are found by default preset lookup."

⚗️ Proposed remedy to synchronize badge logic with lookup logic
-          const isDefault = boolish(preset.isDefault, false);
+          const isDefault = boolish(preset.isDefault, false) || boolish((preset as any).default, false);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isDefault = boolish(preset.isDefault, false);
const isDefault = boolish(preset.isDefault, false) || boolish((preset as any).default, false);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/presets/components/PresetsPanel.tsx` at line 281, The badge
logic only checks preset.isDefault while useDefaultPreset uses both isDefault
and default; update the badge determination in PresetsPanel (the const isDefault
assignment) to consider both fields consistently (e.g., use the same
OR/NULL-coalescing logic used in useDefaultPreset) by replacing the single-field
check with a combined check that passes the resulting value into boolish so
presets with default: true also render the default badge.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/presets/components/PresetsPanel.tsx`:
- Around line 281-283: Replace the undefined isStoredBooleanTrue usage in
PresetsPanel with the imported boolish helper: instead of calling
isStoredBooleanTrue(preset.isDefault ?? ...), call boolish(preset.isDefault ||
(preset as PresetRow & { default?: unknown }).default) so both preset.isDefault
and preset.default are evaluated (using OR to let an explicit false fall through
to the other field) and avoid duplicating engine logic; remove the
isStoredBooleanTrue reference and use boolish(preset.isDefault || (preset as
PresetRow & { default?: unknown }).default) in the PresetsPanel rendering logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ea922550-9041-42e4-9333-2e284228cb78

📥 Commits

Reviewing files that changed from the base of the PR and between 58d988f and 0dec2c0.

📒 Files selected for processing (1)
  • src/features/presets/components/PresetsPanel.tsx

Comment on lines +281 to +283
const isDefault = isStoredBooleanTrue(
preset.isDefault ?? (preset as PresetRow & { default?: unknown }).default,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the undefined function and locate the boolish helper.

# Check if isStoredBooleanTrue is defined anywhere in the file
echo "=== Checking for isStoredBooleanTrue definition in PresetsPanel ==="
rg -n "function isStoredBooleanTrue|const isStoredBooleanTrue" src/features/presets/components/PresetsPanel.tsx

# Locate the boolish helper implementation
echo "=== Locating boolish helper implementation ==="
rg -n -A 5 "export.*function boolish|export.*const boolish" src/engine/generation/runtime-records.ts

# Check for other files using isStoredBooleanTrue (potential duplication)
echo "=== Searching for isStoredBooleanTrue across the codebase ==="
rg -l "function isStoredBooleanTrue|const isStoredBooleanTrue" src/

Repository: Pasta-Devs/Marinara-Engine-Refactor

Length of output: 568


🏁 Script executed:

# Check the import statement at line 16
head -20 src/features/presets/components/PresetsPanel.tsx | tail -10

Repository: Pasta-Devs/Marinara-Engine-Refactor

Length of output: 546


🏁 Script executed:

# Read lines 275-290 to see the exact code at lines 281-283 with context
sed -n '275,290p' src/features/presets/components/PresetsPanel.tsx

Repository: Pasta-Devs/Marinara-Engine-Refactor

Length of output: 914


🏁 Script executed:

# Verify boolish is properly accessible and check its full signature
sed -n '45,60p' src/engine/generation/runtime-records.ts

Repository: Pasta-Devs/Marinara-Engine-Refactor

Length of output: 684


Fix critical runtime error: isStoredBooleanTrue is undefined. This function does not exist anywhere in the codebase and will cause a ReferenceError when the component renders. The boolish helper is already imported from the engine at line 16 but sits unused—employ it directly to satisfy both the runtime requirement and the coding guideline demanding that React components not duplicate engine rules but instead call feature APIs or engine use cases through proper adapters.

The current nullish coalescing approach (preset.isDefault ?? preset.default) only evaluates the first non-nullish value, potentially missing the case where preset.isDefault is explicitly false but preset.default is true. Implement OR-based logic to evaluate both fields consistently:

Corrected implementation
-          const isDefault = isStoredBooleanTrue(
-            preset.isDefault ?? (preset as PresetRow & { default?: unknown }).default,
-          );
+          const isDefault = boolish(preset.isDefault) || boolish((preset as PresetRow & { default?: unknown }).default);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/presets/components/PresetsPanel.tsx` around lines 281 - 283,
Replace the undefined isStoredBooleanTrue usage in PresetsPanel with the
imported boolish helper: instead of calling isStoredBooleanTrue(preset.isDefault
?? ...), call boolish(preset.isDefault || (preset as PresetRow & { default?:
unknown }).default) so both preset.isDefault and preset.default are evaluated
(using OR to let an explicit false fall through to the other field) and avoid
duplicating engine logic; remove the isStoredBooleanTrue reference and use
boolish(preset.isDefault || (preset as PresetRow & { default?: unknown
}).default) in the PresetsPanel rendering logic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants