skills/dag-chain-decomposition/SKILL.md
Algorithms for decomposing DAGs into chains for parallel execution and resource optimization
npx skillsauth add curiositech/windags-skills dag-chain-decompositionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Load this skill when you encounter dependency networks that require optimal parallel execution with minimal coordination overhead. Key triggers:
IF problem has clear topological levels (stratifiable)
AND width ≤ √n
THEN use Chen's stratification algorithm
→ Stratify into levels V₁, V₂, ..., Vₕ
→ Apply maximum matching between adjacent levels
ELSE IF width >> √n (width-dominated problem)
THEN accept minimal compression possible
→ Create b chains (one per antichain element)
→ Focus on efficient chain management, not decomposition
ELSE IF dependencies are tangled (no clear levels)
THEN question dependency model validity
→ Look for missing abstractions
→ Consider alternative graph representations
IF task cannot be assigned to existing chains
AND remaining depth ≥ 3 levels
AND assignment would violate dependencies
THEN create virtual node for deferred resolution
→ Propagate virtual node to next level
→ Resolve in second phase with full context
ELSE IF remaining depth < 3 levels
THEN create new chain immediately
→ Overhead of deferred resolution exceeds benefit
WHEN assigning level Vᵢ to existing chains
FIRST formulate bipartite matching:
- Left: tasks in Vᵢ needing assignment
- Right: existing chains from previous levels
- Edges: assignments that preserve dependencies
IF maximum matching covers all tasks
THEN assign per matching (no new chains needed)
ELSE unmatched tasks each spawn new chain
→ This minimizes total chain count
→ Provably optimal by maximum matching theory
TO measure problem width (coordination lower bound):
1. Identify all mutually incomparable elements (antichain)
2. Find maximum antichain size = width b
IF achieved chain count = b
THEN decomposition is optimal
ELSE IF achieved count > b
THEN investigate inefficiency
→ Check for premature commitment
→ Verify stratification correctness
→ Look for missed matching opportunities
Symptoms: Attempting to use fewer than b chains, or claiming decomposition into k < b chains Detection: Count maximum antichain size; if solution uses fewer chains than antichain size, it's impossible Fix: Measure width first, accept it as absolute lower bound, optimize other aspects
Symptoms: Creating many short chains instead of fewer long ones; poor chain utilization Detection: Chain count significantly exceeds width; many chains with only 1-2 tasks Fix: Use virtual nodes for deferred decisions; resolve assignments only when full context available
Symptoms: Treating long dependency chains as coordination problems; over-parallelizing sequential workflows Detection: Trying to parallelize tasks that must run sequentially; creating false dependencies Fix: Distinguish depth (latency) from width (coordination); long chains ≠ coordination complexity
Symptoms: Greedy assignment without global structure; decisions that block future optimal assignments Detection: Assignment quality degrades with problem size; no clear levelization strategy Fix: Stratify first to isolate levels, then apply maximum matching within each level interface
Symptoms: Creating new chains/agents without fully utilizing existing ones Detection: Chain utilization is low; new resources created while existing ones could handle tasks Fix: Apply maximum matching to existing resources before spawning new ones
Scenario: Deploying software across 3 environments (dev, staging, prod) with 8 microservices, where some services depend on others being deployed first.
Dependencies:
Step 1 - Width Analysis:
Level analysis reveals maximum antichain: {DB-dev, DB-staging, DB-prod, SharedLib-dev, SharedLib-staging, SharedLib-prod}
Width b = 6 (these can all run in parallel)
Minimum agents needed = 6
Step 2 - Stratification:
V₁: {DB-dev, DB-staging, DB-prod, SharedLib-dev, SharedLib-staging, SharedLib-prod} (6 nodes)
V₂: {App1-dev, App1-staging, App1-prod, App2-dev, App2-staging, App2-prod} (6 nodes)
V₃: {Integration-tests-dev, Integration-tests-staging, Integration-tests-prod} (3 nodes)
V₄: {Promotion-to-staging, Promotion-to-prod} (2 nodes)
Step 3 - Chain Assignment: V₁ → V₂ matching:
V₂ → V₃ matching produces 3 unmatched tasks (integration tests), but we can extend existing chains:
Result: 6 parallel agents (optimal), each handling one complete deployment pipeline.
Scenario: Processing sensor data where some transformations depend on data quality metrics that aren't known until runtime.
Initial structure: Raw data → Quality check → [Unknown branching] → Aggregation → Output
Challenge: Can't determine optimal assignment until quality metrics computed, but want to minimize coordination overhead.
Solution using virtual nodes:
Level 1: Raw data ingestion (parallel by sensor type)
Level 2: Quality assessment (one per data stream)
Level 3: Virtual nodes for "post-quality processing" (deferred)
Level 4: Aggregation and output
Maximum matching L1→L2: Direct assignment (each sensor to quality checker)
L2→L3: Create virtual nodes since branching strategy unknown
L3→L4: Resolve during execution based on actual quality metrics
Two-phase resolution:
Benefit: Avoids premature commitment to processing strategy while ensuring resource utilization stays optimal.
Decomposition is complete when ALL conditions are satisfied:
DO NOT use this skill for:
parallel-task-dispatchsequential-pipeline-optimizationreal-time-task-schedulingadaptive-workflow-managementresource-constrained-schedulingevent-driven-orchestrationDelegate to other skills when:
cycle-breaking-strategiesdynamic-load-balancingcritical-path-optimizationtools
Building resilient distributed systems with circuit breakers, retries with full-jitter exponential backoff, retry budgets (per-request 3-attempt + per-client 10% ratio per Google SRE), deadline propagation, and the cascading-failure math (4 layers × 3 retries = 64x amplification). Grounded in Resilience4j, Microsoft Cloud Patterns, AWS Architecture Blog (Marc Brooker), and Google SRE Book.
testing
Designing HTTP cache headers that work correctly across browsers, CDNs, and shared proxies — `Cache-Control` directives per RFC 9111, `stale-while-revalidate` and `stale-if-error` per RFC 5861, the Vary header for varying responses, and surrogate keys for tag-based purging. Grounded in IETF RFCs and Cloudflare/Fastly docs.
development
Use when designing or fixing a Content Security Policy on a real site, choosing between nonce-based and hash-based CSP, adding strict-dynamic, debugging "Refused to execute inline script" errors, deploying CSP in report-only mode first, configuring report-to / report-uri, or auditing an existing policy for unsafe-inline / unsafe-eval / wildcards. Triggers: "CSP blocks legitimate inline script", strict-dynamic, nonce-{RANDOM}, sha256-{HASH}, object-src none, base-uri none, frame-ancestors, Trusted Types, X-Content-Security-Policy obsolete, report-only vs enforced. NOT for general HTTP security headers (HSTS, COOP/COEP), Trusted Types deep dive, CORS configuration, or building a WAF.
tools
Choosing and operating an HTTP API versioning strategy that doesn't break clients — Stripe's date-based pinned versions, the Deprecation/Sunset header pair (RFC 9745 + RFC 8594), URI vs header vs media-type approaches, and the version-transformer pattern. Grounded in Stripe's published architecture and IETF RFCs.