Implement workspace evolution, migrations, and runtime continuity
Enable evolution by default for source-backed workspaces. Add stable conformance ownership, semantic-major review, candidate typechecking, and durable fenced cutover with explicit migrations and forward recovery. Independently supervise package runtimes so unchanged resource owners keep their processes and connections across cutover. Add scoped invocation authority, resource sessions, and typed callback rebinding. Wire opaque object references through generated bindings and RPCs. Add canonical relationship sets, keyed maps, and ordered lists with scoped transactional mutations, revision checks, and inverse consistency. Support planned cascade deletion, protection, tombstones, and lifecycle foundations. Add journaled structural edits, package/function/migration scaffolding, managed repository creation, and resumable bottom-up dependency pin publication. Document lifetime boundaries, revision pinning, prototype compatibility policy, commands, and deferred work. Validate with 210 tests, user-systemd process/connection continuity, generated-package TypeScript checks, and Nix host/protocol checks. TTL handoff, physical reclamation, general multi-step migrations, and root-systemd migration isolation acceptance remain deferred.
This commit is contained in:
Vendored
+37
-9
@@ -1,6 +1,7 @@
|
||||
import { create } from "@bufbuild/protobuf";
|
||||
import { ValueSchema, ObjectValueSchema } from "./camino/api_pb.js";
|
||||
import { derived, jsToProtoValue, liveValue, protoValueToJs } from "./index.js";
|
||||
import { assertReferenceFree, referenceToWire } from "./references.js";
|
||||
export const qxDerived = (get) => ({ kind: "derived", get });
|
||||
// Conversion belongs at the binding boundary. It does not add orchestrator validation.
|
||||
export const decodeQxValue = (type, value, messages) => {
|
||||
@@ -15,8 +16,19 @@ export const decodeQxValue = (type, value, messages) => {
|
||||
throw new Error("Expected QX list");
|
||||
return value.kind.value.values.map((entry) => decodeQxValue(type.value, entry, messages));
|
||||
}
|
||||
if (type.kind === "message")
|
||||
return requireMessage(messages, type.descriptorId).decode(value);
|
||||
if (type.kind === "message") {
|
||||
assertReferenceFree(protoValueToJs(value));
|
||||
const decoded = requireMessage(messages, type.descriptorId).decode(value);
|
||||
assertReferenceFree(decoded);
|
||||
return decoded;
|
||||
}
|
||||
if (type.kind === "object-ref") {
|
||||
if (value.kind.case !== "refValue")
|
||||
throw new Error("Expected a declared RPC object reference");
|
||||
return protoValueToJs(value);
|
||||
}
|
||||
if (value.kind.case === "refValue")
|
||||
throw new Error("Reference supplied to a non-reference value");
|
||||
if (type.kind === "scalar") {
|
||||
if (type.name === "int64" || type.name === "uint64") {
|
||||
if (value.kind.case !== "integerValue")
|
||||
@@ -44,10 +56,16 @@ export const encodeQxValue = (type, value, messages) => {
|
||||
return value === null ? jsToProtoValue(null) : encodeQxValue(type.value, value, messages);
|
||||
if (type.kind === "list")
|
||||
return jsToProtoValue(value.map((entry) => liveValue(encodeQxValue(type.value, entry, messages))));
|
||||
if (type.kind === "message")
|
||||
return requireMessage(messages, type.descriptorId).encode(value);
|
||||
if (type.kind === "object-ref")
|
||||
return jsToProtoValue({ $quixosRef: value });
|
||||
if (type.kind === "object-ref") {
|
||||
referenceToWire(value);
|
||||
return jsToProtoValue(value);
|
||||
}
|
||||
assertReferenceFree(value);
|
||||
if (type.kind === "message") {
|
||||
const encoded = requireMessage(messages, type.descriptorId).encode(value);
|
||||
assertReferenceFree(protoValueToJs(encoded));
|
||||
return encoded;
|
||||
}
|
||||
return jsToProtoValue(value);
|
||||
};
|
||||
const inputValue = (context, type) => {
|
||||
@@ -69,7 +87,7 @@ const inputFields = (type, value, messages) => {
|
||||
};
|
||||
/** The sole unchecked cast connects generated contracts to the dynamic RPC runtime. */
|
||||
export const bindQxHandler = (spec, handler, messages) => {
|
||||
const execute = async (raw) => {
|
||||
const bindContext = (raw) => {
|
||||
const ports = Object.fromEntries(Object.entries(spec.ports).map(([name, port]) => {
|
||||
switch (port.kind) {
|
||||
case "state": {
|
||||
@@ -81,7 +99,9 @@ export const bindQxHandler = (spec, handler, messages) => {
|
||||
}
|
||||
case "edge": {
|
||||
const edge = raw.edge(port.id);
|
||||
return [name, Object.fromEntries(port.primitives.map((primitive) => [primitive, edge[primitive]]))];
|
||||
return [name, { ...Object.fromEntries(port.primitives.map((primitive) => [primitive, edge[primitive]])),
|
||||
...(port.primitives.includes("resolve") ? { collection: edge.collection } : {}),
|
||||
...(port.primitives.includes("resolve") && port.primitives.includes("connect") && port.primitives.includes("disconnect") ? { replace: edge.replace } : {}) }];
|
||||
}
|
||||
case "interface": {
|
||||
const target = raw.interface(port.id);
|
||||
@@ -92,8 +112,16 @@ export const bindQxHandler = (spec, handler, messages) => {
|
||||
case "constructor": return [name, { construct: (input) => raw.constructor(port.id).construct(inputFields(port.inputType, input, messages)) }];
|
||||
}
|
||||
}));
|
||||
const context = { objectId: raw.objectId,
|
||||
return { objectId: raw.objectId, signal: raw.signal,
|
||||
...(raw.openSession ? { openSession: async () => {
|
||||
const session = await raw.openSession();
|
||||
return { id: session.id, close: () => session.close(),
|
||||
run: (work) => session.run((next) => work(bindContext(next))) };
|
||||
} } : {}),
|
||||
input: decodeQxValue(spec.inputType, inputValue(raw, spec.inputType), messages), ports };
|
||||
};
|
||||
const execute = async (raw) => {
|
||||
const context = bindContext(raw);
|
||||
const value = await (typeof handler === "function" ? handler(context) : handler.get(context));
|
||||
return liveValue(encodeQxValue(spec.eventType ?? spec.outputType, value, messages));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user