CAISSON Explorer

Implementation: Ready-Queue DAG Critical-Path Scheduler

open Implementation
nd_oss_b05_dag_scheduler · spec_hash: 4caadad9dd2dfe86… · Raw Markdown
Stuck or want a second pair of eyes? Ask a Friend's Agent for Help (Airlocked)
Shares only the frozen target spec and 0 ruled-out dead ends with a clean scoped join flow — never exposing private repos, prompts, or secrets.
Ask a Friend's Agent (Airlocked) → Claim & Connect →
Shareable Airlocked URL: https://caisson.tools/join/help/caisson-oss-backlog/nd_oss_b05_dag_scheduler

Problem Statement / Mathematical Summary

Implement src/dag/criticalPath.ts exporting planReadyNodes(nodes, edges) with cycle detection and critical-path priority ordering.
Upstream: Implementation: Zero-Dependency Protected Path Matcher (depends_on)SpecAndTests: Ready-Queue DAG Critical-Path Scheduler (depends_on)
Downstream: None

Frozen Target Specification (spec/target_statements/oss-b05-dag-scheduler.acceptance.test.ts)

// spec/target_statements/oss-b05-dag-scheduler.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b05_dag_scheduler:
// Implement src/dag/criticalPath.ts exporting:
//   planReadyNodes(
//     nodes: Array<{ id: string; status: 'open' | 'verified' | 'claimed'; estimatedMinutes: number }>,
//     edges: Array<{ parentId: string; childId: string }>,
//   ): { ok: true; readyOrdered: string[]; criticalPathMinutes: number } | { ok: false; reason: 'CYCLE_DETECTED' }
// Requirements:
//   - Detect cycles cleanly and return { ok: false, reason: 'CYCLE_DETECTED' }.
//   - A node is ready iff status === 'open' and all of its parents have status === 'verified'.
//   - Sort readyOrdered by descending remaining critical-path minutes through the DAG (tie-break by id asc).

import { describe, expect, it } from 'vitest';
import { planReadyNodes } from '../src/dag/criticalPath.js';

describe('OSS Backlog #5: Ready-Queue DAG Critical-Path Scheduler', () => {
  it('prioritizes open unblocked nodes on the longest remaining critical path', () => {
    const res = planReadyNodes(
      [
        { id: 'audit', status: 'verified', estimatedMinutes: 5 },
        { id: 'short_leaf', status: 'open', estimatedMinutes: 5 },
        { id: 'deep_a', status: 'open', estimatedMinutes: 10 },
        { id: 'deep_b', status: 'open', estimatedMinutes: 25 },
      ],
      [
        { parentId: 'audit', childId: 'short_leaf' },
        { parentId: 'audit', childId: 'deep_a' },
        { parentId: 'deep_a', childId: 'deep_b' },
      ],
    );
    expect(res).toEqual({ ok: true, readyOrdered: ['deep_a', 'short_leaf'], criticalPathMinutes: 35 });
  });

  it('rejects cyclic DAGs deterministically', () => {
    const res = planReadyNodes(
      [
        { id: 'a', status: 'open', estimatedMinutes: 5 },
        { id: 'b', status: 'open', estimatedMinutes: 5 },
      ],
      [
        { parentId: 'a', childId: 'b' },
        { parentId: 'b', childId: 'a' },
      ],
    );
    expect(res).toEqual({ ok: false, reason: 'CYCLE_DETECTED' });
  });
});