Skip to content

feat(platform): add nightly copilot automation flow#12407

Closed
Swiftyos wants to merge 47 commits intodevfrom
swiftyos/nightly-autopilot
Closed

feat(platform): add nightly copilot automation flow#12407
Swiftyos wants to merge 47 commits intodevfrom
swiftyos/nightly-autopilot

Conversation

@Swiftyos
Copy link
Copy Markdown
Contributor

Changes 🏗️

  • add the Nightly Copilot autopilot flow with scheduler dispatch and email sweep jobs, non-manual ChatSession metadata, execution tags, callback tokens, and the completion_report repair flow
  • make Copilot sessions configurable for autopilot use cases with prompt overrides, initial messages, disabled tools, approval-aware completion handling, and Jinja email templates
  • update chat APIs and Copilot history UI to support inspecting non-manual sessions, hiding internal content, and consuming callback links into follow-up manual sessions
  • add schema, migration, feature-flag, settings, and focused unit test coverage for the new backend and frontend paths

Checklist 📋

For code changes:

  • I have clearly listed my changes in the PR description
  • I have made a test plan
  • I have tested my changes according to the test plan:
    • mise exec node@22 -- make format
    • poetry run pytest autogpt_platform/backend/backend/copilot/autopilot_test.py autogpt_platform/backend/backend/api/features/chat/routes_test.py autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py autogpt_platform/backend/backend/copilot/sdk/service_test.py autogpt_platform/backend/backend/copilot/tools/completion_report_test.py autogpt_platform/backend/backend/notifications/email_test.py autogpt_platform/backend/backend/copilot/model_test.py::test_chatsession_serialization_deserialization

For configuration changes:

  • .env.default is updated or already compatible with my changes
  • docker-compose.yml is updated or already compatible with my changes
  • I have included a list of my configuration changes in the PR description (under Changes)

@github-project-automation github-project-automation Bot moved this to 🆕 Needs initial review in AutoGPT development kanban Mar 13, 2026
@github-actions github-actions Bot added platform/frontend AutoGPT Platform - Front end platform/backend AutoGPT Platform - Back end labels Mar 13, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR implements a comprehensive Autopilot/Nightly Copilot feature for the AutoGPT platform. It introduces callback-token-based session resumption, email notification workflows for Copilot completions, admin APIs for user and session management, database schema extensions to support session start types and lifecycle tracking, and frontend components for admin Copilot management and callback token consumption flows.

Changes

