Evaluating AI Coding Capability: From Algorithmic Correctness to Engineering Reliability

    This article presents a reliability-oriented framework for evaluating AI coding capability beyond plausible explanations and passing examples. It examines four layers: semantic completeness, algorithmic validity, implementation consistency, and engineering usability. Two case studies illustrate common failure modes: a shortest-path problem with periodic edge availability and multiple objectives, and an out-of-order log replay task with idempotency, dynamic permissions, and snapshots. The discussion covers state dominance, lexicographic path ordering, deterministic replay, snapshot isolation, complexity accounting, reference implementations, targeted counterexamples, and explainable scoring dimensions. Readers gain a practical checklist for reviewing generated code through counterexamples and contract-level reasoning.

    I. Evaluating Coding Ability Starts with Problem Understanding

    When reviewing code generated by AI coding tools, developers can easily be persuaded by clear explanations, complete functions, and seemingly reasonable complexity analysis. But these qualities do not equal correctness: an implementation may pass every example while having already lost necessary information during state modeling.

    A more reliable evaluation should cover four layers:

    1. Semantic completeness: Does the solution identify goal priorities, conditions under which operations take effect, and undefined behavior?
    2. Algorithmic validity: Do key pruning rules, state merges, and greedy choices have sufficient justification?
    3. Implementation consistency: Does the code actually implement the written description, rather than omitting secondary goals?
    4. Engineering usability: Do complexity, memory usage, determinism, and failure handling meet the requirements?

    The two cases below involve graph algorithms and state replay. Both have familiar solution templates on the surface, but applying those templates directly is prone to error.

    II. Shortest Path with Periodic Edge Availability: The Real Difficulty Is the Relationship Between Multiple Objectives

    1. Convert Edge Traversal Rules into Exact Calculations

    Suppose the current arrival time at a node is T, and an outgoing edge has a phase phase, a period period, a traversal duration duration, and a cost cost.

    This edge can only be departed at times satisfying:

    1. (depart + phase) % period == 0

    The nearest legal departure time can be written as:

    1. wait = (period - ((T + phase) % period)) % period
    2. depart = T + wait
    3. arrival = depart + duration

    All calculations should use integers. Start times may be very large, and using floating-point arithmetic for period boundaries can misclassify a time that is exactly legal.

    Modulo semantics also require attention: different implementation environments may handle negative remainders differently. The form above avoids relying on negative modulo behavior when time and phase are nonnegative and the period is positive.

    2. Why a Time-Dependent Label-Setting Algorithm Works for Earliest Arrival Only

    For a single edge, arriving later at its start cannot allow an earlier legal departure, so the edge’s arrival-time function is nondecreasing.

    This is commonly called the first-in, first-out property: a later arrival cannot use the same edge to reach the destination earlier.

    When waiting is allowed, computing the earliest arrival time alone can use one earliest-time label per node and process candidate states in increasing time. With an adjacency list and a priority queue, a conventional implementation can keep the time complexity on the order of O((n+m) log n).

    But this must be emphasized:

    This conclusion directly supports only the “earliest arrival time” objective. It does not automatically prove that the algorithm remains correct after additional cost and path lexicographic ordering are added.

    3. A Subtle Error: Keeping Only One Time-and-Cost Pair per Node

    A common implementation stores for each node:

    1. best[v] = (earliest arrival time, minimum cost at that time)

    It then compares and prunes by this pair. This looks consistent with the objective priority in the problem statement, but it may delete states needed for the final answer.

    Consider the following situation:

    • Route A reaches node u at time 1 with cumulative cost 100;
    • Route B reaches node u at time 2 with cumulative cost 0;
    • The edge from u to the destination can only be departed at times 0, 10, 20, ...;
    • This edge has traversal duration 1 and cost 0.

    Both routes can only depart from u at time 10, and both reach the destination at time 11. Therefore, Route B is the lower-cost choice among the earliest-arrival solutions.

    If the algorithm keeps only the earliest-arrival state at node u, it will retain Route A and discard Route B, producing an incorrect cost.

    This counterexample shows:

    Time priority at an intermediate node is not the same as time priority for the final objective. Periodic waiting may eliminate a time difference, but it does not eliminate a cost difference.

    Therefore, a local update rule such as “compare cost only when earliest times are equal” cannot directly guarantee global correctness.

    4. Correct State Dominance and the Scale Problem

    For two states at the same node:

    1. State A: (time T1, cost C1)
    2. State B: (time T2, cost C2)

    If T1 <= T2 and C1 <= C2, then, ignoring path lexicographic order for now, A can dominate B: A can wait until B’s time and then follow the same suffix, obtaining a result that is no later and no more expensive.

    But if A is earlier and more expensive, the two states usually cannot be merged directly.

    A general approach is to maintain nondominated multi-label states. However, a multi-label method does not automatically satisfy large-scale constraints. In the general case, the number of nondominated states may grow significantly, and one cannot claim that the whole problem still has near-linear complexity without proof.

    After path lexicographic order is added, pruning requires additional care. If two states may ultimately produce the same time and cost, deleting either prefix must have an explicit lexicographic justification; the time-and-cost relationship above cannot replace a complete proof.

    For this kind of task, a qualified technical answer should distinguish three things:

    • the earliest-arrival subproblem that can already be solved efficiently;
    • a multi-label approach that is correct but whose state size may not be controlled;
    • a large-scale complete algorithm that requires additional conditions or further proof.

    Proactively stating the boundaries of an algorithm is more valuable than providing “complete code” with no correctness guarantee.

    5. Lexicographic Order Cannot Compare Only the Immediate Predecessor

    Suppose the two candidate paths are:

    1. [0, 2, 8, 9]
    2. [0, 3, 1, 9]

    The first path is smaller at the first differing node, so it is lexicographically smaller. But its immediate predecessor 8 is larger than the immediate predecessor 1 of the other path.

    This shows that choosing the smaller-numbered predecessor only in tie cases does not produce the lexicographically smallest complete path.

    Storing the full path directly is easy to understand, but it may cause extensive copying and comparison, increasing time and memory costs. A large-scale implementation needs a dedicated path representation and comparison strategy, along with an analysis of its worst-case overhead, rather than simply placing the full path into every priority-queue element.

    6. Graph Algorithm Edge Cases That Must Be Covered

    Tests should include at least:

    • Start equals destination: The empty walk path is [s], returning the start time and zero cost. Because traversal duration is strictly positive, a detour cannot improve the earliest time.
    • Period equals one: Any integer time is a legal departure, so no additional wait should be added.
    • Already at a legal departure time: The wait must be zero.
    • Multiple edges: Different edges between the same pair of nodes may have different periods and costs and must not be merged arbitrarily.
    • Zero-cost equivalent paths: Check lexicographic tie handling.
    • Large integer times: Check the integer range for cumulative time and intermediate calculations.
    • Unreachable destination: Return the agreed empty result, not stale labels.
    • Later but cheaper intermediate state: Specifically verify the state-loss problem described above.

    III. Out-of-Order Log Replay: The Difficulty Is Determinism and Semantic Closure

    The basic flow of a log replay task is: first establish a deterministic order, then perform idempotency checks, and finally execute object-state changes and snapshot recording.

    This type of problem does not necessarily require a complex algorithm, but it strongly tests faithful implementation of rule details.

    1. Sorting Is Part of Replay Semantics

    If the rules require processing in ascending order of (ts, actor, op_id), then object existence, current ownership, and which operations have already been processed must all be determined under that order.

    A log that appears earlier in the raw input must not be assumed to have occurred first.

    However, the original rules still have a boundary that needs clarification: if two logs have exactly the same sort key but contain different operations or payloads, which one should take precedence?

    A stable sort can only preserve the current input order. If the input itself may be arbitrarily shuffled, it cannot guarantee that different input permutations produce the same result.

    Therefore, the system contract needs to specify one of the following:

    • prohibit different content under the same complete sort key;
    • add a deterministic final sort field;
    • or explicitly specify that input order participates in tie-breaking.

    This is business semantics and should not be silently guessed by the implementer.

    2. The Idempotency Key Must Include the Actor

    The rule limits “under the same actor, the same operation identifier takes effect only once,” so the deduplication key should be:

    1. (actor, op_id)

    If only op_id is used, legitimate operations from different actors will be incorrectly deduplicated.

    It is also necessary to distinguish “the operation has been processed” from “the operation changed state.” For example, a deletion may produce no change because the object does not exist, but this does not necessarily mean that a later log with the same key can be retried.

    If the interpretation is “after the first log is processed, later logs with the same key are ignored,” the correct order should be:

    1. read sorted events
    2. if the idempotency key has been seen, skip
    3. register the idempotency key
    4. execute the rule for the event

    If the business wants failed operations to be retryable, it must separately define failure types, retry conditions, and idempotency states; these must not be mixed with the semantics above.

    3. Permissions Must Be Checked Against the State at That Time

    The permission for move and delete operations depends on the object’s current owner when the event is executed.

    For example:

    1. An object initially belongs to A;
    2. A transfers the object to B;
    3. A then attempts to delete the object;
    4. B then attempts to delete the object.

    If no other state changes occur, the third step should be ignored, and only the fourth step should take effect.

    Therefore, permission checks must read the current object state; they must not use the original creator, nor may they judge in advance based on a future state.

    Similarly, whether a deleted object identifier can be recreated must strictly follow the rules. If the create operation checks only whether the object currently exists, then recreating it after deletion should be allowed; an additional restriction such as “an identifier that has ever appeared can never be reused” must not be added arbitrarily.

    4. Snapshots Must Store Historical Values, Not Mutable References

    A typical error is to place the current object directly into a snapshot:

    1. snapshot[id] = objects[id]

    If the object record is a mutable structure, later owner changes may also change the historical snapshot.

    A safer approach is to copy the current state or store an immutable value representation. For example, provided the value itself is immutable, you can store:

    1. (owner, value)

    If value also contains mutable nested structures, the copy depth must be further specified, or an immutable data representation must be used.

    For a nonexistent object, record the agreed empty value rather than omitting the object; otherwise, the caller cannot distinguish “requested but absent” from “never requested.”

    In addition, the snapshot output needs two contract details filled in:

    • When the same label appears again, should it overwrite, be rejected, or retain multiple snapshots?
    • For duplicate object identifiers in the request list, should duplicate positions be preserved, or should they be deduplicated by identifier?

    Different choices affect the return structure. Parts not specified by the original rules should be listed as items to be confirmed.

    5. Complexity Must Include Snapshot Output

    Let the number of logs be E, and let the total number of requested objects across all snapshots be K.

    In a conventional implementation:

    • sorting costs O(E log E);
    • using hash tables to maintain state and idempotency sets typically provides average constant-time lookup and update;
    • snapshot generation must process at least K request positions.

    Therefore, total time can be stated as O(E log E + K) in the average sense; if complex values require deep copies, the amount of copied data should also be included.

    Space includes storage for sorting, current object state, idempotency records, and snapshot results. Writing only “space is the number of objects” omits historical output and the deduplication set.

    IV. How to Design Trustworthy Coding Capability Evaluation

    1. Validate Optimized Versions with Small-Scale Reference Implementations

    For graph problems, you can build a time-expanded state within a small scale and an explicit time bound, retaining time, cost, and path information to form reference results that are easy to inspect. It may be slow, but it is suitable for finding incorrect pruning in optimized algorithms.

    For log problems, you can write a reference implementation that directly replays according to the rules, then compare the final state and all snapshots with the candidate implementation.

    The goal of the reference implementation is ease of review, not high performance.

    2. Combine Random Testing with Targeted Counterexamples

    Random generation helps discover unexpected combinations, but it cannot replace targeted tests.

    For graph problems, actively generate scenarios where periodic waiting eliminates time differences. For log problems, actively construct ownership transfers, duplicate idempotency keys, and historical snapshot isolation scenarios.

    When random testing finds a failing case, continually reduce nodes, edges, or events until a minimal counterexample is obtained. Small counterexamples are more likely to reveal modeling errors and are better suited for long-term regression tests.

    3. Split Scoring into Explainable Dimensions

    It is recommended to evaluate separately:

    • rule understanding;
    • correctness proof;
    • boundary coverage;
    • time and space analysis;
    • consistency between implementation and explanation;
    • identification of undefined semantics;
    • test and reproduction quality.

    A piece of code that performs well on a log task does not mean it can correctly handle multi-objective graph optimization; failing an algorithm problem does not directly imply insufficient ability on all development tasks.

    V. Conclusion: Reliable Code Must Withstand Counterexamples and Contract Review

    The shortest-path problem with periodic edge availability reveals a key issue: a locally optimal state may not contain the information needed for a globally optimal multi-objective solution. Out-of-order log replay shows that even when the flow is simple, sorting ties, idempotency scope, dynamic permissions, and snapshot copying can determine whether the result is correct.

    Therefore, when evaluating AI coding capability, attention should shift from “how quickly code is generated” to “whether the rules are fully understood, key assumptions are proved, complexity boundaries are identified, and reproducible tests verify the result.”

    For practical development, generating code is only the starting point. State modeling, semantic clarification, counterexample testing, and engineering review are the core steps that turn a candidate implementation into reliable software.