Skip to content

Latest commit

 

History

History
224 lines (185 loc) · 59.5 KB

0019-service-projects.md

File metadata and controls

224 lines (185 loc) · 59.5 KB

ADR 0019: Service projects run a real app in a Docker sandbox against mock servers and optional backing services, graded over HTTP

Field Value
Status Accepted. P1 passed with changes on macOS, and the sandbox is measured on Linux (Linux Mint 22.3, kernel 7.0.0-34-generic, Docker Engine 29.8.1, x86_64), with SELinux and rootless Docker unproven (spec). P2 to P8 are built (2026-11-07 to 2026-11-08): the environment allowlist, the sandbox, the lifecycle commands, the mock server, the HTTP grader and the first catalog problem, in TypeScript and in Python, so a service project works from cstudy start to cstudy submit. P10's backing services are built (2026-11-09), and parallel cases after them without their D7; contract tables are still planned. P11's engine work is built (2026-11-09 to 2026-11-10): multi-step cases, the pass-through and the mock server extensions of R33; P9, code intelligence in the container, the Web UI, your own IDE's devcontainer.json and the other flags of cstudy dev, is built (2026-11-10); P11's AI problems are built as 0290 to 0292, beside 0289, its secure file upload, with PP14 on hold; P12, Java and Kotlin, is built (2026-11-10), with Gradle's --offline settled; P13, Go, is built (2026-11-10), with GOPROXY=off and the module cache settled over vendored modules; P14 is planned. Each recommendation's state is in its table
Date 2026-11-05, revised the same day by O15: service projects always run in Docker
Spec service-projects. The bank projects' behavior stays in problem-format, runners, authoring, cli, installation-and-workspaces and web-ui, each of which points to it
Supersedes in part ADR 0014: for service projects only, the rejection of a venv or node_modules per project and of test tools that need a network install. Existing problems do not change
Amends PRD (NFR-6: what "works on your own machine" means, as the owner defined it; ADR 0021 amends it too)
Builds on ADR 0001, ADR 0004, ADR 0012, ADR 0015, ADR 0016, ADR 0017, ADR 0018

Context

The owner wants a kind of project problem where you build a small running service: it has its own dependencies, calls third-party APIs that fail in realistic ways, may own a database whose schema you change, and is judged by what it answers over HTTP. The code base today gives none of that:

  • Grading calls methods. cstudy submit sends a class job through the runner protocol: the runner constructs the entry class and calls the operations of a case, and the core's ops comparator judges the outputs (ADR 0014, Grading job). Nothing addresses a process or an HTTP endpoint.
  • Nothing is installed per project. ADR 0014 rejected a venv or node_modules per project because every start would need the network, and rejected Vitest and Jest for needing a network install. Check S15 rejects dependencies in a starter (package.json with dependencies, a [project] table in pyproject.toml) and rejects lock files (LOCK_FILES in domain/project_checks.py). A Python folder's .venv is a link to the shared venv.
  • A lock file is a thing to ignore. is_untracked in domain/workspace_projects.py names uv.lock and Cargo.lock, the workspace template's .gitignore ignores projects/*/uv.lock and projects/*/Cargo.lock, and archive_folder deletes what is_untracked names before it moves a folder.
  • The schema assumes an entry class. schemas/meta.schema.json requires signature for every problem and project.entry for every project, requires time_class and space_class on every approach outside concurrent, and S14 requires track practical and the ops comparator.
  • User code runs as you, with an allowlisted environment. There is a hang guard and no sandbox (PRD). Before P2, _environment in adapters/subprocess_runner.py handed a runner {**os.environ, ...}, or inherited outright when a launch set no variables, so a token in your shell reached user code. P2 replaced that for every problem (Process environment); a native problem still runs as you and reads your files, so the allowlist stops environment leaks and nothing more.
  • Process ownership has precedents. Every process cstudy starts leads its own process group, _kill_group in adapters/subprocess_runner.py kills it, and OrphanGuard in adapters/process_liveness.py kills it if cstudy dies (Process lifecycle). Language servers live as long as an attempt's page (Lifecycle and limits, entrypoints/web/language_server.py). Containers are outside all of this: they outlive a process group.

The name "service project" is new in the repository. cache-service and notification-service are catalog slugs and do not collide. Three other names do collide, and this ADR resolves them in Names.

P1 measured this design on macOS, on the owner's machine, which was short of memory throughout. A number here that says it was measured comes from that run; any other is an expectation until a phase measures it, and each is marked so.

Decision

Decided by the owner

# Decision (2026-11-05)
O1 cstudy works on your own machine and needs the internet only for the obvious reasons: installing the app and its dependencies and, once built, opt-in AI review with your own key (ADR 0021). Installing dependencies does not break the rule. NFR-6 now says this. ADR 0014's rejection of per-project installs is superseded in part, for this kind of problem. Existing problems do not change
O2 A project problem may have its own dependencies. Either you run the install or cstudy runs it automatically when the problem begins
O3 One general mock server is built into cstudy, written in Python because that matches cstudy, so every language version of a problem shares it
O4 Any project problem can use it by defining configuration files. A project can have several mock servers, all running locally. Their addresses are settled by O15: stable names on the stack's network, which replaces the earlier dynamically assigned ports
O5 Scenarios include a 429 rate limit, alongside outage (503), slow and malformed
O6 The first problem keeps this general concept and is written from scratch: inventory counted per day plus time slots from a third-party vendor, served from one API, with vendor failure handling. The domain is original to cstudy: a coworking space, with desk passes counted per day and meeting rooms booked in time slots from a room vendor. A second vendor with a different response shape is a later level, which is what several mock servers are for
O7 Language order for these problems: TypeScript, then Python, then Kotlin and Java, then Go, then Rust (maybe; decided when reached)
O8 Implementation waits. This documents the plan only
O9 The database and the migration tool are both defined per project, as part of problem design, and cstudy requires neither. A TypeScript problem may use what is common in that ecosystem, and a Python problem could use Alembic. The owner prefers Liquibase, which is a preference, neither a default nor a requirement. A problem may pick SQLite or Postgres according to what it teaches. The manifest and the grading design stay tool-neutral: a declared command, with no tool-specific field
O10 Service projects can run a real database. The problem has a way to run migrations, seed data arrives through migrations, and the service reads the database live. Postgres is wanted because SQLite is too limited for what some problems teach
O11 Docker is how service projects get backing services, such as Postgres, Redis and AWS services emulated locally. Under O15 every service project needs Docker, whether or not it declares services. The existing bank problems never do. AWS services come from Moto server (open source, Apache 2.0); localstack/localstack:4.14.0, pinned by digest, is the fallback for a service Moto cannot serve well. The current LocalStack images need an account and a token, so no problem uses them, and no problem ever asks for an account or a token (owner, 2026-11-08). P10 measured motoserver/moto:5.2.5 serving S3, SQS and DynamoDB offline, as nobody, read-only, in 128m (spec), so the fallback is not needed for those
O12 A service project has standard lifecycle commands whose contents the problem's designer defines. Names are fixed, contents are free, and cstudy calls only the standard names
O13 The CLI and the web UI list what a problem depends on, so you know before starting: language and toolchain version, Docker, each service with its image download size, mock servers by name, the package manager and approximate install size, total download, approximate memory, and whether each requirement is met on this machine, with the reason when it is not. This reuses ADR 0016's display of the JDK range rather than adding a parallel concept
O14 When a problem needs Docker: if Docker is installed but not running, cstudy starts it; if Docker is not installed, cstudy asks you to install it and gives instructions. cstudy does not install Docker itself
O15 Service projects always run in Docker, as their sandbox. Bank problems stay native, need no Docker, and do not change. This supersedes the earlier position of this ADR: your app on the host, mock servers as native host processes, Docker only for problems with services, and dynamic ports. The reasons: per-project dependencies mean running third-party code and install scripts, and security catalog starters contain deliberate flaws, so an unfixed SSRF starter could otherwise reach your LAN or a cloud metadata endpoint. Docker gives a boundary at the project folder: nothing above it is visible
O16 This runs on each user's own Docker, used for other things. cstudy never changes, requires changing, or recommends changing an engine setting. Limits are per container, on cstudy's own stacks only, and it never stops the engine. Requirements are shown before any download. (2026-11-07)
O17 Timers start at "ready", never at up. Startup has a separate generous budget and its own clear failure message; per-case limits and hang guards run from ready, and reported times exclude startup. (2026-11-07)

Names

Name in the brief What the repository already means by it Decision
cstudy mock <slug> cstudy mock exists: a timed practice session with a shared timer and locked hints. mock is also an attempt mode and a Web UI view The new foreground command is cstudy dev <slug>. It also starts services and runs bootstrap, so "mock" would undersell it. Prose says "mock server", never a bare "mock"
commands.init cstudy init creates a workspace The command is commands.install, which says what it does. install is no cstudy verb, and the doctor's installs row counts cstudy's own installs, a different thing
commands.test cstudy test exists Kept on purpose: cstudy test on a service project calls it
commands.run The Web UI calls a test or submission a run (POST /api/v1/runs) Kept: "run" as a verb on an app is plain, and the manifest key cannot be confused with an API route

Shape

  • A service project is kind: project with project.grading: http. It has one language per problem, levels and cstudy submit. project.entry, project.tests, signature, generated test files and complexity classes do not apply to it, so the schema's requirements become conditional at implementation (below).
  • Everything runs in one compose stack. Your app, the mock servers and backing services share one network, so a mock server has a stable name such as http://room-vendor:8080. .env therefore holds fixed values: cstudy writes it from project.env as it copies the starter, an ordinary visible file with no secrets.
  • Only your project folder is visible. It is bind-mounted at the same absolute path as on your machine, so paths match. Parent folders, .cs/ and your home are not there. The toolchain links of existing project folders do not apply to these projects.
  • cstudy calls only standard commands, inside the app container. install, bootstrap, run and test, and optionally reset and grade_setup, as argument lists (spec).
  • The core owns the infrastructure. The generated compose file, hardening, networks, labels and cleanup belong to cstudy. A command must not start a service, or leftovers fall apart. Commands run after services are up.
  • Trust follows location. commands live in the problem's manifest, and grade_setup, hidden data and mock configs live outside the starter. A starter script that a command points to can be edited by you, which is acceptable for install, bootstrap, run and test, because the grader judges behavior over HTTP. It is not acceptable for grade_setup, which therefore must live in the problem's own files. The grader stays outside the app container, and hidden material never enters it.
  • Existing problems are unchanged, apart from the environment allowlist of P2. The bank problems, and every other kind, keep their per-language runners and paths.
  • Language support moves to templates. The per-language decisions, the toolchain image and the install command, live in project templates under cli/src/coding_study/adapters/templates/, so a new language needs a new template and one row in PROJECT_TEMPLATE_LANGUAGES (domain/scaffold.py), and no new core logic.

Honest limits

Limit What it means
The project folder stays writable by the code The sandbox protects everything else from your code. A flawed starter or a bad dependency can still damage or read the project folder, which is why that folder is versioned practice work and holds no secrets
On Linux, access to Docker is effectively root Being in the docker group grants this. cstudy cannot reduce it, never mounts the socket into a container, and says so in the install message
It is a boundary against accidents and bad dependencies, not a hardened multi-tenant jail Container isolation shares a kernel. It is the wall between your machine and code you run on purpose
install has the internet, and reaches more than that Install scripts are off: --ignore-scripts for pnpm, wheels only (--no-build) for uv, so a package that needs a build fails its install. Whatever an install does run can send out what it can read, the project folder and nothing above it, and P1 measured that it can also reach your LAN and a service bound to 127.0.0.1 on your machine, which run and test cannot. cstudy says so at every install

