Skip to content

fix(app): preserve deleted workflow apps - #4932

Merged
turip merged 1 commit into
mainfrom
feat/missing-invoice-workflow-app
Aug 14, 2026
Merged

turip merged 1 commit into
mainfrom
feat/missing-invoice-workflow-app

Conversation

@turip

@turip turip commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Summary

  • preserve deleted app identity while replacing provider behavior with deterministic unavailable operations
  • return billing-owned validation errors for deleted invoicing apps, while allowing invoice deletion with a warning
  • soft-delete Stripe subtype rows, clear secret references atomically, and retain non-secret provider metadata
  • keep deleted and legacy missing-subtype apps resolvable for invoice and public API reads
  • add PostgreSQL-backed adapter, uninstall, and billing lifecycle regressions

Root cause

Invoice reads and advancement resolved the workflow app by instantiating its provider implementation. Stripe uninstallation hard-deleted the provider subtype row, so invoices retaining that historical app reference failed during app construction before billing could record a validation issue or enter the appropriate failed state.

Behavior

Deleted apps retain their ID, type, and public metadata. Generic operations return app.ErrAppDeleted; invoicing operations return critical billing validation issues. External invoice deletion remains available and records a warning when provider cleanup must be skipped.

Stripe uninstallation now preserves the subtype row, sets deleted_at, and clears both secret references in one database update. Active rows require both references and deleted rows disallow them through a database check constraint.

The migration down path requires purging soft-deleted Stripe subtype rows or reconstructing both valid secret references before restoring NOT NULL.

Validation

  • POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/app/... ./openmeter/billing/... ./test/app/stripe
  • nix develop --impure .#ci -c make migrate-check
  • nix develop --impure .#ci -c make lint-go-fast

Maintenance task; no Jira ticket.

Summary by CodeRabbit

  • New Features
    • Added support for safely uninstalling Stripe apps while preserving app identity and historical metadata.
    • Historical invoices remain readable and expandable after an app is deleted.
    • Deleted apps now provide clear status handling across customer, configuration, and invoicing operations.
  • Bug Fixes
    • Prevented deleted apps from being used for new Stripe operations.
    • Added clearer warnings when external invoice cleanup is skipped.
  • Documentation
    • Documented credential lifecycle and deleted-app invoice behavior.

Greptile Summary

The PR preserves deleted workflow-app identities while replacing provider behavior with deterministic unavailable operations.

  • Introduces shared deleted-app implementations and billing-owned validation errors or warnings.
  • Soft-deletes Stripe subtype rows, atomically clears credential references, and enforces the active/deleted credential lifecycle with a database constraint.
  • Keeps deleted and legacy missing-subtype apps resolvable for invoice and public API reads.
  • Adds adapter, uninstall, migration, and billing lifecycle regression coverage.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security failures identified.

Production factories consistently install active or deleted operation implementations, Stripe credential removal is atomic and database-constrained, and the added lifecycle regressions cover historical reads, failed advancement, and invoice deletion.

Important Files Changed

Filename Overview
openmeter/app/deleted.go Adds deterministic unavailable behavior for generic operations on deleted apps while retaining their identity.
openmeter/app/stripe/service/factory.go Rehydrates deleted and legacy missing-subtype Stripe apps without requiring active provider credentials.
openmeter/app/stripe/adapter/stripe.go Soft-deletes Stripe subtype data, clears both credential references atomically, and excludes deleted rows from active provider operations.
openmeter/billing/app.go Adds deleted invoicing behavior that produces critical validation errors for advancement and a warning for skipped external deletion.
openmeter/ent/schema/app_stripe.go Makes credential references nullable and enforces mutually consistent active and deleted credential states.
tools/migrate/migrations/20260814064718_make_stripe_app_secrets_nullable.up.sql Applies the Stripe credential lifecycle constraint and permits NULL references for deleted subtype rows.
test/app/stripe/invoice_test.go Covers historical app resolution, failed invoice advancement, and warning-backed invoice deletion after provider removal.

Sequence Diagram

sequenceDiagram
  participant API as App/Billing caller
  participant Apps as App service
  participant Factory as Provider factory
  participant DB as PostgreSQL
  participant Billing as Invoice lifecycle

  API->>Apps: Resolve historical app ID
  Apps->>DB: Load soft-deleted AppBase
  Apps->>Factory: NewApp(deleted AppBase)
  Factory->>DB: Load retained provider metadata
  Factory-->>Apps: App identity + unavailable operations
  Apps-->>API: Resolvable deleted app
  Billing->>Apps: Resolve invoice workflow app
  Billing->>Factory: Invoke invoicing operation
  Factory-->>Billing: Deleted-app validation issue
  alt Invoice advancement
    Billing->>Billing: Enter failed lifecycle state
  else Invoice deletion
    Billing->>Billing: Delete invoice and record warning
  end
Loading

Reviews (1): Last reviewed commit: "fix(app): preserve deleted workflow apps" | Re-trigger Greptile

Context used (3)

