Studio: foreground and unattended on the same task
Learning objectives
Demonstrate LO2 by designing a bounded background workflow. Demonstrate LO9 by accepting only what your own verification supports. Use a small subtask from your project or current contribution, such as a fix with a local reproducer. This is studio practice in your existing work record. It does not add a separate submission or change contribution requirements. When the task comes from your project, the unattended run's record feeds the final project's evaluation item. The evaluation script scores at least one unattended attempt like this one, with its acceptance check outside what the agent may edit.
Minimal example
Generate. The notes give one summary fix as it might come
back from the two modes. Both candidates are course-written files under
lectures/week-09-background-agents/fixture/, next to the base they start from; no agent
returned them. First predict whether each candidate's branch report is enough.
Verify. From the course checkout, run both against the same unchanged cases, including
the display case. Then print the unattended candidate's diff against the base. If your
terminal has no python command, type python3.
python lectures/week-09-background-agents/fixture/verify.py foreground --tests acceptance; echo "exit $?"
python lectures/week-09-background-agents/fixture/verify.py unattended --tests acceptance; echo "exit $?"
git diff --no-index lectures/week-09-background-agents/fixture/base lectures/week-09-background-agents/fixture/unattended
Inspect the diff and identify which requirement the extra display change violates.
Hands-on exercise
If there is a guest
A practitioner speaks for at most 45 minutes on this week's topic. Write one question beforehand. In that case, do the part "Prepare a request that can stop" before class. That includes the reproducer on the base and the two worktrees. After the talk, run the two modes with a short limit you set in advance and verify at least one candidate in class. Finish the comparison table and the decision line afterwards in your existing record.
Prepare a request that can stop
Choose a task small enough to review in class. Write its observed failure, allowed files, unchanged behavior, verification command, forbidden changes and stop condition. Run the reproducer on the base before asking the agent for a change. If you cannot reproduce the failure or the check cannot fail, ask the teaching team to help narrow the task. Follow the current syllabus's access rules. Run the agent in a dedicated directory or container. Keep employer and cloud credentials out of that environment. Never put keys in the repository, prompts, screenshots or logs. For both runs, start the agent inside its own worktree. Limit what it may edit to that worktree: not the parent directory and not the other worktree. Use the provided agent seat. You need no new paid service or hosted pipeline.
Start from a clean local checkout of your own repository in a dedicated parent directory,
and type these Git commands yourself. Because both worktrees sit under that parent, you
never start the agent outside the dedicated directory.
Commit the acceptance tests you wrote before recording the base. Use fresh sibling
paths and branch names. If they already exist, inspect them and choose unused names.
In the two git worktree add lines, replace BASE_SHA with the full revision that
git rev-parse HEAD prints.
git status --short
git rev-parse HEAD
git worktree add -b studio-w9-foreground ../studio-w9-foreground BASE_SHA
git worktree add -b studio-w9-unattended ../studio-w9-unattended BASE_SHA
git worktree list
Use the same recorded request, base and initial checks in both worktrees. Start no agent
in your original checkout: it stays at the recorded base and is your acceptance copy. In
each worktree, before you run the acceptance tests there,
git diff BASE_SHA -- <paths of your acceptance tests> must print nothing. If it prints
anything, the agent edited them. Do not count a test that the agent rewrote as independent
acceptance evidence. After each run, git status --short in the original checkout and in
the other worktree must show nothing new.
Generate, then verify in each mode
- Foreground: open your usual coding agent in
../studio-w9-foreground. Stay present and allow questions. Record only interventions that affect the task. Stop when it returns a candidate or hits the limit you set. Ask for a diff and check evidence. Allow no push or merge. - Unattended: start a fresh session in
../studio-w9-unattendedwith the same request. Use the agent's supplied non-interactive mode if available. Otherwise send the complete request in an ordinary local terminal and give no further answers until it returns. Keep the computer awake; you may work on the comparison record while it runs. Require it to stop and report ambiguity, a permission request, a failing gate or its agreed limit. Do not weaken permissions to get a result. If the tool requires interaction, stop and record that limitation. It is evidence about this workflow. - Verify each: review
git status --shortandgit diff BASE_SHA. Diff against the recorded base so that changes the agent committed still show. Review every changed hunk (block of changed lines) and the untracked files. Run the exact acceptance command yourself using the unchanged checks. Keep the exit status and meaningful output, not merely the agent's summary. Check that a forbidden test edit or missing result would block acceptance. - Compare: fill the small table below. Keep the scope the same in both runs. Report any clarification you gave in the foreground run as an intervention. It is not a silent improvement of the second prompt.
- Revise: pick one uncertainty, narrow it and specify the next check. Do not spend the whole studio waiting. Stop at your agreed limit, keep the partial result and discuss what smaller task could finish. Reserve the final part of class for verification and revision.
| Evidence | Foreground | Unattended |
|---|---|---|
| Base, candidate revision and allowed scope | ||
| Interventions / unanswered questions | ||
| Preserved acceptance check and actual result | ||
| Unexpected hunks or untracked files | ||
| Observed elapsed time, waiting and rework | ||
| Claim still unknown and next check |
When an agent seat is unavailable
If the supplied agent seat is unavailable, stop the run and record the access blocker. You can still practise the verification on the two course-written candidates from the notes. Work from the course checkout. This route needs no key, network connection or cloud service.
Read. Print each candidate's diff against the base. git diff --no-index compares two
directories; its exit status is 1 whenever they differ.
git diff --no-index lectures/week-09-background-agents/fixture/base lectures/week-09-background-agents/fixture/foreground
git diff --no-index lectures/week-09-background-agents/fixture/base lectures/week-09-background-agents/fixture/unattended
Map every hunk to a line of the request in the notes. Mark each hunk that no line permits.
Predict. On paper, write the result you expect from each candidate's own tests and from the base tests run against it.
Run. Run the four checks. Keep each printed line with its exit status.
python lectures/week-09-background-agents/fixture/verify.py foreground --tests own; echo "exit $?"
python lectures/week-09-background-agents/fixture/verify.py foreground --tests base; echo "exit $?"
python lectures/week-09-background-agents/fixture/verify.py unattended --tests own; echo "exit $?"
python lectures/week-09-background-agents/fixture/verify.py unattended --tests base; echo "exit $?"
Record. Fill the comparison table from what you read and ran. Leave the rows "Interventions / unanswered questions" and "Observed elapsed time, waiting and rework" empty: no agent ran, so there is nothing to observe for them. Label the record "course-written candidates, not an agent run", and keep your paper predictions apart from the results you ran.
Verification
Keep the task request, each diff and check result, the comparison table, one AI-use note (or its existing ID), and this line in your existing record:
Accept / Narrow / Recheck / Stop — evidence: [revision, check result, scope finding].
State separately which run your decision applies to. An unknown result needs a named next check. For a contribution, prepare a proposed PR description locally, and only after verification. Follow that repository's rules when you submit upstream. The studio itself grants no authority to publish or merge. For a project, integrate only the chosen candidate and rerun the checks on the combined revision. Do not combine the two competing fixes.
For a project task, keep the unattended run's handoff record. The final project's evaluation script needs at least one unattended attempt, and this one can be it. The record is the request, the recorded base revision, the returned diff, the agent's report or stop reason, and the acceptance result you ran on the unchanged checks. Keep these five together. Then the script can count the attempt in week 12 whatever its outcome, even a run stopped at its limit. A record from the route without a seat is not an agent run, so it cannot be that attempt. If your task came from a contribution, run one project task unattended in the same way before the final.
After the agent processes have stopped and you have saved the evidence, inspect each
worktree's status. Remove a worktree only after you have committed its intended changes or
saved them elsewhere. Do not force removal to hide untracked or unfinished work. From your
original checkout, remove one with git worktree remove ../studio-w9-foreground. Git
refuses while the worktree still holds modified or untracked files. That is your reminder
to save them first.
Common mistakes
- Starting the second run from the first run's fix makes the comparison invalid; use the same recorded base and acceptance cases.
- Silently answering an unattended question changes the mode; record an intervention or stop and narrow the request.
- Granting more access to finish hides a workflow limit; stop and explain the missing permission.
- Timing a paper exercise as if it were a model run fabricates evidence; label predicted results.
- Keeping only “tests passed” leaves acceptance unresolved; keep the command and actual result.