The first problem and later ones

The sketch is in the spec. It is original to cstudy, in line with ADR 0004. The stack per language is chosen at authoring time, with Express or an equivalent now allowed. Open-ended design discussion cannot be auto-graded and goes in solutions/explanation.md. Data-driven problems stay in the coworking theme, and their domain, database and migration tool are chosen at authoring.

Open to confirm

Recommended by the assistant and not contradicted by the owner. Each is confirmed when its phase starts. P1 changed R7, R22, R24, R27 and R28, which read as it left them, and added to R6 and R23 what the spec holds: init: true, a short grace, a one-off chown for a named volume, and a one-line /etc/passwd. Built by P6: R1, R2, R4, R6, R7, R12, R13, R14, R15, R16, R17, R18, R19, R20, R22, R23, R24, R25, R26, R27, R30 and R35, with R5 as a static check. Built by P10: R5 itself, R10 with a measured template reset, and R35 with backing services; R8's flow is proven on a fixture with a migration runner of its own, and by inventory-reservations-typescript with node-pg-migrate, a real tool. Built after P10 and P11: R11's parallel cases in the grader, with S23's rules on them; their D7 and summary line are planned. R9 is still planned. Built by P11's grader part: R34, joined to P10's services through grader_reach, and of R33 the log assertions on what a request carried, its form fields and headers. Built by P11's mock server part: the rest of R33. Built by P9's code intelligence part: R28, in TypeScript and Python; and by its last part, R29. R3 and R21 are withdrawn because O15 removes what they solved, a .env generated with dynamic ports and .env.local, and their numbers are not reused.

# Recommendation Alternative Trade-off
R1 Install automatically at problem start, in a one-off app container with internet, with visible progress and a clear retry on failure. Install again when the lock file's digest changes You run the install, as a printed command Automatic means one less step and no stale dependencies; it also means a network wait at start, shown first by O13
R2 No daemon. cstudy owns a stack for the duration of each test and submit; cstudy dev <slug> runs one in the foreground for development; the Web UI runs one on request while the attempt page is open. cstudy start exits, so it starts nothing and prints the cstudy dev command A daemon started by cstudy start A daemon survives between commands and needs no second terminal, but it is an unowned process; the sweep then has no owner to check
R4 HTTP black-box grading first. The grader runs on your machine, outside every container. It reaches your app through its published port, polls a health path, and for each case resets the mock servers, sets scenarios, sends a request, compares the response, optionally asserts on the mock server's request log, then stops the stack. One piece of core code covers every language. It emits the same --events, so the CLI and the Web UI render it. Existing entry-class problems keep their path. verify (D1, D3, D9) runs the reference the same way Entry-class grading with a facade The facade is cheaper now but does not test the API. HTTP grading costs a new kind of run, and your app must read its port from the environment and expose a health path. Because no user table is named, it is also what makes R8 possible
R5 project.services names a problem-owned compose file, tool-neutral, so any image can be used. It holds only backing services, and cstudy merges it with the file it generates. Images are pinned by digest. You cannot edit what grading trusts A field per engine Tool-neutral keeps Postgres, Redis and Moto out of the core; it needs static checks on a file format cstudy does not own
R6 docker compose -p <unique name> with up --wait against healthchecks and down -v at the end. Dev uses a persistent named volume; each graded run uses a fresh project name and no reused volume. These compose behaviors are verified by the spike Plain docker run calls Compose already gives names, health waits and one-command teardown
R7 Leftovers. Containers outlive a crashed cstudy, so OrphanGuard and group kill do not cover them. Everything cstudy starts is labeled, a guard process takes a stack down as soon as its owner dies (P1 measured 0.5 s from SIGKILL to nothing left), a sweep at the next command covers a guard that died too, and a doctor row and its fix remove leftovers by label only, never another container or volume. This is a stated requirement, given earlier memory exhaustion on the owner's machine. cstudy.owner_pid is on containers only: a label that changes on a volume makes compose ask, which hangs. down leaves a one-off whose client was killed, measured after P6, so a stack's one-offs go first, by label Rely on down and OrphanGuard alone A crash would leave containers holding memory with nothing to find them
R8 Grading a schema you design. The problem ships a baseline schema and data as the starter's migrations. grade_setup, problem-owned, applies only the baseline with the problem's own tool and loads hidden data; bootstrap then applies the rest, because the tool's tracking table already records the baseline. Your migrations must carry existing data forward, which tests real data migrations. Requests and comparisons stay black-box, so no user table is named. Migrating from empty is checked too. To be proven on the first data-driven problem with its chosen tool Hidden cases that write to your tables They would dictate your schema, which is the thing being practiced
R9 Contract tables, a design point. For live-read checks a problem may declare tables that the grader writes to mid-run and that you may not rename. Otherwise changes go through the API or the mock servers No contract tables A contract table limits your schema freedom, so it is used only when neither the API nor a mock server can make the change
R10 Reset stays engine-neutral: an optional commands.reset, otherwise data resets per run. PostgreSQL's CREATE DATABASE ... TEMPLATE is an example of such a command, not a core feature, and is measured when first used A core reset per engine Core stays small; each problem carries its own script
R11 A parallel case: N requests against limited capacity, asserting that exactly M succeed and the final state through the API. It gives language-neutral concurrency grading, which is what SQLite cannot show Stress cases in each language's runner Runners are per-language work and need an entry class; a parallel case needs neither. As with stress runs, a pass is not a proof of safety
R12 Doctor: a row checks for a running engine and docker compose v2. Any engine that provides this works; Docker Desktop is verified at minimum, and no other is claimed until tested. Without it, service projects show as unavailable with the reason, and the row is WARN, never FAIL, as Go's and Rust's are, since Docker is optional for cstudy overall FAIL FAIL would make cstudy doctor exit 4 for everyone who never starts such a problem
R13 Images pull at problem start with visible progress, as a dependency install does, and run with no internet afterwards, which fits O1. The download size is shown before pulling, and each problem records its image sizes Pull on first test Later and more surprising
R14 One stack per attempt, stopped when the run or the attempt page ends, with memory limits on every container. The Web UI starts a stack only on request A stack from page open Docker's VM and heavy images such as LocalStack cost real memory
R15 Compose files, mock configs and hidden seeds stay in the problem's own files, outside the starter. Anything rendered from them lands under .cs/runs/<run>/, one of the hidden directories, and is mounted read-only into the mock container only. grade_setup and hidden data never appear in the app container Copies in .cs/ that any container can see A copy that a container can read adds a place to hide
R16 The exact command set and contract: install, bootstrap, run, test, optional reset and grade_setup, as argument lists, with a script for anything longer More commands, or shell strings Fewer commands keep the manifest small; shell strings add quoting and a shell to every image
R17 The dependency list comes from a small declared project.requires block plus what cstudy derives from the compose file and lock file. A static check fails when they disagree, so the list cannot drift, and verify checks measured sizes against it. The problem listing shows a short marker with a filter for problems that need nothing extra, the detail view shows it in full, and Start shows the summary before any download and asks for confirmation only when something will download or a requirement is missing, with --yes for scripts Derive everything at display time Sizes need a registry or a measurement; cstudy list has a 500 ms budget (NFR-2)
R18 cstudy test on a service project runs commands.test, then the visible HTTP cases of the unlocked levels as feedback. No native test file is generated Generated tests per language, as ADR 0014 does Generation is per-language work in every phase, which the single grader exists to avoid. The cost: opening a level writes no test file, and the visible cases are not native tests you can debug
R19 A migration that fails in cstudy submit is reported as an install failure is, with its output, and otherwise as code that does not load: the submission is stored and exits 2. A failed install exits 4 and stores nothing Exit 4 for both Your migration is your code, so storing it matches ADR 0014's rule; exit 4 would call your bug an environment problem
R20 A first level asks for one small change as well as orientation, so the starter does not pass it untouched A level the starter already passes cstudy done takes a rating once level 1 passes, so a free pass would weaken it
R22 Docker's states: not installed, installed and stopped, running, and on Linux installed without permission, each with its own message. cstudy starts the engine only when you start or run a service project, and from doctor --fix; never from listing or viewing a problem, or from plain doctor, because starting Docker's VM costs real memory. It says it is starting, shows progress, waits up to a stated timeout and reports clearly if the engine did not come up. It never runs sudo, printing the command instead, and never stops the engine, only its own labeled stacks. Install instructions are one short message per platform with a link to Docker's install page, kept in one place so the requirements summary, doctor and the Web UI's Start match. P1 settled the check: docker info, which starts nothing and wakes no idle VM, and not docker desktop status, which said stopped while the engine answered (spec) Start the engine at doctor or whenever a problem is shown Earlier and less waiting at Start, at the cost of a VM's memory for someone who is only reading

Added with O15, for the same confirmation:

# Recommendation Alternative Trade-off
R23 Hardening of every container cstudy generates: non-root (your UID on Linux), cap_drop: ALL, no-new-privileges, a read-only root filesystem plus tmpfs, memory and pids limits, a cap on each container's log, the Docker socket never mounted, and an explicit environment only, so nothing from your machine leaks in, especially real API keys. Problem-owned services get the limits and no-new-privileges, since an engine such as Postgres needs its own user and writable paths Docker's defaults The limits also protect a small machine from runaway memory. A read-only root breaks a tool that writes outside the project and tmpfs, which the spike looks for
R24 Network. install may use the internet, and P1 measured that it also reaches your LAN and this machine's loopback services (the limit); run and test have no egress. P1 confirmed the catch: a service only on an internal: true network publishes nothing, and docker compose port says :0 with exit 0. So a small forwarder container joins both an internal network and an ordinary one. It holds no user code and publishes on 127.0.0.1 with a dynamic host port: your app's port and, for the grader alone, the token-protected mock server control port. On Linux the bridge of an internal network holds its gateway address, which is this machine's, and through it a container reaches every service listening on all of this machine's addresses, sshd among them. So sandbox's bridge gets no address (com.docker.network.bridge.inhibit_ipv4), sets enable_ipv6: false so an engine with IPv6 on gives it no IPv6 address either, and D11 probes the gateway of each of the stack's networks and reads the container's IPv6 addresses, of which only ::1 and fe80::/10 may be there A grader inside the network, which needs no control port on your machine but puts cases in a container The forwarder keeps hidden cases on your machine at the cost of one small container per stack. "Only the app's port is published" holds for what a learner uses; the control port is the one exception, and a grader inside the network would remove it
R25 One mock container: a pinned Python image, with cstudy's mock server code mounted read-only from cstudy and the configs mounted read-only. Each mock server's name is a network alias of that container, and the process picks the mock server from the request's Host, so every one answers on port 8080 at its own name One container per mock server One process costs less memory and keeps one control interface. A client that rewrites Host gets a clear 404. Several containers isolate a crash, which a stateless server hardly needs
R26 No starter holds a .env, and S15 refuses one. cstudy writes it into the project folder from project.env when it copies the starter: the app's port, stable URLs and fake keys, so the manifest is the only source and nothing is repeated. Once written it is tracked, hashed and archived like any file. The app container's environment is project.env plus a few fixed variables. .env.local is dropped: with fixed values and no secrets you edit .env itself. Changed at P7 from a committed starter file that S19 compared with the manifest, against the owner's rule that no .env is committed A committed .env, or keeping .env.local A committed copy breaks that rule and repeats the manifest; a second file would hide nothing and cost hash and archive rules
R27 Per-language toolchain images, named in project.image, pinned by digest and pulled on demand, shown in the requirements list before download. Pin the multi-architecture index so macOS on arm64 and Linux on amd64 share one pin. The host needs no Node, uv or JDK for a service project. P1 settled it: no image of cstudy's own, node:24-slim with corepack pnpm, and the uv image for Python Images built locally on start Building needs a registry and a Dockerfile anyway, and costs minutes
R28 Built in P9 (2026-11-10), in TypeScript and Python, as P1 settled it; another language keeps no_code_intelligence until its server runs in a sidecar. Riskiest part, for P9. Code intelligence for service projects runs the language server through docker exec -i, with paths matching because of the same-path mount. P1 settled where: a small lsp sidecar and not the app container, the same Node image for both languages, with .cs/lsp/ read-only at its same path in the sidecar only, since TypeScript alone took 468 MiB, which does not fit beside an app in 512 MiB A language server on your machine reading the project folder On your machine, .venv points at an interpreter that exists only in the container and native packages are Linux builds. In a container, hidden directories simply do not exist, a stronger guarantee than today's filter, but there is more to go wrong (spec)
R29 Built in P9 (2026-11-10): cstudy dev writes the file, and --debug runs the app under Node's inspector or debugpy (spec); opening it in VS Code and IntelliJ is not yet measured. Your own IDE uses a generated devcontainer.json, and debugging goes through a port published on 127.0.0.1 by cstudy dev --debug, in a dev stack only A local toolchain matched to the image A generated config avoids two toolchains drifting apart. It does not help LazyVim directly, which the spike tries with a per-project server command
R30 node_modules and .venv stay in the project folder on the bind mount at first, so your editor can read them. It is slower on macOS, and a volume is faster but invisible to your editor. The spike measures the trade-off A volume from the start Speed against an editor that can read dependencies
R31 cstudy dev runs commands.run by default, since your app cannot run outside the stack and still reach the mock servers. --no-run keeps the container idle for an IDE or debugger. cstudy dev --exec [--network] -- <command> runs one command in a one-off app container, which is how you add a dependency with --network A new verb per action One new verb stays one new verb, at the cost of a longer flag list
R32 Separate early phase, for all problems: replace the inherited environment with an allowlist, so tokens do not leak into user code. Built as P2; before it, the runner got {**os.environ, ...} and the other launches named there inherited too. The config key that would add names you want to pass on is not built, since no need for one has appeared Sandbox only service projects and leave native runs as they are The allowlist can surprise someone relying on an inherited variable. It stops environment leaks only: a native problem still runs as you and can read your files
R33 Mock server extensions: SSE streaming with chunk timing and mid-stream drops; matching on request bodies; assertions on logged request bodies, including a byte-prefix check across requests; bodies that use values known at run time. A local mock LLM provider is then just mock config data, with no key or cost, and a fake key is injected. Provider response shapes drift, so each such config records its shape version (spec). Built at P11 (2026-11-10): stream events with after_ms, and drop_after_chunks, stall_after_chunks or a scenario's own malformed stream; match.body and match.body_contains, first match still winning; log entries with body, body_max, body_same_as and body_prefix_stable; and {{request.*}}, {{seq}}, len, words and json as run-time values, with no clock. The byte-prefix check reads one field, a text or a list, since a JSON body never starts with the previous one's whole bytes (spec). An example provider config, a generic chat-completions-style API, ships with the tests and records its shape_version; a problem copies it and owns its copy. Left: no SSE-aware judging of the app's own streamed answer, and no arithmetic or header values in a response (known limits) A second, LLM-specific mock server One program stays one program
R34 Multi-step HTTP cases: a later request can use values captured from earlier responses, for login and OIDC flows. Per-request token signing for a mock identity provider is not in the mock server's scope: use a service container, decided at the first identity problem. Built at P11, as the Keycloak spike recommended: steps with captures, named cookie jars, form bodies, redirects, absolute URLs to declared origins, flows and cleanup steps (spec); a check on what the app prints; and a mock server pass-through that spoils a token in flight, to alg: none or a bad signature, and signs nothing. The provider is the service container, which P10 brings, and a case reaches it, or the mock server in front of it, through grader_reach (spec) Signing inside the mock server Signing would make the deliberately stateless mock server a small identity provider
R35 grade_setup runs in its own short-lived container of the same image, with {problem}/grading/ read-only and the project folder read-only, and it exits before the app container starts. Data it loads does reach the database your app reads, which is inherent in R8; the script and its files do not Run it on your machine It would need your machine to hold the migration tool and to reach a port of the database

Schema rules to relax

At implementation, for grading: http. Until then schemas/meta.schema.json stays as it is.

Rule today Where Change
signature required on every problem, with function or class by kind required and allOf in schemas/meta.schema.json Not used
project.entry required $defs/project Not used
time_class and space_class required on every approach except concurrent allOf in schemas/meta.schema.json Meaningless for an HTTP problem, so not used
Projects are on track practical and use the ops comparator S14 A debugging project-size problem needs other tracks (ADR 0020); the comparator is per case

Phases

Phase Scope
P1 Spike, on macOS and Linux, below. If it fails, the owner is told before anything is built
P2 Environment allowlist for all problems, in place of the inherited environment: _environment in adapters/subprocess_runner.py, adapters/languages/go/toolchain.py, adapters/languages/rust/toolchain.py, adapters/languages/rust/project_suite.py, adapters/languages/jvm/gradle.py, entrypoints/web/language_server.py and entrypoints/web/code_intelligence.py. entrypoints/web/children.py starts cstudy itself, which needs its configuration, so the cut sits where a child runs user or toolchain code. Independent of the rest, so it can ship early. Built: one policy in domain/process_environment.py and one reader of os.environ for it, inherited_environment in adapters/process_environment.py, used by the launches above and by the others that run project code: BoundedProcess (the TypeScript type-check), SubprocessCommandRunner and SubprocessToolProbe (cstudy doctor --fix and its probes, with the same list, since an install behind a proxy needs the same network variables a run does). entrypoints/web/children.py is unchanged, as designed. No config key; see R32
P3 Built. Sandbox runtime: the generated compose file and its hardening, networks, labels, sweep, docker and docker leftovers doctor rows, Docker start and install messages, image pull, a CI job with Docker. The job is path-gated to what can affect the sandbox, with no matrix and no schedule, because of a free account's minutes
P4 Built. The lifecycle commands and their contract; dependency install and lock rules; the TypeScript and Python service templates; the .env written from project.env; project.requires with its static check and the dependency list in cstudy show, cstudy list and cstudy start
P5 Built. The Python mock server, schemas/mock.schema.json, its container, the YAML-to-JSON rendering and cstudy dev with --scenario. P9 added --events, --no-run, --debug, --reset-data and --exec
P6 Built. The HTTP grader, with submit, test and verify wired in, S14 to S23, and D11 apart from the measured image sizes and memory. Installs in CI are small, 27 MB and 9 MB for the two fixtures, so nothing is cached yet; a catalog problem may change that
P7 Built. The first problem in TypeScript, coworking-availability-typescript, and the .env written from project.env in place of a committed one
P8 Built. The Python version of the first problem, coworking-availability-python, on the standard library, graded by the same cases and mock servers as 0277
P9 Built (2026-11-10). Code intelligence in the container, and Web UI: stack status, the scenario picker, and the dependency list in the Problems view, the Problem view and the Start dialog. Code intelligence: a TypeScript or Python service project's server runs in an lsp sidecar of its own per session, a compose project cstudy-l-<pid>-<id> on the pinned node:24-slim, with no network, the app's hardening, 768 MiB, and the project folder and .cs/lsp/ read-only at the session's paths. The broker talks LSP through docker exec with a null processId; TypeScript runs the project's own compiler, basedpyright the project's [tool.pyright] venv. The sidecar goes with the session, or with a guard if cstudy serve dies, and the sweep knows its kind. Docker that does not answer, or a missing image, is a calm 4004 in the status bar: a session starts no engine and pulls nothing. Measured: TypeScript's first diagnostics 1.4 s after didOpen, 386 MiB at peak; basedpyright's 0.8 s, 140 MiB (spec). Web UI: Run tests, Submit and Cancel on the attempt page through cstudy test --events and cstudy submit --events, with the stack's stages in the results panel; a dev stack panel through cstudy dev --events and /api/v1/dev, started only on request, with the app's address, the mock servers and a scenario picker; the dependency list from GET /api/v1/problems/{slug}/needs; and Docker's states in Start, the Attempt view and the Health view (spec). Last part (2026-11-10): the other flags of cstudy dev (--no-run, --debug on a port published on 127.0.0.1 in a dev stack only, --reset-data, --exec with --network) and a generated devcontainer.json (R29) (spec)
P10 Data-driven problems, TypeScript then Python, each choosing its own database and migration tool: project.services and S21, which proves the flow of R8, with parallel cases and any contract table. SQLite needs Docker here as well, like every service project. Built (2026-11-09): a problem's compose file merged into the stack, each service on sandbox alone with no capability, no new privileges, a read-only root unless it says otherwise and labeled named volumes, every command waiting for its healthcheck; S21 as an allowlist that a stack also holds a file to before it starts, and S22's part on the file; grade_setup with backing services, and a graded run with it first running bootstrap from empty; project.grader_reach, which publishes a declared service to the grader through the forwarder with the original Host (spec); cstudy start --fresh removing a dev stack's data; and a fixture with Postgres 17.11 and Redis 7.4.12, measured with the rest in the spec. Moto is measured; Keycloak plugs in as the spike measured it, with no fixture. Planned: the D7 of parallel cases, which are built in the grader's code that P11 changed (spec), and contract tables. The data-driven catalog problems come after: PP5 (0282) is built, and PP6 to PP10 are not.
P11 Mock server extensions and multi-step cases, with the first project-size security and AI problems (ADR 0020). Grader part built: multi-step cases (R34) with the app-output check, log assertions on logged form fields and headers, and the mock server's pass-through with a JWT tamper. Joined with P10 (2026-11-09): grader_reach is the one list of what a case reaches: the graded stack fills StackEndpoints.origins from it, S23 declares the app's origin and its entries alone, S20 holds a pass-through's upstream to a service of the compose file, and a test on a real engine grades a case through a mock server's pass-through to a service with the original Host and an output check (spec). Problems partly done: 0279 and 0281, the first project-size security problems, run on mock servers alone; PP3, the OAuth client against Keycloak, is built as 0280, and PP5 (0282, Postgres with node-pg-migrate) is the first data-driven problem. R33 built (2026-11-10): SSE streaming with drops and stalls, matching on request bodies, log assertions on JSON bodies with the byte-prefix check, run-time values, and an example mock LLM provider config, proven by a test that grades a streaming gateway stand-in through two providers on loopback (spec). The AI problems are built: PP11 to PP13 as 0290 to 0292, and PP15 as 0289; PP14 is on hold
P12 Kotlin and Java templates and problems. Settles Gradle's --offline for these problems. Built (2026-11-10). Image: one for both languages, gradle:9.8.2-jdk25-alpine, Temurin's JDK 25 and Gradle 9.8.2, pinned by the digest of its index: 307 MB to download (306 on arm64), against 357 for the Ubuntu one and 487 for Corretto, and the smallest that holds Gradle, which a starter cannot bring, since a wrapper needs its jar and S15 refuses a jar. A JRE alone cannot build, and one image runs every command. --offline settled (spec): install alone has the network, and fills Gradle's user home in the project's install cache; app.install_cache: true, new, mounts that cache at /cache in every container of the app's image, so bootstrap, run and test build with --offline and no egress. S19 holds gradle to --offline outside install and to the lock in it. The lock is gradle/verification-metadata.xml, the SHA-256 of every artifact, written with --refresh-dependencies, since a warm cache otherwise leaves a POM out (measured); the install runs resolveDependencies, which resolves the inputs of the tasks the commands run without running them. An install with no network fails in 14 s with Gradle's own message; grading is warm-cache only. Engine: a tmpfs over each VOLUME an image declares, since the Gradle image's made an unlabeled anonymous volume that a dev stack's down left behind (measured); a cache volume that is gone installs again; verify measures install_mb in the volume; devcontainer.json mounts the cache. Templates: project-java-service and project-kotlin-service: the JDK's com.sun.net.httpserver on virtual threads, scripts/run.sh building with Gradle and then running the app in its place, JUnit 5 (kotlin.test on it for Kotlin), the daemon off and explicit heaps, app.mem_limit 512m for Java and 1g for Kotlin, measured peaks 458 and 691 MiB with the tests beside the app. Problems: coworking-availability-java (Jackson 3, records, virtual threads) and coworking-availability-kotlin (kotlinx.serialization, coroutines), on 0277's copied cases and mock servers; installs of 9 and 210 MB, a first cstudy start of 15.7 and 23.8 s, and a warm stack of about 5 s in Java. A Java fixture, 5904, runs on a real engine. Code intelligence for JVM service projects still comes later: they keep the calm state, with no sidecar
P13 Go template and problems. Settles GOPROXY=off and vendored modules for these problems. Built (2026-11-10). Image: golang:1.27.3, the Go cstudy's own Go runner selects, on Debian trixie, pinned by the digest of its index: 316 MB to download (309 on arm64), the slimmest Go image already on the machine it was built on, since nothing was pulled; an Alpine one would be smaller and is not measured. Settled: the module cache, not vendored modules (spec). go mod vendor would copy every module into the project folder, past the starter's limits and into every hash and archive of an attempt, so S15 refuses a vendor/ in a starter. install is go mod download, the only Go command with the network, into the install cache (GOMODCACHE=/cache/go/mod), with go.sum the lock; every other command builds with GOPROXY=off and GOFLAGS=-mod=readonly, through P12's app.install_cache, and keeps Go's build cache and GOTMPDIR in /cache too, since the app's /tmp is 128 MiB, too small for the build cache, and noexec, so go test could not run what it builds there (both measured). S19 holds a Go problem to that environment and to go.sum, and refuses another -mod. A module missing from the cache fails at once with Go's "module lookup disabled by GOPROXY=off" (a test on a real engine), and an install with no network fails in under a second with "dial tcp: lookup proxy.golang.org" (measured): neither hangs. Engine: no new mechanism, only S15, S19 and S22 for go.mod and go.sum, and go in the list of what a problem depends on. Template: project-go-service: net/http with no framework, scripts/run.sh building with go build and then running the server in its place, go test -count=1 with httptest, app.mem_limit 512m and ready_timeout_s 180, since Go ships no compiled standard library and a project's first stack compiles what it uses. Measured on macOS with Docker Desktop, under a load average of 50 to 110 from other work: cstudy start takes 19.7 s for the template and 19.2 s for 0310, whose installs download nothing; the first stack is ready after 80.5 s for the template and 67.2 s for 0310, at peaks of 401 and 431 MiB in the app's container, and its first go test takes 22 to 23 s; a warm stack is ready in 9.5 s for the template and 12.7 to 18.8 s for 0310; the install cache then holds 116 and 121 MB, almost all of it the build cache. Problem: coworking-availability-go, on 0277's copied cases and mock servers: a goroutine per vendor with a WaitGroup, a context deadline on each request that the waits honor, and each vendor's body checked after encoding/json decodes it into structs; the reference takes every level with full marks, 50 of 50, and a version with no retry fails v5 and v6 with expected 3 requests, saw 1. A Go fixture, 5905, with go-cmp as a real module, runs on a real engine; its three tests took 15.5 minutes under that load, since each fresh install cache compiles the standard library first, so they carry a docker_go marker and stay a local gate, as the JVM ones do. Code intelligence for Go service projects still comes later: they keep the calm state, with no sidecar
P14 Rust template and problems (maybe; decided when reached). Settles vendored crates for these problems
Later scope: system learner-built systems (below)

Each phase gets its docs and, at release, a website message. This plan runs after or around the code intelligence releases of ADR 0018's Phases (1 Python and TypeScript, 2 Java and Kotlin, 3 Go and Rust) unless the owner reorders it. The two share a language order only loosely: ADR 0018 puts Python and TypeScript in one release, and O7 here puts TypeScript first.

The P1 spike

Measured on macOS (Docker Desktop) and Linux, on an otherwise quiet machine. The spike reports numbers and does not build product code. If it fails, the owner hears before anything is built. Named fallback, not chosen: OS sandboxes, sandbox-exec on macOS, which is deprecated, and bubblewrap on Linux.

Question What to find out
Code intelligence in the container basedpyright and typescript-language-server through docker exec -i with the same-path mount: time to first diagnostics, hover and definition into node_modules. A definition into a standard library inside the image lands on a path your machine cannot read, and the page's read-only library tabs need an answer. Whether killing docker exec stops the server, or only closing its standard input does (unverified)
Your IDE A generated devcontainer.json in VS Code and in IntelliJ, and a per-project server command in LazyVim
Debugger Node's inspector and debugpy through a published port, with breakpoints resolving on the same paths
File speed An install and a test run on a bind mount against a volume, for node_modules and .venv. Whether file-change events reach a watcher inside the container
Run latency cstudy test and cstudy submit shapes against the feedback targets of NFR-1 and NFR-11: up --wait, then a case. Whether reusing a running dev stack for cstudy test is worth it
Memory Docker's VM, the app, mock and forwarder containers, then Postgres, Redis and LocalStack. A dev stack and a graded stack together. Total limits that fit an 18 GB machine
The network catch Whether an internal: true network can publish ports on each platform; the forwarder; that a container cannot reach a public address, a LAN address, a cloud metadata address, or Docker Desktop's host.docker.internal
Compose behaviors -p, --wait, 127.0.0.1::<port>, port, down -v, labels on networks and volumes through an override, the hardening of R23 on each official image, non-root ownership of bind-mounted files
Mounts Whether Docker Desktop shares the paths cstudy needs by default: a Homebrew prefix may not be shared, and then the mock code must be copied under .cs/runs/<run>/. A workspace outside the shared paths, and SELinux labels on Linux
CI Linux runners have Docker, and macOS runners may not by default

Consequences

  • NFR-6 now says what the owner meant, and the PRD's "no network at runtime" is qualified by it. A service project installs dependencies and pulls images at start. Everything else about NFR-6 is unchanged.
  • Docker becomes a requirement for a class of problems, SQLite ones included. Docker Desktop's license requires a paid plan at larger companies; verify the current terms before saying anything more specific in the docs. Other engines are claimed only once tested (R12).
  • Service projects cannot meet NFR-1's project targets: starting a stack plus real waits for Retry-After and delays take seconds, not 1.0 s. NFR-1 gains a target of its own once P6 measures it. As for D6, D7 and D10 in ADR 0017, the new checks stay outside NFR-3's 30 s per problem.
  • A service case runs on the real clock, against ADR 0017's "virtual time wherever code waits". project.clock: virtual is refused with grading: http, and a static limit plus a determinism check keep real waits short and stable.
  • New surface, all planned: project.grading, image, commands, app, env, mocks, services, grader_reach, requires; schemas/mock.schema.json; HTTP, multi-step and parallel case shapes in tests.json; cstudy dev; cstudy start --yes; cstudy list --needs; checks S19 to S23 and D11; docker and docker leftovers doctor rows.
  • is_untracked becomes aware of the kind of project, because a service project's uv.lock is a file grading trusts, while a bank project's is tool output. A service starter's own .gitignore re-includes its lock file.
  • cstudy start writes no .venv link for a service project, and doctor --fix restores none, since its .venv is a real directory in the folder. The risk ADR 0014 guarded against, uv run deleting the shared venv through the link, does not apply there. The same goes for every other toolchain link and for the JDK range: the image is the toolchain.
  • Disk grows per project (node_modules, .venv), and cstudy start --fresh already removes those through remove_untracked. There is no cstudy reset and no remove command (Cleanup).
  • A dev stack and a graded stack can overlap for the length of a run. Declared memory limits bound each, and the spike measures the total.
  • Hidden data and references stay out of the app container for every problem, your own under <workspace>/problems/ included, because no parent folder is mounted. That is stronger than today's hidden directories, as long as the language server runs inside the container too.
  • "No network" stops being an honor rule for authors: the network enforces it for run and test, and D11 probes it.
  • docs/README.md indexes ADRs and docs/architecture.md describes adapters. Both change when the first phase lands.

