Skip to content

fix(flow): handle terminal actions for unloaded flows#376

Open
vchaplygim wants to merge 1 commit into
mainfrom
fix/flow-terminal-actions-db-fallback-signed
Open

fix(flow): handle terminal actions for unloaded flows#376
vchaplygim wants to merge 1 commit into
mainfrom
fix/flow-terminal-actions-db-fallback-signed

Conversation

@vchaplygim

Copy link
Copy Markdown

Description of the Change

Problem

Flows can exist in the database but be absent from the in-memory flow map when worker loading fails at startup. One reproducible case is a flow whose saved provider name no longer exists after the provider was renamed or deleted.

Before this change, terminal actions such as finishFlow, stopFlow, REST PUT /flows/{id} with finish/stop, and GraphQL deleteFlow depended on the in-memory worker path. If the worker was not loaded, these actions returned flow not found or a generic internal error, leaving the flow stuck and its recorded container orphaned.

Solution

This PR adds a DB-backed fallback in the flow controller for unloaded flows:

  • FinishFlow now verifies the DB row exists, removes recorded containers, marks the flow finished, publishes FlowUpdated, and returns success when the worker is missing.
  • StopFlow now verifies the DB row exists, removes recorded running/starting containers, marks active unloaded flows waiting, publishes FlowUpdated, and returns success.
  • REST stop/finish actions now call controller methods directly instead of requiring GetFlow first.
  • GraphQL deleteFlow now routes through controller FinishFlow before deleting the DB row, closing the same cleanup gap.
  • The fix does not attempt to repair provider mappings or resume flows whose provider is missing.

Closes #360

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Configuration change
  • 🧪 Test update
  • 🛡️ Security update

Areas Affected

  • Core Services (Frontend UI/Backend API)
  • AI Agents (Researcher/Developer/Executor)
  • Security Tools Integration
  • Memory System (Vector Store/Knowledge Base)
  • Monitoring Stack (Grafana/OpenTelemetry)
  • Analytics Platform (Langfuse)
  • External Integrations (LLM/Search APIs)
  • Documentation
  • Infrastructure/DevOps

Testing and Verification

Test Configuration

PentAGI Version: local build from this branch, image local/pentagi:flow-fallback-fix
Docker Version: 29.4.3
Host OS: macOS Darwin 25.2.0
LLM Provider: custom OpenAI-compatible test gateway, model openrouter/z-ai/glm-5.2
Enabled Features: []

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: finishFlow mutation returns "flow not found" when provider name was renamed - flow unloaded from in-memory map at startup

1 participant