Skip to content

feat!: typed external facts and per-command HTTP edges - #347

Merged
patrickleet merged 1 commit into
v5from
refactor/v5-review-28a-identity
Nov 25, 2026
Merged

patrickleet merged 1 commit into
v5from
refactor/v5-review-28a-identity

Conversation

@patrickleet

Copy link
Copy Markdown
Collaborator

Task 28 stage A (identity without workarounds), covering review 13 findings #3, #9, #10 and #11. Stacked on #346.

Framework

  • publish_external(source, event), on CausalCommandContext and CausalCommitBuilder, publishes a typed fact from an external source: a provider webhook, a reconciliation, anything that isn't an aggregate transition.
    • The fact's identity is the source alone, so publishing the same source position twice gives one outbox message id. The second commit fails with RepositoryError::DuplicateOutboxMessage.
    • It commits with the command's ledger receipt and gets the ledger's causation, so projection! over the event projects it like an aggregate event.
  • Service::with_http_command(command, edge) exposes one command at POST /{command}.
    • The edge sees the request headers and JSON body (null when the body is empty; malformed JSON is a 400 before the edge runs).
    • It returns HttpCommandDispatch { command_id, input, session, principal }. The command runs through the normal ledgered dispatch_causal_with_receipt. No request header reaches the command unless the edge puts it in the session.
    • The answer is {payload, receipt}, or {code, error} with the error's status.
  • microsvc::command_router(service) mounts only the exposed command paths. router builds on it.
  • Service::command_gateway_routes(binding) gives the service binding an exact route for every command path. An unexposed command is a 404 from the service and can never fall through to the UI.
  • Rename: RepositoryError::DuplicateOutboxMessageInBatch → DuplicateOutboxMessage, covering an id repeated within a batch or already committed.

Demos (e2e-ui and e2e-celld)

  • AUTH_USERS is declared with projection! over a new ZitadelUserProfile event and a SaveAuthUser mutation program, like TODOS.
    • Ingress and scrape both publish profiles with publish_external.
    • Active vs deactivated comes from an exact event-name match, not a substring.
  • Deleted:
    • the hand-written project_auth_user projector, which dispatched on name.contains("deactivated");
    • the scrape's direct auth_users upsert (the dual write);
    • publish.rs;
    • the two hand-written axum routes, the copied session_from_headers, and the loop that registered "closed" routes.
  • The Zitadel secret check moved into each edge. On e2e-celld, command_router also sits behind the internal-secret layer, and the CI red-team 401 still holds.
  • Already fixed in the base, so no change here: serialize data #3 (load: or_create for todo create and force-archive) and feat: domain services + read model transactions + bus.send/listen #10 (Routes::for_stores; AuthDeps is no longer = ChatDeps).
  • Across both demo trees the diff is +1,049 / −1,222 lines.

Behaviour change: the scrape no longer writes auth_users directly. The projection writes the rows after bus delivery, the same as the ingress path already did.

Tests

  • New tests/services/microsvc/transport_http_edge.rs:
    • an exposed command with a wrong secret (401), a correct secret, and a redelivery replaying the receipt;
    • caller x-user-id/x-roles headers being ignored;
    • an empty body and a malformed body;
    • an unexposed command returning 404;
    • an edge for an unregistered command panicking at router build;
    • a closed path behind a NativeGateway with a UI fallback getting the service's 404, never the UI.
  • A duplicate external source fails the whole batch with no receipt.
  • e2e-ui end to end: ingress command → bus → auth_users row with status deactivated.

Verification (local)

  • cargo check --workspace --all-targets --all-features: passes.
  • cargo check -p distributed --tests --no-default-features: passes, and each of the 19 features alone passes.
  • wasm32: scripts/check-wasm32-domains.sh passes, and the 5 celld workers and examples/game/cells pass.
  • cargo test -p distributed --all-features: 2,190 passed, 0 failed.
  • make test-local: 2,865 passed, 0 failed.
  • e2e-ui cargo test --workspace: 98 passed.
  • make ci-offline: the Rust suites pass, UI tests pass 16/16, no generated drift.
  • e2e-celld cargo test --workspace: 31 passed. distributed build tests/e2e-celld shows no drift.

Not done

  • The live Zitadel and celld stacks and the browser Playwright suite were not run locally; this machine's Zitadel belongs to another project's cluster. CI's e2e-ui and celld jobs cover them.
  • There is no unit test of e2e-celld's internal-secret layer combined with command_router; only the CI red-team step checks it.
  • At dispatch level, a duplicate external publish still surfaces as CausalDispatchError::Internal, not a dedicated variant.

The reference app's identity path wrote `auth_users` twice: the scrape
upserted the row directly and also published the event a hand-written
projector (dispatching on `name.contains("deactivated")`) applied
again. It also hand-wrote HTTP routes with a copied
`session_from_headers` that put every request header into the session.

- `publish_external(source, event)` on the causal command context and
  commit builder publishes a typed fact whose identity is its external
  source. It commits with the ledger receipt and carries its causation,
  so `projection!` projects it like an aggregate event. `AUTH_USERS` is
  now declared with `projection!` and a mutation program, like TODOS.
- `Service::with_http_command(command, edge)` exposes one command at
  `POST /{command}`. The edge authenticates from headers and body and
  returns the command id, input, session and principal; nothing else
  from the request reaches the command. `command_router` mounts only
  exposed commands, and `command_gateway_routes` sends every command
  path to the service, so an unexposed one is a 404, never the UI.
- `RepositoryError::DuplicateOutboxMessageInBatch` is renamed
  `DuplicateOutboxMessage`: one message id repeated in a batch or
  already committed.

Deleted from e2e-ui and e2e-celld: `project_auth_user`, the direct
`auth_users` upsert, `publish.rs`, the hand-written ingress and scrape
routes, `session_from_headers` and the closed-route loop.

BREAKING CHANGE: `DuplicateOutboxMessageInBatch` is renamed; the two
Zitadel commands answer the wait-path shape (`{payload, receipt}`).

Implements [[tasks/v5-review-28]]
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53ece0ab-ad53-41a1-a43b-b023fb0a7fdb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@patrickleet
patrickleet changed the base branch from refactor/v5-review-27c-test-binaries to v5 November 25, 2026 05:51
@patrickleet
patrickleet merged commit 53deb8d into v5 Nov 25, 2026
27 checks passed
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.

1 participant