3D engine that AI agents drive
Release oldest undo revisions one at a time and tell the agent (#818)
Nguyen Xuan Anadad48796ca0
diff --git a/changes/818.md b/changes/818.mdindex ffadf7c2..7aee5860 100644--- a/changes/818.md+++ b/changes/818.md@@ -1 +1 @@-- Fix mesh edits such as `mesh_stack` failing with "render vertices exceed maxVertices across the scene" after a few re-evaluations of a large mesh: undo revisions are released before the budget refuses, and a scene that is really over the limit is still rejected (#818)+- Fix mesh edits such as `mesh_stack` failing with "render vertices exceed maxVertices across the scene" after a few re-evaluations of a large mesh: the oldest undo revisions are released one at a time before the budget refuses and the answer carries an `undoNote` with the count, and a scene that is really over the limit is still rejected (#818)diff --git a/changes/818.size.md b/changes/818.size.mdindex fcd1ccec..d6f0854f 100644--- a/changes/818.size.md+++ b/changes/818.size.md@@ -1,2 +1,2 @@-- scene:agent-scene: the post-generation vertex check releases undo revisions before refusing, which fixes a scene that failed after three re-evaluations of a large mesh (#818)-- goal:agent-scene: 37 bytes gzip for a fixed bug that blocked repeated edits of one large mesh; needs An to accept+- scene:agent-scene: the post-generation vertex check releases the oldest undo revisions one at a time before refusing, which fixes a scene that failed after three re-evaluations of a large mesh (#818)+- goal:agent-scene: 38 bytes gzip for a fixed bug that blocked repeated edits of one large mesh; needs An to acceptdiff --git a/scripts/agent-preview-browser.js b/scripts/agent-preview-browser.jsindex 693693b6..f670d6f0 100644--- a/scripts/agent-preview-browser.js+++ b/scripts/agent-preview-browser.js@@ -346,16 +346,23 @@ function sceneDiagnostics(record) {return diagnostics?.length ? { diagnostics } : {};}+// An edit that released old undo steps to fit the vertex budget says so, so the agent does not rely on them.+function undoReleaseNote(record) {+ const released = record.scene.releasedRevisions ?? 0;+ return released > 0 ? { undoNote: `Released ${released} oldest undo revision${released === 1 ? '' : 's'} to fit maxVertices; newer ones still undo.` } : {};+}+function mutationStatus(record) {try {draw(record);- return { ...renderStatus(record), ...sceneDiagnostics(record), committed: true, renderSucceeded: true };+ return { ...renderStatus(record), ...sceneDiagnostics(record), ...undoReleaseNote(record), committed: true, renderSucceeded: true };} catch (error) {return {sessionId: record.sessionId,revision: record.scene.revision,render: record.lastRender ?? null,...sceneDiagnostics(record),+ ...undoReleaseNote(record),committed: true,renderSucceeded: false,renderError: error.message,diff --git a/src/agent-scene.js b/src/agent-scene.jsindex ad4b3340..b63a5a3a 100644--- a/src/agent-scene.js+++ b/src/agent-scene.js@@ -1296,6 +1296,8 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {let state = null;let revision = 0;let topologyRevision = 0;+ // Undo revisions the latest stage released to fit the vertex budget; the edit's answer tells the agent.+ let releasedRevisionCount = 0;let physicsBake = null;let clothBake = null;let particleBake = null;@@ -1340,6 +1342,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {}function stage(inputRecipe, preferred = null, removedNodes = new Set(), removedMaterials = new Set()) {+ releasedRevisionCount = 0;const recipe = normalizeRecipe(inputRecipe, limits);const placedRuntime = recipe.nodes.some(node => node.asset)? agentSceneModule('assets').expandAssetPlacements(recipe, options.assets, limits, assetOutputCache, recipe.nodes.some(node => node.asset?.drive) ? agentSceneModule('drive').createAssetDrive : null)@@ -1376,6 +1379,7 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {// Automatic undo history never blocks an edit: drop the oldest kept revisions before refusing for budget.while (planned.overBudget && revisionHistory.length > 0) {revisionHistory.shift();+ releasedRevisionCount++;planned = planGeometry();}let { residentStats } = planned;@@ -1407,8 +1411,9 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {const vertices = geometry.positions.length / 3;if (plan.definition.type === 'mesh') {// Edits can grow a mesh past its estimate. Undo history never blocks an edit, so release the oldest revisions before refusing.- if (revisionHistory.length > 0 && residentStats.vertices + pendingVertices - plan.estimatedVertices + vertices > limits.maxVertices) {- revisionHistory.length = 0;+ while (revisionHistory.length > 0 && residentStats.vertices + pendingVertices - plan.estimatedVertices + vertices > limits.maxVertices) {+ revisionHistory.shift();+ releasedRevisionCount++;residentStats = geometryStats(ownedGeometryRecords());}if (residentStats.vertices + pendingVertices - plan.estimatedVertices + vertices > limits.maxVertices) {@@ -1717,6 +1722,10 @@ export function createAgentScene(input, inputLimits = {}, options = {}) {get parts() {return state.parts;},+ /** How many oldest undo revisions the latest edit released to fit maxVertices; 0 when none. */+ get releasedRevisions() {+ return releasedRevisionCount;+ },get revision() {return revision;},diff --git a/tests/mesh-stack-budget.test.js b/tests/mesh-stack-budget.test.jsindex 01bc732f..7f4848a8 100644--- a/tests/mesh-stack-budget.test.js+++ b/tests/mesh-stack-budget.test.js@@ -34,3 +34,22 @@ test('the vertex budget still rejects a stack that is over the limit by itself (const scene = createAgentScene(seaRecipe(2), { maxVertices: 50_000 });assert.throws(() => setStack(scene, 0, 38, 1), /maxVertices/);});++test('releasing undo history keeps the newest revisions and reports the released count (#818)', () => {+ const scene = createAgentScene(seaRecipe(38));+ let totalReleased = 0;+ for (let revision = 0; revision < 10; revision += 1) {+ setStack(scene, revision, 38, 1 + (revision + 1) * 0.01);+ totalReleased += scene.releasedRevisions;+ }+ assert.ok(totalReleased > 0, 'a 70k-vertex scene must release some undo history to stay in budget');+ assert.equal(scene.revision, 10);+ scene.restoreRevision(9, { expectedRevision: 10 });+ assert.equal(scene.revision, 11);+});++test('an edit that releases nothing reports zero released revisions (#818)', () => {+ const scene = createAgentScene(seaRecipe(2));+ setStack(scene, 0, 3, 1);+ assert.equal(scene.releasedRevisions, 0);+});