Skip to content

Let a run start from a workspace with only the given files - #1159

Closed
TomNaessens wants to merge 1 commit into
mainfrom
feature/clear-workspace
Closed

TomNaessens wants to merge 1 commit into
mainfrom
feature/clear-workspace

Conversation

@TomNaessens

@TomNaessens TomNaessens commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

This pull request lets a run start from a workspace that holds only given files: runner.start(mode, files).

For more context & screenshots, see https://github.com/dodona-edu/dodona/pull/9211.

Details

Dodona's code playgrounds get a files attribute that loads data files (for example grades.txt) into the workspace, and every Run has to start from the same filesystem. Doing that with separate calls before start() left a window in which the runner was still Ready, so the playground had to track its own preparation state and a second block could still start in between. Writing the files inside the run's Loading phase closes that window: the existing state !== Ready checks and the Stopping path cover it.

  • Runner.start(mode?, files?): when files is given, it forgets the files handed to provideFiles (a runtime recovery must not write them back), clears the workspace and writes each file with updateFile, all inside the run's try, so a failed write is reported like a failed run. Without files, the workspace is left as is.
  • start() now skips the code when Stop was pressed while it was still loading. Before, the program ran anyway, because interrupt() does nothing while the client is idle.
  • Backend.clearWorkspace / PythonWorker.clearWorkspace / clear_workspace in papyros.py: moves the working directory back to /home/pyodide/workspace (a program may have os.chdired into a subdirectory that is about to be removed) and removes every entry. io.files is updated by the files event at the end of the run.

Manual testing instructions

  1. PATH="$(mise where python)/bin:$PATH" yarn setup to rebuild the Python package.
  2. yarn vitest run test/__tests__/state/Files.test.ts test/__tests__/state/RuntimeRecovery.test.ts --exclude '**/.claude/**': the new cases check that a run given files sees only those files (text and binary), starts in the workspace directory after an os.chdir, lists exactly those files afterwards, writes them before the code runs, does not run when stopped during the writes, reports a file that cannot be written, and that a recovery does not replay earlier provided files.
  3. End to end: dodona-edu/dodona#9211 runs a playground twice with a program that appends to a file and shows the same output both times.

Checklist

  • Tests: three cases in Files.test.ts, four in RuntimeRecovery.test.ts
  • AI: Claude Code wrote the change as part of the Dodona code playground files feature

馃 Generated with Claude Code

@TomNaessens TomNaessens self-assigned this Sep 16, 2026
@TomNaessens TomNaessens changed the title Add a way to clear the Python workspace Let a run start from a workspace with only the given files Sep 16, 2026
@TomNaessens
TomNaessens force-pushed the feature/clear-workspace branch 2 times, most recently from db641b5 to f2e5585 Compare September 16, 2026 13:58
@TomNaessens
TomNaessens marked this pull request as ready for review September 16, 2026 14:18
@TomNaessens
TomNaessens requested a lite review from Copilot September 16, 2026 14:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃煛 Changes recommended

The unresolved critical cancellation and moderate large-file recovery issues block approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds support for starting runs with a workspace containing only explicitly supplied files.

Changes:

  • Stages text and binary files before execution.
  • Adds workspace clearing through the backend and Python worker.
  • Adds tests for isolation, recovery, stopping, and write failures.

Review findings include a critical cancellation issue after preparation exceeds the stop timeout and a moderate recovery issue affecting files larger than 1 MiB.

File summaries
File Summary
test/__tests__/state/RuntimeRecovery.test.ts Tests recovery, stopping, and file preparation.
test/__tests__/state/Files.test.ts Tests isolated workspaces and text/binary files.
src/frontend/state/Runner.ts Stages supplied files; contains the reported cancellation and recovery issues.
src/backend/workers/python/PythonWorker.ts Exposes workspace clearing to Python.
src/backend/workers/python/papyros/papyros.py Resets and clears the workspace.
src/backend/Backend.ts Adds the workspace-clearing API.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Lite

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/frontend/state/Runner.ts
Comment thread src/frontend/state/Runner.ts
@TomNaessens
TomNaessens force-pushed the feature/clear-workspace branch from f2e5585 to 045e3eb Compare September 16, 2026 14:31
Runner.start takes an optional list of files. When given, the run clears
the workspace and writes those files during its Loading phase, before the
code runs, and forgets the files handed to provideFiles, so a runtime
recovery does not write them back. Dodona's code playgrounds use this to
start every run from the same filesystem: writing the files before
start() left a window in which the runner was still Ready.

start() also skips the code when Stop was pressed while it was still
loading, instead of running the program anyway.

The worker's clear_workspace moves the working directory back into the
workspace before removing every entry, because a program may have changed
into a subdirectory that is about to be removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@TomNaessens
TomNaessens force-pushed the feature/clear-workspace branch from 045e3eb to c2d97af Compare September 16, 2026 14:36
@TomNaessens

Copy link
Copy Markdown
Contributor Author

馃 Folded into #1168 so the playground stack reads as one series: runner.start(mode, files) and the workspace clearing are now part of the shared runtime PR, rebased onto current main. The approved change itself is unchanged.

@TomNaessens TomNaessens closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants