Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

The object-field options editor silently DROPS default and visibleWhen on every save — and the loss starts in readOptions, not in the writer #7540

Closed

Description

@os-project-manager

Filed unassigned as a sub-issue of objectui#7014, whose Tier-1 row 3 already records the TYPE-level half of this (the module-local interface Option in ObjectFieldInspector.tsx declares value / label / color and neither default nor visibleWhen). What this card adds is the RUNTIME consequence, and one measurement that changes where the repair has to start.

Raised by the domain:ui execution seat while implementing objectui#7014 Q1, and deliberately NOT folded into that PR — the reasoning is in the Q1 report on objectui#7014 and repeated at the bottom here.

The defect

packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx. An author opens any picklist field in the metadata-admin designer, edits any option, and saves. Both default and visibleWhen are gone from the written document. It is not a 422 — the payload is perfectly valid — it is silent data loss of two keys the platform honours.

Where the loss actually happens — the reader, before the writer ever sees it

The writer (patchOptions, around line 383) projects to three keys:

const clean = next.map((o) => {
  const out: Option = { value: o.value };
  if (o.label) out.label = o.label;
  if (o.color) out.color = o.color;
  return out;
});

but the values are already gone by then. readOptions (around line 76) is the projection that loses them:

return raw.map((o: any) => ({
  value: String(o?.value ?? ''),
  label: typeof o?.label === 'string' ? o.label : undefined,
  color: typeof o?.color === 'string' ? o.color : undefined,
}));

That matters for how the card is sized, and it is the reason a writer-only patch cannot close it: whatever patchOptions is taught to carry, it can only carry what readOptions handed it, and readOptions hands it three keys. The repair spans reader plus local type plus writer, not the writer alone.

It also means this is untouched by, and does not conflict with, the patchOptions label-guard change in PR #7536 — different keys, different mechanism, and that fix stays correct as it stands.

The measurement

Re-measured by me on the installed @objectstack/spec 17.2.0, with both controls lit before any row was trusted:

CONTROL clean  { value:'alpha', label:'A' }                ACCEPT  parsed={"label":"A","value":"alpha"}
NEG-CONTROL    { value:'a',     label:'A' }                REJECT  too_small@[value]
default: true                                              ACCEPT  parsed={…,"default":true}
visibleWhen: "x > 1"      (string)                         ACCEPT  parsed={…,"visibleWhen":{"dialect":"cel","source":"x > 1"}}
visibleWhen: {dialect:'cel', source:'x > 1'}               ACCEPT  parsed={…,"visibleWhen":{"dialect":"cel","source":"x > 1"}}
visibleWhen: true         (boolean)                        REJECT  invalid_union@[visibleWhen]
CONTROL unknown key { …, zzz:1 }                           REJECT  unrecognized_keys@[](zzz)

Two usage notes worth carrying, because both cost a reading when they were missed:

  • A select option's value must be at least 2 characters. A one-character value poisons every row with too_small@[value], and the rows that are actually about visibleWhen then say nothing at all. Use something like alpha, and make the clean control ACCEPT before trusting any other line.
  • The boolean form of visibleWhen is REFUSED, not accepted. It is the STRING form that is accepted and canonicalized into the expression envelope. An earlier writeup attributed that canonicalization to the boolean row; if you quote this behaviour, quote the table above.

