Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: resolve cross-step result references in CD plan executor (#2773)
[._.]/ Adam Eivy8855e0b461f8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 359dbbfdf4..8620c417f1 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -26,6 +26,8 @@## Changed+- [issue-2773] **A scheduled Series commission now actually generates its episodes instead of leaving an empty series.** When the Creative Director plans a Series commission, it first creates the series (which mints a fresh id) and then has to run that new series' autopilot — but until now the plan couldn't refer to an id that didn't exist yet when the plan was written, so a Series commission could only ever produce an empty shell. Plan steps can now reference a value produced by an earlier step with `{{steps.<stepId>.result.<key>}}` (e.g. `{{steps.create-series.result.id}}`), and the server resolves it at dispatch time — so the "create the series, then generate its issues/episodes" hand-off works end to end. A plan that references a step that didn't run or didn't produce the named id fails that step with a clear reason and re-plans rather than dispatching an unresolved placeholder. Existing installs pick up the planner guidance automatically on restart.+- **The Cyber Muse (3D) Chief-of-Staff avatar now works with real color and a livelier "coding" state.** The rigged robot renders in its own full textures and color instead of a dark holographic silhouette with the agent-state hue painted over it — the per-state color now lives in the surrounding halo, ground glow, sparkles, and accent light, so the model reads clearly while the scene still signals what the agent is doing. And while an agent is working, the avatar no longer loops a single punch clip: it cycles a varied montage (jab → run → jump → thumbs-up → walk → celebrate) so a busy Chief of Staff looks busy. The run/walk cycles play "in place" so the avatar can't stride out of frame, and a custom GLB missing the montage clips falls back to its single base loop exactly as before.- [issue-2677] **Your Character page is now about you, not a generic adventurer.** The page centers on the human who owns the install — your name, your avatar, your age-based level, and the skills, goals, and metrics derived from how you actually use PortOS — with the old D&D combat mechanics moved out of the way. Damage, rest, dice rolls, manual XP, the JIRA/task XP sync, and the event log now live in a collapsed "RPG mechanics" section that's closed by default; nothing was removed, so those buttons and endpoints still work and existing character files keep their history. When you haven't set a birth date yet there's no age to turn into a level, so instead of a blank badge the page prompts you to "set your birth date" and links straight to the age editor where that field lives. Your name and title now read as human placeholders ("Your name", "Add a title") instead of the old generic "Adventurer" / "Developer": a fresh install starts blank so it prompts for your real name (an existing install keeps whatever name is on record — edit it inline to make it yours).diff --git a/data.reference/prompts/stages/cd-plan.md b/data.reference/prompts/stages/cd-plan.mdindex 51ec6bb350..4b1c3d4dba 100644--- a/data.reference/prompts/stages/cd-plan.md+++ b/data.reference/prompts/stages/cd-plan.md@@ -40,11 +40,32 @@ Parameters (JSON schema): {{parametersJson}}This project is locked to **{{render.aspectRatio}}** ({{render.width}}×{{render.height}}), **{{render.quality}}** quality, target ~{{render.targetDurationSeconds}}s. For any `media_enqueueVideoJob` step, set ONLY the creative params (`prompt`, `negativePrompt`, `style`, and optionally a shorter per-beat `durationSeconds`). Do NOT set `aspectRatio`, `width`, `height`, `fps`, or `steps` — the server forces the locked geometry onto every render, so any values you supply for those are ignored.+## Referencing a prior step's result++A step that CREATES a record (e.g. `pipeline_createSeries`) mints its id only when it runs — you cannot know that id in advance. To thread a just-created id into a LATER step's `args`, reference the earlier step's result with a placeholder:++```+{{steps.<stepId>.result.<key>}}+```++The server resolves it at dispatch time from the referenced step's result. Available result keys are the ids the step returns — commonly `id` (the created record's own id, e.g. a new series' id), plus `seriesId` / `issueId` / `universeId` / `jobId` / `name` when the tool produces them. The referenced step MUST be listed in `dependsOn` so it completes first. A whole-value reference (the `args` value is exactly the placeholder) substitutes the raw id; you may also embed one inside a longer string.++Example — create a series, then run its autopilot on the just-minted id:++```json+{+ "stepId": "run-autopilot",+ "toolName": "pipeline_startSeriesAutopilot",+ "args": { "seriesId": "{{steps.create-series.result.id}}" },+ "dependsOn": ["create-series"]+}+```+## Task1. Decompose the directive into the smallest sequence of registry tool calls that delivers the requested deliverables. Prefer existing records over creating new ones where the constraints name a target universe/series id.2. Give every step a stable, unique `stepId` (e.g. `create-series`, `cover-issue-1`).-3. Use `dependsOn` to encode ordering — a step runs only after every id in its `dependsOn` reaches a terminal-success state. Steps with no dependencies run in listed order (execution is sequential; there are no parallel branches).+3. Use `dependsOn` to encode ordering — a step runs only after every id in its `dependsOn` reaches a terminal-success state. Steps with no dependencies run in listed order (execution is sequential; there are no parallel branches). When a step needs an id produced by an earlier step, reference it with `{{steps.<stepId>.result.<key>}}` (see "Referencing a prior step's result" above) and list that step in `dependsOn`.4. Do NOT invent tool names or arguments. If a deliverable cannot be produced with the available tools, omit it rather than fabricating a step.## Output contractdiff --git a/scripts/migrations/193-cd-plan-locked-render-settings.js b/scripts/migrations/193-cd-plan-locked-render-settings.jsindex 9107b2916a..5311e05406 100644--- a/scripts/migrations/193-cd-plan-locked-render-settings.js+++ b/scripts/migrations/193-cd-plan-locked-render-settings.js@@ -19,11 +19,13 @@import { makePromptReplaceMigration } from './_lib.js';export const ACCEPTED_OLD_MD5 = {- 'cd-plan.md': ['3ce871196a8fd04781b71b6780e89c86'], // pre-193 shipped+ // pre-193 shipped; post-193/pre-199 (locked render settings). Resynced when 199+ // shipped the result-references note — both prior shapes upgrade to the latest.+ 'cd-plan.md': ['3ce871196a8fd04781b71b6780e89c86', '0768d6809645c2c1fe73cacae9740fe9'],};export const NEW_SHIPPED_MD5 = {- 'cd-plan.md': '0768d6809645c2c1fe73cacae9740fe9', // post-193 (locked render settings)+ 'cd-plan.md': 'ef0d96f6ebde43af6c4579969d31cfb7', // post-199 (cross-step result references)};const { applyMigration, up } = makePromptReplaceMigration({diff --git a/scripts/migrations/199-cd-plan-result-references.js b/scripts/migrations/199-cd-plan-result-references.jsnew file mode 100644index 0000000000..8909e7d431--- /dev/null+++ b/scripts/migrations/199-cd-plan-result-references.js@@ -0,0 +1,47 @@+/**+ * Update the `cd-plan` stage prompt to document cross-step RESULT REFERENCES+ * (`{{steps.<stepId>.result.<key>}}`) so the Creative Director planner can thread+ * a just-minted id into a later step's args.+ *+ * Background (#2773): the CD plan executor dispatches each step's pre-authored+ * `args` verbatim and never interpolated a prior step's output. A `series`+ * commission therefore could only ever create an EMPTY series — the planner had+ * no way to reference the id `pipeline_createSeries` mints when handing it to+ * `pipeline_startSeriesAutopilot`. The executor now resolves+ * `{{steps.<stepId>.result.<key>}}` references at dispatch time+ * (server/services/creativeDirector/planAdvance.js#resolvePlanStepArgs); this+ * prompt change teaches the planner the syntax so it actually emits them.+ *+ * Strategy: hash-driven prompt-replace via `./_lib.js`. Idempotent — only an+ * install still carrying the pre-change (post-193) shipped template is+ * auto-updated; a customized copy is left alone with a merge hint.+ */++import { makePromptReplaceMigration } from './_lib.js';++export const ACCEPTED_OLD_MD5 = {+ 'cd-plan.md': ['0768d6809645c2c1fe73cacae9740fe9'], // post-193 shipped (locked render settings)+};++export const NEW_SHIPPED_MD5 = {+ 'cd-plan.md': 'ef0d96f6ebde43af6c4579969d31cfb7', // post-199 (cross-step result references)+};++const { applyMigration, up } = makePromptReplaceMigration({+ accepted: ACCEPTED_OLD_MD5,+ current: NEW_SHIPPED_MD5,+ label: 'creative-director stage prompt',+ customizedHint: (filename) =>+ ` To apply the result-reference note manually, diff:\n` ++ ` data.reference/prompts/stages/${filename}\n` ++ ` against your current:\n` ++ ` data/prompts/stages/${filename}\n` ++ ` and add the "## Referencing a prior step's result" section.`,+ skipFooter: (count) =>+ `⚠️ ${count} cd-plan prompt(s) could not be auto-updated because they were customized.\n` ++ ` Series/multi-step commissions still work when the planner already threads\n` ++ ` ids, but it won't learn the {{steps.…}} syntax until you merge the note.`,+});++export { applyMigration };+export default { up };diff --git a/scripts/migrations/199-cd-plan-result-references.test.js b/scripts/migrations/199-cd-plan-result-references.test.jsnew file mode 100644index 0000000000..db7b075571--- /dev/null+++ b/scripts/migrations/199-cd-plan-result-references.test.js@@ -0,0 +1,25 @@+/**+ * Test for migration 199 — cd-plan gains the "## Referencing a prior step's+ * result" note documenting `{{steps.<stepId>.result.<key>}}` (#2773).+ *+ * Uses the shared prompt-migration harness (seeds a fixture from the live+ * data.reference/ template, asserts an install on the accepted-old hash is+ * auto-updated to the new shipped hash and a customized copy is left alone).+ *+ * Picked up via the vitest include glob in server/vitest.config.js+ * (`../scripts/**\/*.test.js`).+ */+import { describe } from 'vitest';++import { runPromptMigrationTests } from './_testHelpers.js';+import migration, { applyMigration, ACCEPTED_OLD_MD5, NEW_SHIPPED_MD5 } from './199-cd-plan-result-references.js';++describe('migration 199 — cd-plan cross-step result references', () => {+ runPromptMigrationTests({+ migration,+ applyMigration,+ ACCEPTED_OLD_MD5,+ NEW_SHIPPED_MD5,+ prefix: 'migration-199-',+ });+});diff --git a/scripts/setup-data-drift.test.js b/scripts/setup-data-drift.test.jsindex 185ed35397..b486fd5b94 100644--- a/scripts/setup-data-drift.test.js+++ b/scripts/setup-data-drift.test.js@@ -48,7 +48,7 @@ const EXPECTED_STAGE_OLD = {'pipeline-editorial-on-the-nose.md': ['48182b49149e6b5829fbed71b3ffc242'],'pipeline-tv-script.md': ['3f6fecc25573ed054b47db392250034a'],'cd-treatment.md': ['2ffa482e7bfb6fe8b7224505fedbf712', '16d0ef6a7fd2533719a846019122ebee', '95b7685690ecfee4f682b0293b790277'],- 'cd-plan.md': ['3ce871196a8fd04781b71b6780e89c86'],+ 'cd-plan.md': ['3ce871196a8fd04781b71b6780e89c86', '0768d6809645c2c1fe73cacae9740fe9'],'pipeline-series-generate.md': ['bc72731124a2bd6304362f4402c6305d'],};const EXPECTED_STAGE_NEW = {@@ -76,7 +76,7 @@ const EXPECTED_STAGE_NEW = {'pipeline-editorial-on-the-nose.md': 'e5786fb019e5bf19c7aa6ed0c8b35cda','pipeline-tv-script.md': '376f779f4687b598f1c92ca4e770fd5a','cd-treatment.md': 'd940eadfb406ce584f0e244032f33382',- 'cd-plan.md': '0768d6809645c2c1fe73cacae9740fe9',+ 'cd-plan.md': 'ef0d96f6ebde43af6c4579969d31cfb7','pipeline-series-generate.md': '21352c21ed6d4edb7a4b7c32704eff55',};const EXPECTED_PARTIAL_OLD = {diff --git a/server/services/creativeDirector/planAdvance.js b/server/services/creativeDirector/planAdvance.jsindex b8a642188b..fac0bd150b 100644--- a/server/services/creativeDirector/planAdvance.js+++ b/server/services/creativeDirector/planAdvance.js@@ -108,6 +108,95 @@ export function deriveNextPlanAction(plan) {return { type: 'complete' };}+// A single cross-step result reference: `{{steps.<stepId>.result.<dotpath>}}`.+// The reference resolves to a value produced by an EARLIER (terminal-success)+// step's persisted `result` — the id-only summary `summarizeResult` stored (e.g.+// a created series' `result.id`). stepIds allow letters/digits/`_`/`-`; the path+// is a dotted key list into the result object.+// One source for the reference grammar; the anchored form (whole-value → raw+// type preserved) and the global form (embedded → stringified) derive from it so+// widening the id/path character classes can't diverge the two.+const STEP_REF_BODY = String.raw`\{\{\s*steps\.([\w-]+)\.result\.([\w.-]+)\s*\}\}`;+const STEP_REF_ANCHORED = new RegExp(`^${STEP_REF_BODY}$`);+const STEP_REF_GLOBAL = new RegExp(STEP_REF_BODY, 'g');++/**+ * Resolve `{{steps.<stepId>.result.<path>}}` references in a plan step's `args`+ * against the plan's already-completed steps (#2773). The executor otherwise+ * dispatches `args` verbatim and never interpolated prior results — so a step+ * that needs a just-minted id (the classic case: a `series` commission where+ * `pipeline_startSeriesAutopilot` needs the id `pipeline_createSeries` mints)+ * had no way to reference it, and could only ever create an empty series.+ *+ * A whole-string reference (`"{{steps.create-series.result.id}}"`) substitutes+ * the RAW resolved value (type preserved); an embedded reference inside a longer+ * string is stringified in place. References are resolved recursively through+ * nested arrays/objects in `args`.+ *+ * Pure + side-effect-free (exported for direct unit testing). Returns+ * `{ args, error }`: `error` is a non-null human-readable string when any+ * reference points at an unknown step, a step that is not terminal-success, or a+ * missing result key — the executor treats that as a planning error (fail the+ * step → bounded re-plan) rather than dispatching an unresolved `{{…}}` literal.+ *+ * @param {{stepId?: string, args?: object}} step+ * @param {{steps?: Array<object>}} plan+ */+export function resolvePlanStepArgs(step, plan) {+ const args = step?.args || {};+ // Fast path: the vast majority of steps carry no references. Every reference+ // contains the `{{steps.` sentinel, so a cheap serialize-and-scan returns the+ // args untouched without building the step index or walking/cloning the tree.+ if (!JSON.stringify(args).includes('{{steps.')) return { args, error: null };++ const steps = Array.isArray(plan?.steps) ? plan.steps : [];+ const byId = new Map(steps.map((s) => [s.stepId, s]));+ const errors = [];++ const resolveRef = (stepId, path) => {+ const dep = byId.get(stepId);+ if (!dep) { errors.push(`references unknown step "${stepId}"`); return undefined; }+ if (!PLAN_STEP_TERMINAL_SUCCESS.has(dep.status)) {+ errors.push(`references step "${stepId}" which is not complete (status: ${dep.status || 'pending'})`);+ return undefined;+ }+ let val = dep.result;+ for (const seg of path.split('.')) val = val == null ? undefined : val[seg];+ if (val === undefined || val === null) {+ errors.push(`references missing result "${path}" on step "${stepId}"`);+ return undefined;+ }+ return val;+ };++ const resolveString = (str) => {+ if (!str.includes('{{')) return str;+ const whole = STEP_REF_ANCHORED.exec(str);+ if (whole) {+ const v = resolveRef(whole[1], whole[2]);+ return v === undefined ? str : v;+ }+ return str.replace(STEP_REF_GLOBAL, (m, stepId, path) => {+ const v = resolveRef(stepId, path);+ return v === undefined ? m : String(v);+ });+ };++ const resolveValue = (val) => {+ if (typeof val === 'string') return resolveString(val);+ if (Array.isArray(val)) return val.map(resolveValue);+ if (val && typeof val === 'object') {+ const out = {};+ for (const [k, v] of Object.entries(val)) out[k] = resolveValue(v);+ return out;+ }+ return val;+ };++ const resolvedArgs = resolveValue(args);+ return { args: resolvedArgs, error: errors.length ? `Step "${step?.stepId}" ${errors.join('; ')}` : null };+}+// In-memory dedup, same role as completionHook's inflight sets. `inflightPlanner`// covers the updateProject→enqueue window for the planner; `inflightPlanStep`// covers the getProject→recordRun window for a dispatch (released once the@@ -244,12 +333,27 @@ async function runPlanStep(project, step) {// in-memory key so a raced advance sees the persisted state and bails.inflightPlanStep.delete(key);}+ // Resolve cross-step result references in the args (#2773) so this step can+ // consume a prior step's minted id (e.g. a created series' `result.id`). A+ // reference that can't be resolved is a planning error (a mis-authored plan) →+ // fail the step and route through bounded re-plan, never dispatch a literal+ // `{{…}}`. The RESOLVED step flows onward so downstream settle logic (e.g. the+ // autopilot listener's `step.args.seriesId`) sees the concrete id, not the ref.+ const resolved = resolvePlanStepArgs(step, project.plan);+ if (resolved.error) {+ await finishRun(projectId, run?.runId, 'failed', resolved.error);+ const bumped = (step.retryCount || 0) + 1;+ await updatePlanStep(projectId, step.stepId, { status: 'failed', retryCount: bumped, result: { error: resolved.error } });+ console.log(`❌ CD plan ${projectId}: step "${step.stepId}" ${resolved.error}`);+ return handlePlanStepFailure(projectId, { ...step, retryCount: bumped });+ }+ const resolvedStep = { ...step, args: resolved.args };console.log(`▶️ CD plan ${projectId}: dispatching step "${step.stepId}" (${step.toolName})`);// Outside the request lifecycle — catch so a throw becomes a settle, never an// unhandled rejection.- const dispatch = await dispatchCreativeTool(step.toolName, step.args || {}, { projectId })+ const dispatch = await dispatchCreativeTool(resolvedStep.toolName, resolvedStep.args, { projectId }).catch((err) => ({ ok: false, threw: true, error: err.message }));- return settlePlanStepDispatch(projectId, step, run?.runId, dispatch);+ return settlePlanStepDispatch(projectId, resolvedStep, run?.runId, dispatch);}async function settlePlanStepDispatch(projectId, step, runId, dispatch) {diff --git a/server/services/creativeDirector/planAdvance.test.js b/server/services/creativeDirector/planAdvance.test.jsindex ae46cce24f..96d784c533 100644--- a/server/services/creativeDirector/planAdvance.test.js+++ b/server/services/creativeDirector/planAdvance.test.js@@ -12,7 +12,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';// ---- pure derivation (no mocks needed) --------------------------------------import { deriveNextPlanAction, lastRenderedVideoJobId } from './planAdvance.js';+import { deriveNextPlanAction, lastRenderedVideoJobId, resolvePlanStepArgs } from './planAdvance.js';const step = (id, over = {}) => ({ stepId: id, toolName: 't', args: {}, dependsOn: [], status: 'pending', ...over });@@ -89,6 +89,70 @@ describe('deriveNextPlanAction (pure)', () => {});});+describe('resolvePlanStepArgs (pure) — cross-step result references (#2773)', () => {+ const donePlan = (result) => ({ steps: [+ { stepId: 'create-series', status: 'done', result },+ ] });++ it('substitutes a whole-string reference with the raw result value (type preserved)', () => {+ const plan = donePlan({ id: 'ser-42', name: 'Nova' });+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);+ expect(out.error).toBeNull();+ expect(out.args).toEqual({ seriesId: 'ser-42' });+ });++ it('preserves a non-string value type for a whole-string reference', () => {+ const plan = donePlan({ id: 'ser-1', status: 'active', count: 3 });+ const out = resolvePlanStepArgs({ stepId: 'run', args: { n: '{{steps.create-series.result.count}}' } }, plan);+ expect(out.args.n).toBe(3); // number, not "3"+ });++ it('interpolates an embedded reference inside a longer string', () => {+ const plan = donePlan({ name: 'Nova' });+ const out = resolvePlanStepArgs({ stepId: 'run', args: { title: 'Cover for {{steps.create-series.result.name}}' } }, plan);+ expect(out.args.title).toBe('Cover for Nova');+ });++ it('resolves references nested in arrays and objects', () => {+ const plan = donePlan({ id: 'ser-9' });+ const out = resolvePlanStepArgs({ stepId: 'run', args: {+ list: ['{{steps.create-series.result.id}}'],+ nested: { seriesId: '{{steps.create-series.result.id}}' },+ } }, plan);+ expect(out.args).toEqual({ list: ['ser-9'], nested: { seriesId: 'ser-9' } });+ });++ it('leaves non-reference args untouched and clones cleanly', () => {+ const out = resolvePlanStepArgs({ stepId: 'run', args: { name: 'plain', keep: 5 } }, { steps: [] });+ expect(out.error).toBeNull();+ expect(out.args).toEqual({ name: 'plain', keep: 5 });+ });++ it('errors on an unknown referenced step', () => {+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.ghost.result.id}}' } }, { steps: [] });+ expect(out.error).toMatch(/unknown step "ghost"/);+ });++ it('errors when the referenced step is not yet complete', () => {+ const plan = { steps: [{ stepId: 'create-series', status: 'pending', result: null }] };+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);+ expect(out.error).toMatch(/not complete/);+ });++ it('errors on a missing result key', () => {+ const plan = donePlan({ name: 'Nova' }); // no `id`+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);+ expect(out.error).toMatch(/missing result "id"/);+ });++ it('treats a skipped step as a resolvable terminal-success source', () => {+ const plan = { steps: [{ stepId: 'create-series', status: 'skipped', result: { id: 'ser-7' } }] };+ const out = resolvePlanStepArgs({ stepId: 'run', args: { seriesId: '{{steps.create-series.result.id}}' } }, plan);+ expect(out.error).toBeNull();+ expect(out.args.seriesId).toBe('ser-7');+ });+});+// ---- executor (mocked store + dispatch) ------------------------------------const mockGetProject = vi.fn();@@ -379,6 +443,44 @@ describe('advanceAfterPlanStepSettled — runAutopilot plan step', () => {expect(read().plan.steps[0].status).toBe('done');});+ it('threads a just-minted series id into the autopilot step via a result reference (#2773)', async () => {+ // The series-commission shape: create the series (mints an id), then start+ // the autopilot on THAT id — expressed as `{{steps.create-series.result.id}}`+ // because the planner can't know the id until create-series runs.+ const read = makeStore(planProject([+ step('create-series', { toolName: 'pipeline_createSeries', args: { name: 'Nova' } }),+ step('a', { toolName: 'pipeline_startSeriesAutopilot', args: { seriesId: '{{steps.create-series.result.id}}' }, dependsOn: ['create-series'] }),+ ]));+ mockDispatch.mockResolvedValueOnce({ ok: true, mode: 'execute', result: { id: 'ser-77', name: 'Nova' } }); // create-series+ mockDispatch.mockResolvedValueOnce(autopilotDispatch()); // start autopilot+ await advanceAfterPlanStepSettled('cd-1');+ // The autopilot was dispatched with the RESOLVED concrete id, not the literal ref.+ expect(mockDispatch).toHaveBeenNthCalledWith(2, 'pipeline_startSeriesAutopilot', { seriesId: 'ser-77' }, { projectId: 'cd-1' });+ expect(read().plan.steps[1].status).toBe('running');+ // The listener is armed on the resolved id — a terminal frame on 'ser-77' settles it.+ ap.autopilotEvents.emit('ser-77', { type: 'complete', runId: 'r1', steps: 5 });+ await flush();+ const p = read();+ expect(p.plan.steps[1].status).toBe('done');+ expect(p.status).toBe('complete');+ });++ it('fails a step whose result reference cannot be resolved and re-plans (#2773)', async () => {+ // A mis-authored plan: the autopilot references a step that never produced+ // an `id`. The executor must fail the step (not dispatch a `{{…}}` literal)+ // and route through bounded re-plan.+ const read = makeStore(planProject([+ step('create-series', { toolName: 'pipeline_createSeries', args: { name: 'Nova' }, status: 'done', result: { name: 'Nova' } }),+ step('a', { toolName: 'pipeline_startSeriesAutopilot', args: { seriesId: '{{steps.create-series.result.id}}' }, dependsOn: ['create-series'] }),+ ]));+ await advanceAfterPlanStepSettled('cd-1');+ const p = read();+ expect(p.plan.steps[1].status).toBe('failed');+ expect(p.plan.steps[1].result.error).toMatch(/missing result "id"/);+ expect(mockDispatch).not.toHaveBeenCalled(); // never dispatched the unresolved step+ expect(mockEnqueuePlanTask).toHaveBeenCalledTimes(1); // under the replan budget+ });+it('settles immediately off the persisted marker when the run already finished (attach race)', async () => {ap.ctl.active = false; // run is no longer active by the time we attachap.ctl.marker = { status: 'paused', runId: 'r1', lastError: 'canon gate', residualFindings: [], pauseKind: 'canon' };