Following the lead of Stanley and Gessel, we consider a linear map which associates to an acyclic directed graph (or a poset) a quasi-symmetric function. The latter is naturally defined as a multivariate generating series of nondecreasing functions on the graph. We describe the kernel of this linear map by using a simple combinatorial operation that we call cyclic inclusion-exclusion. Our result also holds for the natural noncommutative analogue and for the commutative and noncommutative restrictions to bipartite graphs. An application to the theory of Kerov character polynomials is given.