[Bug] BaseXTerminal disposal error: "Could not dispose an addon that has not been loaded"

Resolved 💬 3 comments Opened Oct 30, 2025 by mrveiss Closed Jan 10, 2026

Bug Description

Console error appears when disposing/closing terminal instances in AutoBot:

BaseXTerminal.vue:171 
[BaseXTerminal] Error disposing terminal: Error: Could not dispose an addon that has not been loaded
    at disposeTerminal (BaseXTerminal.vue:166:22)
    at BaseXTerminal.vue:282:3

Root Cause

Location: autobot-vue/src/components/BaseXTerminal.vue:166-171

The terminal cleanup logic attempts to dispose of an XTerm.js addon that was never properly loaded or initialized. This happens when:

  1. Terminal component is created but initialization fails or is incomplete
  2. Component is destroyed before addon finishes loading
  3. Disposal is called multiple times on the same addon instance

Impact

  • Console pollution: Error messages clutter browser console
  • Memory leaks: Failed disposal may prevent proper cleanup
  • Developer confusion: Unclear if terminal is functioning correctly
  • Potential state issues: Incomplete cleanup might affect subsequent terminal instances

Reproduction Steps

  1. Start AutoBot
  2. Open terminal interface
  3. Close/destroy terminal component
  4. BUG: Check browser console for disposal error

Expected Behavior

Terminal cleanup should:

  1. Check if addon exists before attempting disposal
  2. Track addon loading state
  3. Only dispose loaded addons
  4. Handle edge cases gracefully

Proposed Solution

Add defensive checks in disposal logic:

const disposeTerminal = () => {
  try {
    if (term && typeof term.dispose === 'function') {
      // Check addon loading state before disposal
      if (addonLoaded && addon && typeof addon.dispose === 'function') {
        addon.dispose()
      }
      term.dispose()
    }
  } catch (error) {
    console.warn('[BaseXTerminal] Error disposing terminal:', error)
    // Continue cleanup despite error
  }
}

Alternative Approach

Track addon lifecycle more explicitly:

const addonState = ref<'unloaded' | 'loading' | 'loaded' | 'disposed'>('unloaded')

const loadAddon = async () => {
  addonState.value = 'loading'
  try {
    // Load addon
    await addon.load()
    addonState.value = 'loaded'
  } catch (error) {
    addonState.value = 'unloaded'
    throw error
  }
}

const disposeTerminal = () => {
  if (addonState.value === 'loaded') {
    addon.dispose()
    addonState.value = 'disposed'
  }
  // ... rest of cleanup
}

Files Affected

  • autobot-vue/src/components/BaseXTerminal.vue (lines 166-171, 282)
  • Potentially related terminal components using BaseXTerminal

Related Issues

  • Part of broader AutoBot UI stability improvements
  • May be related to component lifecycle management

Labels

bug, frontend, terminal, medium-priority, cleanup

Additional Context

This is a separate issue from the Knowledge Base problems (#10640, #10641). It affects terminal functionality specifically, not API integration.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