> This page is for Remediation Orchestrator.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/remediation-orchestrator/llms.txt.

# Handling Files

> Store and exchange files with Remediation Orchestrator

Starlark scripts move files through Remediation Orchestrator as small `File` references, not as
bytes. Modules stream contents only inside Temporal activities; never put file
contents into workflow history.

## The File reference

A `File` is metadata (`name`, `file_source`, `size`) pointing at a registered
source. Do not construct, alter, or serialize a `File` yourself. Obtain it from
a module such as `objectstore.get_file`, `http.file`, or another file-producing
module, then pass it directly to a module that accepts a `File`.

| Field | Meaning |
| --- | --- |
| `name` | File name or source path. |
| `file_source` | Registered source that can open the file on behalf of an activity. |
| `size` | File size in bytes, when known. |

## File lifecycle guide for script authors

Treat a `File` as a **lazy handle**, not as bytes. Creating or receiving a
`File` in Starlark does not download, copy, or materialize content into the
workflow. The handle only names a source that a Temporal activity can open
later. Bytes cross process boundaries when an activity opens the source and
streams them — never when the Starlark workflow holds the reference.

Because of that, **Starlark cannot modify file contents**. Transforming,
filtering, appending, or rewriting a file must happen in Go inside a Temporal
activity (or a module API that already runs as one). From the script, obtain a
`File`, pass it to a consumer module, and keep only small metadata in the
workflow (object keys, sizes, status). Do not read content into strings, lists,
or dicts and do not try to edit a `File` in place.

Typical lifecycle:

1. **Produce** a `File` from a module (`http.file`, `objectstore.get_file`,
   ticket attachments, `archive`, and similar).
2. **Pass** that reference through the workflow to another module. Temporal
   workflow history records the handle, not the payload.
3. **Consume** it in an activity-backed API (`objectstore.upload_file`,
   `ssh.write_file`, attach/upload helpers, parsers). The activity opens the
   source and streams bytes.
4. **Return** keys, sizes, and status summaries from the workflow — not file
   contents.

If you need a new transformation (for example, rewrite a log or convert a
format), implement it as a Go activity or module method that accepts and/or
returns `File` references. Do not attempt the rewrite in Starlark.

## Ways to handle files

### 1. Object storage (`objectstore`)

Use the `objectstore` module to keep files in the Remediation Orchestrator deployment's
configured object-storage bucket while passing a small `File` reference through
a Remediation Orchestrator workflow. This is the right boundary for command output, validation
artifacts, large logs, and binaries.

The Remediation Orchestrator operator enables and configures `objectstore`. A script can call it
only when that module is enabled for its deployment.

| API | Role |
| --- | --- |
| `objectstore.upload_file(file, prefix)` | Stream a `File` into object storage; returns the object key. |
| `objectstore.upload_text(text, path)` | Write a small string, such as JSON metadata, as the object at `path`; returns the object key. The string cannot be empty or larger than 1 MiB. |
| `objectstore.get_file(path)` | Return a `File` for an existing object (no bytes in the workflow). |
| `objectstore.list(prefix)` | List object keys under a prefix. |
| `objectstore.create_read_only_presigned_request(path, duration="1h")` | Short-lived external download request. |
| `objectstore.create_write_presigned_post(path, duration="1h")` | Short-lived external upload form. |

Detailed usage is covered below:

