From an engineering task to a bounded execution plan

An independent Python exercise connects an objective, source snapshot, permitted changes, and evidence without treating an admitted plan as an executed refactor.

A plan defines the boundaries of an allowed change.
A plan defines the boundaries of an allowed change.

“Extract title normalization into a separate function” sounds specific enough. Yet it leaves many decisions open: which version of the code to change, where the function should go, whether a neighboring module may be rewritten, and what result would justify calling the work complete. Some of that context may be obvious to a person. A tool or agent needs it made explicit.

A useful intermediate result is a work packet. It connects the objective, initial state, permitted changes, dependencies, and acceptance method. We will use a new, small Python exercise: a validator checks the plan, and a separate mode compares a result declaration with actual files. There is no refactor executor here. The initial tree and candidate tree were authored as teaching fixtures, not produced by an actual refactor.

One task with clear boundaries

In the initial app/card.py, render_title removes extra whitespace and changes the title’s case itself. The objective is to move normalization into app/formatting.py while retaining the public render_title call. One specific change has been selected, with its bytes reviewed in advance and recorded in the contract.

This is an important limit of the example. The validator does not decide whether this refactor is good architecture or generate an arbitrary implementation from a written wish. It answers a narrower question: does the submitted plan fit this task’s already defined boundaries?

Part of the packet What is recorded
Objective Extract normalization while retaining the public function
Input The exact initial file set and its bytes
Permitted changes Create app/formatting.py and replace app/card.py
Dependency rewire requires extract to come first
Effects Only the described candidate-file changes; no external actions
Acceptance The complete expected file set and exact content, including files that must remain unchanged

Another path or a file deletion does not become permitted merely because the worker considers it a convenient extension of the task. A broader refactor requires changing the contract and reviewing the plan again first.

The contract and plan have different sources of authority

In the exercise, task.json is the trusted contract selected by the person responsible for checking. plan.json is an untrusted proposal. The plan references a particular contract and initial snapshot, but it cannot grant itself network access, another file, or a weaker success criterion.

A shortened view is useful for reading:

{
  "task": "title-normalization",
  "source": "reviewed baseline",
  "changes": [
    {
      "id": "extract",
      "action": "create",
      "path": "app/formatting.py",
      "depends_on": []
    },
    {
      "id": "rewire",
      "action": "replace",
      "path": "app/card.py",
      "depends_on": [
        "extract"
      ]
    }
  ],
  "external_effects": [],
  "success": "candidate_state_verified"
}

This is packet-view.json, an explanatory projection rather than the CLI’s complete input. The working documents additionally bind the contract, initial files, and proposed content through digests. A digest helps detect substituted bytes; it does not establish the author’s identity or permission to change a repository. If an untrusted party can replace the trusted contract too, this model no longer has an independent basis for checking.

Shape validation is a separate job as well. The reader rejects unknown fields, duplicate JSON keys, incorrect types, and non-finite constants such as NaN. JSON size is limited to 64 KiB. The Python JSON documentation describes hooks for key pairs and special numeric values and recommends limiting untrusted input. A successful JSON parse alone does not check the task’s boundaries.

Recheck the recorded snapshot

Before admission, the validator reads the initial tree and compares its entire file set with the contract. A stale snapshot reference, a changed app/card.py, or an additional file causes rejection. The directory’s name does not establish that its content is current.

This snapshot describes ordinary file names and bytes. It does not cover permissions, Git history, authorship, or empty directories. The exercise allows up to 16 files, up to 4096 bytes in each, and up to 32768 bytes overall. These are deliberate limits for a small experiment, not recommended quotas for every repository.

A path is checked before use: only a relative form with permitted components is accepted. ../card.py, an absolute path, a backslash, a dot component, and a repeated separator are rejected. Even a correctly spelled app/other.py fails because it is outside the permitted changes.

Lexical checking is not enough for a filesystem. The pathlib documentation distinguishes computations on paths from operations on actual files. The reader separately rejects symbolic links at the root and within the tree. It works with trusted local fixtures without concurrent editing; this exercise does not establish protection against a hostile filesystem or races between checking and reading.

A valid graph does not imply the right dependencies

A plan contains at most 8 steps. Their identifiers and target paths must be unique. A reference to an unknown step is rejected before topological ordering.

That preliminary check is deliberate: TopologicalSorter can automatically add a referenced dependency as a new node without predecessors of its own. The graphlib contract also explains that a complete topological order exists for a graph without cycles. The exercise rejects the entire cyclic plan instead of returning its partially ordered portion as ready.

But the absence of a cycle does not establish that dependencies are complete. Remove extract from rewire’s predecessor list and the graph remains simple and mathematically valid. The task contract still requires that dependency, so the plan is rejected.

The order extract, rewire states a requirement for future execution. It does not confirm that someone has already created the helper or followed that sequence. The validator has no apply command, and admission retains execution_authorized=false.

A success declaration must meet the files

The second mode receives the plan, initial tree, candidate tree, and receipt.json. A receipt here is only a statement: which plan it refers to, which steps are marked complete, and which state the candidate supposedly has. The evaluator does not treat it as sufficient evidence on its own.

It reads the candidate files itself and computes their digest. It then compares that file set with the expected result: permitted files have the exact reviewed bytes, the other initial files are preserved, and there are no extra files. A fabricated digest in the receipt is rejected. Yet even an honestly computed digest of the unchanged initial tree does not make a success claim true: the required changes are absent.

Evaluator result Meaning
plan_accepted The plan matches the contract and the initial state that was read
candidate_verified The supplied candidate files match the reviewed plan
reported_failure An explicit failure declaration is retained; success is not inferred
rejected The input or claimed result contradicts the contract or observation

The declared and observed fields remain separate. Even candidate_verified carries execution_observed=false: the files could have been prepared another way. The evaluator does not execute candidate code or prove behavioral preservation for all inputs. That claim would require separate behavioral tests. What is established here is a match to particular reviewed bytes, not their production history or cryptographic attestation of a worker.

Rejections make the boundary testable

In a local run with Python 3.12.3 in the canonical tools/work-packet-lab, all 50 of 50 native admission and supplied-candidate scenarios produced the expected outcomes. They include a valid plan, a candidate read from disk, a stale snapshot, an extra path, a missing dependency, a cycle, a network effect, a fabricated receipt, a missing helper, and a changed file that should have remained unchanged. Separate checks cover stable responses in fresh Python processes and unchanged example source files. The original test oracles are preserved.

To reproduce admission from the example directory:

python3 -B work_packet.py admit \
  --task task.json --plan plan.json --source fixtures/before

To compare against the supplied candidate:

python3 -B work_packet.py evaluate \
  --task task.json --plan plan.json --source fixtures/before \
  --receipt receipt.json --candidate fixtures/candidate

Exit code 0 means an admitted plan or a verified candidate state, depending on the mode. Code 1 retains a reported failure, 2 means rejection, and 3 means a local input is unavailable. The runner creates only temporary fixtures for negative cases and a separate report; a new report path must be supplied via --report. The evaluator itself reads data. The exercise does not access external repositories or the network, or perform external writes.

This packet gives the next worker concrete boundaries and leaves a reviewer concrete questions. Before applying anything, the owner of writes, their authority, and behavioral checks still need to be defined. A detailed plan makes that transition easier to understand, but it does not perform the transition itself.

  1. Testing Structured AI responses: validation before changing data
  2. Knowledge & AI Context for one task: how to avoid sending the whole platform to a model
  3. Platform Engineering A long task stopped: checkpoints and safe resumption
  4. Testing AI in development: context, action, and checking the result

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article