Skip to content

WP-O2: origin dimension — tolerant resolver + derivation#2825

Open
byteclimber wants to merge 2 commits into
mainfrom
feat/origin-dimension
Open

WP-O2: origin dimension — tolerant resolver + derivation#2825
byteclimber wants to merge 2 commits into
mainfrom
feat/origin-dimension

Conversation

@byteclimber

@byteclimber byteclimber commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Part of the origin-dimension rename: adobe/serenity-docs#46. Combines WP-O2a (tolerant resolver + root rename) and WP-O2b (derivation).

WP-O2a

  • Renamed DIMENSION.SOURCEDIMENSION.ORIGIN, SOURCE_VALUEORIGIN_VALUE, etc. in prompt-tags.js
  • Added resolveAuthorshipRoot in tag-tree.js: reuses an existing origin root, else adopts a legacy source root only if its children ⊆ {ai, human}, else mints a new origin root. Wired into ensureDimensionRoots.
  • handlers/tags.js, markets-subworkspace.js, brand-provisioning.js, serenity.js needed no changes — they already resolve via the shared constants.
  • Deliberately left src/support/elements/** untouched (separate, already-flagged production-triage concern).

WP-O2b

  • makeTypeInjector now strips+injects origin: CREATE derives ai/human, UPDATE re-injects the already-stored value, never re-derives.
  • New resolveOriginForWrite(candidate, isServicePrincipal): service principal may assert a value (invalid falls back to human), user principal always overridden to human.
  • Removed the origin PATCH path from updatePromptById and the || 'human' fallback from mapRowToPrompt.
  • OpenAPI docs updated to describe origin as service-principal-only on write.

Test plan

  • Targeted unit slice (serenity + prompts-storage + brands + serenity-controller): 1696/1696 passing
  • Full suite: 14873/14877 (4 failures are pre-existing test/controllers/audits.test.js order-dependent flakes, unrelated, pass in isolation)
  • Lint + tsc type-check clean
  • it-postgres serenity 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

…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
byteclimber requested a review from MysticatBot July 15, 2026 14:45
@byteclimber
byteclimber marked this pull request as ready for review July 15, 2026 15:29
@github-actions

Copy link
Copy Markdown

This PR will trigger a minor release when merged.

@byteclimber

Copy link
Copy Markdown
Contributor Author

Related: #2785 (intent-classification) touches the same files (prompt-tags.js, tag-tree.js) — worth reviewing/merging in a coordinated order to avoid conflicts.

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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)
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.

WP-O2a: tolerant resolver (origin/source) + root rename

1 participant