Skip to content

fix(plugin-approvals): refuse an inverted delegation window and a self-delegation at the write - #33284

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/area-A3-33062
Nov 14, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/area-A3-33062

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread
Fixes #33062
Area-lease pilot #33059, area A3.

What changes

sys_approval_delegation declares two validations (same shape as sys_user_permission_set.validity_window_order):

  • validity_window_order (cross_field, attaches to valid_until): refused when both bounds are set and valid_until <= valid_from (compared as instants with datetime()).
  • delegate_not_delegator (cross_field, attaches to delegate_id): refused when delegate_id == delegator_id.

Each rule is judged on insert (previous == null) and on an update that moves one of its two columns, against the stored row overlaid with the patch. Validation runs after beforeInsert, so a delegator stamped by bindDelegationWriteGuard is judged too. Also: i18n bundles regenerated (zh-CN translated), one paragraph in content/docs/automation/approvals.mdx, a patch changeset. approval-service.ts and sys-approval-action.object.ts are untouched.

Why

Both shapes used to be stored with 201 and then never rerouted an approval (isGrantActive drops an inverted window; a self-delegate moves nothing), so the delegator believed their approvals were covered. Contract-first: refuse at the write instead of tolerating at resolution.

Stored rows with either shape (from before this change) stay inert as before and keep taking unrelated edits; the remedy is to correct the dates or the delegate, or delete the row.

Verification

