Skip to content

refactor(app/stripe): inject webhook secret service - #4844

Merged
turip merged 1 commit into
fix/stripe-webhook-app-not-found-500from
feat/stripe-webhook-secret-service
Aug 3, 2026
Merged

turip merged 1 commit into
fix/stripe-webhook-app-not-found-500from
feat/stripe-webhook-secret-service

Conversation

@turip

@turip turip commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #4828.

  • remove the generic app-secret cache added by the parent PR
  • introduce a required, read-only WebhookSecretService dependency for Stripe webhook verification
  • keep general Stripe secret operations on the existing secret.Service
  • bind both interfaces to the same service in the default OpenMeter wiring
  • add coverage proving webhook secret lookup uses the dedicated dependency

Why

Caching policy belongs to the deployment that owns the backing secret store. Cloud already has a cache wrapper and can now inject it specifically for the high-volume webhook path without making all OpenMeter secret reads cached.

The adapter dependency is required so deployments cannot silently fall back to an unintended uncached webhook path.

Validation

  • make generate
  • go test -tags=dynamic ./openmeter/secret/service ./openmeter/app/stripe/adapter ./app/common
  • go test -tags=dynamic ./test/app/stripe -run '^$'
  • go test -tags=dynamic ./cmd/server ./cmd/billing-worker ./cmd/jobs/internal -run '^$'
  • go vet -tags=dynamic ./openmeter/app/stripe/... ./openmeter/secret/... ./app/common ./test/app/stripe ./test/app

The PostgreSQL-backed webhook dependency test compiles, but could not be executed locally because PostgreSQL was not available on 127.0.0.1:5432.

Summary by CodeRabbit

  • New Features

    • Stripe webhook signing secrets are now retrieved through a dedicated secret service.
    • Added support for configuring and resolving webhook secrets independently from other application secrets.
  • Bug Fixes

    • Removed secret caching to ensure webhook secret updates and deletions are reflected immediately.
  • Tests

    • Added coverage verifying dedicated webhook secret retrieval for Stripe integrations.

Greptile Summary

The PR separates Stripe webhook-signing-secret reads from general secret operations so deployments can inject a specialized read service.

  • Adds and requires a narrow WebhookSecretService dependency in the Stripe adapter.
  • Binds the default secret service to both interfaces and updates server, worker, jobs, and test wiring.
  • Removes generic caching from the default secret service and adds coverage for dedicated webhook-secret lookup.

Confidence Score: 4/5

The PR appears safe to merge, with one non-blocking validation-error consistency issue.

The new webhook dependency is supplied across the discovered production and test construction paths and preserves the existing secret lookup contract; only the secret-service constructor's validation error classification needs cleanup.

Files Needing Attention: openmeter/secret/service/service.go

Important Files Changed

Filename Overview
openmeter/app/stripe/adapter.go Introduces the narrow read-only WebhookSecretService interface used for webhook authentication.
openmeter/app/stripe/adapter/adapter.go Makes the webhook-secret dependency mandatory and preserves it when creating transaction-bound adapter copies.
openmeter/app/stripe/adapter/stripe.go Routes webhook-signing-secret lookup through the dedicated dependency without changing the lookup input or output contract.
app/common/secret.go Binds both secret interfaces to the same default concrete service for OpenMeter deployments.
openmeter/secret/service/service.go Removes cache state and configuration, but its changed Validate implementation no longer uses the repository's structured validation-error convention.
openmeter/secret/service/secret.go Restores direct validated delegation to the secret adapter for read and mutation operations.
test/app/stripe/appstripe.go Verifies webhook-secret lookup uses the dedicated service rather than the general secret service.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  W[Stripe webhook handler] --> S[Stripe app service]
  S --> A[Stripe adapter]
  A --> D[(Stripe app database row)]
  A --> H[WebhookSecretService]
  H --> X[Secret adapter]
  A -. general secret operations .-> G[secret.Service]
  G --> X
Loading

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
### Issue 1
openmeter/secret/service/service.go:19-22
**Preserve structured validation errors**

`Config.Validate` now returns a plain error for a nil adapter instead of the repository-standard `GenericValidationError`, preventing callers from classifying this constructor failure with `models.IsGenericValidationError` and dropping consistent validation context.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "refactor(app/stripe): inject webhook sec..." | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

Context used (7)

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Stripe adapter now receives a dedicated webhook secret service. The secret service removes in-memory caching and locking. Application wiring and Stripe tests now provide and verify the separate webhook secret dependency.

Changes

Stripe webhook secret handling

