Skip to content

fix(registry): make a manifest's declared driver identity persist - #1734

Merged
lilyshen0722 merged 5 commits into
mainfrom
kai/task043-native-manifest-runtime
Sep 18, 2026
Merged

lilyshen0722 merged 5 commits into
mainfrom
kai/task043-native-manifest-runtime

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes TASK-043. routes/registry/install.ts falls back to the registry manifest's declared runtimeType when the caller omits one — the path a native first-party app installed from the Hub takes, because the Hub's install POST sends no runtimeType of its own. That fallback read a field the schema could not store.

Measured, before the fix

new AgentRegistry({ manifest: { runtime: { type: 'native', runtimeType: 'native' } } })
  .toObject().manifest.runtime   →   { type: 'native', connection: 'mcp' }
AgentRegistry.schema.path('manifest.runtime.runtimeType')  →  undefined

ManifestRuntimeSchema is strict: true with no runtimeType path, so every write dropped the identity while keeping type: 'native' — a value the schema's own enum (standalone / commonly-hosted / hybrid) refuses, stored only because findOneAndUpdate does not run validators by default. So an install landed with runtimeType unset, agentEventService queued its events for the external queue, and nothing listened: an in-process agent that never replies.

The route's test stayed green because its fixture was a hand-written object, not a shape the schema can produce. That gap is the defect behind the defect.

The fix

file change
models/AgentRegistry.ts declare runtimeType on ManifestRuntimeSchema — the driver identity axis, next to type's deployment shape
scripts/seed-native-agents.ts one exported buildRegistryManifest(app) used by both the $set and $setOnInsert manifests: declares the identity, writes no enum-invalid type. Refreshed on every boot like the rest of the manifest, so existing first-party rows pick it up on deploy — no backfill script
utils/agentManifestRegistry.ts carry runtimeType through publish normalization (free token, not an enum, so a new driver needs no release) and refuse a deployment-shape value in that field

Scope note for review: the publish pass-through is here because without it the new schema path has exactly one writer — the boot seeder — and the fallback stays dead for every agent that arrives through publish. Say the word and I will split it out; the model + seeder change stands alone.

Evidence

  • agentRegistry.manifestRuntime.test.js (new): identity survives the constructor, survives an upsert with $set on a real row (the seeder's write path — construction and update are separate Mongoose paths), an undeclared field is still stripped, and type: 'native' still fails the enum.
  • registry.install-runtime-type.test.js: the fallback fixture is now round-tripped through the real model, so deleting the schema path breaks the route test too.
  • seed-native-agents.config.test.js + agentManifestRegistry.test.js: the seeder's manifest shape and the validator's pass-through/refusal.
  • Mutation check: removing runtimeType from ManifestRuntimeSchema fails 4 tests — including copies manifest.runtime.runtimeType into the installation when the caller omits runtimeType.
  • npx jest __tests__/unit/{routes/registry,models,utils,scripts} → 84 suites, 544 tests pass. npm run lint:ts → 0 errors. npm run tsc:check → exit 0.

Not touched: deployment-shape semantics (no existing reader of manifest.runtime.type; frontend has none), the install route's own logic, or the cloud-entitlement gate.

Addendum — head moved to 4b588411 (base refreshed onto 3058d7c8, #1733 merged)

Two test commits on top of the fix:

  1. The cloud gate against a manifest-declared runtimeType. Publish is plain auth, so with the field persisting any owner can declare one, and install.ts copies the manifest value before the gate reads it. Pinned: an unentitled non-admin installing an agent whose manifest declares native gets 403 cloud_agents_not_entitled (a manifest is not a bypass), and an explicit caller runtimeType beats the manifest (a manifest edit cannot re-shape an install the caller already typed). Both fixtures come from the real schema; each fails under its own mutation.
  2. fix(agents): exempt native installs from the staleness sweep, add revive script #1733's seeder-shape assertion. Its merged test asserted the seed upsert "keeps manifest.runtime.type and drops runtimeType" — exactly the shape this PR inverts, so it reds on the refreshed base. The assertion is inverted; the type fallback it guards stays asserted, because every row the old seeder wrote still carries enum-invalid type:'native'.

Suites over routes/registry + models + utils + scripts: 44 suites / 210 tests green, lint:ts 0 errors, tsc:check exit 0.

Open, deliberately not decided here (Vera 69355, card to Sam): restoring the field makes effectiveRuntimeType resolve to native for a first-party builtin app installed from the Hub, and native is in CLOUD_RUNTIME_TYPES — so a non-entitled non-admin now gets 403 where the install previously "succeeded" with a runtimeType that went nowhere (a dead agent). Whether first-party builtin apps should be exempt from that gate is policy, not code shape. The tests above pin the mechanism and hold under either ruling.

Entitlement gate: no exemption — head bf043234

Decision card 69363 ruled option 1, keep the gate (Sam 69366), overriding Wren's 69361 key and Sam's own earlier 69364 confirmation in chat. An exemption was briefly implemented at ef8d8ff7 and is reverted at bf043234; the tree is byte-identical to 4b588411 (git diff --quiet 4b588411 HEAD exits 0), so a re-gate is a zero-diff re-clear.

Why the gate is right, checkable in the repo rather than by intent: the first-teammate path never enters this route. authController.ts:215 installs Scout at registration by writing AgentInstallation directly with buildInstallationConfig(scoutApp), and personaHireService.ts:79-93 does the hire install with findOneAndUpdate + upsert. The cloudAgents gate exists only in routes/registry/install.ts, so its actual subject is a non-admin adding further native apps from the Hub — which is exactly the path #529 routes to the BYO flow. Exempting it would widen who can consume platform compute with no pricing sentence behind it.

Kept from the entitlement work (non-admin, non-entitled): a community row declaring native still 403s, and an explicit caller runtimeType still beats the manifest. The exemption patch itself is preserved in history at ef8d8ff7 should it ever come back as its own product row.

Suites over routes/registry + models + utils + scripts + security: 95 suites / 685 tests green, lint:ts 0 errors, tsc:check exit 0.

install.ts reads manifest.runtime.runtimeType to fill a runtimeType the caller
omitted — the path a native first-party app installs through, since the Hub
sends no runtimeType of its own. No schema path existed for that field and
ManifestRuntimeSchema is strict, so every write dropped it: the fallback could
never fire and a hand-written test fixture kept it green.

- declare runtimeType on ManifestRuntimeSchema (driver identity;  stays
  the deployment shape, whose enum kept refusing 'native' — the value the
  seeder was writing into it)
- seed-native-agents: one buildRegistryManifest, identity only, no enum-invalid
  ; refreshed on every boot like the rest of the manifest
- agentManifestRegistry: carry runtimeType through publish normalization, and
  refuse a deployment shape in that field
- tests: model round-trips (constructor + upsert), the route fixture now comes
  from the real schema, seeder and validator coverage

Measured before the fix: new AgentRegistry({manifest:{runtime:{type:'native',
runtimeType:'native'}}}).toObject() == {type:'native',connection:'mcp'}.
Removing the schema path again fails 4 tests, the route fallback included.
@lilyshen0722
lilyshen0722 force-pushed the kai/task043-native-manifest-runtime branch from 65ee104 to 119f182 Compare September 18, 2026 08:16
…eType

Wren's shape read (69353) calls the entitlement consequence out as the thing to
get right: publish is plain `auth`, so with runtimeType now persisting any
owner can declare one, and install copies the manifest value BEFORE the gate
reads it. These two cases pin that shape:

- a manifest-declared 'native' install by a non-admin, non-entitled installer
  is refused with cloud_agents_not_entitled (the manifest is not a bypass)
- an explicit caller runtimeType wins over the manifest, so a manifest edit
  cannot re-shape an install the caller already typed

Both fixtures come from the real schema, so they fail if the schema path goes
away again — verified: dropping runtimeType fails the first, letting the
manifest overwrite the caller fails the second.

Open, for Vera's 69355 and Sam's ruling: whether a first-party BUILTIN native
app (scout, pod-welcomer, …) should stay entitlement-gated like every other
in-process runtime, or be exempt as the onboarding wedge. That is policy, not
code shape — this commit pins the mechanism either way.
…back asserted

#1733's suite pins the seeder shape it was written against — "keeps
manifest.runtime.type and drops runtimeType" — and that assertion is exactly what
TASK-043 inverts, so it fails against this branch (1 of 44 suites, on the merged
base).

The guard's intent survives the fix and stays asserted: every row the OLD seeder
wrote still carries enum-invalid type:'native' (findOneAndUpdate does not run
validators), so declaredExemptRuntime's `type` fallback is still load-bearing —
and the read-order test above it already pins runtimeType-first, which is what
makes the two PRs order-independent as Wren described.
Ruling (Wren 69359/69361, Sam 69364): first-party native apps are
entitlement-free, so the 403 the restored manifest runtimeType produced is not
intended. Scout reaches every signup ungated — authController upserts it at
workspace creation, capped by dailyRunCap — so gating the Hub copy of the same
app would gate a thing we hand out at signup. cloudAgents exists for the
operator-run tiers; the in-process native runtime is the capped one.

Exemption = effectiveRuntimeType native AND the row itself declares native AND
registry 'commonly-official' AND verified. The row, never manifest content:
publish is plain auth, so an exemption earnable by declaring 'native' would hand
any publisher in-process compute for free. Requiring the row to declare native
stops an official row's provenance being borrowed by an explicit caller
runtimeType to skip another tier's gate.

Tests (non-admin, no entitlement): official+verified native installs and
persists runtimeType; community-declared native 403s; official row that does not
declare native 403s; unverified official 403s. Mutations: dropping the exemption
fails the first, dropping the declares-native half fails the third.
…loud gate"

Decision card 69363 ruled option 1 — keep the gate (Sam 69366). The first-party
native exemption this reverts was implemented on Wren's 69359/69361 key and Sam's
69364 confirmation; Sam then overrode both, and the reason is checkable in the
repo: the first-teammate path never meets this gate. Scout is installed at
registration by the server (authController.ts:215, buildInstallationConfig) and
the hire path writes the model directly (personaHireService.ts:79-93), neither of
which goes through routes/registry/install.ts — the gate is route-level only. Its
actual subject is a non-admin adding further native apps from the Hub, and #529
deliberately routes that 403 to the BYO flow; exempting it would widen who can
consume platform compute without a pricing sentence behind it.

Content is byte-identical to 4b58841 (git diff 4b58841 HEAD is empty), so
re-gating is a zero-diff re-clear. The exemption itself is preserved in history
at ef8d8ff should a product row for it land. Non-admin tests kept: a community
row declaring native 403s, and an explicit caller runtimeType beats the manifest.

This reverts commit ef8d8ff.
@lilyshen0722
lilyshen0722 merged commit 7cba52c into main Sep 18, 2026
19 checks passed
lilyshen0722 added a commit that referenced this pull request Sep 18, 2026
…ips the schema, and a guard set enumerated by its refusal code (#1735)

Rule 24 (Tests and assertions): a test whose fixture builds its own document
proves the reader can read a field, never that the field can be there. The
write is where a strict schema drops what the reader expects, and
findOneAndUpdate does not run validators — so both failure halves can coexist
with a green suite. Check: for each cross-layer read, confirm the writing
schema declares the path and that one test round-trips through the real model.

Rule 25 (Guards and predicates): enumerate a guard set by the refusal code the
client branches on, not by the predicate. Two guards refusing the same thing
for the same stated reason can be implemented by different mechanisms, so a
predicate grep returns a closed-looking set that is not closed.

Both earned by TASK-043 / PR #1734.
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.

1 participant