Later: learner-built systems

scope: system in ADR 0020 names problems where you build several services. They are not designed here: this plan has one run, one health path and one port_env. The compose network at least makes them possible, since several of your services could share it under stable names. That design waits, with these questions open: how several commands.run are declared, what health means for a system, and which service a case addresses.

Revisit

Trigger What to reconsider
The P1 spike fails, or Docker's memory cost proves too high on an 18 GB machine Report to the owner before building. The fallback is the owner's call
Code intelligence or the IDE flow in the container proves unusable The riskiest part of O15: report to the owner, with OS sandboxes as the named fallback
A hand-written commands.test proves too costly to author, or learners miss native tests per level Generated tests per language, from the visible cases
The grade_setup flow cannot work with a problem's chosen migration tool That problem's tool, or a contract table
A problem needs a stateful mock server, or path templates Extending the mock config, which is deliberately stateless
The first identity problem needs signed tokens A service container chosen at that point (R34)
A problem needs a parallel case's expected count to vary A checker over the responses
Real waits push a submission past what is tolerable Lower limits, or running your app on a controllable clock where the language allows

Alternatives considered

Alternative Why rejected
Your app and mock servers native on your machine, with Docker only for services The earlier position of this ADR, superseded by O15: third-party code and deliberately flawed starters would run with your machine in reach
OS sandboxes per platform (sandbox-exec, bubblewrap) Not chosen. Named as the fallback if the spike fails. Two mechanisms, one of them deprecated
A cstudy-managed native Postgres, from prebuilt binaries Rejected by the owner: cstudy should not run a Postgres server directly on your machine, and Docker unlocks many services, such as Postgres, LocalStack and Redis, where a native approach would solve only one
Mock servers in the language of each problem Rejected by O3: one written per language multiplies the work and the behaviors to keep equal
A third-party mock server tool A dependency cstudy would have to install and pin, with scenario rules of its own
Scenario choice as a query parameter of the mocked API It would leak into the vendor's contract, so code could read or fake it
Stacks started by cstudy start cstudy start exits, so they would be unowned
A per-language dependency table in the core A new language would need core code; templates hold the same decisions
Tool-specific fields such as migrations: liquibase Rejected by O9: the core has no knowledge of any migration tool
Grading through the native test framework The second judge that ADR 0010 and ADR 0014 rejected: editable code would give the verdict