Cohort / File(s) Summary
Admin Copilot API Models & Routes
autogpt_platform/backend/backend/api/features/admin/model.py, autogpt_platform/backend/backend/api/features/admin/user_admin_routes.py, autogpt_platform/backend/backend/api/features/admin/user_admin_routes_test.py
Added data models (AdminCopilotUserSummary, TriggerCopilotSessionRequest/Response, SendCopilotEmailsRequest/Response) and three new admin endpoints: GET /admin/copilot/users for user search, POST /admin/copilot/trigger to initiate sessions, POST /admin/copilot/send-emails to dispatch pending notifications. Routes integrate existing copilot utilities with error handling and logging.
Chat Routes & Callback Token
autogpt_platform/backend/backend/api/features/chat/routes.py, autogpt_platform/backend/backend/api/features/chat/routes_test.py
Extended SessionDetailResponse/SessionSummaryResponse with start_type and execution_tag fields; added POST /sessions/callback-token/consume endpoint with ConsumeCallbackTokenRequest/Response; updated session retrieval to include start_type/execution_tag and de-scrub internal content based on session type; replaced direct Prisma access with workspace_db abstraction.
Autopilot Core Subsystems
autogpt_platform/backend/backend/copilot/autopilot.py, autogpt_platform/backend/backend/copilot/autopilot_dispatch.py, autogpt_platform/backend/backend/copilot/autopilot_completion.py, autogpt_platform/backend/backend/copilot/autopilot_prompts.py, autogpt_platform/backend/backend/copilot/autopilot_email.py
Implemented complete Autopilot orchestration: dispatch module handles nightly/callback/invite-CTA session creation with timezone-aware scheduling; completion module manages repair flows for non-manual sessions; prompts module provides data-driven system prompt assembly with context builders; email module delivers templated notifications with dynamic CTA labels; new consume_callback_token function handles atomic token consumption.
Session & Completion Report Models
autogpt_platform/backend/backend/copilot/session_types.py, autogpt_platform/backend/backend/copilot/model.py, autogpt_platform/backend/backend/copilot/db.py
Introduced ChatSessionStartType enum and ChatSessionConfig with tool filtering; extended ChatSessionInfo/ChatSession with start_type, execution_tag, completion_report, and notification metadata; added callback token model and database operations; expanded query capabilities (pending notifications, recent emails, execution tag lookups).
Service & Prompting Integration
autogpt_platform/backend/backend/copilot/service.py, autogpt_platform/backend/backend/copilot/prompting.py, autogpt_platform/backend/backend/copilot/baseline/service.py, autogpt_platform/backend/backend/copilot/sdk/service.py, autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py
Replaced _build_system_prompt with session-aware _resolve_system_prompt; updated get_baseline_supplement and get_available_tools to accept session context; added session-aware tool filtering via is_tool_enabled and iter_available_tools; propagated session parameter through baseline/SDK service paths.
Completion Report Tool & Models
autogpt_platform/backend/backend/copilot/tools/completion_report.py, autogpt_platform/backend/backend/copilot/tools/__init__.py, autogpt_platform/backend/backend/copilot/tools/models.py
Added CompletionReportTool for finalizing non-manual sessions with validation and pending approval checks; extended tool registry with session-scoped tool visibility logic; added ResponseType.COMPLETION_REPORT_SAVED and CompletionReportSavedResponse.
Stream & Session Lifecycle
autogpt_platform/backend/backend/copilot/stream_registry.py
Integrated handle_non_manual_session_completion into mark_session_completed flow to process completion reports after session finishes.
Data Access Layer
autogpt_platform/backend/backend/data/db.py, autogpt_platform/backend/backend/data/db_manager.py, autogpt_platform/backend/backend/data/user.py, autogpt_platform/backend/backend/data/workspace.py, autogpt_platform/backend/backend/data/invited_user.py, autogpt_platform/backend/backend/data/human_review.py
Added batch user search/list functions; introduced callback token CRUD operations; added new query helpers (pending notifications, recent sessions, email state, pending approvals); wired new accessors through DatabaseManager RPC surface; added workspace file batch retrieval.
Configuration & Feature Flags
autogpt_platform/backend/backend/copilot/config.py, autogpt_platform/backend/backend/util/settings.py, autogpt_platform/backend/backend/util/feature_flag.py, autogpt_platform/backend/backend/util/url.py
Added Langfuse prompt name configs for nightly/callback/invite-CTA flows; extended settings with callback start date, invite CTA scheduling, and token TTL parameters; introduced NIGHTLY_COPILOT feature flag; added get_frontend_base_url utility.
Database Schema & Migrations
autogpt_platform/backend/schema.prisma, autogpt_platform/backend/migrations/20260313143000_add_nightly_copilot_chat_sessions/migration.sql
Added ChatSessionStartType enum; extended ChatSession with start_type, executionTag, sessionConfig, completionReport, and notification tracking fields; created ChatSessionCallbackToken table with lifecycle management and indexing; added unique constraint on (userId, executionTag).
Email Templates & Notifications
autogpt_platform/backend/backend/notifications/templates/base.html.jinja2, autogpt_platform/backend/backend/notifications/templates/nightly_copilot.html.jinja2, autogpt_platform/backend/backend/notifications/templates/nightly_copilot_callback.html.jinja2, autogpt_platform/backend/backend/notifications/templates/nightly_copilot_invite_cta.html.jinja2, autogpt_platform/backend/backend/notifications/email.py, autogpt_platform/backend/backend/notifications/email_test.py
Refactored base email template with new card layout, logo, and footer; added three Copilot-specific templates (nightly, callback, invite CTA) with approval callout sections and dynamic CTA buttons; implemented EmailSender.send_template method for Jinja2-based email dispatch.
Executor & Scheduler
autogpt_platform/backend/backend/executor/scheduler.py
Wired async dispatch_nightly_copilot and send_nightly_copilot_emails commands into scheduler; created jobs for nightly dispatch (every 30 min UTC) and email sending (every 15 min UTC); exposed execute endpoints for manual triggering.
Testing Infrastructure
autogpt_platform/backend/backend/copilot/autopilot_test.py, autogpt_platform/backend/backend/copilot/tools/completion_report_test.py, autogpt_platform/backend/backend/conftest.py, autogpt_platform/backend/backend/util/cache_test.py
Added comprehensive Autopilot test suite covering dispatch, email, prompts, completion, and callback flows; introduced completion report tool tests; converted setup fixtures to async; strengthened type casting in cache tests.
Frontend Admin Copilot UI
autogpt_platform/frontend/src/app/(platform)/admin/copilot/page.tsx, autogpt_platform/frontend/src/app/(platform)/admin/copilot/useAdminCopilotPage.ts, autogpt_platform/frontend/src/app/(platform)/admin/copilot/components/AdminCopilotPage/..., autogpt_platform/frontend/src/app/(platform)/admin/layout.tsx
Created comprehensive admin Copilot interface: page component with role-gating, hook managing search/selection/trigger states, detail cards for user info/session triggers/email sweep results, user results table, and sidebar navigation entry.
Frontend Copilot Session Integration
autogpt_platform/frontend/src/app/(platform)/copilot/helpers.ts, autogpt_platform/frontend/src/app/(platform)/copilot/useCallbackToken.ts, autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts, autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx, autogpt_platform/frontend/src/app/(platform)/copilot/components/MobileDrawer/MobileDrawer.tsx
Added callback token consumption hook with API integration and state management; introduced session start-type labeling via getSessionStartTypeLabel helper; parameterized session list queries with dynamic with_auto flag; updated sidebar/drawer to display session start-type badges and processing indicators.
API Schema & Dependencies
autogpt_platform/frontend/src/app/api/openapi.json, autogpt_platform/backend/pyproject.toml, autogpt_platform/backend/backend/util/text.py
Generated OpenAPI schema for all new endpoints and models; added markdown-it-py dependency; expanded HTML sanitization to allow tables and related attributes for email rendering.

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant AdminAPI as Admin API<br/>(user_admin_routes)
    participant DB as Database
    participant Copilot as Copilot Core<br/>(autopilot_dispatch)
    participant Session as Session Manager<br/>(model.py)
    participant Stream as Stream Registry

    Admin->>AdminAPI: POST /admin/copilot/trigger<br/>TriggerCopilotSessionRequest
    AdminAPI->>DB: fetch User
    AdminAPI->>Copilot: trigger_autopilot_session_for_user
    Copilot->>DB: check recent sessions & messages
    Copilot->>DB: create ChatSession (with start_type, execution_tag)
    Copilot->>Session: new ChatSession instance
    Session->>DB: enqueue initial turn
    Copilot-->>AdminAPI: ChatSession created
    AdminAPI-->>Admin: TriggerCopilotSessionResponse
