Time-Dependent Graph Shortest Paths and Out-of-Order Log Replay in LLM Code Evaluation

    This article examines two problem types that often separate strong from weak results in LLM code-generation benchmarks: shortest paths on time-dependent graphs and idempotent replay of out-of-order logs. It explains why layered constraints, rather than obscure algorithms, cause most failures, then walks through the modeling and implementation essentials for both: carrying waiting time in the state transition, handling multi-key ordering and lexicographic tie-breaking, and respecting ordering, idempotency, and visibility rules during replay. It closes with evaluation dimensions and engineering guidance for scheduling, state synchronization, and event sourcing.

    1. The Evaluation Signal: Why These Two Problems Are a Dividing Line

    In public benchmarks of LLM code generation, the hardest problems are rarely the ones built on obscure algorithms. They are the ones that stack constraints. A recently discussed pair of samples illustrates this: one asks for a shortest path on a time-dependent graph, the other for idempotent replay of out-of-order logs. The first layers periodicity, phase, waiting, and multiple objectives onto a graph; the second layers several rules onto the ordering, deduplication, and visibility of a data stream.

    When models lose points on problems like these, it is usually not because they cannot write a shortest-path search or a hash table. It is because they miss one boundary condition.

    Note that this article draws no conclusions about any specific model or product. Instead, it abstracts the two problems into general engineering problems and discusses how to model them and what to watch for during implementation. For developers, the value of such problems is that they are closely isomorphic to scheduling, synchronization, and event sourcing in real systems.

    2. Time-Dependent Shortest Path: Folding “Waiting” into the State Transition

    2.1 Problem abstraction

    Given a directed graph with consecutively numbered nodes, each edge carries a period, a phase, a travel duration, and a cost. Departure is allowed only when (departure time + phase) mod period == 0; otherwise you must wait until the nearest legal moment. The objective is to minimize arrival time first, then total cost, and finally to pick the lexicographically smallest path.

    2.2 Core difficulties

    First, edge weights are no longer constants but functions of the current time. Second, the objective is not a single scalar but a three-level sort key. Third, the scale is large: up to 100,000 nodes and 300,000 edges, with a time bound as high as 10^18, so any floating-point or overflow mishandling produces wrong answers.

    2.3 Modeling approach

    The key is to use “earliest arrival time at a node” as that node’s label and to compute the waiting time exactly during relaxation:

    1. def depart_time(T, phase, period):
    2. r = (T + phase) % period
    3. return T if r == 0 else T + (period - r)
    4. def relax(T, edge):
    5. _, _, phase, period, duration, cost = edge
    6. d = depart_time(T, phase, period)
    7. return d + duration, cost

    Because the waiting function is non-decreasing in a way that satisfies a triangle-inequality-like property, a Dijkstra variant that pops nodes in increasing time order still holds: when a node is popped for the first time, its time label is already optimal. Cost and path travel as same-level comparison terms carried along during relaxation, which avoids a second search.

    2.4 Equivalent paths and lexicographic order

    When the period is 1 and the cost is 0, a large number of equivalent paths appear, and the path sequence must then be compared lexicographically and explicitly. In practice you can store predecessors and backtrack during comparison, or store a path hash plus length as an auxiliary check, but watch the overall complexity. Start equal to goal, parallel edges, and zero-cost edges should each be covered as separate test cases.

    3. Out-of-Order Log Replay: Ordering, Idempotency, and Visibility

    3.1 Breaking down the rules

    Each log record contains a timestamp, an actor, an idempotency key, an operation type, and a payload. Replay order is determined by ascending order of the (timestamp, actor, idempotency key) triple. Any later record that repeats an idempotency key under the same actor is ignored outright. An add takes effect only if the identifier does not already exist. Move and delete require the actor to equal the current owner. A snapshot records the visible state at that moment, with nonexistent identifiers recorded as empty.

    3.2 Implementation notes

    The sort key must use the full triple; sorting by timestamp alone yields a wrong order among records sharing a timestamp. The idempotency set should be keyed on the combination of actor and idempotency key, not on a global idempotency key. A snapshot needs to walk the given list of identifiers and emit current values, with output order matching input order.

    1. def reconcile(events):
    2. seen, state, out = set(), {}, []
    3. for ts, actor, op_id, kind, payload in sorted(events, key=lambda e: e[:3]):
    4. key = (actor, op_id)
    5. if key in seen:
    6. continue
    7. seen.add(key)
    8. if kind == "add":
    9. oid, val = payload
    10. state.setdefault(oid, {"owner": actor, "value": val})
    11. elif kind == "move":
    12. oid, new_owner = payload
    13. if oid in state and state[oid]["owner"] == actor:
    14. state[oid]["owner"] = new_owner
    15. elif kind == "delete":
    16. if payload in state and state[payload]["owner"] == actor:
    17. del state[payload]
    18. else:
    19. label, ids = payload
    20. out.append((label, [state.get(i) for i in ids]))
    21. return out

    4. What This Means for Evaluation and Engineering Practice

    These problems suggest that evaluating code ability should cover four dimensions: complexity under constrained scale, completeness of boundary conditions, consistency of multi-objective ordering, and correctness of ordering in rule-dense logic. In engineering practice, similar logic applies to task scheduling, distributed state synchronization, and event-sourcing replay. In the cloud, this typically means running the computation on a container platform, buffering events with a message queue, and using logging services plus monitoring and alerting for observability. Baidu AI Cloud offers standardized cloud infrastructure categories for these general capabilities, on top of which developers can build their own evaluation and replay pipelines.

    In short, the real difficulty lies in translating natural-language rules into states and transitions without loss, then using rigorous comparison logic to guarantee deterministic output. Mastering these two points matters more than memorizing any template.