Evaluating Complex Reasoning in LLMs: Benchmark Design and Engineering Practices

    This article examines why generating clean code does not guarantee strong complex reasoning in large language models, using two representative tasks: time-dependent shortest paths with periodic constraints and idempotent replay of out-of-order logs. It covers layered benchmark design, hidden test case construction, scoring dimensions, core algorithm details, common failure patterns, and practical engineering recommendations for building reliable and verifiable evaluation workflows.

    1. Background: Why “Writing Code” Is Not the Same as “Complex Reasoning”

    In real development work, a common gap appears: a model can generate clean, well-structured code, yet its accuracy drops sharply when facing problems that combine multiple constraints, evolving state, and overlapping boundary conditions. The two problems in the source material cover two typical difficulty categories.

    The first is the “shortest path with time windows and periodic constraints.” It requires finding the earliest arrival time in a time-dependent graph, comparing cost when arrival times tie, and then comparing path lexicographic order. The second is “out-of-order log replay with idempotent merging.” It requires sorting by a composite key, deduplicating by an idempotency key, and performing additions, deletions, updates, and snapshots under owner validation.

    These tasks share one trait: they cannot be solved by local pattern matching. You must establish global invariants and preserve them strictly during implementation. The discussion below is organized around four layers: benchmark design, algorithm essentials, failure modes, and engineering recommendations.

    2. Benchmark Design: Building Tasks That Actually Discriminate Capability

    2.1 Layered Design Principle

    Structure tasks in three layers: basic correctness, constraint combinations, and extreme scale. The basic layer validates semantic understanding; the combination layer validates cross-rule interaction; the extreme layer validates complexity and numerical safety. Covering all three layers helps avoid false positives where samples pass but hidden cases fail.

    2.2 How to Construct Hidden Test Cases

    Effective hidden cases usually come from four types of intersections: extreme parameter values, overlapping constraint boundaries, coexisting equivalent solutions, and invalid or empty inputs. For example, in the time-dependent graph problem, period = 1 degenerates the waiting logic into an identity operation, cost = 0 reduces the shortest path to pure time comparison, and s == t activates both the zero-length path and lexicographic rules at the same time.

    2.3 Splitting Scoring Dimensions

    Split scoring into semantic correctness, algorithmic complexity, numerical safety, and output stability. This makes it possible to determine during review whether a failure came from misunderstanding or from implementation, instead of assigning a single vague score.

    3. Algorithm Essentials I: Earliest Arrival in a Time-Dependent Periodic Graph

    3.1 State Definition and Waiting Function

    The core state is the “earliest arrival time at a node.” When departing from u, you need the smallest depart >= T that satisfies (depart + phase) % period == 0. A general form is shown below:

    1. def next_depart(T, phase, period):
    2. r = (T + phase) % period
    3. if r == 0:
    4. return T
    5. return T + (period - r)

    Integer arithmetic is required here to avoid floating-point error; the time upper bound can reach 1e18, and any floating-point conversion may introduce unacceptable deviation.

    3.2 Why Static Shortest Path Does Not Apply Directly

    Static shortest path relies on the assumption that path cost is additive and independent of time. In this problem, arrival time changes subsequent waiting, so relaxation must be performed over the time dimension with a priority queue. If two nodes are updated at different times, the earlier-arriving state is never worse than the later one, which guarantees that “the first pop is optimal.”

    3.3 Implementing the Three-Level Comparison

    Designing the sort key as a triple (arrival, cost, path) is the most direct approach, but storing the full path introduces O(n) copying overhead. In practice, a predecessor pointer plus backtracking is more common, with linked lists or hashing used to accelerate lexicographic comparison. Example:

    1. import heapq
    2. def timed_shortest_path(n, edges, s, t, start_time):
    3. g = [[] for _ in range(n)]
    4. for u, v, phase, period, duration, cost in edges:
    5. g[u].append((v, phase, period, duration, cost))
    6. INF = (1 << 62, 1 << 62)
    7. best = [INF] * n
    8. prev = [-1] * n
    9. best[s] = (start_time, 0)
    10. pq = [(start_time, 0, s)]
    11. while pq:
    12. T, c, u = heapq.heappop(pq)
    13. if (T, c) != best[u]:
    14. continue
    15. if u == t:
    16. return T, c, u
    17. for v, phase, period, duration, cost in g[u]:
    18. d = next_depart(T, phase, period)
    19. nt, nc = d + duration, c + cost
    20. if (nt, nc) < best[v]:
    21. best[v] = (nt, nc)
    22. prev[v] = u
    23. heapq.heappush(pq, (nt, nc, v))
    24. return None

    3.4 Complexity and Optimization

    Each edge is effectively relaxed a constant number of times, so the overall complexity is about O(m log n). When period is large and the graph is dense, the bottleneck is heap operations; tiered buckets or a radix heap can be considered, but general implementations should prioritize correctness.

    4. Algorithm Essentials II: Idempotent Replay of Out-of-Order Logs

    4.1 Composite Key for Sorting and Deduplication

    Replay order is ascending (ts, actor, op_id), while the deduplication scope is op_id under the same actor. A set[(actor, op_id)] is therefore needed to record keys that have taken effect; duplicates should be skipped rather than overwritten.

    4.2 State Machine and Owner Validation

    Object state includes owner and value. add takes effect only when the id does not exist; both move and delete require owner == actor; snapshot is read-only and records visible state, using None when the object does not exist. Example:

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

    4.3 Common Mistakes

    The most typical mistake is making the deduplication key a global op_id, which causes cross-actor deletions; next is failing to update owner validation after move, which enables unauthorized deletion; finally, using references instead of copies in snapshots, which lets later changes pollute historical records.

    5. Failure Attribution: The Boundary Between Model and Prompt

    Across both task types, failures usually concentrate in three places: reducing “wait until a valid departure time” to a fixed offset; ignoring lexicographic order in the three-level comparison; and confusing deduplication scope during replay. These are not knowledge gaps but problems of invariant maintenance.

    Prompt engineering can improve output format and step decomposition, but it is hard to replace explicit modeling of constraints. A more reliable approach is to require the prompt to list invariants, complexity targets, and boundary checklists, and to perform small-scale exhaustive validation before large-scale implementation.

    6. Engineering Recommendations

    1. Build a “constraint checklist + invariants” template; for any algorithm problem, write down the state definition and comparison key first.
    2. Use randomized small datasets to cross-check against a brute-force solution, covering extreme values and equivalent-solution scenarios.
    3. Use 64-bit integers uniformly for time and cost, and forbid floating-point values in comparisons.
    4. In log replay systems, write the idempotency key scope into the interface contract to avoid caller misunderstanding.
    5. Use general monitoring, alerting, and logging services to observe replay latency and conflict rates, forming a sustainable regression evaluation loop.

    In summary, improving complex reasoning does not depend on a single technique but on the coordination of three things: layered evaluation, explicit constraints, and verifiable implementation. Turning these three into a process is what moves model output from “looks correct” to “stably deliverable.”