Skip to content

fix: [Workflow] - The model should not become unselectable after an error is generated during AI generation - #8204

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_ai_gen
Nov 27, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_ai_gen

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: [Workflow] - The model should not become unselectable after an error is generated during AI generation

const started = computed(() => !['idle','done','error','stopped'].includes(status.value))

function sendSuggestedRequirement(question: string) {
if (!modelId.value || busy.value) return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here are my observations on this diff:

Irregularities / Potential Issues

  1. includes() may cause a TypeScript error

    • status.value is likely a union type (e.g., 'idle' | 'running' | 'done' | 'error' | 'stopped').
    • Calling .includes() on an array whose element type is inferred as string[] while passing a narrower union is fine, but if the array literal's type is inferred too narrowly (e.g., string literal types), or if status is typed as a string enum, you may get a "Argument of type X is not assignable to parameter of type Y" error. Consider typing the array explicitly:
      const TERMINAL_STATES: Status[] = ['idle', 'done', 'error', 'stopped']
      const started = computed(() => !TERMINAL_STATES.includes(status.value))
  2. Behavioral change — verify intent

    • Old: started = status !== 'idle' → true for done, error, stopped, and any future non-idle state.
    • New: started = false for done, error, stopped. This is likely the intended fix (a finished/errored run isn't "started"), but confirm anywhere started gates UI logic — e.g., showing a Stop button, disabling inputs, highlighting the first message, etc.
  3. Future state values silently become "started"

    • If a new intermediate state (e.g., 'paused', 'queued') is introduced later, it will be treated as started by default. That's probably acceptable, but it's an implicit assumption — an exhaustive check or a shared constant would be more robust.

Optimization / Cleanliness Suggestions

  1. Hoist the array out of the computed

    • A new array is allocated each time the computed re-evaluates. Negligible perf impact, but hoisting avoids it and improves readability/reuse:
      const FINISHED_STATUSES = ['idle', 'done', 'error', 'stopped'] as const
      const started = computed(() => !FINISHED_STATUSES.includes(status.value as ...))
  2. Consider a positive predicate

    • Naming a boolean after a negative set is a bit harder to reason about. Alternatives:
      const running = computed(() => status.value === 'running')      // if that's all you need
      const finished = computed(() => [...].includes(status.value))  // then use !finished
    • Since you already have busy = status === 'running', ask whether started needs distinct semantics at all, or if it can be derived from busy / a dedicated hasStarted flag.
  3. Extract a helper if used elsewhere

    • If ['idle','done','error','stopped'] appears in multiple components, share it (e.g., in a status util/enum module) to prevent drift.
  4. Minor style nit

    • Add spaces after commas ('idle', 'done', 'error', 'stopped') to match the codebase's prevailing formatting (Prettier would enforce this).

Summary: The logic change looks reasonable and likely correct, but (a) make sure the type of status.value is compatible with Array.prototype.includes, (b) confirm no downstream consumer relied on started === true for terminal states, and (c) consider hoisting the array into a typed constant and adding a brief comment explaining what "started" means.

@shaohuzhang1
shaohuzhang1 merged commit cb06203 into v3 Nov 27, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_ai_gen branch November 27, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant