From 84db8f00a6cc46f67a33d0a12acff2f101cbc963 Mon Sep 17 00:00:00 2001 From: Adrian Webb Date: Thu, 29 Oct 2026 22:59:15 -0400 Subject: [PATCH 1/2] test: reproduce retired source authority after pre-acting closure --- .../accepted-decision-authority.test.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts b/tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts index 5d204b44..0f4bbbd3 100644 --- a/tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts +++ b/tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts @@ -47,3 +47,36 @@ it('does not manufacture Decision authority before approval', () => { const result = graphNode(applyOperationalState(current, projected, 4), 'first', 'actor'); expect(result.status).toBe('proposed'); expect(result.authorityRefs?.some(ref => ref.model === 'decision')).toBe(false); }); + +it('re-evaluates Decision conditions after a selected workday closes before acting admission', () => { + for (const priorStatus of ['completed', 'stale'] as const) for (const issued of [true, false]) { + const projected = graphState(graphProjection()), current = structuredClone(projected); + const condition = current.nodes.find(node => node.condition?.conditionType === 'authority')!; + Object.assign(condition, { workdayId: 'closed-before-acting', status: priorStatus, nodeRevision: 3 }); + const actor = graphNode(current, 'first', 'actor'); + Object.assign(actor, { workdayId: 'closed-before-acting', status: 'stale', nodeRevision: 3 }); + const held = structuredClone({ current, projected }); + const next = applyOperationalState(current, projected, 4, new Set(), new Map(), new Map(), new Set(issued ? [actor.id] : [])); + const resolved = next.nodes.find(node => node.id === condition.id)!; + expect(resolved).toEqual({ ...projected.nodes.find(node => node.id === condition.id), nodeRevision: 4, + graphRevisionCreated: condition.graphRevisionCreated, graphRevisionUpdated: 4 }); + expect(resolved).not.toHaveProperty('workdayId'); + expect(graphNode(next, 'first', 'actor')).toEqual(actor); + expect(applyOperationalState(next, projected, 5).nodes).toEqual(next.nodes); + expect({ current, projected }).toEqual(held); + } +}); + +it('does not retain completed authority when current Decision or feedback blocks it', () => { + for (const reason of ['not-current', 'unresolved-feedback'] as const) { + const source = graphSource(), current = graphState(graphProjection([source])); + const old = current.nodes.find(node => node.condition?.conditionType === 'authority')!; + Object.assign(old, { workdayId: 'closed-before-acting', status: 'completed', nodeRevision: 3 }); + if (reason === 'not-current') source.decision!.current = false; + else source.feedback = [{ id: 'concern', kind: 'concern', resolved: false, sourceRef: old.sourceRef }]; + const projected = graphState(graphProjection([source])); + const next = applyOperationalState(current, projected, 4), condition = next.nodes.find(node => node.id === old.id)!; + expect(condition.status).toBe('blocked'); expect(condition).not.toHaveProperty('workdayId'); + expect(graphNode(next, 'first', 'actor').status).not.toBe('ready'); + } +}); From e78e078861deccf947ac24ba438eea692ee67534 Mon Sep 17 00:00:00 2001 From: Adrian Webb Date: Thu, 29 Oct 2026 23:01:09 -0400 Subject: [PATCH 2/2] fix: derive conditions from current authority after workday closure --- .../scenes/component-boundaries.scene.yaml | 6 +++++ guarantees/verifiers/golden.verifiers.yaml | 10 ++++++++ .../execution/execution-graph-state.ts | 7 +++--- .../accepted-unissued-authority-native.ts | 24 +++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/guarantees/agent/golden/scenes/component-boundaries.scene.yaml b/guarantees/agent/golden/scenes/component-boundaries.scene.yaml index 2e855d4c..f592a157 100644 --- a/guarantees/agent/golden/scenes/component-boundaries.scene.yaml +++ b/guarantees/agent/golden/scenes/component-boundaries.scene.yaml @@ -1611,6 +1611,12 @@ workflow: - id: accepted-unissued-fixture-parent action: { verifier: api.golden.accepted-unissued-fixture-parent } expect: { status: passed } + - id: closed-workday-source-condition + action: { verifier: api.golden.closed-workday-source-condition } + expect: { status: passed } + - id: closed-workday-authority-denials + action: { verifier: api.golden.closed-workday-authority-denials } + expect: { status: passed } - id: architecture-living-graph-sql-1 action: { verifier: api.golden.architecture-living-graph-sql-1 } expect: { status: passed } diff --git a/guarantees/verifiers/golden.verifiers.yaml b/guarantees/verifiers/golden.verifiers.yaml index bfcfb548..42d23659 100644 --- a/guarantees/verifiers/golden.verifiers.yaml +++ b/guarantees/verifiers/golden.verifiers.yaml @@ -2841,6 +2841,16 @@ verifiers: ownerPackage: "@treeseed/api" testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-unissued-fixture.test.ts testName: "retains a real closed Workday parent for the native unissued Decision handoff and its public observation" + api.golden.closed-workday-source-condition: + kind: vitestCase + ownerPackage: "@treeseed/api" + testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts + testName: "re-evaluates Decision conditions after a selected workday closes before acting admission" + api.golden.closed-workday-authority-denials: + kind: vitestCase + ownerPackage: "@treeseed/api" + testFile: tests/unit/control-plane/capacity/execution/graph/architecture/living/accepted-decision-authority.test.ts + testName: "does not retain completed authority when current Decision or feedback blocks it" api.golden.architecture-living-graph-sql-1: kind: vitestCase ownerPackage: "@treeseed/api" diff --git a/src/api/control-plane/repositories/capacity/execution/execution-graph-state.ts b/src/api/control-plane/repositories/capacity/execution/execution-graph-state.ts index 053147c3..bffc28c5 100644 --- a/src/api/control-plane/repositories/capacity/execution/execution-graph-state.ts +++ b/src/api/control-plane/repositories/capacity/execution/execution-graph-state.ts @@ -28,9 +28,10 @@ export function applyOperationalState(current: TeamGraph, projected: TeamGraph, const terminalProjectionNodeIds = new Set(); const nodes = projected.nodes.map((node) => { const prior = priorById.get(node.id); - // A terminal simulation no longer owns this decision projection. Retire its - // candidate and review state; a later selected workday gets a fresh attempt. - if (prior?.workdayId && !node.workdayId && node.authorityRefs?.some((reference) => reference.model === 'decision')) { + // Retire terminal simulation workloads, not source-derived conditions. + // Current authority and feedback must remain evaluable before a fresh start. + if (node.kind !== 'condition' && prior?.workdayId && !node.workdayId + && node.authorityRefs?.some((reference) => reference.model === 'decision')) { // Approval may follow estimation closeout. Refresh only never-issued // candidates that have not yet received Decision authority; preflight // must still select the new workday before any execution is admissible. diff --git a/tests/unit/control-plane/governance/proposals/architecture/recovery/accepted-unissued-authority-native.ts b/tests/unit/control-plane/governance/proposals/architecture/recovery/accepted-unissued-authority-native.ts index 4c5db6b1..6c0c6cfc 100644 --- a/tests/unit/control-plane/governance/proposals/architecture/recovery/accepted-unissued-authority-native.ts +++ b/tests/unit/control-plane/governance/proposals/architecture/recovery/accepted-unissued-authority-native.ts @@ -54,6 +54,30 @@ export async function verifyNativeUnissuedDecisionHandoff(f: Awaited node.sourceRef.id === proposalId && node.condition?.conditionType === 'authority'); + assert.ok(condition); expect(condition.status).toBe('completed'); + const parentBefore = await f.store.first('SELECT * FROM capacity_workday_runs WHERE id=?', [closedWorkdayId]); + await f.query("UPDATE execution_nodes SET workday_id=?,status='stale' WHERE id IN (?,?)", + [closedWorkdayId, actor.id, condition.id]); + const retiredActor = await service.node(f.principal, 'team', actor.id); + const closedPreview = await reconcileExecutionGraph(f.store, 'team', { plan: true }); + assert.ok('changes' in closedPreview); expect(closedPreview.changes.changed).toContain(condition.id); + expect((await service.node(f.principal, 'team', condition.id)).status).toBe('stale'); + await Promise.all([reconcileExecutionGraph(f.store, 'team'), reconcileExecutionGraph(f.peerStore!, 'team')]); + expect(await service.node(f.principal, 'team', actor.id)).toEqual(retiredActor); + const restored = await service.node(f.principal, 'team', condition.id); + expect(restored).toMatchObject({ id: condition.id, status: 'completed', authorityRefs: condition.authorityRefs }); + expect(restored).not.toHaveProperty('workdayId'); + const restoredGraph = await service.show(f.principal, 'team', {}); + await reconcileExecutionGraph(f.store, 'team'); expect(await service.show(f.principal, 'team', {})).toEqual(restoredGraph); + const restarted = await createWorkdayService(createCapacityControlPlane(f.store)).preflight(f.principal, 'team', + { ...intent, startsAt: new Date().toISOString(), allocation: { planningPercent: 0 } }); + expect(restarted.selectedDemands).toEqual([expect.objectContaining({ sourceId: actor.id, mode: 'acting', + actingAuthority: expect.objectContaining({ decisionId, executionNodeId: actor.id, executionNodeRevision: retiredActor.nodeRevision + 1 }) })]); + expect(await service.show(f.principal, 'team', {})).toEqual(restoredGraph); + expect(await f.store.first('SELECT * FROM capacity_workday_runs WHERE id=?', [closedWorkdayId])).toEqual(parentBefore); expect({ assignments: await f.store.all('SELECT * FROM capacity_provider_assignments ORDER BY id'), decisions: await f.store.all('SELECT * FROM governance_decisions ORDER BY id'), usage: await f.store.all('SELECT * FROM capacity_usage_actuals ORDER BY id'),