Loading
sequenceDiagram
    participant User
    participant Frontend as Chat Frontend
    participant API as Chat API<br/>(routes.py)
    participant TokenMgr as Token Manager<br/>(autopilot.py)
    participant DB as Database
    participant Copilot as Copilot Engine<br/>(session lifecycle)

    User->>Frontend: Click callback token link<br/>with ?callbackToken=xyz
    Frontend->>Frontend: useCallbackToken hook<br/>detects token
    Frontend->>API: POST /callback-token/consume<br/>ConsumeCallbackTokenRequest
    API->>TokenMgr: consume_callback_token(token_id, user_id)
    TokenMgr->>DB: get_chat_session_callback_token(token_id)
    alt Token already consumed
        TokenMgr-->>API: return session_id
    else New consumption
        TokenMgr->>DB: create_chat_session (MANUAL type)
        TokenMgr->>DB: mark_chat_session_callback_token_consumed
        TokenMgr-->>API: CallbackTokenConsumeResult
    end
    API-->>Frontend: ConsumeCallbackTokenResponse
    Frontend->>Frontend: onConsumed(session_id)
    Frontend->>Frontend: Invalidate session list
    Frontend->>Frontend: Load Copilot chat
    Frontend-->>User: Display conversation
Loading
sequenceDiagram
    participant Scheduler
    participant Dispatch as Autopilot Dispatch<br/>(autopilot_dispatch.py)
    participant DB as Database
    participant Prompt as Prompts Engine<br/>(autopilot_prompts.py)
    participant Session as Session Manager<br/>(model.py)
    participant Email as Email Service<br/>(autopilot_email.py)

    Scheduler->>Dispatch: dispatch_nightly_copilot()
    Dispatch->>DB: list_users (batched)
    loop For each user
        Dispatch->>DB: check nightly feature flag<br/>resolve timezone
        Dispatch->>DB: _crosses_local_midnight<br/>(compute target date)
        Dispatch->>DB: session_exists_for_execution_tag
        Dispatch->>Prompt: _build_autopilot_system_prompt<br/>(with context)
        Dispatch->>Session: _create_autopilot_session<br/>(NIGHTLY start_type)
        Dispatch->>DB: enqueue_session_turn
    end
    Scheduler->>Email: send_nightly_copilot_emails()
    Email->>DB: get_pending_notification_chat_sessions
    loop For each pending session
        Email->>DB: handle_non_manual_session_completion<br/>(if not manual)
        Email->>Email: _send_completion_email
    end
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested reviewers

  • kcze

