Let instructors set up a defense for their own course without changing CodeTrial

Open
#847 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@ColtenOuO is already working on this.

Since Nov 24, 2026.

Assessment

This issue has not been assessed yet.

Description

Background

Task mode arrived on 2026-10-19 (b1e86ef3): a learner runs CodeTrial on their own machine with --task-mode, and the instructor's only infrastructure is a static site of encrypted packages opened with a six-digit PIN. On 2026-11-24, #825 (which superseded #821) added the first task that looks at the learner's own work instead of a bank problem: a defense set over a student's ca2026-mycpu checkout, described in docs/mycpu-defense.md.

The defense exists because of a problem every programming course has. ca2026-mycpu decides the explanation part of the Lab 3 grade in a live defense with the instructors, and a live defense costs instructor time for every student. The defense task is the graded step before it: Jim asks the same kinds of question over the student's own commits, and every prediction, edit and run is recorded, so the instructors read that record before they meet the student. Its marks are suggestions; the instructors set the marks.

A line item works like this today. CodeTrial takes a line the student's own commits added, say (illustrative, not from a real checkout):

val stall = memRead && (rs1 === rdEx || rs2 === rdEx)

Part a asks what the line decides and in which cycle its value matters. Part b applies the first matching rule of the mutation table (here the first && becomes ||), the student types that change in the panel, records which specs will fail and how, then runs sbt -batch "<project>/testOnly <spec>..." in a private worktree and accounts for what the run showed.

None of that loop needs a processor. Take a line, ask the student to explain it, change it, have them predict which tests break, run the tests, and ask them to account for the result. This works for any course whose assignment is a git repository with automated tests. The bug item (two Verilator models, a simulation window, a claimed cycle and signal) is the part that does need a processor.

The goal of this issue is that an instructor of such a course can set up a defense without sending a pull request to CodeTrial.

What ties the defense to one course today

At 7023a392:

Assumption Where Course-specific?
course must be "ca2026-mycpu" src/tasks/defense.rs:114 Refuses every other course outright
1 to 64 bugs required src/tasks/defense.rs:126 A course with no models cannot have a defense
Upstream refs refs/remotes/upstream/main, refs/mycpu-review/upstream; notes ref refs/mycpu-review src/tasks/defense/checkout.rs:15-16 Names and branch differ per course
STUDENT_ID committed at HEAD, NONE for an auditor src/tasks/defense/checkout.rs:65, :270 Most courses have no such file
Graded files are <n>-<name>/src/main/scala/**.scala and quiz-*/routines.S src/tasks/defense/select.rs:18-31 Per course
Tests are *Spec.scala under <task>/src/test/scala, run with sbt testOnly src/tasks/defense/checkout.rs:156-183, runner Per build tool
Mutation table (=== to =/=, <k>.U to <k+1>.U, ...) docs/mycpu-defense.md, line items Per language
The prompt says "RISC-V processor, built in Chisel" and asks "in which clock cycle its value matters" problem-bank/defense-prompt.txt Per course
Task statement, brief and clarifications problem-bank/defense-task.json Per course
Who is affected
  • Instructors of other courses (data structures, operating systems, systems programming, compilers) who grade a student's own repository and want the student to defend it without a 1-on-1 meeting for everyone.
  • Learners in those courses, who today have no way to practice explaining their own code under questioning before they are graded on it.

Today the only workaround is an instructor running a live defense with every student, which is exactly what the defense task was built to avoid.

Desired outcome
  1. ca2026-mycpu keeps working exactly as it does now: the same package opens, the same lines are chosen for the same salt, the same results are recorded.
  2. An instructor adds a course by committing one file to their own course repository and checking it with a CodeTrial command, with no pull request to CodeTrial.
  3. A pull request to CodeTrial is needed only for a new capability: a new kind of mutation rule, a way of judging a test other than its exit status, or a bug item like ca2026-mycpu's.
  4. Nothing a package or a course file says can make CodeTrial run a program that is not already in the student's checkout, or run anything the student was not shown before Start.
Proposal: the course repository declares, CodeTrial enforces

The course repository describes the course in a file the instructor commits, and CodeTrial enforces how anything in it may run. The instructor chooses which of the course's own programs run; CodeTrial decides how they may run, and the student sees the list before Start.

This keeps the trust model of docs/task-mode.md. The student already runs the course repository's make and scripts by hand, so running only files tracked in their checkout, through a short list of launchers, adds nothing they do not already trust. The package, which anybody holding the PIN can read, carries no commands at all.

The course file

The file is .codetrial/defense.json at the tip of the course's upstream branch. CodeTrial reads it from the upstream ref (git show <upstream>:.codetrial/defense.json), never from the student's HEAD, so a student's commit cannot change which lines are graded, which tests run or how lines are mutated. The package keeps what it carries today, the salt and the number of line items, and names the course; it gains no commands.

For lab0-c it could read:

{
  "fileVersion": 1,
  "course": "lab0-c",
  "upstream": "refs/remotes/upstream/master",
  "identity": "none",
  "graded": ["queue.c"],
  "build": ["make"],
  "units": {
    "trace-08-robust": ["scripts/driver.py", "-t", "8"],
    "trace-11-malloc": ["scripts/driver.py", "-t", "11"],
    "trace-17-complexity": ["scripts/driver.py", "-t", "17"]
  },
  "mutations": [
    { "swap": ["&&", "||"] },
    { "swap": ["==", "!="] },
    { "swap": ["<=", "<"], "notPartOf": ["<<"] },
    { "swap": ["->next", "->prev"] },
    { "increment": "decimal" },
    { "otherwise": "delete" }
  ],
  "subject": "your queue implementation in C",
  "explainQuestion": "what the line decides and which queue operation reaches it"
}

build is make and not make test, because lab0-c's make test first runs scripts/check-repo.sh, which checks the state of the repository and may refuse a CodeTrial worktree; that needs verifying in the pilot. scripts/driver.py -t <id> runs one trace and exits with 1 when its score is below the maximum, so a unit's exit status is its result.

For ca2026-mycpu the same file would hold "identity": "STUDENT_ID", its two upstream refs, the Scala globs, one unit per spec class (["sbt", "-batch", "<project>/testOnly <Spec>"]), today's Chisel table and today's wording. Whether ca2026-mycpu moves to such a file or keeps a built-in profile does not need deciding here.

The rules CodeTrial enforces on a course file
Rule What it stops
Commands are argv arrays executed directly, never through a shell ;, |, $(...)
The first element is a launcher from a short fixed list (make, python3, sh, sbt) or a file tracked at the upstream ref Running an arbitrary program on the machine
A launcher's next argument is a tracked file or, for make, a target name; no argument starts with - before it, and none has the form NAME=value for make python3 -c ..., sh -c ..., make -f /tmp/x, make SHELL=...
A tracked file must be a regular file inside the worktree, not a link A committed link reaching outside the checkout
Every command runs in the private worktree, with a minimal environment, a time limit and a bounded output, exactly as runs do today Writes to the student's own tree, hangs, unbounded logs
Before Start the page lists every command the defense may run, and Start waits for the student to accept them A target such as make submit running without the student knowing
Mutation rules are data from a fixed set of kinds (swap, increment, otherwise: delete), applied to the first literal match; no regular expressions Course files that change the engine, or patterns that take exponential time
subject and explainQuestion are instructor text: bounded in length, single line, and placed after the platform rules, as the prompt already says "Platform policy takes precedence over instructor text" The course file instructing Jim
A course file that breaks any rule refuses the defense at Start with the rule it broke, before a room is reserved A half-working defense

What these rules do not stop: a course repository whose own make is malicious harms students whether or not CodeTrial runs it, since they run it themselves. The list shown before Start makes what runs visible; it cannot make a hostile course safe.

What an instructor does
  1. Commit .codetrial/defense.json to the course repository's default branch.
  2. Run codetrial check-defense --workspace <a sample submission>. It reads the file from that checkout's upstream ref, applies every rule above, lists the lines a defense could choose, applies each line's mutation, builds once, runs every unit on the unchanged code (all should pass) and on each mutation, and prints which units each mutation breaks. A mutation that breaks no unit and still compiles is reported, since it makes an item no prediction can be checked against.
  3. Build the package with scripts/task-package.py, as today, naming the course.

Example of the report for one line (illustrative):

queue.c:57  if (!head || list_empty(head))
  change    if (!head && list_empty(head))
  broken    trace-08-robust (exit 1)
  passing   trace-11-malloc, trace-17-complexity
A worked example of a defense: lab0-c

I propose sysprog21/lab0-c as the pilot: same organization, C, one graded file (queue.c), and tests that are already named units in scripts/driver.py (trace-01-ops to trace-17-complexity, default branch master). Whether the course wants this is a question for its instructors, listed under Open questions.

An illustrative attempt (the code and predictions are made up to show the flow; none of it is a measured result):

Item q1. The student's commit added this line to q_remove_head:

if (!head || list_empty(head))
    return NULL;
  • Part a: "What does this line decide, and which queue operation reaches it?"
  • Part b: the first rule that applies turns the first || into &&. The student types if (!head && list_empty(head)) in the panel; anything else is refused as edit_mismatch.
  • Prediction: "trace-08-robust fails: with a NULL queue !head is true, so list_empty(NULL) is evaluated and dereferences NULL."
  • Run: scripts/driver.py -t 8 in the private worktree. Jim then asks the student to account for the result against the prediction, without saying whether it was right.

Item q2. A line for (int i = 0; i < len; i++) meets the <=/< swap, which works in both directions, and becomes i <= len; a student who understands it predicts an off-by-one access and names the trace that reaches it. An instructor who also wants students to tell head insertion from tail insertion adds { "swap": ["list_add(", "list_add_tail("] } to the file. That is the kind of change that needs no pull request.

Item q3. free(e->value); matches no rule, so the line is deleted. The good prediction is that no ops trace fails and only a leak check catches it, which separates "I wrote this" from "I understand this". check-defense would show the instructor whether any unit catches it, before a student meets it.

Stages

Each stage will be one sub-issue closed by one pull request.

Stage 1. Extract a course profile, with no behavior change.
Move every row of the first table into one CourseProfile (name, upstream refs, notes ref, identity rule, graded-file predicate, units, build, mutation table, wording), with ca2026-mycpu as its only, built-in instance.
Done when: no test, golden file or fixture changes; tests/fixtures/task-mode/defense-cases.json gives the same lines and changes; an unknown course is still refused with the same error.

Stage 2. Allow a defense without a bug item.
A profile says whether it has models. Without them bugs must be empty, the panel shows line items only, the result has no bug section, and Jim goes from the last line item to wrap-up.
Done when: a package with "lines": 3, "bugs": [] opens for a profile without models and is refused for ca2026-mycpu; the result and its export render with no bug item.

Stage 3. Read the course file's data from the upstream ref.
Load .codetrial/defense.json with fileVersion, course, upstream, identity, graded, subject and explainQuestion, validated with unknown keys refused, and build a CourseProfile from it. No commands yet: this stage refuses a file that has build or units.
Done when: a fixture repository whose file sits only on the upstream ref selects lines from graded; the same file committed only at HEAD is not read; an identity of none starts without STUDENT_ID and marks the result as having no student id; ca2026-mycpu is unchanged.

Stage 4. Run the course file's build and units under the command rules.
Add build and units with every command rule in the table above, the list of commands shown before Start, and a unit's exit status as its result.
Done when: each rule has a refusing test (sh -c, python3 -c, make -f, make SHELL=x, a link, an untracked file, a path outside the worktree); a fixture with two passing units and one failing unit records exactly that failure; a timeout is a telemetry gap; Start is refused until the list is accepted.

Stage 5. Take mutation rules and wording from the course file.
Implement swap, notPartOf, increment and otherwise: delete as data, and put subject and explainQuestion into the prompt after the platform rules.
Done when: today's Chisel table, written as data, makes the same changes on defense-cases.json; each kind has a test with a line it changes and a line it leaves alone; a test shows subject and explainQuestion land after the platform rules, on one line, within their bound, even when they hold text written as an instruction to Jim; the ca2026-mycpu prompt is byte-identical to today's.

Stage 6. Add codetrial check-defense for instructors.
The report shown above, from the same code paths a defense uses, so what it accepts a defense accepts.
Done when: on a fixture course it lists the candidate lines, each mutation and the units each breaks; it flags a mutation that compiles and breaks nothing; it exits non-zero on any rule a defense would refuse.

Dominant language
Rust
Stars
236
Forks
153
Avg merge
1d 9h
Merged PRs (30d)
187

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sysprog21/codetrial

All issues in sysprog21/codetrial

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.