Layer / File(s) Summary
Webhook secret contract and adapter flow
openmeter/app/stripe/adapter.go, openmeter/app/stripe/adapter/*
The adapter defines WebhookSecretService, requires it in Config, preserves it across transaction scopes, and uses it in GetWebhookSecret.
Application dependency wiring
app/common/*, cmd/*/wire_gen.go, test/app/*
Application constructors, Wire providers, generated initializers, and test adapter configurations pass the webhook secret service.
Direct secret service access
openmeter/secret/service/*
The secret service removes cache and lock state. Reads, updates, and deletes delegate directly to the adapter.
Webhook secret test coverage
test/app/stripe/*
The test environment creates a separate webhook secret mock. Tests verify retrieval through that service and confirm the regular secret service is not called.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: release-note/ignore, area/billing

Suggested reviewers: tothandras, galexihu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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: injecting a dedicated webhook secret service for Stripe.
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 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/stripe-webhook-secret-service

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 requested a review from tothandras August 3, 2026 15:32
@turip
turip marked this pull request as ready for review August 3, 2026 15:32
@turip
turip requested a review from a team as a code owner August 3, 2026 15:32
Comment on lines 19 to 22
func (c Config) Validate() error {
var errs []error

if c.Adapter == nil {
errs = append(errs, errors.New("adapter is required"))
}

if c.CacheSize < 0 {
errs = append(errs, fmt.Errorf("cache size must not be negative: %d", c.CacheSize))
}

if c.CacheTTL < 0 {
errs = append(errs, fmt.Errorf("cache ttl must not be negative: %s", c.CacheTTL))
return errors.New("adapter cannot be null")
}

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.

P2 Preserve structured validation errors

Config.Validate now returns a plain error for a nil adapter instead of the repository-standard GenericValidationError, preventing callers from classifying this constructor failure with models.IsGenericValidationError and dropping consistent validation context.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/secret/service/service.go
Line: 19-22

Comment:
**Preserve structured validation errors**

`Config.Validate` now returns a plain error for a nil adapter instead of the repository-standard `GenericValidationError`, preventing callers from classifying this constructor failure with `models.IsGenericValidationError` and dropping consistent validation context.

**Context Used:** AGENTS.md ([source](https://github.com/openmeterio/openmeter/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/app/stripe/app_test.go (1)

67-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use t.Context() for the webhook-secret test.

The caller passes a parent context, and TestGetWebhookSecret accepts and uses it instead of the subtest context. Use t.Context() so fixture setup and webhook lookup follow the subtest lifecycle.

  • test/app/stripe/app_test.go#L67-L69: remove the ctx argument from the helper call.
  • test/app/stripe/appstripe.go#L807-L838: remove the ctx parameter and use t.Context() for both operations.

As per coding guidelines, use t.Context() whenever a testing.T or testing.TB is available.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/app/stripe/app_test.go` around lines 67 - 69, Update
test/app/stripe/app_test.go lines 67-69 to call TestGetWebhookSecret without the
parent ctx argument. In test/app/stripe/appstripe.go lines 807-838, remove the
helper’s ctx parameter and use t.Context() for both fixture setup and webhook
lookup operations.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/secret/service/service.go`:
- Around line 19-24: Update Config.Validate to collect validation errors in an
errs slice, wrapping the missing Adapter error with its field context, and
return models.NewNillableGenericValidationError(errors.Join(errs...)) instead of
a plain errors.New result. Preserve the nil result when no validation errors
exist.

---

Nitpick comments:
In `@test/app/stripe/app_test.go`:
- Around line 67-69: Update test/app/stripe/app_test.go lines 67-69 to call
TestGetWebhookSecret without the parent ctx argument. In
test/app/stripe/appstripe.go lines 807-838, remove the helper’s ctx parameter
and use t.Context() for both fixture setup and webhook lookup operations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b541b367-eb90-447e-9a81-e5daf223a4a3

📥 Commits

Reviewing files that changed from the base of the PR and between 760b6d8 and ea75320.

📒 Files selected for processing (16)
  • app/common/app.go
  • app/common/secret.go
  • cmd/billing-worker/wire_gen.go
  • cmd/jobs/internal/wire_gen.go
  • cmd/server/wire_gen.go
  • openmeter/app/stripe/adapter.go
  • openmeter/app/stripe/adapter/adapter.go
  • openmeter/app/stripe/adapter/stripe.go
  • openmeter/secret/service/secret.go
  • openmeter/secret/service/secret_test.go
  • openmeter/secret/service/service.go
  • test/app/stripe/app_test.go
  • test/app/stripe/appstripe.go
  • test/app/stripe/invoice_test.go
  • test/app/stripe/testenv.go
  • test/app/testenv.go
💤 Files with no reviewable changes (1)
  • openmeter/secret/service/secret_test.go

Comment on lines 19 to +24
func (c Config) Validate() error {
var errs []error

if c.Adapter == nil {
errs = append(errs, errors.New("adapter is required"))
}

if c.CacheSize < 0 {
errs = append(errs, fmt.Errorf("cache size must not be negative: %d", c.CacheSize))
}

if c.CacheTTL < 0 {
errs = append(errs, fmt.Errorf("cache ttl must not be negative: %s", c.CacheTTL))
return errors.New("adapter cannot be null")
}

return models.NewNillableGenericValidationError(errors.Join(errs...))
return nil

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Use the standard Validate error contract.

Collect the adapter error with field context. Return models.NewNillableGenericValidationError(errors.Join(errs...)).

The current plain error loses the standard structured validation result. As per coding guidelines, “For Validate() error, collect field errors and return models.NewNillableGenericValidationError(errors.Join(errs...)), preserving field context with wrapped errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/secret/service/service.go` around lines 19 - 24, Update
Config.Validate to collect validation errors in an errs slice, wrapping the
missing Adapter error with its field context, and return
models.NewNillableGenericValidationError(errors.Join(errs...)) instead of a
plain errors.New result. Preserve the nil result when no validation errors
exist.

Source: Coding guidelines

@turip
turip merged commit 5d1c8b2 into fix/stripe-webhook-app-not-found-500 Aug 3, 2026
23 of 24 checks passed
@turip
turip deleted the feat/stripe-webhook-secret-service branch August 3, 2026 15:38
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.

2 participants