MCPcopy Create free account
hub / github.com/apache/maka / MemorySessionStore

Class MemorySessionStore

packages/runtime/src/__tests__/session-manager.test.ts:17170–17460  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17168}
17169
17170class MemorySessionStore implements SessionStore {
17171 private headers = new Map<string, SessionHeader>();
17172 private messages = new Map<string, StoredMessage[]>();
17173 private executionBoundaries = new Map<string, ExecutionBoundary>();
17174 private sandboxBoundaryRequests = new Map<string, SandboxBoundaryRequest>();
17175 readonly failReadMessagesFor = new Set<string>();
17176 readonly failNextReadMessagesFor = new Map<string, number>();
17177 readonly failListTurnsFor = new Set<string>();
17178 readonly failUpdateHeaderFor = new Set<string>();
17179 failNextAppendMessage: ((message: StoredMessage) => boolean) | undefined;
17180 failAfterNextAppendMessage: ((message: StoredMessage) => boolean) | undefined;
17181 disposeCount = 0;
17182 nextReadHeaderGate: { started: Gate; release: Gate } | undefined;
17183 nextGraphOperatorProvisionGate: { started: Gate; release: Gate } | undefined;
17184 generatedTitleAttempted: Gate | undefined;
17185
17186 async createSubagent(
17187 input: CreateSessionInput,
17188 initialBoundary?: ExecutionBoundary,
17189 ): Promise<{ header: SessionHeader; created: boolean }> {
17190 const parent = input.subagentParent;
17191 const spawn = input.subagentSpawn;
17192 if (!parent || !input.subagentRuntime || !spawn) {
17193 throw new Error('Missing child-session metadata');
17194 }
17195 const existing = Array.from(this.headers.values()).find((header) => {
17196 const candidate = header.subagentParent;
17197 return (
17198 candidate?.parentSessionId === parent.parentSessionId &&
17199 candidate.spawnedBy.parentRunId === parent.spawnedBy.parentRunId &&
17200 candidate.spawnedBy.toolCallId === parent.spawnedBy.toolCallId &&
17201 candidate.swarm?.swarmId === parent.swarm?.swarmId &&
17202 candidate.swarm?.itemId === parent.swarm?.itemId
17203 );
17204 });
17205 if (existing) {
17206 if (
17207 existing.subagentSpawn?.requestFingerprint !== spawn.requestFingerprint ||
17208 existing.subagentParent?.spawnedBy.parentTurnId !== parent.spawnedBy.parentTurnId
17209 ) {
17210 throw new Error('Child-session spawn identity was reused for different work');
17211 }
17212 return { header: existing, created: false };
17213 }
17214 return { header: await this.create(input, initialBoundary), created: true };
17215 }
17216
17217 async createAgentGraphOperator(
17218 input: CreateSessionInput,
17219 request: AgentGraphOperatorProvisionRequest,
17220 _expectedRevision: number,
17221 initialBoundary?: ExecutionBoundary,
17222 ): Promise<{ header: SessionHeader } & AgentGraphOperatorProvisionResult> {
17223 const gate = this.nextGraphOperatorProvisionGate;
17224 if (gate) {
17225 this.nextGraphOperatorProvisionGate = undefined;
17226 gate.started.release();
17227 await gate.release.promise;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected