Forge Fate
AI

How Should I Judge Code I Did Not Write?

4 min read

An AI coding agent reports that it simplified a query while preserving behavior. The code is shorter and tests reportedly pass. Is that enough to accept it?

Connect the behavior that must remain, the changed code's effects, and what tests actually establish. A missing tie-break condition in a paginated list illustrates the process.

Code and diffs below are educational examples, not changes from a real project or output collected from a particular model. Execution results were checked with Python 3.14.5 while preparing this revision on 2026-10-24.

1. Write the behavior contract before reading code

Assume:

  • Newer creation times appear first.
  • Equal creation times are ordered by ascending unique id.
  • Page size is 2; page numbering starts at 1.
  • Empty input or a page beyond the end returns an empty list.
  • Data does not change during retrieval.

“Newest first” alone can hide the tie-break requirement. Put tied ID 13 before 12 in the input:

Input orderidCreated
11110:00
21309:00
31209:00
41408:00
51507:00

The contract implies:

text
11 → 12 → 13 → 14 → 15
RequestExpected IDs
Page 1[11, 12]
Page 2[13, 14]
Page 3[15]
Page 4[]

These expectations come from the sorting/paging rules, not copied implementation outputs. Distinguishing program output from correct output is the test-oracle problem. The Oracle Problem in Software Testing: A Survey

2. Identify the condition removed by a one-line diff

The example represents same-day times as minutes since midnight: 10:00 is 600, 09:00 is 540.

diff
- key = lambda row: (-row["created_at"], row["id"])+ key = lambda row: -row["created_at"]

The original uses descending created_at, then ascending id; the revision retains only the first. Ask what order was promised for equal timestamps, rather than whether the code is shorter.

Python sorting is stable: equal keys preserve input order, leaving 13 before 12. This is not random reordering across executions; stable input order conflicts with the required ID order. Python sorting documentation

Database pagination also needs tie handling. Google Cloud's pagination documentation describes adding a tie-break column for a definite order, but this Python run does not validate an actual database. Pagination and tie-breaking

3. Correct counts can accompany incorrect results

RequestContract expectationOutput without tie-break
Page 1[11, 12][11, 13]
Page 2[13, 14][12, 14]
Page 3[15][15]

Both versions return page counts 2, 2, 1, with five total items and no duplicates or omissions on this fixed input. Tests checking only two items on page 1, one on the last page, or five overall miss the defect.

The risk is which items appear in which order across the page boundary. Assert IDs and order, not just counts. Input design matters too: placing tied IDs as 12, 13 would conceal the missing condition. Reverse order makes it observable.

4. Apply the same tests to faulty and corrected implementations

The standard-library script tests both versions. It prints assertion failures and continues so both sets of results can be compared.

python
import platformimport unittestROWS = [    {"id": 11, "created_at": 600},    {"id": 13, "created_at": 540},    {"id": 12, "created_at": 540},    {"id": 14, "created_at": 480},    {"id": 15, "created_at": 420},]def page_ids(rows, page, *, with_tie_break):    if with_tie_break:        key = lambda row: (-row["created_at"], row["id"])    else:        key = lambda row: -row["created_at"]    ordered = sorted(rows, key=key)    start = (page - 1) * 2    return [row["id"] for row in ordered[start:start + 2]]CASES = [    ("first_page", ROWS, 1, [11, 12]),    ("second_page", ROWS, 2, [13, 14]),    ("last_page", ROWS, 3, [15]),    ("empty_input", [], 1, []),    ("past_last_page", ROWS, 4, []),]print("Python", platform.python_version())for name, with_tie_break in [    ("missing_tie_break", False),    ("restored_tie_break", True),]:    print(name)    passed = 0    for label, rows, page, expected in CASES:        actual = page_ids(rows, page, with_tie_break=with_tie_break)        try:            unittest.TestCase().assertEqual(actual, expected)        except AssertionError:            print(f"  FAIL {label}: expected={expected}, actual={actual}")        else:            passed += 1            print(f"  PASS {label}")    print(f"  result: {passed}/5 passed")    print("  page_counts:", [        len(page_ids(ROWS, p, with_tie_break=with_tie_break))        for p in (1, 2, 3)    ])

Observed output:

text
Python 3.14.5missing_tie_break  FAIL first_page: expected=[11, 12], actual=[11, 13]  FAIL second_page: expected=[13, 14], actual=[12, 14]  PASS last_page  PASS empty_input  PASS past_last_page  result: 3/5 passed  page_counts: [2, 2, 1]restored_tie_break  PASS first_page  PASS second_page  PASS last_page  PASS empty_input  PASS past_last_page  result: 5/5 passed  page_counts: [2, 2, 1]

Removing the tie-break fails pages 1 and 2. Restoring it while retaining the same expectations passes all five checks.

diff
- key = lambda row: -row["created_at"]+ key = lambda row: (-row["created_at"], row["id"])

The evidence is more specific than “five tests exist”: these tests detected this deliberately removed tie-break condition. That does not establish coverage of every other defect.

5. Record questions the passing tests do not answer

The run verifies sorting and page IDs on fixed input.

AreaChecked here?
Tie order across a page boundaryYes
Last page, empty input, past-end pageYes
Zero or negative page numberNo
Actual SQL/ORM sorting and paginationNo
Inserts/deletes between page requestsNo
Response fields, permissions, errors, performanceNo

This table defines evidence boundaries rather than demanding every imaginable test. If the actual change moves sorting into a data-access layer, a passing Python function is insufficient: inspect both ordering conditions in the real query and test that path. If scope is only restoring this function's tie-break, focus on it and relevant boundary inputs. Match verification to behavior touched by the real diff.

6. Request the specific missing evidence

Available evidenceDecision
Clear contract; relevant diff and executed path agreeConsider acceptance within checked scope
Tests check counts but not tie orderRequest page-ID/order assertions
Test code exists without execution resultsRequest command, target, and result
Function passes but actual query path changedDefer until that path is checked
Responses/permissions also changed with unclear impactNarrow the change or review further

A concrete follow-up is more useful than “be more thorough”:

text
Preserve created_at descending, then id ascending for ties.Current tests only check page counts.Supply tied rows in reverse ID order and assert IDs/order on pages 1 and 2.Confirm the checks fail when the tie-break is removed and pass when restored.Derive expectations from the contract, not implementation output.Report execution commands, results, and unchecked scope.

Separate explanations from execution evidence in the answer. Agreement from another model is not evidence that a test ran.

7. Can you identify what to change for the next requirement?

Judging correctness connects to maintainability. Suppose ties must now show larger IDs first. Change the tie-break and recalculate expectations for the first two pages from the new contract.

Changing expectations is justified because the requirement changed. That differs from changing them merely to accommodate a failing implementation under an unchanged requirement.

Even for code you did not write, evidence improves when you can explain the intended behavior, its responsible code, the inputs/tests checking the change, and what remains unchecked.

The next article considers how much to invest in learning tools and improving the work environment.

Report an error or share feedback

Open a draft with this article’s title and URL. Review the message and recipient before sending.

To: [email protected]

Open email draft

If no email app opens, copy these details into your usual email service.

Contact information