Repository navigation
fix(agents): exempt native installs from the staleness sweep, add revive script - #1733
Merged
Merged
Conversation
…ive script markStaleInstallations reads two liveness signals, an unexpired runtime token or one used since the cutoff, with AgentEvent recency as the fallback. Both are runtime-token signals in disguise: a native seat runs in-process, holds no token, and gets an AgentEvent only when a person addresses it, so a quiet pod reads as a dead agent. Measured 2026-09-18: 21 of 30 Scout installs were 'stale', and pod authorization requires 'active', so every @-mention in those pods 403'd. Native installs (config.runtime.runtimeType 'native') no longer enter the evaluation, and the updateMany filter carries the same exemption so a pair installed both natively and remotely never writes onto the native row. The legacy 'internal' runtime type is deliberately not exempt and stays swept. scripts/revive-native-installations.ts restores the rows the cron already marked: dry run by default (prints the count and a per-agent breakdown), --apply sets status back to active and clears staleSince. Idempotent; it cannot restore rows the prune step already deleted. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…e reviving them Vera's read-only count on dev found 19 stale Scout rows carrying runtimeType 'native' and 2 with no config.runtime at all, written under the early first-teammate shape on 2026-09-01/02. Reviving those two alone is a one-day fix: the sweep's `$nin` treats a missing runtimeType as sweepable, so they would go stale again at the next 04:00. The script now finds stale rows with no `config.runtime.runtimeType`, resolves each agent against its AgentRegistry row, and — only when that row declares an exempt runtime — sets the runtimeType in the same `--apply` before the revive update runs. Rows whose agent has no registry declaration are reported under `backfill.skipped` and left untouched. Dry run reports the pre-runtime subset as its own count. The registry's ManifestRuntimeSchema is strict and drops `runtime.runtimeType` on write (measured with the seed's own upsert shape; only `runtime.type: 'native'` survives), so the declaration is read from either field and only an exempt runtime name counts — a deployment-shape value never backfills. A test pins the stripping so the script cannot silently start depending on the dropped field. Co-Authored-By: Claude Fable 5.1 <[email protected]>
samxu01
pushed a commit
that referenced
this pull request
Sep 18, 2026
…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.
lilyshen0722
added a commit
that referenced
this pull request
Sep 18, 2026
) * fix(registry): make a manifest's declared driver identity persist 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. * test(registry): pin the cloud gate against a manifest-declared runtimeType 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. * test(revive): the seeder writes runtimeType now; keep the `type` fallback 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. * feat(registry): exempt first-party native installs from the cloud gate 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. * Revert "feat(registry): exempt first-party native installs from the cloud 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.
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.
What
TASK-041 (Connectors v2, Sam 69271/69274).
agentInstallationCleanupService.markStaleInstallationsmarks an install stale when the owning agent user has no unexpired runtime token, no token used since the cutoff, and no AgentEvent since the cutoff. A native seat (config.runtime.runtimeType === 'native') runs in-process and holds no runtime token, and it gets an AgentEvent only when a person addresses it, so a pod that is quiet for a week reads as a dead agent. Pod authorization requiresstatus: 'active', so every @-mention in such a pod 403s. Measured 2026-09-18: 21 of 30 Scout installs werestale.backend/services/agentInstallationCleanupService.ts:STALENESS_EXEMPT_RUNTIME_TYPES = ['native']andisStalenessExempt(install). The mark step projectsconfig.runtime, filters exempt installs out before the pair evaluation (an all-native pair is never looked up), and theupdateManyfilter carries'config.runtime.runtimeType': { $nin: [...] }so a pair installed both natively and remotely never writes onto the native row.internalis deliberately NOT exempt: it is the legacy in-process runtime type and stays swept exactly as before.backend/scripts/revive-native-installations.ts(+npm run revive:native-installations): restores rows the cron already marked. Dry run by default, prints the candidate count and a per-agent breakdown;--applysetsstatus: 'active'and unsetsstaleSince. Idempotent. It cannot restore rows the prune step already deleted (14 d afterstaleSince); those are reinstalls.Proof
backend/__tests__/unit/services/agentInstallationCleanup.nativeExempt.test.js(5): exact exemption set; a native install past the window with no token and no events stays active and is never looked up; aninternalinstall in the same state is still marked;config.runtimeis projected (without it the exemption silently reads nothing); a mixed native+remote pair carries the$ninguard on the write.backend/__tests__/unit/scripts/revive-native-installations.test.js(3, in-memory Mongo): dry run counts 2 stale native rows and changes nothing; apply revives them, clearsstaleSince, leaves theinternalandmoltbotstale rows alone; a second apply finds nothing.agentInstallationCleanup.staleness+failureCountsuites andunguardedScriptImporterspass unchanged (20/20 across the five suites).tsc:checkclean;lint:tsclean on the two TypeScript files.Live run (after merge + deploy, per Sam 69274)
From the admin side, in the running backend pod:
npm run revive:native-installationsfirst (Vera reads the count), then-- --apply. Nothing this PR touches is on the C4 path.Pre-runtime rows (b7cdcea, after Vera's dev count)
Vera's read-only count on dev: 19 stale Scout rows carry
runtimeType: 'native', 2 carry noconfig.runtimeat all (early first-teammate shape, 2026-09-01/02). Reviving those two alone would last one day — the sweep's$nintreats a missing runtimeType as sweepable. Ruling (69346): backfill, then revive, same script, same--apply.config.runtime.runtimeTypeare resolved against theirAgentRegistryrow; only a declared exempt runtime backfills, and the revive update re-checks the field so an un-backfilled row is never flipped.ManifestRuntimeSchemais strict and dropsmanifest.runtime.runtimeTypeon write — measured with the seed's own upsert shape; onlyruntime.type: 'native'survives. The script reads either field and refuses deployment-shape values (standalone/commonly-hosted/hybrid). A test pins the stripping.backfill: { candidates, eligible, byAgent, skipped, applied }beside the total; the log line names the pre-runtime subset. Expected on dev: 21 would be revived, 2 of them backfilled.Follow-up, not in this PR:
backend/routes/registry/install.ts:345falls back toagent.manifest.runtime.runtimeTypefor native installs from the v2 UI. That field is stripped by the same strict subschema, so the fallback is dead on seeded rows and the bug it describes (runtimeType null → external queue → agent never replies) is plausibly still live. Worth its own row.🤖 Generated with Claude Code