perf(runtime-host): baseline materialized Session copy cost - #5526
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Ran the committed script against a representative built dist — it deterministically fails on the first fixture. Two P-level findings inline.
What verified clean: the measurement path is real — session.branch.create drives the production HostSessionRevisionCoordinator.#copy, turns are genuinely settled (4 runs / 12 messages materialized), the input contract matches session-revision.ts, the doc's copy-boundary table matches current source (blobId sharing, todo initializeCopy, linked-children modes, turn_state exclusion), the benchmark:session-copy script entry is inert to CI globs, and ASF headers pass.
On numbers provenance: good news — the doc contains no fabricated figures; it's a methodology document. But combined with the P1, the PR as committed delivers instructions for a baseline that has never been produced. Once the script actually runs, the doc should carry at least one recorded row (commit + platform) or the "baseline" framing should soften.
P3s:
directoryBytes(lines ~158-167) is TOCTOU on SQLite transient files —-wal/-shmcan vanish between readdir and stat → ENOENT crash. Catch and skip ENOENT.- The script leans on TS-
privateinternals (deps.store.readHeaderRecordSnapshot,listInvocations) and arecoverInterruptedSessionsStrictmonkey-patch — works on compiled JS, but a rename breaks it silently-ish; a public accessor or composition-returned handle is sturdier. - A
turn.startresult of'blocked'burns the full 10s deadline and throws a misleading timeout — check the result kind. - The doc asks readers to record commit/Node/platform, but the script prints only
console.table— emitprocess.version/process.platform/git SHA so output is self-describing.
| if (!sourceSummary || !sourceTurnId) throw new Error('Benchmark source did not settle'); | ||
| const targetSessionId = randomUUID(); | ||
| const startedAt = performance.now(); | ||
| const copied = await composition.handlers['session.branch.create']( |
There was a problem hiding this comment.
P1 — dead on arrival: the one-shot copy races two settlement windows. I ran the unmodified script twice; both runs died at historySize=4:
session_busy—isSessionActiveclears only when the run'sdonesettles, strictly after the projectedturn_state:'completed'thatwaitForCompletedTurnwaits for;source_revision_conflict(expected 20, actual 21) —expectedSourceRevisionis read once at line 100, but the source header keeps revising after the final turn (post-turn bookkeeping).
Both outcomes are retryable-by-design, so the fix is small: retry on session_busy (idle wait) and re-read readHeaderRecordSnapshot inside the retry on source_revision_conflict. I verified this in a tmp copy: with attempts=2 the copy commits cleanly (~11ms, 12 messages, amplification 1.00). Without it the PR's sole deliverable produces zero rows.
| }, | ||
| operationContext, | ||
| ); | ||
| const copyMs = performance.now() - startedAt; |
There was a problem hiding this comment.
P2 — single-sample latency. copyMs is one performance.now() delta per fixture, run sequentially in ascending order in one process — heap/GC carryover plus single-run noise. For data meant to drive the #5439 design decision (does copy cost grow with retained history), repeat N times and report median (and ideally a warmup pass), or state the limitation in the doc.
Refs #5439
Summary
npm --workspace @maka/runtime-host run benchmark:session-copysession.branch.createhandler over 4/16/64/128 settled turnsThis is the baseline/control-group slice for #5439. It does not introduce durable shared-prefix storage or parent-prefix dependencies.
Verification
npx biome check packages/runtime-host/scripts/session-copy-cost-benchmark.mjs docs/architecture/session-copy-cost-baseline.md packages/runtime-host/package.jsonnode --check packages/runtime-host/scripts/session-copy-cost-benchmark.mjsgit diff --check@maka/coreand@maka/storagebuilds pass in the isolated worktree@maka/runtimebuild is currently blocked by the local dependency state (@slack/socket-modetypes unavailable andHttpsProxyAgentgeneric mismatch), so the benchmark could not be executed against a freshly built runtime dist