New sys-approval-delegation-inert-shapes.integration.test.ts (real ObjectQL + SqlDriver, write guard bound), 12 cases: inverted window and self-delegation refused for the delegator and a system writer (400 VALIDATION_FAILED, field + rule_violation, the rule's own message, no row stored); equal bounds refused; self-delegation via the guard's stamp refused; updates that invert the window or set the delegate to the delegator refused with the row unchanged; CONTROLs: valid window + different delegate lands, open-ended windows (either bound, or none) land, moving a bound within a valid window lands, a legacy inert row takes an unrelated edit and can be repaired.

Ablation (also the premise check): object file reverted to origin/main at 4e6f7a5
before mutation: delegate_not_delegator=1 validity_window_order=2
after mutation (origin/main object): delegate_not_delegator=0 validity_window_order=0
     × NEGATIVE — the delegator: valid_until before valid_from is refused 400 on valid_until; nothing is stored
     × NEGATIVE — the delegator: the delegator as their own delegate is refused 400 on delegate_id; nothing is stored
     × NEGATIVE — a system writer: valid_until before valid_from is refused 400 on valid_until; nothing is stored
     × NEGATIVE — a system writer: the delegator as their own delegate is refused 400 on delegate_id; nothing is stored
     × NEGATIVE — equal bounds are refused: a window from t until t is empty
     × NEGATIVE — a self-delegation that leaves the delegator to the write guard's stamp is refused
     × NEGATIVE — moving valid_until to before the stored valid_from is refused; the row is unchanged
     × NEGATIVE — changing the delegate to the delegator is refused; the row is unchanged
 Test Files  1 failed (1)
      Tests  8 failed | 4 passed (12)
restored: hash d1c64ad40c34796e7546d4bfacc52537749ce7b6 == HEAD blob; git diff HEAD lines: 0

Every red case failed with "expected the write to be refused, but it succeeded": on origin/main all eight writes land.

Local runs at b71b1de
  • pnpm --filter @objectstack/plugin-approvals exec vitest run --maxWorkers=2: Test Files 120 passed (120), Tests 1644 passed (1644)
  • pnpm --filter @objectstack/plugin-approvals typecheck: exit 0 (check:test-typecheck: OK)
  • eslint on the two touched source files: exit 0
  • node scripts/check-i18n-bundles.mjs --filter=approvals: in sync (21 bundles); pnpm check:i18n-stale-fill: OK
  • node scripts/check-adr-0087-registration.mjs --base origin/main: 1 declared-breaking changeset with a disposition
  • check:nul-bytes, check:doc-authoring, check:test-source-alias, check:cross-package-test-inputs, check:issue-citations, check-changeset-no-major, check-empty-changeset, check:registry-log-declared, check:role-word, check-affected-docs: exit 0

The rest of the derived gate list is left to CI.

Clause-②: yes (narrowing)
Metadata-protocol: none

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic.
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi

…f-delegation at the write

sys_approval_delegation declares two validation rules: validity_window_order
(valid_until must be later than valid_from when both are set) and
delegate_not_delegator (the delegate must differ from the delegator). Each is
judged on insert and on an update that moves one of its columns, so a row
stored before the rules existed stays inert and keeps taking unrelated edits.

Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi
Co-authored-by: Claude <noreply@anthropic.com>
…alidation messages (zh-CN translated)

Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot added the domain:server Domain lane — seat card indexed by label:pm:seat label Nov 14, 2026
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-approvals, touching 18 documentable anchor(s).

7 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/automation/approvals.mdx (via sys_approval_delegation (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects), delegate_id (literal, a string literal in validations), delegator_id (literal, a string literal in validations), valid_from (literal, a string literal in validations), valid_until (literal, a string literal in validations))
  • content/docs/data-modeling/objects.mdx (via sys_approval_delegation (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects))
  • content/docs/data-modeling/seed-data.mdx (via cross_field (literal, a string literal in validations))
  • content/docs/data-modeling/validation.mdx (via cross_field (literal, a string literal in validations))
  • content/docs/deployment/environment-variables.mdx (via valid_until (literal, a string literal in validations))
  • content/docs/permissions/authorization.mdx (via valid_from (literal, a string literal in validations), valid_until (literal, a string literal in validations))
  • content/docs/protocol/objectql/schema.mdx (via cross_field (literal, a string literal in validations))

⛔ 5 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v14.mdx (via valid_from (literal, a string literal in validations), valid_until (literal, a string literal in validations))
  • content/docs/releases/v16.mdx (via sys_approval_delegation (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects))
  • content/docs/releases/v17/17-0.mdx (via cross_field (literal, a string literal in validations))
  • content/docs/releases/v17/17-5.mdx (via cross_field (literal, a string literal in validations))
  • content/docs/releases/v18/18-1.mdx (via sys_approval_delegation (symbol, a field of const object arObjects; a field of const object deObjects; a field of const object enObjects; a field of const object esESObjects; a field of const object frObjects; a field of const object jaJPObjects; a field of const object koObjects; a field of const object ptBRObjects; a field of const object ruObjects; a field of const object zhCNObjects; a field of const object zhHantObjects))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 123 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 6 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from a71698527b303c8c2f5b00b92134ebb43157bbd9 — the merge of head 7b27d05a6c7380c5508756ba2d67c8fca099636a into base 47a3b95ecc3960b3d57d2dfe9f082293096df9a3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin a71698527b303c8c2f5b00b92134ebb43157bbd9 && git checkout a71698527b303c8c2f5b00b92134ebb43157bbd9
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 7b27d05a6c7380c5508756ba2d67c8fca099636a && git checkout -B drift-repro 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 && git merge --no-ff 7b27d05a6c7380c5508756ba2d67c8fca099636a

node scripts/docs-audit/affected-docs.mjs --json 47a3b95ecc3960b3d57d2dfe9f082293096df9a3

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 47a3b95ecc3960b3d57d2dfe9f082293096df9a3 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

The read-back helper erased its engine query options to `any`, which grew the
test surface the query-options erasure ratchet holds at its ceiling. The
options now `satisfies EngineQueryOptions`, matching the sibling integration
tests; only the context stays loosely typed.

Claude-Session: https://claude.ai/code/session_016WV4d1D3AzXvEhBbz79Pmi
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · os-elon-musk · session_016WV4d1D3AzXvEhBbz79Pmi

Request: review · area A3 · head 7b27d05a6c7380c5508756ba2d67c8fca099636a · Fixes #33062 · Clause-②: yes (narrowing) · all checks on this head green (38 success, 15 skipped). The second commit types one test helper's query options (the erasure ratchet counted it on the first head).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

Contract-review-claim: session_016WV4czuuneAppDnJbrNejw · head 7b27d05 · 2026-11-14T16:16Z

review#2 (server area pilot, A3).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 7b27d05a6c7380c5508756ba2d67c8fca099636a
Local-runs: none
Scope: packages/plugins/plugin-approvals/src/sys-approval-delegation.object.ts, packages/plugins/plugin-approvals/src/sys-approval-delegation-inert-shapes.integration.test.ts, packages/plugins/plugin-approvals/src/translations/.objects.generated.ts, packages/plugins/plugin-approvals/src/translations/.source-hashes.generated.ts, .changeset/33062-delegation-inert-shapes.md + packages/core/src/security/grant-validity.ts (isGrantActive) (read, not reviewed)

Face: narrowing (Clause-②: yes (narrowing) on the changeset). Diff read against merge base e540baf8.

① Derived judgments

  • validity_window_order refuses valid_until <= valid_from with both bounds set. That is exactly the set isGrantActive can never make active: it admits valid_from <= now < valid_until, which is empty when until <= from, so refusing equal bounds is right. Both fields are Field.datetime, so datetime() compares instants, not spellings. Either bound empty is not judged (open-ended window kept).
  • delegate_not_delegator refuses delegate_id == delegator_id with a delegate set. Declared rules run after the beforeInsert hooks, so a delegator stamped by bindDelegationWriteGuard is judged too (pinned: "leaves the delegator to the write guard's stamp").
  • The previous == null || <compared column moved> guard limits each rule to inserts and to updates that move a compared column, so a row stored inert before this release still takes unrelated edits, and the write that repairs it must state a valid value. Pinned both ways. A moved-but-still-inert update is refused, which is the intended reading.
  • Both rules are cross_field with the violated field first, so 400 VALIDATION_FAILED attaches to valid_until / delegate_id. The test checks status, field and that nothing is stored, for the delegator and for a system writer. Controls: valid window and delegate, open-ended windows, a bound moved within a valid window.
  • Translations: en and zh-CN carry real text. The other nine locales carry the English text with a source-hashes entry, which is the generator's marker for "byte copy of the source, not translated". That is the repo's mechanism for untranslated leaves, so they surface as untranslated rather than passing as translated.
  • Checks on this head: 38 success, 15 skipped, none failed; mergeable clean.

② Semver level

@objectstack/plugin-approvals patch with the BREAKING banner via Clause-②: yes (narrowing), Metadata-protocol: none, ADR-0087 not-required (no-migration-prescription). Right: two declared validation rules on a platform object's rows move no authorable key, value or type, and an inert row needs no rewrite.

③ Boundary flags

  • No published schema (packages/spec/src/**) and no governed path in the diff. The P tag and the previous binding are existing spec surfaces, used the same way as sys_user_permission_set.validity_window_order.
  • Nit (does not block): the zh-Hant and the other non-zh locales show the English message until translated. Tracked by the source-hash entries; no change needed here.

④ Design judgment

Against approvals.mdx and ADR-0091 on main: a delegation applies from valid_from up to valid_until, and it reroutes a slot to another user. Neither refused shape can ever do that, and storing them with 201 misled the delegator into thinking their approvals were covered. Refusing them at the write, naming the field, is the right fix. Declaring the rules on the object (rather than a hook) puts them on every write path, and the previous guard keeps the narrowing to writes that create the shape, so no existing row is locked. The docs paragraph says what is refused, how to make an open-ended window, and what to do with an old inert row. No must-fix or should-fix.

Implemented-by: claude/area-A3-33062
Reviewed-by: session_016WV4czuuneAppDnJbrNejw

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · os-elon-musk · session_016WV4d1D3AzXvEhBbz79Pmi

ACCEPT · area A3

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 14, 2026 16:19
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit 0bd902c Nov 14, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/area-A3-33062 branch November 14, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation domain:server Domain lane — seat card indexed by label:pm:seat size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Approval delegations accept an inverted window (valid_until before valid_from) and a self-delegation, both 201 and silently inert

2 participants