You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/01 05:10:03 UTC
(maka) branch feat/persistence-forward-roll-guard created (now a8ec9282a3)
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a change to branch feat/persistence-forward-roll-guard
in repository https://gitbox.apache.org/repos/asf/maka.git
at a8ec9282a3 ci(release): trigger the State Root forward roll on durable-state decoders
This branch includes the following new commits:
new 9c16eecd16 fix(runtime-host): migrate persisted access grants through one registry
new 406786ed7d test(release): qualify the control namespace beside the State Root
new a8ec9282a3 ci(release): trigger the State Root forward roll on durable-state decoders
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 01/03: fix(runtime-host): migrate persisted access grants through one registry
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch feat/persistence-forward-roll-guard
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 9c16eecd1668a13cabd8ba23c949b7e8187f3c26
Author: AstroHan <le...@outlook.com>
AuthorDate: Tue Sep 1 12:59:54 2026 +0800
fix(runtime-host): migrate persisted access grants through one registry
An access file records what the Host already granted, written by whichever
build issued it and read with no peer present to negotiate a version. Decoding
was fail-closed on the grant vocabulary: a stored grant naming an operation the
current protocol no longer defines failed the whole file, and the Host refused
to start over a capability it could not have served either way. The
TaskLedger-to-SessionTodo cutover retired `task.ledger.query` without a
successor entry, which stranded workspaces holding a credential issued before
it.
Replace the three scattered constants that encoded this by hand with one
registry keyed by the persisted grant, stating whether it is replaced by named
successors or released. A stored grant that is still a current operation and
names no entry keeps itself; one that is neither is released rather than
fatal. `task.ledger.query` now names `session.todo.query` as its successor.
The write path is unchanged and still strict: issuing a grant the current
protocol does not define is rejected. Reading tolerates history; writing does
not create it.
A Session Guest credential no longer fails the file when a stored grant falls
outside the current guest list. The guest policy is re-applied on decode and is
the whole authority over what a guest may do, so a grant the list no longer
names is a version difference, and failing the file only stranded the
workspace.
Generated-by: Claude Code (Opus 5)
---
.../access-credential-grant-migration.test.ts | 140 +++++++++++++++++++++
.../src/server/access-credential-store.ts | 106 +++++++++-------
2 files changed, 201 insertions(+), 45 deletions(-)
diff --git a/packages/runtime-host/src/__tests__/access-credential-grant-migration.test.ts b/packages/runtime-host/src/__tests__/access-credential-grant-migration.test.ts
new file mode 100644
index 0000000000..5103fe7fef
--- /dev/null
+++ b/packages/runtime-host/src/__tests__/access-credential-grant-migration.test.ts
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// These fixtures are hand-written access files, not values produced by the
+// current writer. An access file on a user's disk was serialized by whichever
+// build issued it, so round-tripping today's writer would only prove today's
+// encoder agrees with itself.
+
+import assert from 'node:assert/strict';
+import { createHash } from 'node:crypto';
+import { mkdtemp, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import {
+ ACCESS_FILE_NAME,
+ issuedAccessGrants,
+ readAccessCredentialFile,
+ SESSION_GUEST_OPERATION_GRANTS,
+} from '../server/access-credential-store.js';
+
+async function readStoredFile(
+ t: { after: (fn: () => Promise<unknown>) => void },
+ file: unknown,
+): Promise<Awaited<ReturnType<typeof readAccessCredentialFile>>> {
+ const directory = await mkdtemp(join(tmpdir(), 'maka-access-grant-'));
+ t.after(() => rm(directory, { recursive: true, force: true }));
+ const path = join(directory, ACCESS_FILE_NAME);
+ await writeFile(path, JSON.stringify(file), 'utf8');
+ return readAccessCredentialFile(path);
+}
+
+function storedCredential(
+ operationGrants: readonly string[],
+ overrides: Record<string, unknown> = {},
+): Record<string, unknown> {
+ return {
+ credentialId: 'credential-under-test',
+ credentialHash: createHash('sha256').update('maka_rh_secret').digest('hex'),
+ principalId: 'client-under-test',
+ principalKind: 'remote_owner',
+ status: 'active',
+ operationGrants,
+ canPublishClientCapabilities: false,
+ canUseHostPaths: false,
+ createdAt: '2026-01-01T00:00:00.000Z',
+ ...overrides,
+ };
+}
+
+test('a grant issued before the SessionTodo cutover carries to its successor', async (t) => {
+ const file = await readStoredFile(t, {
+ schemaVersion: 3,
+ credentials: [storedCredential(['host.status', 'task.ledger.query'])],
+ sessionGrants: [],
+ turnAccessRequests: [],
+ });
+
+ assert.deepEqual(
+ [...(file.credentials[0]?.operationGrants ?? [])],
+ ['host.status', 'session.todo.query'],
+ );
+});
+
+test('a stored grant the protocol no longer defines is released, not fatal', async (t) => {
+ // The Host cannot serve an operation it does not define, so refusing the file
+ // would strand the workspace over a capability that is gone either way.
+ const file = await readStoredFile(t, {
+ schemaVersion: 3,
+ credentials: [storedCredential(['host.status', 'some.operation.retired.without.registration'])],
+ sessionGrants: [],
+ turnAccessRequests: [],
+ });
+
+ assert.deepEqual([...(file.credentials[0]?.operationGrants ?? [])], ['host.status']);
+});
+
+test('a Session Guest credential survives a guest policy that no longer names its grants', async (t) => {
+ const file = await readStoredFile(t, {
+ schemaVersion: 3,
+ credentials: [
+ storedCredential(['host.status', 'task.ledger.query', 'some.retired.guest.operation'], {
+ principalKind: 'session_guest',
+ }),
+ ],
+ sessionGrants: [],
+ turnAccessRequests: [],
+ });
+
+ assert.deepEqual(
+ [...(file.credentials[0]?.operationGrants ?? [])],
+ [...SESSION_GUEST_OPERATION_GRANTS],
+ );
+});
+
+test('a schema 1 file written before principalKind existed still opens', async (t) => {
+ const file = await readStoredFile(t, {
+ schemaVersion: 1,
+ credentials: [
+ {
+ credentialId: 'historical-credential',
+ credentialHash: createHash('sha256').update('maka_rh_secret').digest('hex'),
+ principalId: 'historical-client',
+ status: 'active',
+ operationGrants: ['host.status', 'session.transcript.query'],
+ canPublishClientCapabilities: false,
+ canUseHostPaths: false,
+ createdAt: '2026-01-01T00:00:00.000Z',
+ },
+ ],
+ sessionGrants: [],
+ turnAccessRequests: [],
+ });
+
+ assert.deepEqual(
+ [...(file.credentials[0]?.operationGrants ?? [])],
+ ['host.status', 'session.transcript.page', 'session.transcript.overlay.release'],
+ );
+});
+
+test('issuing a grant the protocol does not define is still rejected', async () => {
+ // Reading tolerates history; writing does not create it.
+ assert.throws(() => issuedAccessGrants(['not.an.operation' as never]), /Unknown Runtime Host/u);
+});
diff --git a/packages/runtime-host/src/server/access-credential-store.ts b/packages/runtime-host/src/server/access-credential-store.ts
index 77da3af44a..8d136876e8 100644
--- a/packages/runtime-host/src/server/access-credential-store.ts
+++ b/packages/runtime-host/src/server/access-credential-store.ts
@@ -37,27 +37,47 @@ import {
const ACCESS_FILE_SCHEMA_VERSION = 4;
const PRE_CAPABILITY_OWNER_ACCESS_FILE_SCHEMA_VERSION = 3;
const ACCESS_FILE_MAX_BYTES = 512 * 1024;
-const LEGACY_TRANSCRIPT_QUERY_GRANT = 'session.transcript.query';
-const TRANSCRIPT_QUERY_REPLACEMENT_GRANTS = [
- 'session.transcript.page',
- 'session.transcript.overlay.release',
-] as const satisfies readonly OperationKey[];
-const TURN_QUERY_GRANT = 'session.turns.query';
-const TURN_QUERY_REPLACEMENT_GRANTS = [
- TURN_QUERY_GRANT,
- 'session.turn_landmarks.query',
-] as const satisfies readonly OperationKey[];
-// Operations that left the protocol entirely. A previously issued access file
-// may still grant them; the grant is released on decode — there is nothing to
-// migrate it to — because failing the whole file would keep the Host from
-// starting over a capability it could not serve anyway.
-const RETIRED_OPERATION_GRANTS = new Set([
+// What a stored operation grant means to the current protocol. An access file
+// is the Host's own record of what it already granted, written by a build that
+// may be several releases old, and no peer is present to negotiate a version.
+// `replace` carries the stored authority to the operations that succeeded it;
+// `release` drops it because nothing did.
+type PersistedGrantMigration =
+ | { readonly kind: 'replace'; readonly successors: readonly OperationKey[] }
+ | { readonly kind: 'release' };
+
+// Every grant this Host has ever persisted under a name the current protocol no
+// longer serves, plus the grants whose authority widened across a rename. A
+// stored grant that is still a current operation and names no entry here keeps
+// itself; one that is neither is released, because failing the whole file would
+// keep the Host from starting over a capability it could not serve either way.
+// The write path stays strict — `validateIssuedGrants` still rejects a grant
+// the current protocol does not define.
+const PERSISTED_GRANT_MIGRATIONS: ReadonlyMap<string, PersistedGrantMigration> = new Map<
+ string,
+ PersistedGrantMigration
+>([
+ // The transcript query split into paging and its overlay release.
+ [
+ 'session.transcript.query',
+ {
+ kind: 'replace',
+ successors: ['session.transcript.page', 'session.transcript.overlay.release'],
+ },
+ ],
+ // Turn query kept its name and gained a separate landmark query beside it.
+ [
+ 'session.turns.query',
+ { kind: 'replace', successors: ['session.turns.query', 'session.turn_landmarks.query'] },
+ ],
+ // TaskLedger became SessionTodo; the query carried its authority over.
+ ['task.ledger.query', { kind: 'replace', successors: ['session.todo.query'] }],
// Retired with the Claude subscription provider, whose client identity the
// usage report required.
- 'oauth.account.usage.fetch',
+ ['oauth.account.usage.fetch', { kind: 'release' }],
// Retired with the second execution-inspection contract; no shipped surface
- // called execution.inspect.resolve, so a stored grant is released on decode.
- 'execution.inspect.resolve',
+ // called execution.inspect.resolve.
+ ['execution.inspect.resolve', { kind: 'release' }],
]);
export const ACCESS_FILE_NAME = 'runtime-host-access.json';
@@ -322,17 +342,12 @@ function decodeStoredCredential(value: unknown): StoredAccessCredential {
if (new Set(storedOperationGrants).size !== storedOperationGrants.length) {
throw new Error('Duplicate Runtime Host access operation grant');
}
- const migratedOperationGrants = validateStoredGrants(
- migrateStoredOperationGrants(storedOperationGrants),
- );
- if (
- principalKind === 'session_guest' &&
- migratedOperationGrants.some(
- (grant) => !(SESSION_GUEST_OPERATION_GRANTS as readonly OperationKey[]).includes(grant),
- )
- ) {
- throw new Error('Session Guest credential has an invalid operation grant');
- }
+ const migratedOperationGrants = migrateStoredOperationGrants(storedOperationGrants);
+ // A Session Guest credential carries whatever the guest policy granted when it
+ // was issued, and the policy is re-applied below, so a stored grant the
+ // current guest list no longer names is a version difference rather than a
+ // fault. Replacing it is the whole authority; failing the file would only
+ // strand the workspace.
const operationGrants = Object.freeze(
principalKind === 'session_guest'
? [...SESSION_GUEST_OPERATION_GRANTS]
@@ -440,27 +455,28 @@ function decodeCapabilityOwner(value: unknown): ClientCapabilityOwnerIdentity |
return Object.freeze({ principalId, clientInstanceId });
}
-function migrateStoredOperationGrants(grants: readonly string[]): readonly string[] {
- const migrated: string[] = [];
+function migrateStoredOperationGrants(grants: readonly string[]): readonly OperationKey[] {
+ const migrated: OperationKey[] = [];
const seen = new Set<string>();
for (const stored of grants) {
- const replacements = RETIRED_OPERATION_GRANTS.has(stored)
- ? []
- : stored === LEGACY_TRANSCRIPT_QUERY_GRANT
- ? TRANSCRIPT_QUERY_REPLACEMENT_GRANTS
- : stored === TURN_QUERY_GRANT
- ? TURN_QUERY_REPLACEMENT_GRANTS
- : [stored];
- for (const replacement of replacements) {
- if (seen.has(replacement)) continue;
- seen.add(replacement);
- migrated.push(replacement);
+ const migration = PERSISTED_GRANT_MIGRATIONS.get(stored);
+ const successors: readonly OperationKey[] = migration
+ ? migration.kind === 'replace'
+ ? migration.successors
+ : []
+ : Object.hasOwn(HOST_OPERATION_SPECS, stored)
+ ? [stored as OperationKey]
+ : [];
+ for (const successor of successors) {
+ if (seen.has(successor)) continue;
+ seen.add(successor);
+ migrated.push(successor);
}
}
- return migrated;
+ return Object.freeze(migrated);
}
-function validateStoredGrants(grants: readonly string[]): readonly OperationKey[] {
+function assertCurrentOperationGrants(grants: readonly string[]): readonly OperationKey[] {
for (const grant of grants) {
if (!Object.hasOwn(HOST_OPERATION_SPECS, grant)) {
throw new RuntimeHostAccessInputError(`Unknown Runtime Host operation grant: ${grant}`);
@@ -470,7 +486,7 @@ function validateStoredGrants(grants: readonly string[]): readonly OperationKey[
}
function validateIssuedGrants(grants: readonly OperationKey[]): readonly OperationKey[] {
- validateStoredGrants(grants);
+ assertCurrentOperationGrants(grants);
for (const grant of grants) {
if (!operationAllowsRemoteOwner(grant)) {
throw new RuntimeHostAccessInputError(`Runtime Host operation ${grant} is local-owner only`);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 03/03: ci(release): trigger the State Root forward roll on durable-state decoders
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch feat/persistence-forward-roll-guard
in repository https://gitbox.apache.org/repos/asf/maka.git
commit a8ec9282a3d2fd68543ff3f089d9b964cfd860e8
Author: AstroHan <le...@outlook.com>
AuthorDate: Tue Sep 1 13:05:45 2026 +0800
ci(release): trigger the State Root forward roll on durable-state decoders
The released State Root qualification already runs on every pull request that
touches CLI packaging, and it is the only check that reads durable state a
previously released build wrote. Its trigger named the packaging around the
decoders but never the decoders themselves, so retiring a persisted operation
grant went green here while workspaces holding a credential from an earlier
build could no longer start.
Add the durable-state decoders to that trigger: the access authority and its
credential store, the operational state store that migrates runtime.sqlite,
the storage root authority, the SQLite schemas, and the State Root
composition. These are the files whose input is written by a build that is
already installed elsewhere, where no peer is present to negotiate a version
and the only proof is a real forward roll.
A workflow policy test now fails if one of these paths leaves the trigger,
because losing coverage here is silent: the lane simply stops running and
every check still reports green.
Generated-by: Claude Code (Opus 5)
---
.github/workflows/cli-package-validation.yml | 12 ++++++++++++
scripts/release-cli-workflow-policy.test.mjs | 24 ++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/.github/workflows/cli-package-validation.yml b/.github/workflows/cli-package-validation.yml
index 1bd0b62743..d6938da538 100644
--- a/.github/workflows/cli-package-validation.yml
+++ b/.github/workflows/cli-package-validation.yml
@@ -34,11 +34,23 @@ on:
- 'packages/runtime-host/package.json'
- 'packages/runtime-host/src/client/peer-client.ts'
- 'packages/runtime-host/src/peer-mesh/**'
+ # The decoders below read state a previously released build wrote, with no
+ # peer present to negotiate a version, so a released-artifact forward roll
+ # is the only check that exercises them the way a user's upgrade does. The
+ # State Root qualification job is already here; these paths are what make
+ # it run when the decoders themselves change, rather than only when the
+ # CLI packaging around them does.
+ - 'packages/runtime-host/src/server/access-authority.ts'
+ - 'packages/runtime-host/src/server/access-credential-store.ts'
- 'packages/runtime-host/src/server/peer-listener.ts'
- 'packages/runtime-host/src/transport/peer-native.ts'
- 'packages/storage/package.json'
- 'packages/storage/src/file-lifetime-owner.ts'
- 'packages/storage/src/native-file-lock.ts'
+ - 'packages/storage/src/operational-state-store.ts'
+ - 'packages/storage/src/root-authority.ts'
+ - 'packages/storage/src/sqlite-*-schema.ts'
+ - 'packages/storage/src/state-root-composition.ts'
- 'scripts/generate-runtime-host-peer-*'
- 'scripts/release-cli-package.mjs'
- 'scripts/qualify-released-cli-state-root.mjs'
diff --git a/scripts/release-cli-workflow-policy.test.mjs b/scripts/release-cli-workflow-policy.test.mjs
index 4abe6ef970..45eaff02ea 100644
--- a/scripts/release-cli-workflow-policy.test.mjs
+++ b/scripts/release-cli-workflow-policy.test.mjs
@@ -262,3 +262,27 @@ function namedStep(steps, name) {
assert.ok(step, `missing workflow step: ${name}`);
return step;
}
+
+test('the State Root qualification runs when a durable-state decoder changes', () => {
+ // Nothing else exercises these decoders against state a previously released
+ // build wrote. Without them on this trigger, retiring a persisted operation
+ // grant went green here and stranded workspaces on upgrade instead.
+ const workflow = readWorkflow('cli-package-validation.yml');
+ const pullRequestPaths = workflow.slice(
+ workflow.indexOf('pull_request:'),
+ workflow.indexOf('workflow_call:'),
+ );
+ for (const path of [
+ 'packages/runtime-host/src/server/access-authority.ts',
+ 'packages/runtime-host/src/server/access-credential-store.ts',
+ 'packages/storage/src/operational-state-store.ts',
+ 'packages/storage/src/root-authority.ts',
+ 'packages/storage/src/sqlite-*-schema.ts',
+ 'packages/storage/src/state-root-composition.ts',
+ ]) {
+ assert.ok(
+ pullRequestPaths.includes(`- '${path}'`),
+ `${path} decodes durable state and must trigger the released forward roll`,
+ );
+ }
+});
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
(maka) 02/03: test(release): qualify the control namespace beside the State Root
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch feat/persistence-forward-roll-guard
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 406786ed7df919d2ae62c43a280d1100a87c73cf
Author: AstroHan <le...@outlook.com>
AuthorDate: Tue Sep 1 13:03:51 2026 +0800
test(release): qualify the control namespace beside the State Root
The released State Root qualification seeded and compared only the State Root
directory, so it could not observe the durable surface that actually decides
whether a Host starts. The Runtime Host access file lives in the account-local
control namespace and is opened before the Kernel starts; a credential issued
by an older build is the record that stranded workspaces across the
TaskLedger-to-SessionTodo cutover, and this harness was structurally blind to
it.
Seed a remote-owner credential from the released build and read it back on
inspect. The grant set comes from what the released build reports it can
issue rather than a list written here, so the fixture keeps covering renames
that have not happened yet. Golden capture and restore now span every durable
location instead of the State Root alone.
The recorded facts carry the credential identity and not its grants: a rename
is supposed to move a stored grant to its successor, so comparing grant lists
across builds would report a correct migration as a lost fact. What must hold
is that the credential survives and the target Host opens the file at all.
Generated-by: Claude Code (Opus 5)
---
scripts/qualify-released-cli-state-root.mjs | 62 ++++++++++++++++++------
scripts/qualify-released-cli-state-root.test.mjs | 21 +++++++-
scripts/released-cli-state-root-fixture.mjs | 59 ++++++++++++++++++++++
3 files changed, 127 insertions(+), 15 deletions(-)
diff --git a/scripts/qualify-released-cli-state-root.mjs b/scripts/qualify-released-cli-state-root.mjs
index 5a4faf250a..77f69f0443 100644
--- a/scripts/qualify-released-cli-state-root.mjs
+++ b/scripts/qualify-released-cli-state-root.mjs
@@ -21,6 +21,7 @@ import { spawnSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import {
cpSync,
+ existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
@@ -174,23 +175,41 @@ export async function qualifyReleasedCliStateRoot(input) {
}
}
+// The State Root is not the whole durable surface. The Runtime Host access file
+// and the rest of the control records live in the account-local control
+// namespace, and the Host opens them before the Kernel starts — so a golden
+// copy that captured only the State Root could not restore, or observe, the
+// state that decides whether the Host starts at all. The control path mirrors
+// resolveRootControlNamespace in @maka/storage; this harness runs on Linux
+// only, so it names the Linux location rather than importing across the
+// installed artifacts it is here to compare.
+export function durableStateLocations(scope) {
+ return [
+ { live: join(scope, 'state-root'), golden: join(scope, 'golden-root') },
+ {
+ live: join(userInfo().homedir, '.cache', 'maka', 'runtime-hosts'),
+ golden: join(scope, 'golden-control'),
+ },
+ ];
+}
+
async function qualifyInstalledArtifacts(input) {
const { scope, source, target } = input;
- const rootPath = join(scope, 'state-root');
- const goldenPath = join(scope, 'golden-root');
+ const locations = durableStateLocations(scope);
+ const rootPath = locations[0].live;
mkdirSync(rootPath, { recursive: true });
const seeded = runFixture({ action: 'seed', artifact: source, rootPath, scope });
assertFacts(seeded);
- cpSync(rootPath, goldenPath, { recursive: true, force: true });
+ captureGolden(locations);
const sourceReady = await runInstalledRuntimeHost({ artifact: source, rootPath, scope });
const sourceFacts = runFixture({ action: 'inspect', artifact: source, rootPath, scope });
assertSameFacts(seeded, sourceFacts, 'source self-reopen');
- restoreGolden(rootPath, goldenPath);
+ restoreGolden(locations);
const writerFence = await proveWriterFence({ source, target, rootPath, scope });
- restoreGolden(rootPath, goldenPath);
+ restoreGolden(locations);
const targetReady = await runInstalledRuntimeHost({ artifact: target, rootPath, scope });
const targetFacts = runFixture({ action: 'inspect', artifact: target, rootPath, scope });
assertSameFacts(seeded, targetFacts, 'target transition');
@@ -529,7 +548,8 @@ function assertFacts(value) {
!value.rootId ||
!value.session?.id ||
!value.session?.message?.id ||
- !value.scheduledTask?.id
+ !value.scheduledTask?.id ||
+ !value.access?.credentialId
) {
throw new Error('Released fixture evidence is incomplete');
}
@@ -542,15 +562,29 @@ function assertSameFacts(expected, actual, stage) {
}
}
-function restoreGolden(rootPath, goldenPath) {
- for (const entry of readdirSync(rootPath)) {
- rmSync(join(rootPath, entry), { recursive: true, force: true });
+function captureGolden(locations) {
+ for (const { live, golden } of locations) {
+ rmSync(golden, { recursive: true, force: true });
+ if (!existsSync(live)) continue;
+ cpSync(live, golden, { recursive: true, force: true });
}
- for (const entry of readdirSync(goldenPath)) {
- cpSync(join(goldenPath, entry), join(rootPath, entry), {
- recursive: true,
- force: true,
- });
+}
+
+function restoreGolden(locations) {
+ for (const { live, golden } of locations) {
+ if (existsSync(live)) {
+ for (const entry of readdirSync(live)) {
+ rmSync(join(live, entry), { recursive: true, force: true });
+ }
+ }
+ if (!existsSync(golden)) continue;
+ mkdirSync(live, { recursive: true });
+ for (const entry of readdirSync(golden)) {
+ cpSync(join(golden, entry), join(live, entry), {
+ recursive: true,
+ force: true,
+ });
+ }
}
}
diff --git a/scripts/qualify-released-cli-state-root.test.mjs b/scripts/qualify-released-cli-state-root.test.mjs
index 87c3bd8822..d24c0de389 100644
--- a/scripts/qualify-released-cli-state-root.test.mjs
+++ b/scripts/qualify-released-cli-state-root.test.mjs
@@ -20,10 +20,11 @@
import assert from 'node:assert/strict';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join, resolve } from 'node:path';
+import { isAbsolute, join, resolve } from 'node:path';
import test from 'node:test';
import {
assertExpectedEpochRelation,
+ durableStateLocations,
parseQualificationArgs,
qualificationSandboxArgs,
qualificationSandboxInvocation,
@@ -190,3 +191,21 @@ test('computes the exact artifact SHA-256', () => {
rmSync(root, { recursive: true, force: true });
}
});
+
+test('durable state covers the control namespace, not only the State Root', () => {
+ // The access file the Host opens before its Kernel starts lives beside the
+ // State Root, not inside it. A golden copy scoped to the State Root alone
+ // restored a workspace whose control records had already moved on, so the
+ // transition it proved was never the one a user performs.
+ const locations = durableStateLocations('/qualification-scope');
+ assert.ok(locations.length >= 2);
+ assert.ok(locations.some(({ live }) => live === '/qualification-scope/state-root'));
+ assert.ok(
+ locations.some(({ live }) => live.endsWith(join('.cache', 'maka', 'runtime-hosts'))),
+ 'the account-local control namespace must be captured and restored',
+ );
+ for (const { live, golden } of locations) {
+ assert.ok(isAbsolute(live) && isAbsolute(golden));
+ assert.ok(!golden.startsWith(`${live}/`), 'a golden copy must not nest inside its live path');
+ }
+});
diff --git a/scripts/released-cli-state-root-fixture.mjs b/scripts/released-cli-state-root-fixture.mjs
index b67f374057..252de0595d 100644
--- a/scripts/released-cli-state-root-fixture.mjs
+++ b/scripts/released-cli-state-root-fixture.mjs
@@ -23,6 +23,7 @@ import { pathToFileURL } from 'node:url';
const SESSION_NAME = 'Released State Root qualification';
const MESSAGE_ID = 'released-state-root-message';
const TASK_TITLE = 'Released State Root durable task';
+const ACCESS_PRINCIPAL_ID = 'released-state-root-qualification-client';
const FUTURE_FIRE_DELAY_MS = 24 * 60 * 60 * 1_000;
const input = parseFixtureArgs(process.argv.slice(2));
@@ -113,6 +114,7 @@ async function seedFixture(packageRoot, rootPath, rootOwner, rootId) {
schedule: task.schedule,
effect: task.effect,
},
+ access: await seedAccessCredential(packageRoot, rootOwner.controlDirectory),
};
} finally {
scheduledTasks.close();
@@ -120,6 +122,62 @@ async function seedFixture(packageRoot, rootPath, rootOwner, rootId) {
}
}
+// The access file lives in the account-local control namespace rather than the
+// State Root, and the Host opens it before the Kernel starts. A credential
+// issued by the released build is therefore the one durable record that decides
+// whether the current build can start at all.
+async function seedAccessCredential(packageRoot, controlDirectory) {
+ const accessAuthority = await loadInstalled(
+ packageRoot,
+ 'node_modules/@maka/runtime-host/dist/server/access-authority.js',
+ );
+ const protocol = await loadInstalled(
+ packageRoot,
+ 'node_modules/@maka/runtime-host/dist/protocol/index.js',
+ );
+ const authority = await accessAuthority.openRuntimeHostAccessAuthority(controlDirectory);
+ try {
+ // Ask the released build what it is able to grant instead of naming
+ // operations here. A fixture that hard-codes today's keys stops covering
+ // the next rename the moment that rename lands.
+ const issued = await accessAuthority.issueAccessCredential(authority, {
+ principalKind: 'remote_owner',
+ principalId: ACCESS_PRINCIPAL_ID,
+ operationGrants: [...protocol.REMOTE_OWNER_OPERATION_GRANTS],
+ canPublishClientCapabilities: false,
+ canUseHostPaths: false,
+ });
+ if (!issued.ok) {
+ throw new Error(
+ `The released access credential could not be issued: ${issued.error.message}`,
+ );
+ }
+ return { credentialId: issued.result.credentialId, principalId: issued.result.principalId };
+ } finally {
+ await authority.close();
+ }
+}
+
+// Grants are deliberately absent from the facts: a rename is supposed to move a
+// stored grant to its successor, so comparing the grant list across builds
+// would report a correct migration as a lost fact. The credential identity is
+// what must survive, and the Host refusing to open the file is what fails.
+async function inspectAccessCredential(packageRoot, controlDirectory) {
+ const store = await loadInstalled(
+ packageRoot,
+ 'node_modules/@maka/runtime-host/dist/server/access-credential-store.js',
+ );
+ const file = await store.readAccessCredentialFile(join(controlDirectory, store.ACCESS_FILE_NAME));
+ const credential = file.credentials.find(
+ (candidate) => candidate.principalId === ACCESS_PRINCIPAL_ID,
+ );
+ if (!credential) throw new Error('The released access credential fact is missing');
+ if (!credential.operationGrants.includes('host.status')) {
+ throw new Error('The released access credential lost its liveness grant');
+ }
+ return { credentialId: credential.credentialId, principalId: credential.principalId };
+}
+
async function inspectFixture(packageRoot, rootPath, rootOwner, rootId) {
const sessionsModule = await loadInstalled(
packageRoot,
@@ -158,6 +216,7 @@ async function inspectFixture(packageRoot, rootPath, rootOwner, rootId) {
schedule: task.schedule,
effect: task.effect,
},
+ access: await inspectAccessCredential(packageRoot, rootOwner.controlDirectory),
};
} finally {
scheduledTasks.close();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org