Let instructors set up a defense for their own course without changing CodeTrial
维护者通常 1 天内回复
@ColtenOuO 已经在做这个了。
开始于 2026年11月24日。
评估
这个 Issue 还没有评估数据。
描述
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
- 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.
- 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.
- 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.
- 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
- Commit
.codetrial/defense.jsonto the course repository's default branch. - 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. - 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 typesif (!head && list_empty(head))in the panel; anything else is refused asedit_mismatch. - Prediction: "
trace-08-robustfails: with a NULL queue!headis true, solist_empty(NULL)is evaluated and dereferences NULL." - Run:
scripts/driver.py -t 8in 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.
- 主要语言
- Rust
- 星标
- 236
- 派生
- 153
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 187
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
sysprog21/codetrial 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 70/100
维护者通常 1 天内回复
-
Unify Java harness validation error messages可能已有人在做 @weichieh0204 今天认领。 未关闭
sysprog21/codetrial#872 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Inferred void class operations are never checked against the starter's return type可能已有人在做 @papaya0112 今天认领。 未关闭
sysprog21/codetrial#871 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Edge Thumbnail Store accepts a store that does not refresh a key on overwrite可能已有人在做 @BOBOGUAGUA428 今天认领。 未关闭
sysprog21/codetrial#869 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 sysprog21/codetrial 的全部 Issue
相似的 Issue
-
needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
manaflow-ai/cmux#59692 ·
维护者通常 1 天内回复
-
Retire stale Python-parity labels in Rust ingress and auth tests可能已有人在做 @github-actions 今天认领。 未关闭factory factory:building factory:unowned ralph-status:in-progress via:opencode-free/hy4-flash-free
难度 2/5 1-3 小时 新手友好度 82/100
JoshCLWren/comic-pile#5874 · 2 条评论 ·
维护者通常 1 天内回复
-
status:ready unit
难度 2/5 1-3 小时 新手友好度 75/100
nonagenticai/conveyor#787 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复