diff --git a/deploy/cloudflare-resident/reset.test.ts b/deploy/cloudflare-resident/reset.test.ts index 05b94455d..25bdad399 100644 --- a/deploy/cloudflare-resident/reset.test.ts +++ b/deploy/cloudflare-resident/reset.test.ts @@ -1,4 +1,5 @@ import { NativeOperationJournal, nativeOperationRecordSchema, validNativeOperationKey } from "./nativeOperation.js"; +import { nativeOperatorScopeClosing, nativeOperatorScopeKey } from "./nativeScope.js"; import { selectedResidentMember } from "../../src/execution/residentMembers"; import { runInNewContext } from "node:vm"; import ts from "typescript"; @@ -400,7 +401,7 @@ describe("archive teardown exclusion", () => { }, ); - it("discards one exact unknown restore only after confirmed runtime destruction", async () => { + it("discards exact unknown restore and refresh fetch records only after confirmed runtime destruction", async () => { const ref = { version: 1, kind: "operation", @@ -468,6 +469,8 @@ describe("archive teardown exclusion", () => { NativeOperationJournal, NATIVE_OPERATION_PREFIX: "native-operation:", nativeOperationRecordSchema, + nativeOperatorScopeClosing, + nativeOperatorScopeKey, CLEANUP_PENDING_KEY: "cleanup", RESOURCE_KEY: "resource", NATIVE_EMERGENCY_DISCARD_PREFIX: "native-emergency-discard:", @@ -507,11 +510,11 @@ describe("archive teardown exclusion", () => { resident.swapIncarnation = () => {}; await expect(resident.teardown({ key, recordHash: "0".repeat(64) })).rejects.toThrow( - "exact closed native restore changed or another hold remains (holds=1, eligible=true, hashMatch=false)", + "exact closed native operation changed or another hold remains (holds=1, eligible=true, hashMatch=false)", ); rows.set("native-operation:op:other", structuredClone(rows.get(key))); await expect(resident.teardown({ key, recordHash })).rejects.toThrow( - "exact closed native restore changed or another hold remains (holds=2, eligible=true, hashMatch=true)", + "exact closed native operation changed or another hold remains (holds=2, eligible=true, hashMatch=true)", ); rows.delete("native-operation:op:other"); const ineligible = structuredClone(rows.get(key)) as { native: { closed: boolean } }; @@ -519,7 +522,7 @@ describe("archive teardown exclusion", () => { rows.set(key, ineligible); const ineligibleHash = (await new NativeOperationJournal(storage).list()).operations[0]!.recordHash; await expect(resident.teardown({ key, recordHash: ineligibleHash })).rejects.toThrow( - "exact closed native restore changed or another hold remains (holds=1, eligible=false, hashMatch=true)", + "exact closed native operation changed or another hold remains (holds=1, eligible=false, hashMatch=true)", ); rows.set(key, structuredClone(initialRows.get(key))); expect(effects).toEqual([]); @@ -642,6 +645,131 @@ describe("archive teardown exclusion", () => { expect(rows.has(key)).toBe(true); expect(rows.has(otherKey)).toBe(true); expect(effects).toEqual(["destroy"]); + + // A refresh fetch can retain an opaque native effect beside an opaque + // archive restore. The full reset must name both original records. + rows.clear(); + for (const [name, value] of initialRows) rows.set(name, value); + const fetchKey = "native-operation:op:fetch"; + const fetchScope = { + version: 1, + kind: "operation", + id: "77777777-7777-4777-8777-777777777777", + boot: ref.boot, + owner: { opOwner: "op:fetch" }, + }; + rows.set(fetchKey, { + opOwner: "op:fetch", + origin: { + producer: "refresh-step", + resource, + callId: "66666666-6666-4666-8666-666666666666", + sourceId: "fetch", + actor: "system", + traceId: null, + parentSourceId: "refresh_test_1", + build: "test-build", + workerVersion: null, + startedAt: 0, + }, + native: { + version: 1, + closed: true, + scope: fetchScope, + pending: { "88888888-8888-4888-8888-888888888888": { kind: "opaque" } }, + }, + }); + rows.set(nativeOperatorScopeKey({ opOwner: "op:fetch" }), { + kind: "operation", + id: fetchScope.id, + owner: fetchScope.owner, + boot: fetchScope.boot, + closing: true, + closed: false, + bootstrap: "ready", + }); + const fetchHash = (await new NativeOperationJournal(storage).list()).operations.find( + (row) => row.key === fetchKey, + )!.recordHash; + const mixedTargets = [ + { key, recordHash }, + { key: fetchKey, recordHash: fetchHash, unknownEffect: { originBuild: "test-build" } }, + ]; + effects.length = 0; + lateRecordWrite = false; + await expect( + resident.teardown([mixedTargets[0], { ...mixedTargets[1], recordHash: "0".repeat(64) }]), + ).rejects.toThrow("resident-cleanup-refused"); + expect(effects).toEqual([]); + await expect( + resident.teardown([ + { key, recordHash }, + { key: fetchKey, recordHash: fetchHash }, + ]), + ).rejects.toThrow("eligible=false, hashMatch=true"); + await expect( + resident.teardown([mixedTargets[0], { ...mixedTargets[1], unknownEffect: { originBuild: "other-build" } }]), + ).rejects.toThrow("eligible=false, hashMatch=true"); + expect(effects).toEqual([]); + const scopeKey = nativeOperatorScopeKey({ opOwner: "op:fetch" }); + const originalScope = rows.get(scopeKey) as Record; + rows.set(scopeKey, { ...originalScope, id: "99999999-9999-4999-8999-999999999999" }); + await expect(resident.teardown(mixedTargets)).rejects.toThrow("eligible=false, hashMatch=true"); + expect(effects).toEqual([]); + rows.set(scopeKey, originalScope); + rows.delete(key); + await expect(resident.teardown(mixedTargets[1])).rejects.toThrow("eligible=false, hashMatch=true"); + expect(effects).toEqual([]); + rows.set(key, initialRows.get(key)); + const fetchRecord = rows.get(fetchKey); + const unrelated = structuredClone(fetchRecord) as { origin: { sourceId: string } }; + unrelated.origin.sourceId = "snapshot"; + rows.set(fetchKey, unrelated); + const unrelatedHash = (await new NativeOperationJournal(storage).list()).operations.find( + (row) => row.key === fetchKey, + )!.recordHash; + await expect( + resident.teardown([ + mixedTargets[0], + { key: fetchKey, recordHash: unrelatedHash, unknownEffect: { originBuild: "test-build" } }, + ]), + ).rejects.toThrow("eligible=false, hashMatch=true"); + expect(effects).toEqual([]); + rows.set(fetchKey, fetchRecord); + const mixedInitialRows = new Map(rows); + destroyFails = true; + await expect(resident.teardown(mixedTargets)).rejects.toThrow("runtime destruction unconfirmed"); + expect([...rows.values()]).toContainEqual( + expect.objectContaining({ + key: fetchKey, + unknownEffect: { originBuild: "test-build" }, + originalOperationOutcome: "unknown", + state: "prepared", + }), + ); + rows.clear(); + for (const [name, value] of mixedInitialRows) rows.set(name, value); + destroyFails = false; + effects.length = 0; + expect(await resident.teardown(mixedTargets)).toMatchObject({ + containerStopped: true, + storageCleared: true, + discardedUnknownNatives: mixedTargets, + errors: [], + }); + expect(effects).toEqual(["destroy"]); + for (const target of mixedTargets) { + expect(rows.has(target.key)).toBe(false); + expect([...rows.values()]).toContainEqual( + expect.objectContaining({ + key: target.key, + recordHash: target.recordHash, + ...(target.unknownEffect ? { unknownEffect: target.unknownEffect } : {}), + originalOperationOutcome: "unknown", + state: "runtime-destroyed", + }), + ); + } }); }); @@ -1007,13 +1135,20 @@ describe("full resident reset", () => { expect(await invalid.json()).toEqual({ error: "one exact native key and record hash are required" }); const targets = [ { key: "native-operation:op:archive", recordHash: "a".repeat(64) }, - { key: "native-operation:op:other", recordHash: "b".repeat(64) }, + { key: "native-operation:op:other", recordHash: "b".repeat(64), unknownEffect: { originBuild: "build-1" } }, ]; const duplicate = await endpoint({}, { resource, discardUnknownNative: [targets[0], targets[0]] }); expect(duplicate.status).toBe(400); expect(await duplicate.json()).toEqual({ error: "two to 64 distinct exact native keys and record hashes are required", }); + const missingBuild = await endpoint( + {}, + { resource, discardUnknownNative: [targets[0], { ...targets[1], unknownEffect: {} }] }, + ); + expect(missingBuild.status).toBe(400); + const singleUnknown = await endpoint({}, { resource, discardUnknownNative: targets[1] }); + expect(singleUnknown.status).toBe(400); const selectedPlan = await endpoint({}, { resource, dryRun: true, discardUnknownNative: targets }); expect(selectedPlan.status).toBe(200); expect(await selectedPlan.json()).toMatchObject({ dryRun: true, originalOperationOutcome: "unknown" }); diff --git a/deploy/cloudflare-resident/worker.ts b/deploy/cloudflare-resident/worker.ts index 81a48d3db..08665c537 100644 --- a/deploy/cloudflare-resident/worker.ts +++ b/deploy/cloudflare-resident/worker.ts @@ -38,6 +38,8 @@ import { NativeRunScopes, CloudflareNativeScopeTransport, type NativeScopeTransport, + nativeOperatorScopeClosing, + nativeOperatorScopeKey, nativeScopeRetirementKey, NATIVE_SCOPE_CONTROL_MS, type NativeScopeRef, @@ -3595,7 +3597,7 @@ const DESTROY_UNCONFIRMED_KEY = "resident:destroyUnconfirmed"; const CLEANUP_PENDING_KEY = "resident:cleanupPending"; /** Retain the exact unknown-effect record after an explicitly selected full reset. */ const NATIVE_EMERGENCY_DISCARD_PREFIX = "native-emergency-discard:"; -type NativeDiscardTarget = { key: string; recordHash: string }; +type NativeDiscardTarget = { key: string; recordHash: string; unknownEffect?: { originBuild: string } }; type NativeDiscardSelection = NativeDiscardTarget | NativeDiscardTarget[]; const RECREATE_ADMISSION_KEY = "resident:recreateAdmission"; /** The row under RUNTIME_UNREACHABLE_KEY: the count and both instants, so the @@ -15945,6 +15947,7 @@ export class ResidentDO extends Sandbox { resource: string; key: string; recordHash: string; + unknownEffect?: { originBuild: string }; original: unknown; originalOperationOutcome: string; state: string; @@ -15955,17 +15958,45 @@ export class ResidentDO extends Sandbox { targets.length > 0 && unresolved.size === 0 && audits.every(({ old }) => old?.state === "runtime-destroyed"); if (targets.length) { const hashes = await journal.fingerprints(NATIVE_OPERATION_PREFIX); - const eligible = targets.every((target) => { - const parsed = nativeOperationRecordSchema.safeParse(unresolved.get(target.key)); - return ( - parsed.success && - "opOwner" in parsed.data && - parsed.data.native.closed === true && - !!parsed.data.native.scope && - Object.values(parsed.data.native.pending).some((attempt) => attempt.restore) && - !Object.values(parsed.data.native.pending).some((attempt) => !attempt.restore) - ); - }); + const eligible = ( + await Promise.all( + targets.map(async (target) => { + const parsed = nativeOperationRecordSchema.safeParse(unresolved.get(target.key)); + if (!parsed.success || !("opOwner" in parsed.data)) return false; + const record = parsed.data; + const pending = Object.values(record.native.pending); + // The journal cannot name the opaque effect. The operator must select + // its original build explicitly and keep its result unknown. + const unknownFetch = + targets.length >= 2 && + !!target.unknownEffect && + target.unknownEffect.originBuild === record.origin?.build && + target.key === `native-operation:${record.opOwner}` && + !!record.native.scope && + nativeOperatorScopeClosing( + await this.ctx.storage.get(nativeOperatorScopeKey({ opOwner: record.opOwner })), + { opOwner: record.opOwner }, + record.native.scope, + ) && + record.origin?.producer === "refresh-step" && + record.origin.resource === resource && + record.origin.sourceId === "fetch" && + record.origin.actor === "system" && + pending.length === 1 && + pending[0].kind === "opaque" && + !pending[0].process && + !pending[0].restore; + return ( + record.native.closed === true && + !!record.native.scope && + (unknownFetch || + (!target.unknownEffect && + pending.some((attempt) => attempt.restore) && + !pending.some((attempt) => !attempt.restore))) + ); + }), + ) + ).every(Boolean); const hashMatch = targets.every((target) => hashes[target.key] === target.recordHash); if ( !resumeWithoutRecord && @@ -15976,7 +16007,7 @@ export class ResidentDO extends Sandbox { !hashMatch) ) throw new Error( - `resident-cleanup-refused: exact closed native restore changed or another hold remains (holds=${unresolved.size}, eligible=${eligible}, hashMatch=${hashMatch})`, + `resident-cleanup-refused: exact closed native operation changed or another hold remains (holds=${unresolved.size}, eligible=${eligible}, hashMatch=${hashMatch})`, ); } for (const [key, value] of unresolved) { @@ -15996,6 +16027,7 @@ export class ResidentDO extends Sandbox { (old.resource !== resource || old.key !== target.key || old.recordHash !== target.recordHash || + JSON.stringify(old.unknownEffect ?? null) !== JSON.stringify(target.unknownEffect ?? null) || old.original === undefined || old.originalOperationOutcome !== "unknown" || !["prepared", "runtime-destroyed"].includes(old.state)), @@ -16024,6 +16056,7 @@ export class ResidentDO extends Sandbox { resource, key: target.key, recordHash: target.recordHash, + ...(target.unknownEffect ? { unknownEffect: target.unknownEffect } : {}), original: current.get(target.key), originalOperationOutcome: "unknown", state: "prepared", @@ -16043,6 +16076,7 @@ export class ResidentDO extends Sandbox { resource, key: target.key, recordHash: target.recordHash, + ...(target.unknownEffect ? { unknownEffect: target.unknownEffect } : {}), original: current.get(target.key), originalOperationOutcome: "unknown", state: "runtime-destroyed", @@ -17257,21 +17291,34 @@ async function handleReset(env: Env, body: Record): Promise - !!value && - typeof value === "object" && - !Array.isArray(value) && - Object.keys(value).sort().join(",") === "key,recordHash" && - validNativeOperationKey((value as { key?: unknown }).key) && - typeof (value as { recordHash?: unknown }).recordHash === "string" && - /^[a-f0-9]{64}$/.test((value as { recordHash: string }).recordHash); + const validDiscardTarget = (value: unknown): value is NativeDiscardTarget => { + if (!value || typeof value !== "object" || Array.isArray(value)) return false; + const target = value as { key?: unknown; recordHash?: unknown; unknownEffect?: unknown }; + const keys = Object.keys(value).sort().join(","); + if ( + !validNativeOperationKey(target.key) || + typeof target.recordHash !== "string" || + !/^[a-f0-9]{64}$/.test(target.recordHash) + ) + return false; + if (keys === "key,recordHash") return true; + if (keys !== "key,recordHash,unknownEffect" || !target.unknownEffect || typeof target.unknownEffect !== "object") + return false; + const unknownEffect = target.unknownEffect as { originBuild?: unknown }; + return ( + Object.keys(unknownEffect).join(",") === "originBuild" && + typeof unknownEffect.originBuild === "string" && + unknownEffect.originBuild.length > 0 && + unknownEffect.originBuild.length <= 128 + ); + }; const validDiscard = Array.isArray(discard) ? discard.length >= 2 && discard.length <= 64 && discard.every(validDiscardTarget) && new Set(discard.map((target: NativeDiscardTarget) => target.key)).size === discard.length && new Set(discard.map((target: NativeDiscardTarget) => target.recordHash)).size === discard.length - : validDiscardTarget(discard); + : validDiscardTarget(discard) && !discard.unknownEffect; if (discard !== undefined && !validDiscard) return json( { diff --git a/docs/decisions/0111-explicit-native-disposal-requires-confirmed-full-reset.md b/docs/decisions/0111-explicit-native-disposal-requires-confirmed-full-reset.md index 6d5f0a004..a5a2320f5 100644 --- a/docs/decisions/0111-explicit-native-disposal-requires-confirmed-full-reset.md +++ b/docs/decisions/0111-explicit-native-disposal-requires-confirmed-full-reset.md @@ -19,6 +19,10 @@ Keep Kill scoped to one run. Do not use a full resident reset as its automatic f The one-record rule protects exact selection, unknown outcomes and the original archive evidence. It does not handle two closed opaque restores on one resident: neither single-record selector can pass the other hold. Keep the same full-reset boundary and allow a complete set of two to 64 exact key and hash pairs. The Worker rejects any omitted, duplicate, changed or ineligible record before destruction. It writes all prepared audits in one storage transaction, confirms one runtime destruction, and writes all destruction audits in one transaction. The hardest race is a late original restore reply during backup cleanup. The final transaction compares every selected record and removes the set only when all hashes still match; one changed record leaves the whole set in place. An uncertain destroy or mixed audit state still refuses a repeat. This extension retains the original reason for the decision: no result is credited to an opaque restore, and no runtime evidence is deleted without confirmed destruction. +## Amended 2026-10-23 + +The complete-set guard can meet a closed refresh fetch beside a closed dependency restore. The fetch can retain an opaque native effect with no process handle or restore identity. A process Kill has no identity to target, and the journal does not identify the action or destination. Admit that fetch only inside a complete set through a new explicit unknown-effect selection that quotes its original build and exact key and hash. The Worker checks the selected build, system `refresh-step`/`fetch` origin, resource, one pending opaque non-restore effect, and the embedded scope against the original closing scope row. Every other opaque non-restore record stays ineligible. This is deliberate disposal of unknown evidence after a full resident reset, not proof that the fetch effect was local or ended. The reset still requires the complete exact set, confirms container destruction, and retains each original and its unknown-effect selection in the audit. After backup cleanup, one transaction checks all selected hashes and the whole unresolved count, so a late reply or new record leaves the set in place. The original reason for the decision still applies: no unknown result is credited, and no resident state is removed without confirmed destruction. A remote effect may survive, and a separate deployment permit remains a separate obligation. + ## Consequences The explicit mode deletes every workspace, thread binding and backup on that resident. It does not prove the original restore ended or repair remote effects. An older Worker cannot run the mode. The deployment fence still refuses until the hold is removed, so a separate qualified installation path is required before this mode can resolve a hold on an older serving Worker. diff --git a/docs/how-to/operate-production.md b/docs/how-to/operate-production.md index 0ee90d530..45e690ac1 100644 --- a/docs/how-to/operate-production.md +++ b/docs/how-to/operate-production.md @@ -199,6 +199,8 @@ An opaque dependency restore can leave a closed operator record without its orig If the same resident has two to 64 closed opaque operator restores, select every unresolved native record from the fresh preview in one JSON array. Pass it as `--discard-native-records-json '[{"key":"","recordHash":""},{"key":"","recordHash":""}]'` with `--full`. A missing, duplicate, changed, ineligible or additional record refuses before destruction. The Worker saves each original record with `originalOperationOutcome: "unknown"`, then confirms one container destruction before it deletes the selected records and backups. Each audit remains after recreation. A late reply, active work, uncertain destruction or incomplete backup cleanup refuses or retains the cleanup hold. A repeated completed request does not destroy the new resident. This is a repository-wide data reset, not a per-run shutdown receipt; it discards every workspace and backup named in the preview. It is available only after a Worker containing this route serves. The ordinary deployment fence still refuses until the reset is complete. +The complete set can also include a closed system refresh fetch with one native effect whose result is unknown. For that entry, add `"unknownEffect":{"originBuild":""}` beside its exact key and hash in the JSON array. The Worker checks the saved build, owner, resource and original closing scope; the step must be `fetch`. A single fetch selector and other unknown native effects remain held. This selection accepts that the fetch effect is unknown, including any remote effect. The reset keeps each original outcome and the explicit selection in its audit, and it does not release a separate deployment permit. + ## Bring existing residents onto the pool-user generation fence A resident created before durable pool-user spends has no generation ledger. The newer Worker refuses another thread or operation on that resident with `pool-generation-unknown` until its container is confirmed destroyed and a fresh generation is recorded. A Worker deploy or a `warm` status alone does not do this. Keep its existing work held while the ledger is unknown. diff --git a/docs/reference/specs/resident-repos.md b/docs/reference/specs/resident-repos.md index a86d05890..f96da337d 100644 --- a/docs/reference/specs/resident-repos.md +++ b/docs/reference/specs/resident-repos.md @@ -882,7 +882,7 @@ The [owned background operation design](../../plans/2026-10-17-001-owned-backgro | The deployed Worker and Resident image complete a cold mirror, checkout and dependency restore without FUSE resources or Worker archive buffering. | `[gap]` Requires the reviewed image and Worker in the authorized Cloudflare qualification target. Local proof is insufficient. | | Teardown preserves pending restores, retained receipts and invalid native evidence before destruction or cleanup. An explicit legacy reset still reports unknown operation outcomes and retains backup state until deletion completes. | `[unit]` `deploy/cloudflare-resident/reset.test.ts::archive teardown exclusion::*`; `deploy/cloudflare-resident/reset.test.ts::full rebuild backup cleanup::retains failed…` | -| An explicit emergency full reset selects one closed opaque operator restore or the complete set of two to 64 such restores by exact native keys and record hashes. An omitted, duplicate, changed, invalid or additional record, active owner, or unconfirmed destruction refuses before native evidence is removed. The initial refusal reports bounded hold count, eligibility and hash match without exposing the records. Prepared and confirmed-destruction audits cover every selected original with outcome unknown. After backup cleanup, one transaction compares every selected record and removes the exact set; a late reply leaves all changed evidence in place. A repeated completed request cannot destroy the new resident. Ordinary reset and offboard still refuse unresolved restores. | `[unit]` `deploy/cloudflare-resident/reset.test.ts::archive teardown exclusion::discards one exact unknown restore only after confirmed runtime destruction`; `deploy/cloudflare-resident/reset.test.ts::full resident reset::does not discard a selected restore while another original owner is active`; `::does not destroy a new resident when the exact disposal already completed`; `src/core/commands/repo.test.ts::repo rebuild --full::sends a complete exact native restore set from the public command`; `deploy/cloudflare-resident/reset.test.ts::archive teardown exclusion::*` | +| An explicit emergency full reset selects one closed opaque operator restore or the complete set of two to 64 such restores and system refresh fetches by exact native keys and record hashes. A fetch also needs an explicit unknown-effect selection with its original build, system `refresh-step`/`fetch` origin, matching resource and original scope row, and exactly one pending opaque non-restore effect; it does not prove the action, destination or result. Other non-restore operations remain held. An omitted, duplicate, changed, invalid or additional record, active owner, or unconfirmed destruction refuses before native evidence is removed. The initial refusal reports bounded hold count, eligibility and hash match without exposing the records. Prepared and confirmed-destruction audits cover every selected original with outcome unknown. After backup cleanup, one transaction compares every selected record and removes the exact set; a late reply leaves all changed evidence in place. A repeated completed request cannot destroy the new resident. Ordinary reset and offboard still refuse unresolved restores. A separate deployment permit stays separate. | `[unit]` `deploy/cloudflare-resident/reset.test.ts::archive teardown exclusion::discards exact unknown restore and refresh fetch records only after confirmed runtime destruction`; `deploy/cloudflare-resident/reset.test.ts::full resident reset::does not discard a selected restore while another original owner is active`; `::does not destroy a new resident when the exact disposal already completed`; `src/core/commands/repo.test.ts::repo rebuild --full::sends a complete exact native set with an explicit unknown effect from the public command`; `deploy/cloudflare-resident/reset.test.ts::archive teardown exclusion::*` | | Scheduled provisioning records its stable producer and original operator before workspace cleanup or clone, under deployment protection. A delayed callback rechecks onboarding and its saved resource; unknown original work cannot start a second clone. | `[unit]` `deploy/cloudflare-resident/runRegistration.test.ts::owned background operation admission::owns scheduled provisioning before cleanup and reaches warm after cloning`; `::leaves onboarding untouched when deployment protection refuses provisioning`; `::rechecks onboarding after admission before a delayed callback can clean a warm tree`; `::ignores a stale provisioning payload for another resident resource`; `::keeps an unknown provisioning effect held instead of starting another clone`; `deploy/cloudflare-resident/drain.test.ts::global deploy admission evidence::holds a real deployment permit around the provisioning owner and releases after its ending` | | Provisioning and refresh build commands run through the explicit native build-user role, with a writable build-user home and the existing isolated scope. A build without that operator scope refuses before root fallback. | `[unit]` `deploy/cloudflare-resident/runRegistration.test.ts::owned background operation admission::runs a refresh build with its writable user home in the original operator scope`; `::refuses a build without an original operation before any root fallback`; `[agent]` `npm run check:native-scope` verifies the actual build-user home is writable while system configuration remains read-only. | diff --git a/src/core/commands/repo.test.ts b/src/core/commands/repo.test.ts index 330e53e44..959bfa461 100644 --- a/src/core/commands/repo.test.ts +++ b/src/core/commands/repo.test.ts @@ -961,10 +961,10 @@ describe("repo offboard / rebuild (--dry-run)", () => { }); describe("repo rebuild --full", () => { - it("sends a complete exact native restore set from the public command", async () => { + it("sends a complete exact native set with an explicit unknown effect from the public command", async () => { const targets = [ { key: "native-operation:op:first", recordHash: "a".repeat(64) }, - { key: "native-operation:op:second", recordHash: "b".repeat(64) }, + { key: "native-operation:op:second", recordHash: "b".repeat(64), unknownEffect: { originBuild: "build-1" } }, ]; const client = mockClient({ rebuild: ok({ wouldRemove: {}, reprovision: { defaultRef: "main" } }) }); const commands = bind({ admin: client }); @@ -990,6 +990,18 @@ describe("repo rebuild --full", () => { admin, ); expect(duplicate).toMatchObject({ ok: false, error: "invalid_input" }); + const missingBuild = await commands.invoke( + "repo.rebuild", + { + args: ["acme/api"], + options: { + full: true, + discardNativeRecordsJson: JSON.stringify([targets[0], { ...targets[1], unknownEffect: {} }]), + }, + }, + admin, + ); + expect(missingBuild).toMatchObject({ ok: false, error: "invalid_input" }); expect(client.rebuild).toHaveBeenCalledTimes(1); }); diff --git a/src/core/commands/repo.ts b/src/core/commands/repo.ts index 374ae8e04..59a82a8b9 100644 --- a/src/core/commands/repo.ts +++ b/src/core/commands/repo.ts @@ -763,7 +763,7 @@ export const repoRebuild = defineCommand({ .string() .max(40000) .optional() - .describe("JSON array of two to 64 exact native keys and record hashes from one full-reset preview"), + .describe("JSON array of two to 64 exact native records; an unknown fetch also names its originBuild"), }), action: "repo:write", effect: "write", @@ -843,7 +843,10 @@ export const repoRebuild = defineCommand({ handler: async ({ args, options, deps, span }) => { const dryRun = options.dryRun ?? false; const full = options.full ?? false; - let discardUnknownNative: { key: string; recordHash: string } | { key: string; recordHash: string }[] | undefined = + let discardUnknownNative: + | { key: string; recordHash: string; unknownEffect?: { originBuild: string } } + | { key: string; recordHash: string; unknownEffect?: { originBuild: string } }[] + | undefined = options.discardNativeKey && options.discardNativeRecordHash ? { key: options.discardNativeKey, recordHash: options.discardNativeRecordHash } : undefined; @@ -862,6 +865,10 @@ export const repoRebuild = defineCommand({ .object({ key: z.string().regex(/^native-operation:.{1,495}$/), recordHash: z.string().regex(/^[a-f0-9]{64}$/), + unknownEffect: z + .object({ originBuild: z.string().min(1).max(128) }) + .strict() + .optional(), }) .strict(), ) diff --git a/src/core/residentAdmin.test.ts b/src/core/residentAdmin.test.ts index 917a74314..203c26c6b 100644 --- a/src/core/residentAdmin.test.ts +++ b/src/core/residentAdmin.test.ts @@ -133,7 +133,7 @@ describe("makeResidentAdminClient (real fetch client)", () => { ).toMatchObject({ status: 200, data: { discardedUnknownNative: { key: "native-operation:op:archive" } } }); const targets = [ { key: "native-operation:op:archive", recordHash: "a".repeat(64) }, - { key: "native-operation:op:other", recordHash: "b".repeat(64) }, + { key: "native-operation:op:other", recordHash: "b".repeat(64), unknownEffect: { originBuild: "build-1" } }, ]; expect(await client.rebuild("repo:acme/api", false, true, undefined, targets)).toMatchObject({ status: 200, diff --git a/src/core/residentAdmin.ts b/src/core/residentAdmin.ts index a0e3886c0..21d8889ac 100644 --- a/src/core/residentAdmin.ts +++ b/src/core/residentAdmin.ts @@ -31,7 +31,9 @@ export interface ResidentAdminClient { dryRun: boolean, full?: boolean, resident?: number, - discardUnknownNative?: { key: string; recordHash: string } | { key: string; recordHash: string }[], + discardUnknownNative?: + | { key: string; recordHash: string; unknownEffect?: { originBuild: string } } + | { key: string; recordHash: string; unknownEffect?: { originBuild: string } }[], ): Promise; residents(): Promise; /** Read the selected resident's workload count and the records behind it. */