An open-source, self-hosted system for apps built with web technologies.
Preserve Process parent lineage after exit
zohayrslileha8606189cb50
diff --git a/scripts/contracts/client-surface.ts b/scripts/contracts/client-surface.tsindex d8f7922..5301322 100644--- a/scripts/contracts/client-surface.ts+++ b/scripts/contracts/client-surface.ts@@ -118,10 +118,21 @@ assert(remaining)first.reconcile(new Map([["ordinary", remaining]]))await assert.rejects(removed, /representation was removed/)+const parent = {+ identity: "parent",+ reference: "parent-reference",+ name: "manager",+ program: "program",+ options: {},+ startedAt: new Date(),+ server: null,+ client: null+}const requester = {identity: "requester",reference: "requester-reference",program: "program",+ parent,client: { window: { process: "requester", layer: "over" } }}const target = {@@ -130,7 +141,7 @@ const target = {program: "program",client: { window: { process: "target", layer: "over", position: { x: 10, y: 20 } } }}-const processes = new Map([[requester.identity, requester], [target.identity, target]])+const processes = new Map<string, object>([[parent.identity, parent], [requester.identity, requester], [target.identity, target]])const calls: unknown[][] = []const localWindow = {state(identity: string) { return { position: identity === "target" ? { x: 70, y: 80 } : { x: 0, y: 0 } } },@@ -147,13 +158,29 @@ const processManager = {}const authManager = {processManager,- programManager: { programs: new Map() },+ programManager: { programs: new Map([["program", {+ reference: "program-reference",+ identity: "program",+ assetId: "00000000-0000-4000-8000-000000000000",+ installed: true,+ name: "Program",+ version: null,+ description: null,+ hasAgent: false,+ server: null,+ client: null+ }]]) },}const request = host(authManager as never, requester.identity, () => ({ size: { width: 1, height: 1 } }), () => "owner", localWindow as never)assert.deepEqual(await request("desktopSurface"), [{ size: { width: 1, height: 1 } }])const targetAddress = { identity: target.identity, reference: target.reference }const requesterAddress = { identity: requester.identity, reference: requester.reference }+processes.delete(parent.identity)+const parentAnswer = await request("parent", requesterAddress)+assert(Array.isArray(parentAnswer))+const retainedParent = parentAnswer[0] as { identity: string }+assert.equal(retainedParent.identity, parent.identity)await request("windowLocalMove", requesterAddress, { x: 70, y: 80 })await request("windowLocalSurfaceAdd", requesterAddress, undefined, visibility)await request("windowLocalSurfaceRemove", requesterAddress, undefined, visibility)diff --git a/scripts/contracts/client-system-access.ts b/scripts/contracts/client-system-access.tsindex 5e06060..6a02207 100644--- a/scripts/contracts/client-system-access.ts+++ b/scripts/contracts/client-system-access.ts@@ -40,8 +40,8 @@ const outsideService = { program: "outside", process: "main", endpoint: "server"assert(access.ownsProgram(ownProgram))assert(!access.ownsProgram(outsideProgram))-assert(access.ownsProcess(sibling as never))-assert(!access.ownsProcess(outside as never))+assert(access.ownsProcess(sibling))+assert(!access.ownsProcess(outside))assert(access.ownsService(ownService))assert(access.ownsService(ownExactService))assert(!access.ownsService(outsideService))@@ -49,7 +49,7 @@ assert.equal(await access.program(ownProgram as never), ownProgram)assert.equal(await access.service(ownService), ownService)assert.equal(await access.service(ownExactService), ownExactService)await assert.rejects(access.program(outsideProgram as never), /Execution is not permitted/)-await assert.rejects(access.process(outside as never), /Execution is not permitted/)+await assert.rejects(access.process(outside), /Execution is not permitted/)await assert.rejects(access.service(outsideService), /Execution is not permitted/)await assert.rejects(access.requirePrograms(), /Execution is not permitted/)await assert.rejects(access.requireNetwork("https://api.example.com/v1/users"), /Execution is not permitted/)@@ -62,7 +62,7 @@ permissions = { services: ["outside"] }assert.equal(await access.service(outsideService), outsideService)await assert.rejects(access.program(outsideProgram as never), /Execution is not permitted/)-await assert.rejects(access.process(outside as never), /Execution is not permitted/)+await assert.rejects(access.process(outside), /Execution is not permitted/)await assert.rejects(access.requirePrograms(), /Execution is not permitted/)permissions = { services: [] }@@ -74,7 +74,7 @@ await assert.rejects(access.requirePrograms(), /Execution is not permitted/)permissions = { programs: ["outside"] }assert.equal(await access.program(outsideProgram as never), outsideProgram)-assert.equal(await access.process(outside as never), outside)+assert.equal(await access.process(outside), outside)assert.equal(await access.service(outsideService), outsideService)await assert.rejects(access.requirePrograms(), /Execution is not permitted/)@@ -117,7 +117,7 @@ await access.requireStorage(homedir())permissions = { all: [] }assert.equal((await access.program(outsideProgram as never)).identity, "outside")-assert.equal((await access.process(outside as never)).identity, outside.identity)+assert.equal((await access.process(outside)).identity, outside.identity)assert.equal(await access.service(outsideService), outsideService)await access.requirePrograms()await access.require("appearance", [])diff --git a/scripts/contracts/process-lifecycle.ts b/scripts/contracts/process-lifecycle.tsindex fb67c35..8d761f3 100644--- a/scripts/contracts/process-lifecycle.ts+++ b/scripts/contracts/process-lifecycle.ts@@ -51,6 +51,26 @@ async function register(manager: ProcessManager, identity: string) {return await manager.register(identity, null, program(identity), {}, launch, null, false, null, null)}+// Parentage retains the exact Process entity after it exits. Absence and+// ended lineage therefore remain distinct states at every System boundary.+{+ const manager = processManager()+ const parent = await register(manager, "parent")+ const child = await manager.register("child", null, parent.program, {}, launch, null, false, null, parent)+ const boundary = manager as unknown as {+ parent(value: unknown): Promise<{ identity: string } | null>+ endHost(process: Process, server: ServerProcessBoundary, args: unknown[]): Promise<unknown[]>+ }++ await manager.remove(parent.identity)++ assert.equal((await boundary.parent({ identity: child.identity, reference: child.reference }))?.identity, parent.identity)++ const retained = (await boundary.endHost(child, {} as ServerProcessBoundary, ["parent"]))[0] as { identity: string }++ assert.equal(retained.identity, parent.identity)+}+// A failed configuration cannot leave either its Process identity or an// unattached runtime behind in the registry.{diff --git a/source/client/core/link-manager/auth-manager/process-manager/process.ts b/source/client/core/link-manager/auth-manager/process-manager/process.tsindex 6ca853a..9ea8ad1 100644--- a/source/client/core/link-manager/auth-manager/process-manager/process.ts+++ b/source/client/core/link-manager/auth-manager/process-manager/process.ts@@ -29,8 +29,8 @@ export default class Process {public client: ClientState | null- // Retained only as an address. The pane gate verifies that the parent is- // still live before an SDK handle may resolve it.+ // Retained lineage from creation. It remains sufficient to reconstruct+ // the same Process handle after the parent leaves the live registry.public readonly parent: ProcessRecord | null// What its launch said, carried for its whole life.diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex dadb90e..f5603b7 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -348,17 +348,17 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()return []}- // A Process parent is resolved by its exact retained address.+ // Parentage is immutable lineage. Its retained record remains a valid+ // Process handle source after the parent leaves the live registry.if (word === "parent") {const target = await permittedProcess(args[0])- const parent = target.parent ? resolveProcess(target.parent) : null- if (target.parent && !parent) throw new Error("The parent Process no longer exists")+ if (!target.parent) return [null]- if (parent) await access.process(parent)+ await access.process(target.parent)- return [parent ? record(parent) : null]+ return [sdkProcess(target.parent, programOf(target.parent))]}// A retained Process handle remains able to report its own ending.diff --git a/source/client/view/components/desktop-host/system-access.ts b/source/client/view/components/desktop-host/system-access.tsindex 860d7db..b377e9c 100644--- a/source/client/view/components/desktop-host/system-access.ts+++ b/source/client/view/components/desktop-host/system-access.ts@@ -65,7 +65,7 @@ export default class SystemAccess {return program}- public async process(process: Process) {+ public async process<Subject extends Pick<Process, "program">>(process: Subject) {if (!await this.canProcess(process)) throw new Error(denied)diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex d3fba98..2d8c9d0 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -1756,17 +1756,15 @@ export default class ProcessManager extends TheLink {return [await this.system.programStartup(program, String(rest[1]), rest[2])]}- // Which live process made this one through `program.process.create()`.- // The child retains a handle, but the registry remains authoritative:- // once the parent disappears that retained handle no longer resolves.+ // Which exact process made this one through `program.process.create()`.+ // Parentage is immutable lineage; liveness belongs to the returned+ // Process handle rather than to this relationship.if (word === "parent") {const target = this.system.holdProcess(rest[0], process)if (!target.parent) return [null]- if (this.processes.get(target.parent.identity) !== target.parent) throw new Error("The parent Process no longer exists")-return [processReference(target.parent)]}@@ -2594,6 +2592,14 @@ export default class ProcessManager extends TheLink {return await this.exitProcess(identity)}+ @Connect("/parent")+ protected async parent(value: unknown) {++ const process = this.system.holdProcess(value)++ return process.parent ? processReference(process.parent) : null+ }+@Connect("/endpoint/start")protected async startEndpoint(identity: string, which: string, launch?: ServerLaunch | ClientLaunch) {