Skip to content

Fix generated middleware composition across the finalized route graph#698

Merged
cssbruno merged 7 commits into
mainfrom
codex/generated-middleware-pipeline
Jun 24, 2026
Merged

Fix generated middleware composition across the finalized route graph#698
cssbruno merged 7 commits into
mainfrom
codex/generated-middleware-pipeline

Conversation

@cssbruno

@cssbruno cssbruno commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Problem

Generated RegisterMiddleware middleware was applied only to the "/" fallback handler inside the generated mux. More-specific generated routes—such as dynamic sitemap and realtime endpoints—and routes mounted later by lifecycle services could bypass the documented app-wide middleware chain.

Changes

  • Build the raw generated route mux without route-local middleware wrapping.
  • Snapshot registered middleware around the complete route graph returned by Handler().
  • Keep Application.Mux raw for lifecycle route registration while serving it through a finalized wrapped Application.Handler.
  • Make ServeMux() expose the generated route graph behind the same finalized middleware wrapper.
  • Apply the same composition model to embedded and backend-only generated apps.
  • Regenerate the generated-Go golden fixture.
  • Document middleware ownership for App(), Handler(), ServeMux(), and caller-added routes.

Regression coverage

  • Verifies dynamic sitemap registration is inside the finalized wrapped route graph.
  • Rejects the old pattern that wrapped only the generated root fallback.
  • Proves middleware created before a lifecycle route is mounted still observes that mounted route exactly once.

Validation

  • go test ./internal/appgen -update
  • go test ./internal/appgen ./runtime/app
  • Full repository CI

@github-actions github-actions Bot added the ops Operations, release, deployment, and CI hardening label Jun 24, 2026
@github-actions github-actions Bot added compiler Compiler internals, pipeline, and generated metadata runtime GOWDK Runtime packages and server behavior docs Documentation work labels Jun 24, 2026
@cssbruno cssbruno marked this pull request as ready for review June 24, 2026 16:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10609cb75d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/appgen/source.go
Args: []ast.Expr{handler, call(id("registeredMiddlewares"))},
Ellipsis: token.Pos(1),
}
return handler

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update backend-only middleware assertions

With this change returning the backend-only handler unwrapped at the route level, the backend generation tests still look for the old route-local gowdkruntime.ApplyMiddlewares(...) call. I verified go test ./internal/appgen -run TestGenerateBackendAppRegistersBackendRoutes -count=1 and go test ./internal/appgen -run TestGenerateBackendAppWiresSecurityHeaders -count=1 both fail on those stale expected strings, so the appgen CI gate remains blocked until those expectations are updated to the new finalized-wrapper output.

Useful? React with 👍 / 👎.

@cssbruno cssbruno merged commit bc969d8 into main Jun 24, 2026
20 checks passed
@cssbruno cssbruno deleted the codex/generated-middleware-pipeline branch June 24, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler Compiler internals, pipeline, and generated metadata docs Documentation work ops Operations, release, deployment, and CI hardening runtime GOWDK Runtime packages and server behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant