Repository navigation
fix(service-bridge): skip the upstream response envelope on every east-west handler (wiki-v2 incident 181) - #16
Merged
Conversation
…t-west handler (docmost#181) Docmost's global TransformHttpResponseInterceptor (main.ts, unmodified upstream) wraps every handler return value as { data, success, status } unless the HANDLER carries SKIP_TRANSFORM metadata. No service-bridge handler opted out, so every /api/service/* body on the wire contradicted service-bridge.openapi.json (bare bodies). The platform's Phase C client read those bodies raw, which took production down on v0.3.1 (wiki-v2 incident docmost#181: authz sync dead, /v1 500, placeholder workspace). - @SkipTransform() (the upstream per-handler decorator, as upstream uses on health/robots) on all 23 service-bridge handlers + POST /api/collab/force-disconnect (24 east-west operations) - fitness test: service-scope-coverage.spec.ts asserts SKIP_TRANSFORM metadata on every route handler; the controller list is now derived from ServiceBridgeModule so a new controller cannot escape (service-bridge.contract.spec.ts derives the same way); collab-disconnect.controller.spec.ts covers the sibling handler - wire proof: service-bridge.wire.spec.ts boots a real NestFastifyApplication with the global prefix and the real interceptor, asserts bare bodies on three representative routes, and keeps an UNdecorated fixture route as the negative control (must come back wrapped) - spec 1.1.1: info.description states the bare-body guarantee and the pre-setup 404 "Workspace not found" contract; README section added No upstream-owned file is touched (all under boundary-excluded prefixes). Co-Authored-By: Claude Fable 5.1 <[email protected]>
…in cannot rewrite its keys (docmost#181) Found by the first true end-to-end run of the change feed (wiki-v2 incident 181 fix branch, content-smoke + an isolated local stack): after a space create the relay advanced its cursor past the new outbox rows and wrote NOTHING to SpiceDB. In the built image postgres.js parses a stored jsonb column to an OBJECT and the application Kysely's CamelCasePlugin then camelCases its NESTED keys (workspace_id -> workspaceId), so the R2 mapper (which reads the stored snake_case keys) saw spaces with a null workspace and unmapped members and pages. Every live event was silently dropped; only the snapshot reconcile ever wrote tuples. The R2 real-Postgres spec never caught it because its fixture passed a pre-stringified JSON string to a ::jsonb parameter; postgres.js infers json for that parameter and stringifies it AGAIN, so the stored value was a jsonb STRING scalar that reads back as a string the feed then parsed. Production stores a real object. - authz-change-feed.service.ts: readRawAfter selects `payload::text as payload_json` and parses it; a text column can be touched by no result-key plugin, so the mapper sees the stored snake_case keys in every environment. Mapper unchanged. - authz-outbox-commit-safety.pg.spec.ts: the fixture stores a real jsonb object (postgres.js json helper) with a jsonb_typeof guard, plus a spaces case asserting workspaceId survives the app-shaped Kysely (PostgresJSDialect + CamelCasePlugin). Fails on the previous feed; passes now. - authz-change-feed.service.spec.ts: a structural test pins `payload::text` in the feed's SQL; the spy rows answer payload_json as a string. Doc comments corrected (the R1 note was right for the production path). Fork suites: 39 suites / 339 tests; tsc clean. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…UTHZ_CHANGE_EVENT_DROPPED (review round 1, wiki-v2 incident 181) The second incident-181 defect (a key-shape mismatch made every live change-feed event map to null) survived a whole release because a null mapping was silent and the cursor advanced past it. This adds the detector the security review asked for: - authz-change-event.ts: isExpectedSkip(row) is true only for tables the mapper does not know and for the one documented no-op (a page_permissions cascade DELETE whose page_id could not be resolved). - authz-change-feed.service.ts: getChanges() collects every other null mapping and logs ONE greppable warning per poll: AUTHZ_CHANGE_EVENT_DROPPED count=N rows=[table:id=..:op=..]. The cursor still advances (the feed cannot wedge); the reconciler remains the backstop. - spec: a known-table row without space_id warns with the table and id, an unknown-table row stays silent, nextCursor still advances past both. Verified RED (no warning) then GREEN; service-bridge + authz suites 39/39. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Two fork-side defects behind wiki-v2 incident 181. (1) Every east-west handler (the 23
/api/service/*routes andPOST /api/collab/force-disconnect) now carries upstream's per-handler@SkipTransform(), so the bodies on the wire are exactly the bare shapesservice-bridge.openapi.jsondeclares instead of Docmost's global{ data, success, status }envelope; a metadata fitness assertion derived fromServiceBridgeModuleand a wire-level proof through the real Fastify pipeline (with an undecorated negative control) make the class unshippable again. (2) Found by the first true end-to-end run of the change feed: the feed read the outboxpayloadas jsonb, postgres.js parses it to an object in the built image, and the application Kysely'sCamelCasePluginthen camelCases its NESTED keys, so the R2 mapper (which reads the stored snake_case keys) silently dropped every live event (spaces with a null workspace, members and pages unmapped) while only the snapshot reconcile ever wrote tuples. The feed now readspayload::text; the real-Postgres spec's fixture is fixed (it had stored a double-encoded jsonb string scalar, which is why it passed) and pins the production shape.Context
Production release
v0.3.1of wiki-v2 (the first with the Phase C platform client on the hot path) broke on 2026-09-05: the upstreamTransformHttpResponseInterceptorregistered inmain.ts(unmodified upstream code) wraps every handler return value unless the HANDLER carriesSKIP_TRANSFORMmetadata (it reads the handler only, never the class). No service-bridge handler opted out, so the platform readundefinedeverywhere: authorization sync dead (page.events is not iterable),/v1500, the platform running on the placeholder workspace id, and a duplicate root admin seeded under it. The fork side of the fix is this PR; the platform side (strict client, fail-closed workspace resolution, residue repair, deploy smoke) is the paired wiki-v2 PR. Full investigation, corrections to the original write-up, and the plan: cccvu/wiki-v2#181.Related issues
What changed
@SkipTransform()(import of the upstream decorator, applied exactly as upstream does onhealth.controller.ts) on all 23 route handlers across the sixservice-bridge/*.controller.tsfiles and onauthz/collab/collab-disconnect.controller.tsforceDisconnect. Handler level only: a class-level decorator would be a silent no-op.service-bridge/service-scope-coverage.spec.ts: the controller list is now derived fromServiceBridgeModulemetadata (pinned against the reviewed named set), and a newit.eachassertsSKIP_TRANSFORMmetadata on every route handler, so a new route or a new controller cannot ship envelope-wrapped.service-bridge.contract.spec.tsderives its list the same way.collab-disconnect.controller.spec.tscovers the sibling handler.service-bridge/service-bridge.wire.spec.ts: boots aNestFastifyApplicationwithsetGlobalPrefix('api')and the realTransformHttpResponseInterceptor(asmain.tsdoes), asserts three representative routes answer the bare spec bodies asapplication/json, and keeps an UNdecorated fixture route that must come back wrapped (negative control: the test cannot pass vacuously).service-bridge/authz-change-feed.service.ts:readRawAfterselectspayload::text as payload_jsonand parses it, so no result-key plugin can rewrite the data; the mapper is unchanged (snake_case). Doc comments corrected: the R1 note thatCamelCasePluginrecurses into the payload was RIGHT for the production read path; R2 observed a string only because its fixture passed a pre-stringified JSON string to a::jsonbparameter, which postgres.js stringifies again (a jsonb string scalar).service-bridge/authz-outbox-commit-safety.pg.spec.ts: the fixture now stores a real jsonb object via the postgres.js json helper with ajsonb_typeof(payload) = 'object'guard, plus aspacescase assertingworkspaceIdsurvives the app-shaped Kysely (PostgresJSDialect+CamelCasePlugin). Against the previous feed this spec FAILS (4 of 5 cases, including the pre-existing delivered-row case); it passes now.service-bridge/authz-change-feed.service.spec.ts: a structural test pinspayload::textin the feed's SQL and the spy rows answerpayload_jsonas a string.docs/integrations/authorization/service-bridge.openapi.jsoninfo.version 1.1.0 to 1.1.1 with two description sentences: the bare-body guarantee, and the pre-setup contract (until first-run setup creates a workspace row, every operation answers the upstream404 "Workspace not found", the only response a consumer may treat as not-provisioned).README.mdgets the same note. Schemas unchanged.apps/server/src/service-bridge/,apps/server/src/authz/,docs/integrations/).How this was tested
Received: undefined), and the wire spec's three route assertions failed with exactly the four envelope lines while the negative control passed.cd docmost/apps/server && pnpm exec jest src/authz src/service-bridge src/editor-compat= 39 suites, 339 passed.AUTHZ_TEST_PG_URL): RED with the previous feed (4 of 5 cases), GREEN now (5 of 5). The production read path was reproduced INSIDE the built fork image (docker exec ... node -ewith the image's own kysely, kysely-postgres-js and postgres modules and the app'spostgres()options):select payloadarrives as an object withworkspaceId/deletedAt,select payload::textarrives as a string whose parse keepsworkspace_id/deleted_at.content-smokedispatch: after a space create the live feed now projects the space, its members, page structure, restriction markers and page ACL grants and revokes within seconds (before this fix the relay advanced its cursor and wrote nothing).bash scripts/check-upstream-boundary.shfrom the super: "Upstream boundary intact" (exit 0).pnpm exec tsc --noEmit: one pre-existing error inauthz-outbox-commit-safety.pg.spec.ts(identical count on the pristinewiki-v2tip); no new diagnostics.content-smokeworkflow_dispatch run (linked there) boots this fork viamake dev-build, runs Docmost first-run setup, and drives the platform through/v1and the change feed.Checklist
Scope
Tests
Docs & contracts
service-bridge.openapi.json1.1.1 description,README.md).Safety
Housekeeping
Known limitations / follow-ups
404 "Workspace not found"comes from an upstreammain.tspre-handler; the platform keys itsnot-provisionedreason (observability only, never a fallback) on that literal. An upstream rename degrades the platform to a fail-closederrorreason, which is the safe direction.{ ok: true }bodies; the platform ignores them (spec unchanged).🤖 Generated with Claude Code