WP-O2: origin dimension — tolerant resolver + derivation#2825
Open
byteclimber wants to merge 2 commits into
Open
WP-O2: origin dimension — tolerant resolver + derivation#2825byteclimber wants to merge 2 commits into
byteclimber wants to merge 2 commits into
Conversation
…rigin
WP-O2a: renames DIMENSION.SOURCE -> DIMENSION.ORIGIN (and SOURCE_VALUE ->
ORIGIN_VALUE) in prompt-tags.js, and gives the authorship root its own
tolerant resolver in tag-tree.js (resolveAuthorshipRoot): it reuses an
existing `origin` root, else adopts a legacy `source` root whose children
are a subset of {ai, human}, else mints a new `origin` root — never a
second, empty one. ensureDimensionRoots/provisionDimensionTree/
ensureClosedValue route through this resolver instead of blind-creating
the authorship root. parseCreateTagBody and the provisioning seams in
markets-subworkspace.js already validate/seed against ALL_DIMENSIONS/
DIMENSION_ROOT_NAMES, so they pick up the rename automatically.
WP-O2b: generalizes makeTypeInjector (handlers/prompts.js, and its
subworkspace twin) to also strip+inject `origin` on every prompt write:
CREATE always derives to `ai`; UPDATE re-injects whichever `origin` tag
the request already carries (never re-derived), falling back to `ai`
only if none is found. prompts-storage.js's upsertPrompts now derives
`origin` from the caller's authenticated principal (service principal:
honor an asserted ai/human value; user principal: always override to
human) via the new resolveOriginForWrite; updatePromptById no longer
accepts `origin` in a PATCH body; mapRowToPrompt drops the `|| 'human'`
read fallback. brands.js wires isServicePrincipal from context.s2sConsumer
into upsertPrompts. OpenAPI docs updated to describe the new origin
semantics without changing the query filter/sort surface.
Tracks WP-O2a (spacecat-api-service#2816, SITES-48001) and WP-O2b
(spacecat-api-service#2817, SITES-48002) from serenity-docs PR #46.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
byteclimber
marked this pull request as ready for review
July 15, 2026 15:29
|
This PR will trigger a minor release when merged. |
Contributor
Author
|
Related: #2785 (intent-classification) touches the same files ( |
4 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This was referenced Jul 20, 2026
aliciadriani
added a commit
that referenced
this pull request
Jul 21, 2026
…LMO-6275) (#2866) ## WP-O2b (LLMO-6275) — origin derivation + injector generalization **Canonical WP-O2b implementation** (serenity dimension-root program, epic 46). Stacked on `claude/wp-o2a-origin`. Generalizes `makeTypeInjector` → `makePromptTagInjector` to strip-and-inject both `type` and `origin` with the spec §3 item-3 asymmetry (CREATE injects the derived value; UPDATE re-injects the prompt's STORED origin, never re-derives), strips by resolved tag id beneath the root (never by name), derives `origin` from the request principal (service principal → asserted body value validated against the vocabulary; user principal → `human`, body ignored, never rejected), stops patching `origin` on update, `mapRowToPrompt` returns `row.origin` (no `|| 'human'` fallback), and KEEPS `origin` on `V2PromptInput` (the DRS `origin:'ai'` upsert guard, item 6). Spec gates 5–8, including the **gate5/6 controller coverage** in `test/controllers/brands.test.js`. Verify: node24 type-check + lint + npm test (unit) green. `it/`-postgres waits the WP-O1 mock release (not a finding). **Supersedes #2864** (the earlier "salvage" implementation from #2825), which lacked the gate5/6 controller coverage. This branch is also the confirmed base for WP-S2 (#2867). History preserved in #2864. --- ## WP-O2b — derive & inject the `origin` dimension server-side The **derivation** half of WP-O2 in the origin rename ([serenity-docs#46](adobe/serenity-docs#46)). Tracks **LLMO-6275** (epic LLMO-6270). > **Stacked on WP-O2a.** Base is `claude/wp-o2a-origin` ([#2862](#2862)), so this diff is *only* the derivation — it builds on O2a's `DIMENSION.ORIGIN`, `ORIGIN_VALUE`, `STANDARD_PROMPT_TAG_VALUES`, and the tolerant `ensureDimensionRoots` resolver. Review/merge O2a first. **Draft — do not merge.** `origin` (who authored a prompt's text: `human` / `ai`) becomes a function of the **write path**, never a caller-supplied field, with the create/update asymmetry [origin-dimension.md §3](adobe/serenity-docs#46) requires. ### Serenity tag path — `handlers/prompts.js` + `prompts-subworkspace.js` - `makeTypeInjector` → **`makePromptTagInjector`**, now stamping both `type` and `origin`: - **CREATE** strips any caller-supplied tag id beneath the `origin` root (by **resolved id, never by name** — a customer category named `ai` survives) and injects the derived `human`. - **UPDATE** leaves `origin` alone — the stored value the caller echoes rides through the replace-mode write, **never re-derived** (re-deriving would relabel an edited `ai` prompt `human`; stripping-without-injecting would make it invisible — both illegal). - `resolveClosedValueInjection` generalizes `resolveTypeValueInjection` (the origin root is resolved tolerantly, so it addresses whichever physical root — `origin` or a legacy `source` — the project carries). ### v2 prompts API — `controllers/brands.js` + `prompts-storage.js` - `createPromptsByBrand` derives `origin` from the **principal**: an IMS/JWT **user** → `human` (body ignored, never rejected); a **service principal** (admin `x-api-key`, e.g. DRS) → validated body value — the DRS `origin:'ai'` contract stays honoured. - `upsertPrompts` preserves the stored `origin` on a match-update; `updatePromptById` no longer patches `origin`; `mapRowToPrompt` returns `row.origin` verbatim (no `|| 'human'`). - OpenAPI: `origin` documented as service-principal-only / read-only for users and not patchable on update; the `origin` query filter + sort enum stay. The user-facing elmo write surface (Source picker, CSV import) is **WP-O3b**, a separate WP — not here. ### Gates ([origin-dimension.md §7](adobe/serenity-docs#46)) - **5** (a user cannot write origin) — v2 arm + Serenity create arm ✅ - **6** (a service principal can) — DRS `origin:'ai'` honoured ✅ - **7** (editing does not relabel) — an `ai` prompt stays `ai` across an edit ✅ - **8** (strip by id) — a category named `ai` survives a create carrying an origin id ✅ ### Verification - `npm test` **exit 0** — 15285 passing, coverage thresholds met. - `npm run type-check` clean; `eslint` clean on all touched paths; `docs:lint` valid (only pre-existing warnings, incl. the unrelated `/configurations/` ambiguity). - `test/it/` integration is **out of scope** — it needs WP-O1 ([spacecat-shared#1831](adobe/spacecat-shared#1831)) released for the PE-client mock image; not run here. --------- Co-authored-by: Alicia Adriani <aadriani+adobe@adobe.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
solaris007
pushed a commit
that referenced
this pull request
Jul 21, 2026
# [1.674.0](v1.673.3...v1.674.0) (2026-07-21) ### Bug Fixes * **deps:** trigger prod deploy for spacecat-shared-data-access 4.11.0 (LLMO-6401) ([#2879](#2879)) ([038e4da](038e4da)) ### Features * **serenity:** derive + inject prompt origin server-side — WP-O2b (LLMO-6275) ([#2866](#2866)) ([331071f](331071f)), closes [#2825](#2825) [#2867](#2867)
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.
Summary
Part of the origin-dimension rename: adobe/serenity-docs#46. Combines WP-O2a (tolerant resolver + root rename) and WP-O2b (derivation).
WP-O2a
DIMENSION.SOURCE→DIMENSION.ORIGIN,SOURCE_VALUE→ORIGIN_VALUE, etc. inprompt-tags.jsresolveAuthorshipRootintag-tree.js: reuses an existingoriginroot, else adopts a legacysourceroot only if its children ⊆{ai, human}, else mints a neworiginroot. Wired intoensureDimensionRoots.handlers/tags.js,markets-subworkspace.js,brand-provisioning.js,serenity.jsneeded no changes — they already resolve via the shared constants.src/support/elements/**untouched (separate, already-flagged production-triage concern).WP-O2b
makeTypeInjectornow strips+injectsorigin: CREATE derivesai/human, UPDATE re-injects the already-stored value, never re-derives.resolveOriginForWrite(candidate, isServicePrincipal): service principal may assert a value (invalid falls back tohuman), user principal always overridden tohuman.originPATCH path fromupdatePromptByIdand the|| 'human'fallback frommapRowToPrompt.originas service-principal-only on write.Test plan
test/controllers/audits.test.jsorder-dependent flakes, unrelated, pass in isolation)tsctype-check cleanit-postgresserenity IT suite not updated — it drives the real mock Docker image still pinned at@adobe/spacecat-shared-project-engine-client@1.10.0(pre-WP-O1). Needs a follow-up once WP-O1: rename authorship tag root from source to origin (PE-client mock) spacecat-shared#1815 (WP-O1) releases and this repo's dependency bumps.Depends on: adobe/spacecat-shared#1815 (WP-O1) for full IT verification.
Closes #2816, #2817
Jira: SITES-48001, SITES-48002 · Tracking: cross-repo plan in adobe/serenity-docs#46
🤖 Generated with Claude Code