So both dropped keys are keys the spec ACCEPTS, and default is ruled enforce on the object-field face (objectstack#7246, implemented by PR #7388) — the engine seeds the insert path from the option marked default: true. An author who sets a picklist default in the designer, or who authored one in a *.form.ts, loses it the next time anyone edits that field in the UI.

What has to be decided before this is implementable

The mechanical part is small. The part that is not mechanical, and the reason this is a card rather than a drive-by:

The inspector has no per-option UI for either key. The CelPredicateField uses in that file are FIELD-level — they write through patchDef({ visibleWhen: … }) — so there is no per-option control to wire up. That leaves at least two shapes, and they are different products:

  1. Preserve what the editor does not display. readOptions keeps the whole authored option and patchOptions writes back the untouched keys, so the editor stops being lossy for anything it has no opinion about. Cheapest, and it also protects any key added later.
  2. Author them. Give the option row real per-option controls for default (a radio across the option list, since at most one can hold it) and visibleWhen (a CelPredicateField per option). Much larger, and it is a genuine design question about that panel.

Related history worth reading before choosing: objectui#6247 covered per-option visibleWhen in metadata-admin from the renderer side.

Whichever way it goes, note the shape to avoid: widening the local Option type WITHOUT moving the reader and the writer would declare two keys the editor still cannot carry — a declared-but-not-carried divergence, which is the exact shape objectui#7014 exists to remove.

Why this is not in the Q1 PR (objectui#7538)

Q1's ruled scope is the Tier-1 named types, and its diff lives entirely in @object-ui/types. Taking this on would have: put a second in-flight claim on a file another seat is already changing (PR #7536, not yet merged); moved the diff into @object-ui/app-shell, a different package with its own type-check, its own large suite and its own gate face that the Q1 diff does not otherwise carry; and required the design call above, which is not a mechanical repair. Recorded here instead of done quietly.

Generated by Claude Code

Activity

  1. claude commented on Sep 4, 2026

    @claude
    Contributor

    os-dev-report

    {
      "issue": 7540,
      "status": "done",
      "branch": "claude/issue-7540-option-editor-key-loss",
      "pr": "https://github.com/objectstack-ai/objectui/pull/7629",
      "premise_still_valid": true,
      "summary": "Implemented shape 1 only, as scoped: the loss site was the READER, so `readOptions` now keeps the whole authored option (parking keys the editor has no control for on a module-local carrier) and `patchOptions` spreads that carrier's contents back into the written document, displayed keys last. All three parts -- `interface Option`, reader, writer -- moved together, per the card's declared-but-not-carried fence. Round trip measured, not asserted: one Label edit on an option carrying color+default+visibleWhen wrote 2 keys before and 5 keys after. No authoring UI was added and no fenced path was touched; the #7536 label repair is untouched and its 5 pins stay green in every run.",
      "tests": "ALL RUNS ON 7001725f (tree as pushed, working tree clean). Exit codes captured by redirect to file, never through a pipe. (1) New + existing pins: `pnpm exec vitest run .../ObjectFieldInspector.optionKeyPreservation.test.tsx .../ObjectFieldInspector.optionLabel.test.tsx --maxWorkers=2` -> `Test Files 2 passed (2)` / `Tests 15 passed (15)`, lock VERDICT command-exit 0. (2) Containing subtree: `pnpm exec vitest run packages/app-shell/src/views/metadata-admin/ --maxWorkers=2` -> `Test Files 226 passed (226)` / `Tests 2341 passed | 1 skipped (2342)`, VERDICT command-exit 0 (held lock 8m34s). (3) Dependent closure from vitest's OWN module graph: `pnpm exec vitest related --run .../ObjectFieldInspector.tsx` -> `Test Files 53 passed (53)` / `Tests 414 passed (414)`, spanning exactly metadata-admin + studio-design. (4) `pnpm exec turbo run type-check --concurrency=2` (WHOLE REPO) -> `Tasks: 81 successful, 81 total`, VERDICT command-exit 0. (5) `pnpm exec eslint` on both changed files -> exit 0, `12 problems (0 errors, 12 warnings)`; the 12 are pre-existing (`: any` count is 1 at origin/main and 1 at HEAD). (6) `node scripts/check-changeset-presence.mjs` -> exit 0, verdict line: `1 source file(s) of 1 released package(s) changed, and this change declares 1 changeset(s)`. `pnpm run changeset:check` -> exit 0, fixed-group and no-major both green. TYPE-CHECK COVERAGE MEASURED, NOT ASSUMED: the package runs `tsc --noEmit && tsc -p tsconfig.test.json`; `--listFiles` on that second program contains the new test file (count 1) and the changed source (count 1), so the new test really is type-checked. ABLATION: restored the ORIGINAL `readOptions` projection only, leaving the repaired writer in place -- the sharpest test of the card's claim that the reader is the loss site. Predictions written before the run; observed matched case-for-case, 10 of 10. Ablated totals `Tests 7 failed | 8 passed (15)` vs repaired `15 passed (15)`. RED: default on untouched row, default on edited row, visibleWhen string form, visibleWhen envelope form, both keys together, carrier-never-leaks, spec-refused-key-carried. GREEN as predicted: 'written option ACCEPTED by SelectOptionSchema and FieldSchema' -- dropping both keys still yields a document the contract accepts, which is precisely why the bug was silent and why a validity test can never detect it; kept in the suite as a deliberate non-detector. Also green as predicted: the pure-contract controls, the nothing-extra case, and all 5 of the #7536 pins. NO REBUILD LEG APPLIES and this was checked rather than skipped: the test imports './ObjectFieldInspector', the relative SOURCE, not a package dist, so vitest resolves the mutated file directly -- there is no dist that could serve a stale copy. MUTATION CONFIRMED ON DISK before reading any result: injected old-projection anchor count 1 (expected 1), removed carrier-attach anchor count 0 (expected 0), blob 31c5cf3e -> b490fcf0. RESTORE PROVEN: `git checkout HEAD -- ABSOLUTE_PATH` (trap on EXIT INT TERM with an absolute path), then blob back to 31c5cf3e == HEAD's blob AND `git diff HEAD` empty. DECLARED NARROWING: the full `packages/app-shell/` suite is 615 test files and its 226-file metadata-admin subset alone took 8m34s on the shared box, so it cannot finish inside the 10-minute foreground ceiling; CI runs it in full regardless. What was run instead is the complete transitive dependent closure, with all three evidences: population from the tool (vitest `related` walked its own module graph, 53 files, two directories), counts from the tool's output (53/414 and 226/2341), and invariance for untouched files (the diff's three touched symbols -- `interface Option` line 95, `readOptions` line 125, `patchOptions` line 449 -- are all module-local with no export modifier; the file's only export is the component at line 258 with an unchanged signature, and the whole-repo type-check 81/81 confirms no type consumer moved). Repo-wide `pnpm lint` is CI-owned; `eslint.config.js` declares no projectService and no parserOptions.project, so type-aware linting is off and a one-file diff cannot move the verdict on any file it does not contain. NOT MEASURED: no browser dogfood run (verified at the component's write boundary and against the contract, not by driving the designer). NOT MEASURED: CI gate outcomes -- reported at draft-PR time per the dispatch contract.",
      "mcp_calls": "2 -- issue_read(get) and issue_read(get_comments). The PR create, the full body read-back and this comment all went over REST curl after a repo-scoped REST read probe returned HTTP 200.",
      "open_questions": [
        {
          "question": "NON-BLOCKING, already decided and shipped -- flagging the one judgement call a reviewer could reasonably want the other way. Should the editor carry through an option key that `SelectOptionSchema` REFUSES (it is strict), or keep silently dropping it? Preserving it means a save of such a document now surfaces unrecognized_keys at options[0] where it previously succeeded by quietly rewriting the author's document.",
          "options": [
            "A (shipped) -- blanket pass-through of every key the editor does not display. Matches the card's shape 1 wording ('protects any key added later') and the house precedent one level up (`readFields` preserves unknown field keys and strips only a NAMED tombstone list). Measured support: all five entries in the retired-key registry (indexed, referenceTo, formula, isSystem, sortOrder) are FIELD-level, there is no option-level entry, and this editor has only ever written the three keys it displays -- so no key it authored can come back as one the spec refuses. The pin asserts the document was ALREADY illegal before the inspector opened it, so the case cannot be misread as this PR creating a 422.",
            "B -- explicit two-key allowlist (default, visibleWhen only). Cannot ever surface a pre-existing violation, but silently launders unknown keys and needs a code change every time the spec accepts a new option key."
          ],
          "recommendation": "A, because the editor declines to hide a pre-existing contract violation rather than laundering an author's document on a read they did not ask for, and it is the same contract readFields keeps one level up. It is a behaviour change, not a contract change -- the published accept set is identical. Reversible in one line if the maintainer prefers B; say so and I will switch."
        }
      ],
      "out_of_scope_findings": []
    }

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdomain:ui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions