Skip to content

feat: ai context compaction backend#23276

Merged
notgiorgi merged 1 commit into
mainfrom
05-19-feat_add_ai_thread_context_compaction
May 20, 2026
Merged

feat: ai context compaction backend#23276
notgiorgi merged 1 commit into
mainfrom
05-19-feat_add_ai_thread_context_compaction

Conversation

@notgiorgi
Copy link
Copy Markdown
Contributor

Closes:

Description:

Copy link
Copy Markdown
Contributor Author

notgiorgi commented May 19, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@notgiorgi notgiorgi marked this pull request as ready for review May 19, 2026 12:58
Comment on lines +3369 to +3371
if (row === undefined) {
throw new Error('Failed to create thread compaction');
}
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.

throw new Error('Failed to create thread compaction') uses a plain Error instead of a typed error class. Per the backend rules, errors should be categorised using the existing error classes in errors.ts (or a new one created if none fits). Use an appropriate class such as UnexpectedServerError or create a new one.

Suggested change
if (row === undefined) {
throw new Error('Failed to create thread compaction');
}
if (row === undefined) {
throw new UnexpectedServerError('Failed to create thread compaction');
}

Spotted by Graphite (based on custom rule: packages/backend rules)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 19, 2026

Docs PR opened: lightdash/mintlify-docs#667

Added a new AI agents guide page documenting thread context compaction, including how it works and how to enable it.

@notgiorgi notgiorgi force-pushed the 05-19-feat_add_ai_thread_context_compaction branch from 246e4c9 to d6993bb Compare May 19, 2026 13:02
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

🧪 Test Selection

✅ Tests that will run

Test Description
Preview Environment Deploys a preview environment for testing
Frontend E2E Tests Runs Cypress app tests
Backend API Tests Runs Vitest API tests
CLI Tests Runs CLI integration and dbt version tests

⏭️ Tests skipped (no relevant file changes detected)

Test How to trigger manually
Timezone Tests Add test-timezone to PR description

Tip: Add test-all to your PR description to run all tests.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Your preview environment pr-23276 has been deployed.

Preview environment endpoints are available at:

@notgiorgi notgiorgi force-pushed the 05-19-feat_add_ai_thread_context_compaction branch from d6993bb to 272c2ce Compare May 19, 2026 15:49
Comment on lines +66 to +73
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists(AI_THREAD_COMPACTION_TABLE_NAME);

if (await knex.schema.hasColumn(AI_PROMPT_TABLE_NAME, 'token_usage')) {
await knex.schema.alterTable(AI_PROMPT_TABLE_NAME, (table) => {
table.dropColumn('token_usage');
});
}
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.

The down migration drops the ai_thread_compaction table AND drops the token_usage column from ai_prompt. Deleting columns and tables are explicitly listed as dangerous operations that must not appear in migrations, because they are destructive and cannot be safely run while old code is still live. Remove the column drop (and ideally the table drop) from the down function, or at minimum make the column nullable rather than dropping it.

Suggested change
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTableIfExists(AI_THREAD_COMPACTION_TABLE_NAME);
if (await knex.schema.hasColumn(AI_PROMPT_TABLE_NAME, 'token_usage')) {
await knex.schema.alterTable(AI_PROMPT_TABLE_NAME, (table) => {
table.dropColumn('token_usage');
});
}
export async function down(knex: Knex): Promise<void> {
// Intentionally left as a no-op.
// Dropping columns and tables are destructive operations that cannot be safely
// run while old code is still live. The table and column are left in place to
// avoid data loss and to prevent breaking running instances.

Spotted by Graphite (based on custom rule: Migration guide)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@notgiorgi notgiorgi force-pushed the 05-19-feat_add_ai_thread_context_compaction branch from 272c2ce to 688496c Compare May 19, 2026 16:00
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Preview Environment

🌐 URL: https://lightdash-preview-pr-23276.lightdash.okteto.dev

📋 Logs: View in GCP Console

🔧 SSH: ./scripts/okteto-ssh.sh 23276

@notgiorgi notgiorgi force-pushed the 05-19-feat_add_ai_thread_context_compaction branch from 688496c to 0dccf22 Compare May 20, 2026 07:15
Copy link
Copy Markdown
Contributor Author

notgiorgi commented May 20, 2026

Merge activity

  • May 20, 9:49 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 20, 9:49 AM UTC: @notgiorgi merged this pull request with Graphite.

@notgiorgi notgiorgi merged commit 6acc28a into main May 20, 2026
23 checks passed
@notgiorgi notgiorgi deleted the 05-19-feat_add_ai_thread_context_compaction branch May 20, 2026 09:49
lightdash-bot pushed a commit that referenced this pull request May 20, 2026
# [0.2985.0](0.2984.4...0.2985.0) (2026-05-20)

### Features

* ai context compaction backend ([#23276](#23276)) ([6acc28a](6acc28a)), closes [#150](#150)
@lightdash-bot
Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 0.2985.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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