Skip to content

Network File Imports & Exports

James Dunkerley edited this page Nov 20, 2026 · 1 revision

Home · Architecture · Execution

In short

  • A network file import and a network file export are each a durable job of their own, not a run.
  • A file package announces its formats by entry point, and the core names none of them.
  • An import runs in the API process. An export's writer runs in a child process, as a solve does.
  • Both are recorded before they are queued, and their files are cleaned up by an action, never by a clock.

File formats

  • A file package advertises one class per format under the tz_ps_conductor.network_file_formats entry point.
  • The class subclasses NetworkFileReader, NetworkFileWriter or both (tz_ps_ports/network_file_format.py).
  • src/tz_ps_conductor/network_file_formats.py discovers them and skips a broken one.
  • Only a self-contained reader can be imported over HTTP. That keeps a Calliope model.yaml, which names other files, off the upload path.
  • Writing a format is covered in Adding a framework.

Import

An import is a durable job of its own, not a run. NetworkImports.submit:

  1. refuses what it can before a byte is stored;
  2. streams the upload to <root>/imports/<uuid><extension>, because a reader needs a path, which the object store never gives;
  3. records the request;
  4. enqueues import_durably(import_id).

The workflow:

  • It reads the file and saves the network in separate steps, marking each phase.
  • It reads a cancel from the record at each mark.
  • The read step keeps the parsed network in memory for the save step. After a restart, the save step reads the file again.
  • A failure is returned as an ImportOutcome with an ImportFailureReason, not raised.
  • What the reader could not carry over comes back as NetworkFileWarnings.
  • A cancelled import deletes the network it saved, unless another write has added a version since.

The sequence shows an import from upload to outcome. All of it runs in the API process.

sequenceDiagram
  participant C as Client
  participant N as NetworkImports
  participant ST as Staging directory
  participant IS as ImportStore
  participant Q as DBOS import queue
  participant WH as Warehouse

  C->>N: POST import with file
  N->>ST: write staged file
  N->>IS: submit as queued
  N->>IS: record_dispatch
  N->>Q: enqueue import_durably
  N-->>C: 202 with import id
  Q->>N: step mark_running
  Q->>N: step read_staged_file
  N->>ST: reader reads the file
  Q->>N: step mark_saving
  Q->>N: step save_read_network
  N->>WH: add imported network
  Q->>N: step record_outcome
  N->>IS: record_outcome
  N->>ST: delete staged file
  C->>N: GET import
Loading

Export

NetworkExports.submit pins the version, checks the network's framework has a writer for the format, records the request and enqueues export_durably(export_id). Its three steps are: mark running, write the file, record the outcome.

The write step

  1. It puts the version into an input handover at exports/<id>/input/.
  2. It runs the format's writer in a child through LocalProcessExporter. That is the same machinery as a solve: the pipe, the parent watch, the memory limit and the kill on cancel.
  3. In the child, build_prepared_export in src/tz_ps_conductor/export_process.py reads the handover into a model, calls writer.write, and copies the file to the object exports/<id>/file.

Fetching the file

Request Answer
GET /api/exports/{id}/file, export succeeded The file is streamed, and deleted once sent
The export has no file 409 export-not-succeeded
The file is already gone 410 export-file-gone

Clean-up. An export's objects are deleted by an action: the input at the outcome, everything on a failure or cancel, and whatever an ended export left at the next start.

Statuses

ImportStatus and ExportStatus share one shape.

From To By
(new) queued submit
queued running mark_running; an import enters phase reading
running running mark_saving, import only, phase saving
running succeeded or failed record_outcome
queued failed the executor refused it, or the sweep found its workflow ended
queued or running cancelled mark_cancelled, which records no outcome

Clone this wiki locally