- [Upload a file](#upload-a-file)
- [Download a file as a `File` reference](#download-a-file-as-a-file-reference)
- [Share read access with a presigned URL](#share-read-access-with-a-presigned-url)
- [Let an external client upload with a
  presigned POST](#let-an-external-client-upload-with-a-presigned-post)

### 2. HTTP (`http`)

Use `http` when the bytes live at a URL or must be posted as multipart form
data. Prefer `http.file` / `http.upload` over `http.get` response bodies for
anything that may be large.

| API | Role |
| --- | --- |
| `http.file(url, name="", auth="")` | Build a `File` that streams an authenticated GET when an activity opens it. The bearer token is minted at open time and never enters workflow history. |
| `http.upload(url, file, field="file", headers={}, auth="")` | POST a `File` as `multipart/form-data`. The activity opens and streams the file. |

```starlark
artifact = http.file(
    "https://artifacts.example.com/diagnostics/" + node_id + ".tar.gz",
    name=node_id + ".tar.gz",
    auth="artifact-service",
)
response = http.upload(
    "https://intake.example.com/upload",
    artifact,
    auth="intake-service",
)
```

`auth` is the name of an OAuth2 client-credentials profile under
`[modules.http.auth.<name>]` in TOML (not a `{secret:NAME}` placeholder). See
[Managing Secrets](/remediation-orchestrator/guides/secrets-management#authenticate-http-with-an-oauth2-profile)
for the profile configuration.

`http.get` / `post` / `put` / `patch` return a response body as a string. That
is fine for small JSON or status payloads; do not use it for logs, archives, or
binaries.

### 3. Host I/O (`ssh`)

Use `ssh.write_file` to place a `File` on a remote host over SFTP. Parent
directories are created as needed. The activity streams bytes from the `File`
source to the destination path.

| API | Role |
| --- | --- |
| `ssh.write_file(host, path, file, cluster_id="")` | Write `file` to `path` on `host`; returns bytes written. |

```starlark
report = objectstore.get_file("artifacts/diagnostics/report.txt")
bytes_written = ssh.write_file(
    "repair-host.example.com",
    "/tmp/report.txt",
    report,
)
```

Command helpers such as `ssh.bash` / `ssh.execute` return stdout and stderr as
strings. Keep those outputs small; persist large command output through
`objectstore` instead of returning it from the workflow.

### 4. Ticketing attachments

Ticket modules produce and consume `File` references so attachments never enter
workflow history as raw bytes.

**Jira / Jira Service Management**

| API | Role |
| --- | --- |
| `request.attachments()` | List attachments on a work item as `[File]`. |
| `request.attach(file, comment="")` | Attach a `File` to the work item. |
| Work-item `read` revisions | Attachment content may appear as `File` revisions. |

```starlark
files = request.attachments()
for f in files:
    objectstore.upload_file(f, "tickets/" + request.key)
```

### 5. Archives (`archive`)

Use `archive` to pack or unpack `File` references without loading archive bytes
into Starlark. Creation and extraction stream inside activities / file sources.

| API | Role |
| --- | --- |
| `archive.new(name="archive.tar.gz")` | Start an archive creator. |
| `creator.add(file, path="")` | Add a `File` (optional path inside the archive). |
| `creator.to_file()` | Return a `File` for the resulting tar.gz (built when opened). |
| `archive.open(archive_file)` | Open an archive `File` for reading. |
| `reader.list_files()` | List paths inside the archive. |
| `reader.extract_file(path)` | Extract one member as a `File`. |
| `reader.extract_files(pattern)` | Extract matching members as `[File]`. |

```starlark
creator = archive.new(name="diagnostics.tar.gz")
creator.add(objectstore.get_file("artifacts/run-42/log.txt"), path="log.txt")
creator.add(http.file("https://example.com/summary.json", name="summary.json"))
bundle = creator.to_file()
objectstore.upload_file(bundle, "artifacts/run-42")
```

## Upload a file

`objectstore.upload_file(file, prefix)` streams a `File` from its existing
source into object storage. It appends the file's `name` to `prefix` and returns
the resulting object key.

```starlark
f = http.file("https://example.com/data/results.json", name = "results.json")
object_key = objectstore.upload_file(f, "validation/results")
```

For a `File` named `results.json`, this stores the object at
`<objectstore_default_bucket>/validation/results/results.json`. To select a
different allowed bucket, pass an `s3://` path as the prefix:

```starlark
object_key = objectstore.upload_file(artifact, "s3://shared-artifacts/diagnostics")
```

The returned value is the object key, not a durable local path. Retain the
`File` reference when a downstream Remediation Orchestrator module needs to consume the file; it
lets that module stream the contents without loading them into workflow history.

To get a `File` again later, use `objectstore.get_file(object_key)`.

## Download a file as a `File` reference

`objectstore.get_file(path)` verifies that the object exists and returns a
`File`. It does not copy file bytes into the Starlark workflow. Pass the
returned reference to a module that accepts files.

```starlark
report = objectstore.get_file("validation/results/results.json")
bytes_written = ssh.write_file("node-001", "/tmp/results.json", report)
```

`objectstore.list(prefix)` returns object keys under a prefix when a workflow
needs to find stored artifacts. It returns metadata only, not their contents.

## Share read access with a presigned URL

`objectstore.create_read_only_presigned_request(path, duration="1h")` creates a
temporary GET request for one object. `duration` is a Go-style duration such as
`"15m"` or `"2h"`; it must be greater than zero and no longer than seven days.

```starlark
def share_report():
    """Return a short-lived request for downloading a report.

    Returns:
        dict: request details for an authorized download client
    """
    request = objectstore.create_read_only_presigned_request(
        "artifacts/diagnostics/report.txt",
        duration="15m",
    )
    return {
        "url": request.url,
        "method": request.method,
        "signed_header": request.signed_header,
    }

register_workflow(share_report)
```

`register_workflow` exposes this as a script entrypoint. An authorized client
starts it with `POST /api/v1/script/<script>/share_report` (or a
[schedule](/remediation-orchestrator/guides/script-development#cron-schedules)); the workflow returns the
short-lived request details in its result. See [Registering
entrypoints](/remediation-orchestrator/guides/script-development#registering-entrypoints) and [Choose a
trigger](/remediation-orchestrator/guides/script-development#choose-a-trigger).

The download client must use the returned HTTP method and include every value in
`signed_header`. Treat the URL and headers as short-lived bearer credentials;
return them only to an authorized caller and use the shortest practical
duration.

## Let an external client upload with a presigned POST

`objectstore.create_write_presigned_post(path, duration="1h")` creates a
temporary multipart-form upload request. The supplied `path` determines the
object-key scope the storage provider allows. The returned `fields` are
provider-generated form fields and must be sent unchanged with the file.

```starlark
def request_artifact_upload():
    """Create a short-lived upload form for an external client.

    Returns:
        dict: form URL and required multipart fields
    """
    post = objectstore.create_write_presigned_post(
        "incoming/workflow-42/",
        duration="15m",
    )
    return {
        "url": post.url,
        "fields": post.fields,
    }

register_workflow(request_artifact_upload)
```

`register_workflow` exposes this as a script entrypoint (`POST
/api/v1/script/<script>/request_artifact_upload`, or a schedule). The workflow
returns the form URL and fields; an authorized upload client then posts the file
to object storage.

For example, that client sends a `multipart/form-data` POST to `url`, adds every
returned field as a form field, and adds the binary as the `file` form part.
Preserve the returned `key` field unless the provider's returned policy
explicitly allows the client to change it; the signature is valid only for the
policy returned by Remediation Orchestrator.

## ScreenTest dispatch contract

A ScreenTest validator declares its dispatch input and result-document handoff
with `contract="dispatch"`.
The declaration is metadata on the validator; the dispatch message itself is
supplied separately through launch arguments:

- **Input:** `launch_args["dispatch_contract"]` contains the dispatch JSON
  string. For schema 3.0.0, this is a `TEST_INVOCATION` message containing the
  requested invocations, their targets, and criteria.
- **Output:** the validator returns its usual verdict fields and a
  `result_record` File referencing the framework's result document. This is
  the result document to publish, rather than a new document built from the
  verdict summary.

For example, a 3.0.0 dispatch message requesting one test on one node is:

```json
{
  "schema_version": "3.0.0",
  "message_id": "message-1",
  "correlation_id": "correlation-1",
  "kind": "TEST_INVOCATION",
  "sender": "example/pipeline",
  "sent_at": "2026-01-01T00:00:00Z",
  "test_invocation": {
    "invocations": [{
      "invocation_id": "invocation-1",
      "test_entry_point": {"reference": "smoke", "test_type": "SNST"},
      "targets": [{
        "target_type": "NODE",
        "target_identifiers": [{"target_id": "node-01", "target_id_type": "HOSTNAME"}]
      }]
    }]
  }
}
```

```starlark
def validate_dispatch(node_group, launch_args):
    """Run a dispatch message through the validator's framework.

    Args:
        node_group: screentest.NodeGroup, the nodes to validate.
        launch_args: dict[string:any], launch arguments, including dispatch_contract.

    Returns:
        dict: the verdict and a File referencing the framework's result document.
    """
    # The framework integration supplies the verdict and the persisted document.
    outcome = run_framework(node_group, launch_args["dispatch_contract"])
    return {
        "result": outcome.passed,
        "result_record": outcome.document,
    }

screentest.validator(
    register_workflow(validate_dispatch),
    contract="dispatch",
    launch_args_config=[{"name": "dispatch_contract", "type": "string", "default": ""}],
)
```

`run_framework` above represents the validator's own framework adapter, which
executes the supplied dispatch message. Its `document` must be an existing
`File`, such as one returned by
`objectstore.get_file()`. Return the File object itself so its internal source
identifier survives the workflow result conversion. Keep the document's bytes
out of workflow return values.

The declaration is stored with the validator entrypoint and is available on a
resolved validator as `contract`. Unknown contract values are rejected, and a
dispatch declaration requires the default all-or-nothing node locking.
Omitting the declaration preserves existing validator behavior; omitting the
optional `result_record` field preserves the existing result shape.

Declaring the `dispatch_contract` launch argument allows the validator to receive
the message; `contract="dispatch"` declares the input/output protocol it follows.
Spec-driven callers supply the message from their configured `invocations`.
The dispatch execution integration is responsible for checking that those
callers and validator declarations agree, validating the message, and enforcing
the result-document requirement. The shared-store configuration controls
publication; declaring a contract does not enable uploads.

The orchestration publishes result documents after recording the phase's test
verdicts. Publication failures preserve those verdicts. Canceling the run during
result publication cancels the orchestration without changing the completed
phase or its test results.

## Rules for file handling

**Do**

- Use `File` references and object storage for logs, command output, archives,
  and binaries that may be large.
- Keep workflow return values, activity arguments, and activity results to small
  metadata such as object keys, sizes, and status summaries.
- Use specific, workflow-scoped prefixes and the shortest practical presigned
  URL or POST lifetime.
- Pass a `File` directly between compatible modules when possible; it streams
  the contents at activity execution time.
- When using `objectstore`, record the object key returned by `upload_file` (and
  a concise summary) so operators can find the artifact without storing its
  contents in history.

**Do not**

- Do not return a log, binary, archive, or other file content from a workflow,
  or pass it as a string, list, or dict between module calls.
- Do not read a large file into a workflow merely to re-upload it. Use
  `upload_file` or pass the existing `File` reference.
- Do not put sensitive data in object keys, workflow arguments, return values,
  logs, or error messages.
- Do not expose presigned URLs, signed headers, or POST fields to unauthorized
  users, and do not use a longer lifetime than the handoff requires.
- Do not assume temporary workflow history can hold large artifacts. History has
  payload and event-size limits; large logs or binaries can exceed them and make
  a workflow fail or become difficult to replay.