@turip
turip requested a review from a team as a code owner August 14, 2026 07:40
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0690c9e6-6206-49d3-bf37-fc9d7a9030df

📥 Commits

Reviewing files that changed from the base of the PR and between 371a6f9 and 72c8a36.

⛔ Files ignored due to path filters (8)
  • openmeter/ent/db/appstripe.go is excluded by !**/ent/db/**
  • openmeter/ent/db/appstripe/where.go is excluded by !**/ent/db/**
  • openmeter/ent/db/appstripe_create.go is excluded by !**/ent/db/**
  • openmeter/ent/db/appstripe_update.go is excluded by !**/ent/db/**
  • openmeter/ent/db/migrate/schema.go is excluded by !**/ent/db/**
  • openmeter/ent/db/mutation.go is excluded by !**/ent/db/**
  • openmeter/ent/db/setorclear.go is excluded by !**/ent/db/**
  • tools/migrate/migrations/atlas.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (29)
  • openmeter/app/app.go
  • openmeter/app/custominvoicing/adapter/appconfig.go
  • openmeter/app/custominvoicing/app.go
  • openmeter/app/custominvoicing/customerdata.go
  • openmeter/app/custominvoicing/factory.go
  • openmeter/app/deleted.go
  • openmeter/app/errors.go
  • openmeter/app/sandbox/app.go
  • openmeter/app/sandbox/mock.go
  • openmeter/app/stripe/README.md
  • openmeter/app/stripe/adapter/customer.go
  • openmeter/app/stripe/adapter/stripe.go
  • openmeter/app/stripe/adapter/stripe_test.go
  • openmeter/app/stripe/app.go
  • openmeter/app/stripe/app_test.go
  • openmeter/app/stripe/appcustomer.go
  • openmeter/app/stripe/appinvoice.go
  • openmeter/app/stripe/clientapp.go
  • openmeter/app/stripe/config.go
  • openmeter/app/stripe/service/factory.go
  • openmeter/app/stripe/types.go
  • openmeter/billing/README.md
  • openmeter/billing/app.go
  • openmeter/billing/errors.go
  • openmeter/ent/schema/app_stripe.go
  • test/app/stripe/appstripe.go
  • test/app/stripe/invoice_test.go
  • tools/migrate/migrations/20260814064718_make_stripe_app_secrets_nullable.down.sql
  • tools/migrate/migrations/20260814064718_make_stripe_app_secrets_nullable.up.sql
💤 Files with no reviewable changes (1)
  • openmeter/app/custominvoicing/adapter/appconfig.go

📝 Walkthrough

Walkthrough

The change separates app metadata from operations, adds deleted-app implementations, soft-deletes Stripe records while clearing secrets, preserves historical identities, and updates invoice synchronization and deletion behavior for deleted apps.

Changes

Deleted app lifecycle

Layer / File(s) Summary
Operation contracts and deleted-app behavior
openmeter/app/..., openmeter/billing/..., openmeter/app/custominvoicing/..., openmeter/app/sandbox/...
Adds shared operation interfaces and deleted-app implementations. Factories now select deleted or active operations.
Stripe operation encapsulation
openmeter/app/stripe/app.go, openmeter/app/stripe/appcustomer.go, openmeter/app/stripe/appinvoice.go, openmeter/app/stripe/service/factory.go, openmeter/app/stripe/types.go
Moves Stripe runtime methods to appOperations, adds construction through New, and supports deleted-app construction.
Stripe soft deletion and secret constraints
openmeter/app/stripe/adapter/*, openmeter/ent/schema/app_stripe.go, tools/migrate/migrations/*, openmeter/app/stripe/README.md
Soft-deletes Stripe records, clears secret references, supports historical reads, and enforces active and deleted credential states.
Deleted-app invoice integration
openmeter/billing/README.md, test/app/stripe/*
Validates historical identity reads, failed synchronization with critical issues, and invoice deletion with skipped-cleanup warnings.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 72c8a

The change preserves deleted workflow app identity and provides deterministic handling for billing and provider operations; no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant StripeApp
  participant StripeAdapter
  participant BillingWorkflow
  participant InvoiceAPI

  StripeApp->>StripeAdapter: uninstall app
  StripeAdapter->>StripeAdapter: clear secrets and set DeletedAt
  InvoiceAPI->>StripeAdapter: request deleted app data
  StripeAdapter-->>InvoiceAPI: return preserved metadata
  BillingWorkflow->>StripeApp: validate invoice workflow
  StripeApp-->>BillingWorkflow: return deleted-app validation issue
  BillingWorkflow-->>InvoiceAPI: record failure or cleanup warning
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving deleted workflow app identity and behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/missing-invoice-workflow-app

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@turip turip added release-note/bug-fix Release note: Bug Fixes area/billing labels Aug 14, 2026
@turip
turip merged commit 80707a5 into main Aug 14, 2026
28 of 31 checks passed
@turip
turip deleted the feat/missing-invoice-workflow-app branch August 14, 2026 08:39
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