Poem

🐰 Hops with glee through nightly schemes,
Callback tokens in your dreams!
Sessions start with autopilot's gleam,
Emails whisper—what a team!
From dispatch to prompt's delight,
Copilot dances through the night. 🌙

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch swiftyos/nightly-autopilot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 13, 2026

🔍 PR Overlap Detection

This check compares your PR against all other open PRs targeting the same branch to detect potential merge conflicts early.

🔴 Merge Conflicts Detected

The following PRs have been tested and will have merge conflicts if merged after this PR. Consider coordinating with the authors.

  • feat(platform): Add dynamic LLM model registry with admin UI #11699 (Bentlybro · updated 6d ago)

    • .claude/skills/pr-review/SKILL.md (2 conflicts, ~117 lines)
    • autogpt_platform/backend/backend/api/features/chat/routes.py (3 conflicts, ~29 lines)
    • autogpt_platform/backend/backend/api/features/chat/routes_test.py (2 conflicts, ~247 lines)
    • autogpt_platform/backend/backend/api/features/store/routes.py (3 conflicts, ~29 lines)
    • autogpt_platform/backend/backend/blocks/llm.py (2 conflicts, ~577 lines)
    • autogpt_platform/backend/backend/copilot/baseline/service.py (1 conflict, ~27 lines)
    • autogpt_platform/backend/backend/copilot/config.py (1 conflict, ~15 lines)
    • autogpt_platform/backend/backend/copilot/config_test.py (2 conflicts, ~75 lines)
    • autogpt_platform/backend/backend/copilot/context.py (6 conflicts, ~89 lines)
    • autogpt_platform/backend/backend/copilot/context_test.py (4 conflicts, ~61 lines)
    • autogpt_platform/backend/backend/copilot/prompting.py (7 conflicts, ~86 lines)
    • autogpt_platform/backend/backend/copilot/sdk/agent_generation_guide.md (1 conflict, ~68 lines)
    • autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.py (1 conflict, ~38 lines)
    • autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools_test.py (2 conflicts, ~94 lines)
    • autogpt_platform/backend/backend/copilot/sdk/file_ref.py (16 conflicts, ~562 lines)
    • autogpt_platform/backend/backend/copilot/sdk/file_ref_integration_test.py (3 conflicts, ~206 lines)
    • autogpt_platform/backend/backend/copilot/sdk/file_ref_test.py (8 conflicts, ~1651 lines)
    • autogpt_platform/backend/backend/copilot/sdk/mcp_tool_guide.md (2 conflicts, ~39 lines)
    • autogpt_platform/backend/backend/copilot/sdk/service.py (3 conflicts, ~43 lines)
    • autogpt_platform/backend/backend/copilot/sdk/service_test.py (5 conflicts, ~269 lines)
    • autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py (2 conflicts, ~12 lines)
    • autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py (2 conflicts, ~9 lines)
    • autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer.py (9 conflicts, ~112 lines)
    • autogpt_platform/backend/backend/copilot/tools/agent_generator/fixer_test.py (1 conflict, ~108 lines)
    • autogpt_platform/backend/backend/copilot/tools/agent_generator/helpers.py (2 conflicts, ~8 lines)
    • autogpt_platform/backend/backend/copilot/tools/agent_generator/validator.py (14 conflicts, ~195 lines)
    • autogpt_platform/backend/backend/copilot/tools/e2b_sandbox.py (4 conflicts, ~33 lines)
    • autogpt_platform/backend/backend/copilot/tools/e2b_sandbox_test.py (3 conflicts, ~25 lines)
    • autogpt_platform/backend/backend/copilot/tools/find_block_test.py (1 conflict, ~123 lines)
    • autogpt_platform/backend/backend/copilot/tools/models.py (3 conflicts, ~26 lines)
    • autogpt_platform/backend/backend/copilot/tools/run_block.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/copilot/tools/workspace_files.py (1 conflict, ~6 lines)
    • autogpt_platform/backend/backend/data/block_cost_config.py (1 conflict, ~104 lines)
    • autogpt_platform/backend/backend/data/tally.py (1 conflict, ~6 lines)
    • autogpt_platform/backend/backend/executor/scheduler.py (2 conflicts, ~30 lines)
    • autogpt_platform/backend/poetry.lock (3 conflicts, ~17 lines)
    • autogpt_platform/backend/pyproject.toml (1 conflict, ~5 lines)
    • autogpt_platform/backend/schema.prisma (1 conflict, ~5 lines)
    • autogpt_platform/frontend/src/app/(platform)/admin/layout.tsx (1 conflict, ~7 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx (5 conflicts, ~75 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/helpers.ts (2 conflicts, ~8 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx (4 conflicts, ~277 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/tools/GenericTool/helpers.ts (5 conflicts, ~76 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts (4 conflicts, ~65 lines)
    • autogpt_platform/frontend/src/app/api/openapi.json (11 conflicts, ~428 lines)
    • docs/integrations/block-integrations/llm.md (7 conflicts, ~35 lines)
  • feat(backend/api): External API v2 #12206 (Pwuts · updated 1d ago)

    • autogpt_platform/backend/backend/api/features/chat/routes.py (2 conflicts, ~15 lines)
    • autogpt_platform/backend/backend/api/features/chat/routes_test.py (1 conflict, ~12 lines)
    • autogpt_platform/backend/backend/api/features/library/db.py (1 conflict, ~39 lines)
    • autogpt_platform/backend/backend/api/features/store/db.py (2 conflicts, ~10 lines)
    • autogpt_platform/backend/backend/api/features/store/routes.py (1 conflict, ~4 lines)
    • autogpt_platform/backend/backend/api/rest_api.py (2 conflicts, ~84 lines)
    • autogpt_platform/backend/backend/copilot/baseline/service.py (1 conflict, ~19 lines)
    • autogpt_platform/backend/backend/copilot/config.py (2 conflicts, ~17 lines)
    • autogpt_platform/backend/backend/copilot/constants.py (1 conflict, ~24 lines)
    • autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools.py (1 conflict, ~38 lines)
    • autogpt_platform/backend/backend/copilot/sdk/e2b_file_tools_test.py (2 conflicts, ~16 lines)
    • autogpt_platform/backend/backend/copilot/sdk/service.py (3 conflicts, ~21 lines)
    • autogpt_platform/backend/backend/copilot/sdk/service_test.py (1 conflict, ~214 lines)
    • autogpt_platform/backend/backend/copilot/sdk/tool_adapter.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/copilot/sdk/tool_adapter_test.py (2 conflicts, ~9 lines)
    • autogpt_platform/backend/backend/copilot/sdk/transcript_builder.py (1 conflict, ~21 lines)
    • autogpt_platform/backend/backend/copilot/tools/__init__.py (2 conflicts, ~97 lines)
    • autogpt_platform/backend/backend/copilot/tools/agent_generator/core.py (2 conflicts, ~12 lines)
    • autogpt_platform/backend/backend/copilot/tools/find_block_test.py (1 conflict, ~123 lines)
    • autogpt_platform/backend/backend/data/db_accessors.py (1 conflict, ~16 lines)
    • autogpt_platform/backend/backend/data/db_manager.py (3 conflicts, ~12 lines)
    • autogpt_platform/backend/backend/data/human_review.py (4 conflicts, ~119 lines)
    • autogpt_platform/backend/backend/data/tally.py (1 conflict, ~6 lines)
    • autogpt_platform/backend/backend/executor/scheduler.py (2 conflicts, ~30 lines)
    • autogpt_platform/backend/backend/util/request_test.py (1 conflict, ~5 lines)
    • autogpt_platform/backend/backend/util/settings.py (1 conflict, ~7 lines)
    • autogpt_platform/backend/poetry.lock (3 conflicts, ~17 lines)
    • autogpt_platform/backend/pyproject.toml (1 conflict, ~5 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx (4 conflicts, ~255 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunBlock/helpers.tsx (1 conflict, ~5 lines)
    • autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPage.ts (1 conflict, ~41 lines)
    • autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/NewAgentLibraryView.tsx (1 conflict, ~4 lines)
    • autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/SelectedScheduleView.tsx (4 conflicts, ~22 lines)
    • autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/SidebarRunsList.tsx (1 conflict, ~4 lines)
    • autogpt_platform/frontend/src/app/api/openapi.json (4 conflicts, ~132 lines)
    • docs/integrations/block-integrations/llm.md (7 conflicts, ~35 lines)
  • feat(platform): Add waitlist feature with admin management and user notifications #11723 (ntindle · updated 7d ago)

    • autogpt_platform/backend/backend/api/features/store/db.py (1 conflict, ~146 lines)
    • autogpt_platform/backend/backend/api/features/store/routes.py (2 conflicts, ~146 lines)
    • autogpt_platform/backend/backend/api/rest_api.py (1 conflict, ~5 lines)
    • autogpt_platform/frontend/src/app/(platform)/admin/layout.tsx (1 conflict, ~6 lines)
    • autogpt_platform/frontend/src/app/api/openapi.json (3 conflicts, ~431 lines)
    • docs/integrations/block-integrations/llm.md (7 conflicts, ~35 lines)
  • feat(platform): load copilot messages from newest first with cursor-based pagination #12328 (kcze · updated 3h ago)

    • 📁 autogpt_platform/
      • backend/backend/api/features/chat/routes.py (2 conflicts, ~33 lines)
      • backend/backend/copilot/db.py (2 conflicts, ~252 lines)
      • frontend/src/app/(platform)/copilot/useCopilotPage.ts (1 conflict, ~5 lines)
  • fix(copilot): resolve OTel context ValueError during stream cancellation #12421 (Otto-AGPT · updated 18h ago)

    • 📁 autogpt_platform/backend/backend/copilot/sdk/
      • service.py (2 conflicts, ~89 lines)
  • fix(platform): pre-check invite eligibility before Supabase signup #12451 (Otto-AGPT · updated 16h ago)

    • 📁 autogpt_platform/frontend/src/app/api/
      • openapi.json (2 conflicts, ~47 lines)
  • feat(blocks): add AutoPilotBlock for invoking AutoPilot from graphs #12439 (majdyz · updated 4m ago)

    • 📁 autogpt_platform/backend/backend/
      • copilot/prompting.py (1 conflict, ~13 lines)
      • notifications/test_notifications.py (1 conflict, ~4 lines)
  • fix(frontend/builder): persist agent name on Agent Executor block after reload #12372 (okxint · updated 1d ago)

    • 📁 autogpt_platform/backend/backend/copilot/
      • service.py (1 conflict, ~11 lines)
  • fix(backend): handle soft-deleted ghost rows in workspace file overwrite #12379 (deepakdevp · updated 1d ago)

    • 📁 autogpt_platform/backend/backend/data/
      • db_manager.py (2 conflicts, ~10 lines)
  • feat(copilot): GitHub CLI support — inject GH_TOKEN and connect_integration tool #12426 (majdyz · updated 11m ago)

    • 📁 autogpt_platform/backend/backend/
      • copilot/tools/__init__.py (1 conflict, ~5 lines)
      • notifications/test_notifications.py (1 conflict, ~4 lines)
  • feat(backend/blocks): MCP message signing and tool integrity verification #12455 (dataCenter430 · updated 3h ago)

    • 📁 autogpt_platform/backend/
      • poetry.lock (1 conflict, ~5 lines)
  • fix(platform): try-compact-retry for prompt-too-long errors in CoPilot SDK #12413 (majdyz · updated 9m ago)

    • 📁 autogpt_platform/backend/backend/notifications/
      • test_notifications.py (1 conflict, ~4 lines)
  • fix(backend): Clean up orphaned schedules without schedule_id #11927 (Bentlybro · updated 1d ago)

  • feat(frontend,backend): add button to generate data to admin dashboard on local dev #11791 (ntindle · updated 4d ago)

🟡 Medium Risk — Some Line Overlap

These PRs have some overlapping changes:

🟢 Low Risk — File Overlap Only

These PRs touch the same files but different sections (click to expand)

Summary: 14 conflict(s), 1 medium risk, 28 low risk (out of 43 PRs with file overlap)


Auto-generated on push. Ignores: openapi.json, lock files.

Comment thread autogpt_platform/backend/backend/copilot/autopilot.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/autopilot.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/autopilot.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/autopilot.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/autopilot.py Outdated
Comment thread autogpt_platform/backend/backend/copilot/model.py Outdated
Comment thread autogpt_platform/backend/backend/data/understanding.py Outdated
Comment thread autogpt_platform/backend/backend/notifications/email.py Outdated
Comment thread autogpt_platform/backend/backend/notifications/email.py Outdated


async def get_user_session_count(user_id: str) -> int:
async def get_pending_notification_chat_sessions(
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.

🤖 🟠 Should Fix: get_pending_notification_chat_sessions does a global scan — it filters on startType != MANUAL AND completedAt IS NOT NULL AND notificationEmailSentAt IS NULL AND notificationEmailSkippedAt IS NULL, but the only new index is (userId, startType, updatedAt). Without a userId predicate, that index can't be used here. At scale this is a full table scan every 30 minutes.

Consider a partial index:

CREATE INDEX "ChatSession_pending_notification_idx"
  ON "ChatSession" ("updatedAt")
  WHERE "startType" != 'MANUAL'
    AND "completedAt" IS NOT NULL
    AND "notificationEmailSentAt" IS NULL
    AND "notificationEmailSkippedAt" IS NULL;

Or add completedAt, notificationEmailSentAt, notificationEmailSkippedAt to the existing index and always include a date range predicate in the query.

][:limit]


async def get_recent_completion_report_chat_sessions(
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.

🤖 🟠 Should Fix: Over-fetches max(limit * 5, 10) rows with only startType != MANUAL as the filter, then discards rows without completion_report in Python. For a user with 50+ autopilot sessions that lack a completion report, the effective yield could be well under limit.

Either add a DB-level filter that checks if completionReport is not NULL (e.g., Prisma completionReport: { not: DbNull }), or document why this can't be done and make the multiplier configurable. As-is, callers can silently receive fewer results than requested.

"callbackSessionMessage" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"consumedAt" TIMESTAMP(3),
"consumedSessionId" TEXT,
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.

🤖 🟡 Nice to Have: consumedSessionId has an index but no foreign key constraint, while the sibling column sourceSessionId has both. This means a ChatSessionCallbackToken can have a consumedSessionId pointing to a non-existent or deleted session with no referential integrity enforcement. Consider adding:

ALTER TABLE "ChatSessionCallbackToken"
  ADD CONSTRAINT "ChatSessionCallbackToken_consumedSessionId_fkey"
  FOREIGN KEY ("consumedSessionId") REFERENCES "ChatSession"("id")
  ON DELETE SET NULL ON UPDATE CASCADE;

failed_count: int = 0


async def _ensure_session_title_for_completed_session(session: ChatSession) -> None:
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.

🤖 🟡 Nice to Have: If _generate_session_title raises (LLM timeout, API error, etc.), the exception propagates out of this function uncaught, which bubbles up through _process_pending_copilot_email_candidates and gets caught by _NON_FATAL_EMAIL_SWEEP_ERRORS — but only if the exception type matches. A generic Exception would escape that handler and abort the entire sweep iteration.

Even in the best case (exception is caught), the email goes out with subject "Autopilot update" instead of a meaningful title and there's no log entry explaining why. Suggest wrapping the _generate_session_title call in a try/except with a warning log:

try:
    generated_title = await _generate_session_title(...)
    title = generated_title.strip() if generated_title else ""
except Exception:
    logger.warning("Failed to generate title for session %s", session.session_id, exc_info=True)
    title = ""

try:
from backend.copilot.autopilot import handle_non_manual_session_completion

await handle_non_manual_session_completion(session_id)
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.

🤖 🟡 Nice to Have: handle_non_manual_session_completion runs in the critical path of mark_session_completed with no timeout guard. If a DB call inside hangs (e.g., Prisma connection pool exhausted during a spike), this blocks the entire completion handler indefinitely.

The try/except Exception does protect against failures, but only once an exception is raised — a hung coroutine won't raise. Consider wrapping with asyncio.wait_for(..., timeout=30) and catching asyncio.TimeoutError alongside the generic handler, or running it via asyncio.create_task to decouple it from the hot path.

return result


async def _send_nightly_copilot_emails() -> int:
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.

🤖 🔵 Nit: _send_nightly_copilot_emails returns processed_count (= sent + skipped + failed), which excludes running_count and repair_queued_count. This means the scheduler log shows e.g. 150 when 200 candidates were picked up and 50 were deferred — the 50 running sessions look like they were never seen.

Consider returning the full PendingCopilotEmailSweepResult struct from the inner function and logging a richer summary at the outer layer (or at minimum returning candidate_count for the scheduler).

}

for user in batch:
if not await is_feature_enabled(
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.

🤖 🟠 Should Fix: The dispatch loop processes all 500 users in a batch sequentially, with is_feature_enabled (which hits Supabase to build the LaunchDarkly context) called for every user — even users who will immediately fail the midnight check. This is the dominant cost:

for user in batch:
    if not await is_feature_enabled(Flag.NIGHTLY_COPILOT, user.id, ...):  # Supabase DB call
        continue   # most users exit here, but AFTER the network round-trip

At 500 users × ~10 ms per flag call = 5+ seconds per batch, 10k users = 50+ seconds just for flag evaluation. The 30-minute cron window will hold, but this leaves little headroom and will silently degrade as user count grows.

Two fixes, in order of impact:

  1. Bulk flag evaluation — LaunchDarkly supports bulk context evaluation; batch all user contexts and evaluate them in one call, or add a TTL cache (e.g., functools.lru_cache + expiry, or Redis) so the same user is not re-fetched on every 30-min run.
  2. Parallelize eligible users — Move the per-user session-creation work into asyncio.gather after the flag/midnight checks have filtered the cohort down:
eligible = [u for u in batch if passes_fast_checks(u)]
await asyncio.gather(*[_dispatch_for_user(u, ...) for u in eligible])

return False
if invited_user.created_at > now_utc - invite_cta_delay:
return False
if await _session_exists_for_execution_tag(user.id, get_invite_cta_execution_tag()):
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.

🤖 🟡 Nice to Have: _try_create_invite_cta_session (line 210) and _try_create_callback_session (line 254) each call _session_exists_for_execution_tag explicitly, then immediately call _create_autopilot_session — which calls it again for the same execution tag. This is a redundant double round-trip to DB for every eligible user.

Remove the pre-check from _try_create_* helpers and rely solely on the guard inside _create_autopilot_session, or vice versa. As-is the responsibility is split confusingly across two layers.



def get_callback_execution_tag() -> str:
return AUTOPILOT_CALLBACK_TAG
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.

🤖 🟠 Should Fix: AUTOPILOT_CALLBACK_TAG = "autopilot-callback:v1" is a static string — every user can only ever receive ONE callback session via the dispatch loop, for their entire account lifetime. Once a callback session exists for a user, the dispatch loop silently skips them forever.

This is likely intentional for the v1 rollout, but it means:

  • A user who got a callback in Feb 2026 and ignored it will never get another one, no matter how much they use the product later.
  • There is no "re-engagement" path through dispatch — only admin override.

If this is intentional, add a comment explaining the one-shot design. If not, the tag should incorporate a date or cohort period (like nightly does with autopilot-nightly:{date}) so users can re-enter the callback funnel.

@github-actions github-actions Bot added the conflicts Automatically applied to PRs with merge conflicts label Mar 18, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically applied to PRs with merge conflicts platform/backend AutoGPT Platform - Back end platform/frontend AutoGPT Platform - Front end size/xl

Projects

Status: ✅ Done
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants