Skip to content

Add a defense task over a student's mycpu checkout - #825

Open
jserv wants to merge 8 commits into
mainfrom
chisel-task-mode
Open

jserv wants to merge 8 commits into
mainfrom
chisel-task-mode

Conversation

@jserv

@jserv jserv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

This supersedes #821, which was merged by mistake and then removed from main; it carries that series, reworked after its review, with the review fixes and the tests its mutation run asked for.

A course that grades a student's own RISC-V core in Chisel (ca2026-mycpu) needs to know the student wrote it and understands it. This adds an opt-in defense set to task mode: codetrial web --task-mode --workspace <path-to-checkout> examines the student's own checkout. Lines the student added, chosen with the package's own salt, are explained to Jim; a stated change is typed and its failing specs predicted before a real sbt testOnly run; and the student's core, built with a mutant drawn per attempt, is run beside the clean build (retire log, waveform, obs-trace window) until the student states the cycle, signal, rule and exercise of the bug. Edits and builds happen in a private git worktree, so the student's tree and index are never written, and the page never learns the mutant or what a claim is checked against.

Jim examines without saying right or wrong and is told the panel's events once neither he nor the learner is speaking. A package may allow up to three hints (hints, default 0); each is recorded against its item and caps that item's suggested marks at 2. The result gains a defense section of suggested marks, labelled as suggestions generated on the student's machine. Item code is colored from a vendored tree-sitter-scala grammar, a defense set's setup advances by itself and remembers its PIN per set version, and scripts/task-package.py gains pin new and pin check. docs/mycpu-defense.md is the contract; non-defense task mode is unchanged.

Verified with ./scripts/test.sh on the branch, rebased on main: every gate passes except the browser test "a formatter that cannot load changes nothing, and the next press loads it", which fails on main as well. Each of the series' commits builds with clippy and passes its own tests. Every mutant that survived #821's mutation run is either killed by a test, checked by applying it by hand, or gone because the line now says what it computes in one step. A rehearsal against a public ca2026-mycpu checkout and a live Gemini room exercised the panel, hints and the bug item end to end.

Left out, as open questions: defense packages keep packageVersion, taskContract and rubricProfile at 1 under task-mode's draft clause; the defense prompt is not pinned in tests/golden/task-prompts.json; a replacement connection is told how many hints each item had but not their wording; and when the student's bootcamp gate stamp is stale, the course's Makefile reruns that gate in the student's bootcamp clone, which the contract names as the one write outside the worktree.


Summary by cubic

Task mode previously only posed tasks from a packaged bank; it can now pose a defense set that examines a student's own ca2026-mycpu checkout, so a course can grade whether the student understands the RISC-V core they wrote. Start it with codetrial web --task-mode --workspace <checkout>; edits and builds run in a private git worktree, so the student's checkout is never modified.

New Features

  • Jim asks about lines the student added, then the student types a stated change and predicts which specs fail before the real sbt testOnly run.
  • A bug item builds the student's core with a per-attempt mutant and compares it with the clean build until the student states the cycle, signal, rule and exercise; the page never shows the mutant or the check.
  • Defense packages can allow up to three hints; each hint is recorded and caps that item's suggested marks at 2.
  • Results gain a defense section with suggested marks, and task-package.py gains pin new and pin check.
  • Chisel lines in the defense panel are colored with a vendored tree-sitter-scala grammar.

Migration

  • A defense set is a task-mode package with a defense object in place of a bank; docs/mycpu-defense.md is the contract.
  • --workspace is accepted only with --task-mode, and non-defense task mode is unchanged.
  • The checkout must sit on a clean HEAD with a committed STUDENT_ID and an upstream remote; the asked-about lines are those the student added since the merge base.

Written for commit 94b8af8. Summary will update on new commits.

View guided diff Turn on auto-fix

cubic-dev-ai[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

A defense shows the student's own Chisel lines, which read better with
the constructs that make hardware told apart from plain Scala. The
tree-sitter-scala grammar is vendored as the other grammars are, pinned
by checksum, and web/chisel-highlight.js colors Scala's keywords,
literals, comments and types, and Chisel's constructors, hardware
types, literal and width suffixes and hardware operators. Lines are
always drawn as text, and stay plain until the grammar loads or when it
cannot. A snippet parsed once gets a longer parse budget than the
editor's keystroke one, so a cold first parse is not cancelled.

Change-Id: Icd584cedafe09350d55d7348f3a44cb0b8eda693
A defense examines the student's own ca2026-mycpu work, so CodeTrial
reads their checkout: its graded files must be clean at HEAD, with a
committed STUDENT_ID and an upstream remote, and the lines the student
added since the merge base are the candidates, kept when the course's
review script would ask about them and not already asked in a push
review note. They are ordered by an HMAC with the package's own salt,
a different file each time while one is left, as the course's defense
script does with its own. Every edit happens in a private worktree of
HEAD, so the student's tree and index are never written; git is read
with the student's configuration overridden where it would change
what is parsed, and a worktree that cannot be removed loses only its
own registration, never the student's others.

Change-Id: I5a76ea447cbd04dcb2a4c938e67d7b1617123233
@jserv

jserv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Folded the series: 31 commits became 8, each owning its feature together with the review fixes and the mutant tests for it, and rebased onto main. The only change to the tree beyond folding is that the defense tests now sit in files named for what they test (the old test file was past its size ceiling), plus the one remaining surviving mutant from the last mutation run (kill_group was split by platform, so its non-unix body could never be tested; it is one function now) and the title test cubic asked to keep sensitive to a hard-coded title.

cubic-dev-ai[bot]

This comment was marked as resolved.

A defense runs the course's own tools on the student's code: sbt for a
change's specs, make for a model and the model on a program. Any of
them can print without end, outlive its limit or leave a process
behind, and none may stall the attempt. Each runs in its own process
group, under coreutils' timeout where it is installed, with stdout and
stderr read from one pipe into a shared 64 KiB tail while it runs; at
the end the whole group is killed, a command past its limit is a
timeout, and one that cannot start is a telemetry gap with its reason.
Output already read is kept even when an escaped process holds the
pipe.

Change-Id: Ie4c409b8161c385d16778d75f90439b39fc47471
A course that defends its students' own work needs no task bank: a
defense set's package carries the course settings instead, named in
its defense object, and poses the one built-in defense task. The
object is closed and bounded: the package's own salt, how many lines
to ask about, the course's task directories and the bugs one is drawn
from per attempt, the time each kind of run may take and how many
hints Jim may give, at most three. Its cases are shared with the
packaging tool in tests/fixtures/task-mode/defense-cases.json. The plan
of a defense is drawn from the checkout at admission: the chosen lines
with the code around them, each with the stated change part b asks
for, and the bug.

Change-Id: Ida384ce7800a3566bcd00650481e198b940005a8
A defense is evidence for the instructors, so each step of it is kept:
part b's prediction before its run, the run of the stated change in
the worktree with the specs it failed, and for the bug item the two
models of the student's core, with and without the drawn mutant, run
on the student's built programs. The obs trace of each run is read
into a window table, and the first retire record in which the models
differ is what the student's one claim of cycle, signal, rule and
exercise is checked against. The page's view never carries the
mutant, its rule or those checks. The facts become a defense section
with suggested marks on the course's scale, labelled as suggestions
generated on the student's machine, and stay within the result's
bound.

Change-Id: I49925940685a58a0913d1a894c449323e7ef1819
A defense set is admitted only over the learner's own checkout,
named with codetrial web --task-mode --workspace: the attempt is
prepared at Start, and a retried Start reaches the same one. The
panel's requests under /api/defense act on that attempt alone, while
work is open and each item only once it is begun, one at a time. Jim
is the examiner: he is given the items and the bug item without its
mutant, says nothing is right or wrong, and hears each panel event as
a platform note once neither he nor the learner is speaking. A package
that allows hints gives him request_defense_hint, granted only after
an answer begun once the item opened, each hint capping that item's
suggested marks. The review adds a mark per item's explanation, and a
connection that replaces a lost one is told where the panel stands.
docs/mycpu-defense.md states the contract.

Change-Id: I8bc399a953dff081140ee4280d241bfe32712af2
A defense set's page has a panel of its own in place of the editor,
the public cases and the public runs. Each item opens on an overview
of what it asks, with its code colored as Chisel, and a Begin button,
offered no more once the items are over; then its controls: the
change typed in a one-line editor, the prediction and the run, and
for the bug item the model builds, each simulation's retire records,
waveform and window table, and the one claim. Typed answers and focus
survive redraws, a failed request is tried again and a refusal is
not. The result shows the suggested marks item by item. The setup of a
defense set moves on by itself from the rules to Start, and the
browser remembers its PIN for that set version until the server
refuses it.

Change-Id: I9ab9f86288ea454be56bb939550bf594c373b10a
An instructor builds a defense set from a bank that holds defense.json
in place of problems, and the tool checks it against the cases
CodeTrial itself is tested with, sharing the header checks of a task
bank. pin new draws PINs from the operating system's secure random
source, every one of the 10^6 equally likely; pin check reads one as
build does and says whether it opens a built version, checking the
manifest and the ciphertext's hash first so that a damaged package is
told apart from a wrong PIN, and prints neither. Both find the
cryptography dependency as build does.

Change-Id: I3be11c47c69004100030c44ef621a7254d5138bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant