From aadaa18db522398461b6670eec563dfe528c41ce Mon Sep 17 00:00:00 2001 From: Jannik Lehmann Date: Fri, 19 Sep 2025 15:33:20 +0200 Subject: [PATCH 1/3] fix: Filter out archived Agentic Chat workflows Users were seeing inactive Agentic Chat threads (older than 30 days) in their workflow history even after the underlying conversation threads were deleted. This change adds a `not_archived` scope to the Workflow model and applies it to user queries in WorkflowsResolver to exclude chat workflows older than CHECKPOINT_RETENTION_DAYS (30 days). EE: true --- .../ai/duo_workflows/workflows_resolver.rb | 2 +- ee/app/models/ai/duo_workflows/workflow.rb | 1 + ee/spec/models/ai/duo_workflows/workflow_spec.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ee/app/graphql/resolvers/ai/duo_workflows/workflows_resolver.rb b/ee/app/graphql/resolvers/ai/duo_workflows/workflows_resolver.rb index f76f136ee9eaba..e710063a46b322 100644 --- a/ee/app/graphql/resolvers/ai/duo_workflows/workflows_resolver.rb +++ b/ee/app/graphql/resolvers/ai/duo_workflows/workflows_resolver.rb @@ -51,7 +51,7 @@ def resolve(**args) workflows = workflows.for_project(object).from_pipeline else - workflows = workflows.for_user(current_user.id) + workflows = workflows.for_user(current_user.id).not_archived if args[:project_path].present? project = Project.find_by_full_path(args[:project_path]) diff --git a/ee/app/models/ai/duo_workflows/workflow.rb b/ee/app/models/ai/duo_workflows/workflow.rb index 9c0cf8a6830b63..7aa89210f01c8e 100644 --- a/ee/app/models/ai/duo_workflows/workflow.rb +++ b/ee/app/models/ai/duo_workflows/workflow.rb @@ -37,6 +37,7 @@ class Workflow < ::ApplicationRecord scope :with_workflow_definition, ->(definition) { where(workflow_definition: definition) } scope :with_environment, ->(environment) { where(environment: environment) } scope :from_pipeline, -> { where.not(workflow_definition: :chat).with_environment(:web) } + scope :not_archived, -> { where(created_at: CHECKPOINT_RETENTION_DAYS.days.ago..) } TARGET_STATUSES = { start: :running, diff --git a/ee/spec/models/ai/duo_workflows/workflow_spec.rb b/ee/spec/models/ai/duo_workflows/workflow_spec.rb index c009a0eb889aa3..231897848f14b2 100644 --- a/ee/spec/models/ai/duo_workflows/workflow_spec.rb +++ b/ee/spec/models/ai/duo_workflows/workflow_spec.rb @@ -118,6 +118,21 @@ end end + describe '.not_archived' do + let!(:recent_workflow) { create(:duo_workflows_workflow, created_at: 1.day.ago) } + let!(:archived_workflow) do + create(:duo_workflows_workflow, created_at: (Ai::DuoWorkflows::CHECKPOINT_RETENTION_DAYS + 1).days.ago) + end + + it 'finds workflows that are not archived' do + expect(described_class.not_archived).to contain_exactly(recent_workflow) + end + + it 'excludes workflows older than CHECKPOINT_RETENTION_DAYS' do + expect(described_class.not_archived).not_to include(archived_workflow) + end + end + describe '#only_known_pre_approved_agent_priviliges' do let(:agent_privileges) { [] } let(:pre_approved_agent_privileges) { [] } -- GitLab From a8346dcfe763bdd5324ffd4c4bc122aa7b7ee4c4 Mon Sep 17 00:00:00 2001 From: Mark Chao Date: Tue, 23 Sep 2025 14:02:47 +0800 Subject: [PATCH 2/3] Remove archived workflow testing --- .../api/graphql/ai/duo_workflows/workflows_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/ee/spec/requests/api/graphql/ai/duo_workflows/workflows_spec.rb b/ee/spec/requests/api/graphql/ai/duo_workflows/workflows_spec.rb index 41a8f49ed88f10..eacd85cb10a7a4 100644 --- a/ee/spec/requests/api/graphql/ai/duo_workflows/workflows_spec.rb +++ b/ee/spec/requests/api/graphql/ai/duo_workflows/workflows_spec.rb @@ -63,7 +63,6 @@ workflow_without_environment, workflow_with_ide_environment, workflow_with_web_environment, - archived_workflow, stalled_workflow, non_stalled_workflow_with_checkpoint ] @@ -447,12 +446,6 @@ returned_workflows_by_id = returned_workflows.index_by { |w| w['id'] } - # Check archived workflow - archived_result = returned_workflows_by_id[archived_workflow.to_global_id.to_s] - expect(archived_result).not_to be_nil - expect(archived_result['archived']).to be(true) - expect(archived_result['stalled']).to be(false) # archived workflows in created state are not stalled - # Check stalled workflow (running state with no checkpoints) stalled_result = returned_workflows_by_id[stalled_workflow.to_global_id.to_s] expect(stalled_result).not_to be_nil -- GitLab From 230fdbd5a65985a40d76d3de54d07ad9f53a2ce0 Mon Sep 17 00:00:00 2001 From: Jannik Lehmann Date: Fri, 26 Sep 2025 15:09:10 +0200 Subject: [PATCH 3/3] remove redundant test case --- ee/spec/models/ai/duo_workflows/workflow_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ee/spec/models/ai/duo_workflows/workflow_spec.rb b/ee/spec/models/ai/duo_workflows/workflow_spec.rb index 231897848f14b2..9f3161e5cf08b3 100644 --- a/ee/spec/models/ai/duo_workflows/workflow_spec.rb +++ b/ee/spec/models/ai/duo_workflows/workflow_spec.rb @@ -127,10 +127,6 @@ it 'finds workflows that are not archived' do expect(described_class.not_archived).to contain_exactly(recent_workflow) end - - it 'excludes workflows older than CHECKPOINT_RETENTION_DAYS' do - expect(described_class.not_archived).not_to include(archived_workflow) - end end describe '#only_known_pre_approved_agent_priviliges' do -- GitLab