Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
34555de
perf(runtime-host): add bounded transcript paging
M4n5ter Aug 12, 2026
4140d1f
perf(runtime-host): harden transcript data plane
M4n5ter Aug 12, 2026
32d7493
fix(runtime-host): refresh transcript operation grant
M4n5ter Aug 12, 2026
609982c
fix(runtime-host): pin transcript overlay handoff
M4n5ter Aug 12, 2026
768d606
fix(runtime-host): retire terminal transcript overlays
M4n5ter Aug 12, 2026
9d7cd99
fix(runtime-host): close transcript paging review gaps
M4n5ter Aug 12, 2026
9894063
fix(runtime-host): harden transcript data bounds
M4n5ter Aug 12, 2026
e682f9d
fix(runtime-host): bound transcript preparation
M4n5ter Aug 12, 2026
4dd5d75
fix(runtime-host): keep capacity waits outside session lanes
M4n5ter Aug 12, 2026
ed995df
perf(storage): chunk durable transcript records
M4n5ter Aug 12, 2026
651ead3
perf(transcript): reduce paging overhead
M4n5ter Aug 12, 2026
19d4b81
fix(transcript): close storage and connection bounds
M4n5ter Aug 12, 2026
e4cf95c
style(storage): format transcript fixture
M4n5ter Aug 12, 2026
3fc0132
perf(transcript): keep migration and partial writes bounded
M4n5ter Aug 12, 2026
a925b95
fix(transcript): bound upgrade and capacity failure
M4n5ter Aug 12, 2026
468638a
fix(transcript): refine bounded admission retries
M4n5ter Aug 12, 2026
b27ad55
fix(transcript): release consumed overlay state
M4n5ter Aug 12, 2026
f847475
fix(transcript): close paging integrity boundaries
M4n5ter Aug 12, 2026
4dd05e6
fix(transcript): fail closed on overlay release
M4n5ter Aug 12, 2026
5be2364
refactor(transcript): trim redundant test machinery
M4n5ter Aug 12, 2026
69aa62b
fix(transcript): close upgrade review gaps
M4n5ter Aug 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/desktop/src/main/__tests__/runtime-host-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function subscription(
hostEpoch: 'host-1',
subscriptionId: `subscription-${sessionId}`,
activeAssistantStreams: [],
transcriptBootstrap: null,
snapshot: {
schemaVersion: SESSION_CONTINUITY_SCHEMA_VERSION,
session: {
Expand All @@ -72,6 +73,9 @@ function subscription(
lifecycle.push(`${sessionId}:transcript`);
return [] as T[];
},
loadTranscriptPage: async () => {
throw new Error('Fake subscription does not expose transcript pages');
},
close: async () => {
lifecycle.push(`${sessionId}:close`);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test("read adapters project ordinary failures without hiding reconnectable failu
}

const failure = new RuntimeHostOperationError(
"session.transcript.query",
"session.transcript.page",
"host_draining",
"Runtime Host is draining",
);
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/main/runtime-host-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
type QueueRetractInput,
type QueueRetractResult,
type SessionCatalogFilter,
SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES,
type SessionCatalogChangedFrame,
type ScheduledTaskChangedFrame,
type SessionCatalogItem,
Expand Down Expand Up @@ -1262,6 +1263,7 @@ export class DesktopRuntimeHostClient {
this.#assertOpen();
const subscription = await this.connection.openSessionSubscription({
sessionId,
transcript: { kind: "tail", maxBytes: SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES },
});
if (this.#closeTask) {
await subscription.close().catch(() => undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function isRecoverableSubscriptionFailure(error: unknown): boolean {
error.reason === "slow_consumer" ||
error.reason === "sequence_gap" ||
error.reason === "projection_revision_invalid" ||
error.reason === "transcript_expired"
error.reason === "transcript_release_failed"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,7 @@ class FakeConnection {
class FakeSubscription implements RuntimeHostSessionSubscription, AsyncIterator<SubscriptionFrame> {
readonly hostEpoch = 'host-1';
readonly activeAssistantStreams = [];
readonly transcriptBootstrap = null;
readonly subscriptionId: string;
readonly #frames: SubscriptionFrame[] = [];
readonly #waiters: Array<{
Expand Down Expand Up @@ -1299,6 +1300,10 @@ class FakeSubscription implements RuntimeHostSessionSubscription, AsyncIterator<
return (await this.transcript).map(decodeMessage);
}

async loadTranscriptPage(): Promise<never> {
throw new Error('Fake subscription does not expose transcript pages');
}

async close(): Promise<void> {
this.#closed = true;
for (const waiter of this.#waiters.splice(0)) {
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/runtime-host-session-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
type RuntimeHostConnection,
type RuntimeHostSessionSubscription,
} from '@maka/runtime-host/client';
import type {
import {
InteractionAnsweredSnapshot,
InteractionPendingSnapshot,
SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES,
SessionContinuitySnapshot,
SubscriptionFrame,
} from '@maka/runtime-host/protocol';
Expand Down Expand Up @@ -98,6 +99,7 @@ export class RuntimeHostSessionChannel {
): Promise<RuntimeHostSessionChannelOpenResult> {
const subscription = await options.connection.openSessionSubscription({
sessionId: options.sessionId,
transcript: { kind: 'tail', maxBytes: SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES },
});
const initialRoot = structuredClone(subscription.snapshot.rootTurn);
const channel = new RuntimeHostSessionChannel(subscription, [], options, options.connection);
Expand Down Expand Up @@ -299,7 +301,10 @@ export class RuntimeHostSessionChannel {
await previous.close().catch(() => undefined);
let replacement: RuntimeHostSessionSubscription;
try {
replacement = await this.#connection.openSessionSubscription({ sessionId: this.sessionId });
replacement = await this.#connection.openSessionSubscription({
sessionId: this.sessionId,
transcript: { kind: 'tail', maxBytes: SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES },
});
} catch (error) {
if (this.#canRecover(error)) continue;
throw error;
Expand Down Expand Up @@ -429,8 +434,8 @@ export class RuntimeHostSessionChannel {
(error.reason === 'connection_closed' ||
error.reason === 'sequence_gap' ||
error.reason === 'projection_revision_invalid' ||
error.reason === 'slow_consumer' ||
error.reason === 'transcript_expired')
error.reason === 'transcript_release_failed' ||
error.reason === 'slow_consumer')
);
}

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/runtime-host-session-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import {
} from '@maka/runtime-host/adapter';
import type { DirectRequestOperationKey, RuntimeHostConnection } from '@maka/runtime-host/client';
import { readRuntimeHostResources, readRuntimeHostSessions } from '@maka/runtime-host/client';
import type {
import {
InteractionPendingSnapshot,
OperationInput,
OperationOutput,
SessionCatalogItem,
SessionCatalogProjection,
SessionUpdateResult,
SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES,
WorkspaceTarget,
} from '@maka/runtime-host/protocol';
import {
Expand Down Expand Up @@ -1044,7 +1045,10 @@ async function loadCurrentMessages(
connection: RuntimeHostSessionDriverConnection,
sessionId: string,
): Promise<StoredMessage[]> {
const subscription = await connection.openSessionSubscription({ sessionId });
const subscription = await connection.openSessionSubscription({
sessionId,
transcript: { kind: 'tail', maxBytes: SESSION_TRANSCRIPT_BOOTSTRAP_MAX_BYTES },
});
const draining = (async () => {
for await (const _frame of subscription) {
// The transcript is pinned to the subscription snapshot. Drain newer
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"clean": "node ../../scripts/clean-paths.mjs dist tsconfig.tsbuildinfo",
"build": "tsc -p tsconfig.json",
"benchmark:transcript": "node scripts/transcript-data-plane-benchmark.mjs",
"typecheck": "tsc -p tsconfig.json --noEmit",
"test": "npm run clean && npm run build && npm run test:dist",
"test:dist": "node --test \"dist/**/*.test.js\""
Expand Down
159 changes: 159 additions & 0 deletions packages/runtime-host/scripts/transcript-data-plane-benchmark.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { performance } from 'node:perf_hooks';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { createSessionStore } from '@maka/storage';
import { ClientSessionSubscription } from '../dist/client/session-subscription.js';
import {
createSessionTranscriptBootstrap,
readSessionTranscriptPage,
} from '../dist/server/session-transcript-pager.js';

const BOOTSTRAP_BYTES = 16 * 1024;
const RTT_MS = Number.parseInt(process.env.MAKA_TRANSCRIPT_BENCHMARK_RTT_MS ?? '20', 10);
const cases = [
{ name: '5k-small-messages', messages: 5_000, textBytes: 96 },
{ name: '15MiB-single-message', messages: 1, textBytes: 15 * 1024 * 1024 },
{ name: '17MiB-transcript', totalBytes: 17 * 1024 * 1024, textBytes: 4 * 1024 },
{ name: '64MiB-transcript', totalBytes: 64 * 1024 * 1024, textBytes: 4 * 1024 },
];

const results = [];
for (const fixture of cases) results.push(await runFixture(fixture));
console.table(results);

async function runFixture(fixture) {
const messages = buildMessages(fixture);
const root = await mkdtemp(join(tmpdir(), 'maka-transcript-benchmark-'));
const store = createSessionStore(root);
const setupAt = performance.now();
const session = await store.create({
cwd: root,
backend: 'fake',
llmConnectionSlug: 'fake',
model: 'fake-model',
permissionMode: 'ask',
name: fixture.name,
labels: [],
});
await store.appendMessages(session.id, messages);
const setupMs = performance.now() - setupAt;
const reader = sqliteReader(store);
try {
const openedAt = performance.now();
const throughSequence = await reader.readDurableHighWater(session.id);
const { bootstrap, state } = await createSessionTranscriptBootstrap({
reader,
sessionId: session.id,
subscriptionId: `benchmark-${fixture.name}`,
throughSequence,
rootTurn: null,
activeAssistantStreams: [],
maxBytes: BOOTSTRAP_BYTES,
});
const bootstrapCpuMs = performance.now() - openedAt;
let pageRequests = 0;
let transferredRawBytes = bootstrap.durable.rawBytes + bootstrap.overlay.rawBytes;
const subscription = new ClientSessionSubscription(
{
hostEpoch: 'benchmark-host',
subscriptionId: state.subscriptionId,
nextSequence: 1,
activeAssistantStreams: [],
transcript: bootstrap,
snapshot: {
schemaVersion: 3,
session: {
sessionId: state.sessionId,
metadataRevision: 1,
status: 'active',
createdAt: 1,
lastUsedAt: 1,
isArchived: false,
},
projectionRevision: 1,
rootTurn: null,
goal: null,
queue: {
hostEpoch: 'benchmark-host',
queueRevision: 0,
steering: [],
followup: [],
},
interactions: { pending: [] },
},
},
async () => undefined,
async (request) => {
pageRequests += 1;
const page = await readSessionTranscriptPage({ reader, state, request });
transferredRawBytes += page.rawBytes;
return page;
},
);
const materializeAt = performance.now();
const materialized = await subscription.loadTranscript((value) => value);
const materializeCpuMs = performance.now() - materializeAt;
if (materialized.length !== messages.length) {
throw new Error(
`${fixture.name} materialized ${materialized.length}/${messages.length} messages`,
);
}
const wireRequests = 1 + pageRequests;
return {
fixture: fixture.name,
messages: messages.length,
rawMiB: decimalMiB(transferredRawBytes),
bootstrapKiB: decimalKiB(bootstrap.durable.rawBytes + bootstrap.overlay.rawBytes),
wireRequests,
pageRequests,
setupMs: setupMs.toFixed(1),
bootstrapCpuMs: bootstrapCpuMs.toFixed(1),
materializeCpuMs: materializeCpuMs.toFixed(1),
modeledRttFloorMs: wireRequests * RTT_MS,
};
} finally {
await store.close?.();
await rm(root, { recursive: true, force: true });
}
}

function buildMessages(fixture) {
const messages = [];
let encodedBytes = 0;
const targetCount = fixture.messages ?? Number.POSITIVE_INFINITY;
while (
messages.length < targetCount &&
(fixture.totalBytes === undefined || encodedBytes < fixture.totalBytes)
) {
const index = messages.length;
const message = {
type: 'user',
id: `message-${index}`,
turnId: `turn-${index}`,
ts: index + 1,
text: 'x'.repeat(fixture.textBytes),
};
messages.push(message);
encodedBytes += Buffer.byteLength(JSON.stringify(message), 'utf8');
}
return messages;
}

function sqliteReader(store) {
return {
readDurableHighWater: (sessionId) => store.readTranscriptHighWaterSnapshot(sessionId),
readDurablePage: (sessionId, request) => store.readTranscriptPageSnapshot(sessionId, request),
readDurableMessagesById: (sessionId, messageIds, throughSequence) =>
store.readTranscriptMessagesSnapshot(sessionId, messageIds, throughSequence),
readActiveOverlay: async () => [],
};
}

function decimalMiB(bytes) {
return (bytes / (1024 * 1024)).toFixed(2);
}

function decimalKiB(bytes) {
return (bytes / 1024).toFixed(2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ test('two Clients query and control one Agent graph through Session invalidation
try {
desktop = await connect(root, 'desktop');
tui = await connect(root, 'tui');
subscription = await desktop.openSessionSubscription({ sessionId: ROOT_SESSION_ID });
subscription = await desktop.openSessionSubscription({
sessionId: ROOT_SESSION_ID,
transcript: { kind: 'none' },
});

const [desktopSnapshot, tuiSnapshot] = await Promise.all([
desktop.request('agent.graph.query', { rootSessionId: ROOT_SESSION_ID }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,42 @@ test('keeps a formerly accepted local-only grant inert when opening an existing
}
});

test('migrates the released transcript query grant when opening an existing access file', async () => {
const directory = await mkdtemp(join(tmpdir(), 'maka-access-authority-transcript-legacy-'));
const credential = 'maka_rh_existing_transcript_client';
try {
await writeFile(
join(directory, 'runtime-host-access.json'),
`${JSON.stringify({
schemaVersion: 1,
credentials: [
{
credentialId: 'existing-transcript-client',
credentialHash: createHash('sha256').update(credential).digest('hex'),
principalId: 'existing-transcript-client',
principalKind: 'remote_owner',
status: 'active',
operationGrants: ['host.status', 'session.transcript.query', 'session.transcript.page'],
canPublishClientCapabilities: false,
canUseHostPaths: false,
createdAt: '2026-01-01T00:00:00.000Z',
},
],
})}\n`,
{ mode: 0o600 },
);

const authority = await openRuntimeHostAccessAuthority(directory);
assert.deepEqual(authority.authenticate(credential)?.operationGrants, [
'host.status',
'session.transcript.page',
'session.transcript.overlay.release',
]);
} finally {
await rm(directory, { recursive: true, force: true });
}
});

test('a rejected required WebSocket listener releases Local IPC and root ownership', async () => {
const base = await mkdtemp(join(tmpdir(), 'maka-websocket-startup-rollback-'));
const root = join(base, 'root');
Expand Down
Loading
Loading