C3 AI Documentation Home

Query Interruption

Overview

Query interruption allows users to stop a running query before it completes. This is useful when:

  • A query is taking longer than expected
  • The user realizes they asked the wrong question
  • The user wants to refine their query mid-execution

When a query is interrupted:

  1. The agent stops executing additional steps
  2. Any steps that already completed are preserved
  3. The query is marked as "Interrupted" in the UI and history
  4. The user can immediately submit a new query

Enabling the Stop Button

The stop button is enabled by default. To configure its visibility, update the GenAiUiConfig:

JavaScript
// Enable stop button (default)
GenAiUiConfig.setConfigValue('showStopButton', true);

// Disable stop button
GenAiUiConfig.setConfigValue('showStopButton', false);

How It Works

UI Behavior

When a query is running:

  1. The search/submit button is replaced with a stop button (red stop icon)
  2. Clicking the stop button immediately:
    • Re-enables the search input
    • Marks the current result as interrupted
    • Stops UI polling for updates

Backend Behavior

The interruption mechanism works as follows:

  1. UI calls Genai.Query.Result.interrupt(): Sets interrupted: true on the query result and updates the status to Completed

  2. Agent checks for interruption: The dynamic agent checks _is_query_interrupted() at the start of each step and after each step completes

  3. Agent stops gracefully: When interruption is detected, the agent:

    • Marks the current call step as completed
    • Exits the step loop without executing additional steps
    • Preserves all work completed up to that point

Important Notes

  • Steps are not rolled back: Any steps that completed before the interruption are preserved in the database
  • Timing matters: If you click stop while a step is executing (e.g., waiting for LLM response), the agent won't check for interruption until that step completes
  • Immediate UI feedback: The UI updates immediately when you click stop, even if the backend is still processing

Querying Interrupted Results

To find interrupted queries programmatically:

JavaScript
// Fetch interrupted results
var interruptedResults = Genai.Query.Result.fetch({
  filter: Filter.eq('interrupted', true),
  include: 'this, plan.steps.this, searchQuery.rawQuery, statusHistory',
  order: 'descending(meta.created)',
  limit: 10,
});

// Display results
interruptedResults.objs.forEach(function (r) {
  console.log('Query:', r.searchQuery?.rawQuery);
  console.log('Steps completed:', r.plan?.steps?.length || 0);
});

To view step details for an interrupted query:

JavaScript
var result = Genai.Query.Result.fetch({
  filter: Filter.eq('interrupted', true),
  include: 'this, plan.steps.this, searchQuery.rawQuery',
  order: 'descending(meta.created)',
  limit: 1,
}).objs[0];

console.log('Query:', result.searchQuery?.rawQuery);

if (result.plan?.steps) {
  result.plan.steps.forEach(function (step, index) {
    console.log('Step', index + 1, ':', step.content);
  });
}

UI Indicators

  • Running query: Stop button (red stop icon) replaces the submit button
  • No query running: Normal submit button (search icon)

Result Container

When viewing an interrupted result, a banner displays: "Response was interrupted."

History Page

Interrupted queries display an "Interrupted" status badge in the query history grid, distinguishing them from completed, failed, or pending queries.

Status Dropdown

The interim status dropdown shows "Interrupted" with a stop icon for interrupted queries, instead of the normal status progression.

Configuration Reference

PropertyTypeDefaultDescription
showStopButtonbooleantrueWhether to show the stop button when a query is running
Was this page helpful?