Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(editor): the bundle carries the run-up, as one ordered stream

esengine785612e265d3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0336f08a8..07d888f54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,22 @@ published separately; it ships inside the editor.
name reads the same everywhere it appears, and keep the shape, because a value
that was `undefined` and one that was `0` are different bugs.
+- **The bundle carries the run-up: what the editor was asked to do, in order.**
+ One stream rather than one per source, because a reproduction *is* an order —
+ opened a scene, deleted an entity, undid it, hot-reloaded, crashed — and two
+ streams only carry that order if whoever reads them re-merges by timestamp.
+
+ It is recorded at the two doors the editor already funnels through: the command
+ registry's single dispatch point and the undo stack's single commit. A command
+ that was **refused** is recorded too, since "I pressed undo and nothing
+ happened" is a bug report that a stream of successes would show as silence. An
+ undo names the step it reached, not just that undo occurred.
+
+ The stream is kept unredacted, which is only defensible because what enters it
+ is safe by construction: ids and shapes (`modify×1 Transform`), never a name or
+ a value. Repeats collapse with a count, so a gizmo drag cannot push the
+ interesting thing out of the buffer.
+
- **The GPU is readable while it works.** The engine captured its backend, vendor,
renderer and driver version at init all along — a lost backend cannot be asked
who it was — but the only way to read them was off a *loss report*, so a healthy
diff --git a/desktop/src/commands/registry.ts b/desktop/src/commands/registry.ts
index b7f4a3359..1ca38b526 100644
--- a/desktop/src/commands/registry.ts
+++ b/desktop/src/commands/registry.ts
@@ -16,6 +16,7 @@
import type { Command, Keybinding } from './types';
import { chordMatches, normalizeChord } from './keybinding';
import { PerfMonitor } from '@/engine/PerfMonitor';
+import { note } from '@/diagnostics/timeline';
import { ContributionRegistry, type Disposable, type Owner } from '@/contrib/ContributionRegistry';
const OVERRIDE_KEY = 'estella.keybindings';
@@ -133,7 +134,15 @@ class CommandRegistry {
/** Run a command by id (no-op if missing or currently disabled). */
run(id: string): void {
const c = this.contrib.get(id);
- if (c && (c.isEnabled?.() ?? true)) PerfMonitor.measure(`cmd.${id}`, () => c.run());
+ if (!c) return;
+ // A command that was asked for and REFUSED is worth as much in a report as
+ // one that ran: "undo, nothing happened, undo again" is a bug report.
+ if (!(c.isEnabled?.() ?? true)) {
+ note('command', id, 'disabled');
+ return;
+ }
+ note('command', id);
+ PerfMonitor.measure(`cmd.${id}`, () => c.run());
}
/** The enabled command bound to a key event, if any (honors overrides). */
diff --git a/desktop/src/diagnostics/index.ts b/desktop/src/diagnostics/index.ts
index c4fcc9e4d..d383e1620 100644
--- a/desktop/src/diagnostics/index.ts
+++ b/desktop/src/diagnostics/index.ts
@@ -11,4 +11,5 @@ export { diagnosticsRegistry, type DiagnosticSection } from './registry';
export { collectBundle, serializeBundle, bundleFileName, BUNDLE_FORMAT, type DiagnosticBundle } from './bundle';
export { exportDiagnostics } from './export';
export { captureBuildStamp, captureAppVersion } from './sections';
+export { note, timelineSnapshot, clearTimeline, type TimelineEvent, type TimelineKind } from './timeline';
export { personal, resolve, placeholder, stableTag, type DetailLevel, type Personal } from './redact';
diff --git a/desktop/src/diagnostics/sections.ts b/desktop/src/diagnostics/sections.ts
index 9d9212ee4..207ac47d6 100644
--- a/desktop/src/diagnostics/sections.ts
+++ b/desktop/src/diagnostics/sections.ts
@@ -13,6 +13,7 @@
import { takeCensus, getDeviceIdentity, getDeviceStatus, getDeviceLostReport } from 'esengine';
import { diagnosticsRegistry } from './registry';
import { personal } from './redact';
+import { timelineSnapshot } from './timeline';
import { EngineHost } from '@/engine/EngineHost';
import { checkEngineBuild } from '@/engine/EngineGuard';
import { ProjectStore } from '@/project/ProjectStore';
@@ -142,6 +143,21 @@ diagnosticsRegistry.register({
},
});
+/**
+ * The run-up: what the editor was asked to do, newest last.
+ *
+ * Kept in the clear. Every entry is an id or a shape by construction (see
+ * timeline.ts), so there is nothing here to redact — and a timeline of
+ * placeholders would answer none of the questions a timeline is for.
+ */
+diagnosticsRegistry.register({
+ id: 'timeline',
+ collect: () => {
+ const t = timelineSnapshot(Date.now());
+ return t.kept > 0 ? t : null;
+ },
+});
+
/**
* Settings that differ from their default — the ones that can change behaviour,
* and a short list rather than the whole page. A value can be anything a project
diff --git a/desktop/src/diagnostics/timeline.ts b/desktop/src/diagnostics/timeline.ts
new file mode 100644
index 000000000..15e9b36c8
--- /dev/null
+++ b/desktop/src/diagnostics/timeline.ts
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file timeline.ts
+ * @brief What the editor was asked to do, in the order it was asked.
+ *
+ * @details ONE stream, not one per source. A reproduction is an order — opened a
+ * scene, deleted an entity, undid it, hot-reloaded, crashed — and two
+ * streams only carry that order if a reader re-merges them by timestamp.
+ * The kind is a field.
+ *
+ * Deliberately dependency-free: it is written to from the command
+ * registry and the undo stack, both of which sit under everything else,
+ * so importing anything here would close a cycle.
+ */
+
+export type TimelineKind = 'command' | 'edit' | 'engine';
+
+export interface TimelineEvent {
+ /** Epoch ms. Absolute in the buffer, relative in a report. */
+ at: number;
+ kind: TimelineKind;
+ /** Command id, edit label, or engine event name. */
+ id: string;
+ /** One line of what it touched. Never the user's own content — see note(). */
+ detail?: string;
+ /** Consecutive repeats collapse into the last one, with a count. */
+ count: number;
+}
+
+/**
+ * How many events are kept. Not the log's 2000: a log line is one message, this
+ * is one gesture, and a report needs the run-up rather than the session. The
+ * buffer keeps the NEWEST — unlike the diagnostics aggregator, where the first
+ * distinct failure is the one that explains the rest.
+ */
+const CAPACITY = 300;
+
+const events: TimelineEvent[] = [];
+
+/**
+ * Record one event. `detail` must ALREADY be free of the user's own content:
+ * this stream is kept unredacted, so callers pass shapes and counts.
+ *
+ * Consecutive identical events collapse — a gizmo drag records one edit per
+ * frame, and 300 slots of "Move entity" would push out what matters.
+ */
+export function note(kind: TimelineKind, id: string, detail?: string): void {
+ const last = events[events.length - 1];
+ if (last && last.kind === kind && last.id === id && last.detail === detail) {
+ last.count++;
+ last.at = Date.now();
+ return;
+ }
+ events.push({ at: Date.now(), kind, id, detail, count: 1 });
+ if (events.length > CAPACITY) events.shift();
+}
+
+/**
+ * The events, oldest first, timed RELATIVE to `now` in seconds.
+ *
+ * Relative because "4 seconds before the report" is the readable fact, and an
+ * absolute clock in a bug report mostly tells you which timezone the reporter is
+ * in. The absolute time of the newest event is kept once, at the top.
+ */
+export function timelineSnapshot(now: number): {
+ capacity: number; kept: number; newestAt: string | null;
+ events: { tMinusSec: number; kind: TimelineKind; id: string; detail?: string; count: number }[];
+} {
+ const newest = events[events.length - 1];
+ return {
+ capacity: CAPACITY,
+ kept: events.length,
+ newestAt: newest ? new Date(newest.at).toISOString() : null,
+ events: events.map((e) => ({
+ tMinusSec: Math.round((now - e.at) / 100) / 10,
+ kind: e.kind,
+ id: e.id,
+ ...(e.detail !== undefined ? { detail: e.detail } : {}),
+ count: e.count,
+ })),
+ };
+}
+
+/** Drop everything — for tests, and for a user who wants a clean run-up. */
+export function clearTimeline(): void {
+ events.length = 0;
+}
diff --git a/desktop/src/engine/EditorHistory.ts b/desktop/src/engine/EditorHistory.ts
index 91533903a..5108bfdc8 100644
--- a/desktop/src/engine/EditorHistory.ts
+++ b/desktop/src/engine/EditorHistory.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { createStore } from 'zustand/vanilla';
+import { note } from '@/diagnostics/timeline';
/**
* Editor undo/redo. One user gesture (a field edit, a drag, a future add/delete)
@@ -66,6 +67,29 @@ export interface HistoryChange {
* and stays correct when the stack was empty at mark time. A mark holding the
* head entry instead would have all three problems.
*/
+/**
+ * One line of what a step touched, for the crash timeline: how many entities and
+ * which components, never a name or a value. The timeline is kept unredacted, so
+ * what goes into it has to be safe by construction rather than by a later pass.
+ */
+/** `undo`, or `undo modify×1 Transform` when the step said what it touched. */
+function joinDetail(verb: string, shape: string | undefined): string {
+ return shape ? `${verb} ${shape}` : verb;
+}
+
+function describeChanges(changes: readonly HistoryChange[]): string | undefined {
+ if (changes.length === 0) return undefined;
+ const kinds = new Map<string, number>();
+ const components = new Set<string>();
+ for (const c of changes) {
+ kinds.set(c.kind, (kinds.get(c.kind) ?? 0) + 1);
+ if (c.component) components.add(c.component);
+ }
+ const parts = [...kinds].map(([k, n]) => `${k}×${n}`);
+ if (components.size > 0) parts.push([...components].sort().join('+'));
+ return parts.join(' ');
+}
+
export interface HistoryMark {
readonly seq: number;
}
@@ -116,6 +140,10 @@ export class EditorHistoryImpl {
this.undoStack.push({ id: ++this.seq, label, doc, ops, changes });
if (this.undoStack.length > HISTORY_LIMIT) this.undoStack.shift();
this.redoStack.length = 0;
+ // The run-up to a crash, recorded where every edit already converges. What
+ // is noted is the SHAPE — kinds and components, never a name or a value —
+ // because this line is kept whether or not the report is ever redacted.
+ note('edit', label, describeChanges(changes));
this.bump();
}
@@ -304,6 +332,10 @@ export class EditorHistoryImpl {
if (!entry) return;
EditorHistoryImpl.apply(entry, 'undo');
this.redoStack.push(entry);
+ // WHICH step was undone, not just that undo happened: a report showing
+ // "undo" with no subject cannot be replayed or even read, and the command
+ // itself has no way to know what it reached.
+ note('edit', entry.label, joinDetail('undo', describeChanges(entry.changes)));
this.bump();
}
redo() {
@@ -311,6 +343,7 @@ export class EditorHistoryImpl {
if (!entry) return;
EditorHistoryImpl.apply(entry, 'redo');
this.undoStack.push(entry);
+ note('edit', entry.label, joinDetail('redo', describeChanges(entry.changes)));
this.bump();
}
canUndo() {
diff --git a/desktop/tests/crash-timeline.test.ts b/desktop/tests/crash-timeline.test.ts
new file mode 100644
index 000000000..0a900fd92
--- /dev/null
+++ b/desktop/tests/crash-timeline.test.ts
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The run-up to a crash: one ordered stream, recorded where the editor's
+ * two write doors already converge.
+ *
+ * The stream is kept UNREDACTED, which is only defensible if what goes
+ * into it is safe by construction — ids and shapes, never a name or a
+ * value. That property is what most of this file checks.
+ */
+import { describe, it, expect, beforeEach } from 'vitest';
+import { note, timelineSnapshot, clearTimeline } from '@/diagnostics/timeline';
+import { commands } from '@/commands';
+import { EditorHistory } from '@/engine/EditorHistory';
+
+const NOW = 1_000_000_000_000;
+
+beforeEach(() => clearTimeline());
+
+describe('the timeline', () => {
+ it('is one stream, so the order across sources survives', () => {
+ // Two streams carry this order only if a reader re-merges them by clock.
+ // The kind is a field precisely so nobody has to.
+ note('command', 'project.open');
+ note('edit', 'Delete entity', 'remove×1');
+ note('command', 'edit.undo');
+ const t = timelineSnapshot(NOW);
+ expect(t.events.map((e) => `${e.kind}:${e.id}`)).toEqual([
+ 'command:project.open', 'edit:Delete entity', 'command:edit.undo',
+ ]);
+ });
+
+ it('collapses a repeat instead of flushing the interesting thing out', () => {
+ // A gizmo drag records one edit per frame. Without collapsing, the
+ // buffer would hold nothing but the drag.
+ note('command', 'project.open');
+ for (let i = 0; i < 500; i++) note('edit', 'Move entity', 'modify×1 Transform');
+ const t = timelineSnapshot(NOW);
+ expect(t.events).toHaveLength(2);
+ expect(t.events[0].id).toBe('project.open');
+ expect(t.events[1].count).toBe(500);
+ });
+
+ it('keeps the newest when it overflows, and says the buffer is full', () => {
+ for (let i = 0; i < 400; i++) note('command', `cmd.${i}`);
+ const t = timelineSnapshot(NOW);
+ expect(t.kept).toBe(t.capacity);
+ expect(t.events[t.events.length - 1].id).toBe('cmd.399');
+ expect(t.events[0].id).not.toBe('cmd.0');
+ });
+
+ it('times events relative to the report, not to a clock in some timezone', () => {
+ note('command', 'project.open');
+ const t = timelineSnapshot(Date.now() + 4200);
+ expect(t.events[0].tMinusSec).toBeGreaterThanOrEqual(4.1);
+ expect(t.events[0].tMinusSec).toBeLessThanOrEqual(4.4);
+ expect(t.newestAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
+ });
+});
+
+describe('what the editor records', () => {
+ it('notes a command at the one place commands dispatch', () => {
+ // A command of this test's own, so what is asserted is the dispatch
+ // point rather than any real command's implementation.
+ let ran = 0;
+ const off = commands.register(
+ { id: 'test.noop', label: 'noop', category: 'test', run: () => { ran++; } },
+ 'plugin:test');
+ commands.run('test.noop');
+ off.dispose();
+ expect(ran).toBe(1);
+ const t = timelineSnapshot(NOW);
+ expect(t.events.some((e) => e.kind === 'command' && e.id === 'test.noop')).toBe(true);
+ });
+
+ it('notes a command that was REFUSED, which is half of a bug report', () => {
+ // "I pressed undo and nothing happened" is a report. A stream that only
+ // held what ran would show nothing at the moment being described.
+ expect(EditorHistory.canUndo()).toBe(false);
+ commands.run('edit.undo');
+ const t = timelineSnapshot(NOW);
+ const undo = t.events.find((e) => e.id === 'edit.undo');
+ expect(undo?.detail).toBe('disabled');
+ });
+
+ it('notes an edit as a shape — no name, no value ever reaches the stream', () => {
+ // The stream is not redacted, so this is the property that makes that
+ // safe. An entity called "SecretBossName" must not appear here.
+ EditorHistory.describe({
+ kind: 'modify', entity: 7, name: 'SecretBossName',
+ component: 'Transform', field: 'x', before: 1, after: 999,
+ });
+ EditorHistory.record('Move entity', () => {}, () => {});
+ const t = timelineSnapshot(NOW);
+ const edit = t.events.find((e) => e.kind === 'edit');
+ expect(edit?.id).toBe('Move entity');
+ expect(edit?.detail).toBe('modify×1 Transform');
+ expect(JSON.stringify(t)).not.toContain('SecretBossName');
+ expect(JSON.stringify(t)).not.toContain('999');
+ });
+
+ it('names the step an undo reached, not just that undo happened', () => {
+ // Found by reading a real timeline: it showed `command:edit.undo` with
+ // no subject. "Undo" alone cannot be read back or replayed, and the
+ // command has no way to know which step it reached.
+ EditorHistory.describe({ kind: 'add', entity: 3, name: 'Sprite0' });
+ EditorHistory.record('Add Entity', () => {}, () => {});
+ clearTimeline();
+ EditorHistory.undo();
+ EditorHistory.redo();
+ const t = timelineSnapshot(NOW);
+ expect(t.events.map((e) => `${e.id}|${e.detail}`)).toEqual([
+ 'Add Entity|undo add×1', 'Add Entity|redo add×1',
+ ]);
+ expect(JSON.stringify(t)).not.toContain('Sprite0');
+ });
+
+ it('records an edit with nothing declared, rather than dropping the step', () => {
+ // `describe` is optional today. A step without it still has to appear —
+ // "something changed here and did not say what" is a finding, and a gap
+ // in the sequence is not.
+ EditorHistory.record('Untold edit', () => {}, () => {});
+ const t = timelineSnapshot(NOW);
+ const edit = t.events.find((e) => e.id === 'Untold edit');
+ expect(edit).toBeDefined();
+ expect(edit?.detail).toBeUndefined();
+ });
+});