Skip to content
48 changes: 47 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,53 @@ tool under `tools/` keeps its own.

## [Unreleased]

## [v0.12.0] - 2026-11-29

This release lets `stages.Build` run soffice on the host, so a host without a docker socket has the
office and picture routes; `stages.Options.LibreOfficeExec`'s zero value keeps soffice in
`picture.LibreOfficeImage`. It also renders SVG through librsvg's rsvg-convert in place of magick,
so docproc never follows an SVG's references to files and URLs, whatever magick was built with.
The office and picture stages require rsvg-convert, and their identities change: each `Version`
carries rsvg-convert's version line. `dispatch.Version` stays "1", and the run directory's schema
stays "2".

### Added

- `picture.RsvgConvertSpec` and `picture.RsvgConvertMinimum`, 2.58, declaring librsvg's
rsvg-convert, and `picture.Config.RsvgConvert`, which `picture.NewConverter` requires, panicking
on a nil one, and version-checks through `Tool.AtLeast`, refusing one older than the minimum with
a `*tool.VersionError` wrapping `tool.ErrTooOld`. 2.58 is Ubuntu 24.04 LTS's, after 2.56.3 fixed
CVE-2023-38633; Debian 13 ships 2.60.
- `stages.Build` builds rsvg-convert through the exec runner, found through the lookup as
`rsvg-convert`, as it builds magick, and the office and vision-converted routes require it: a host
without it, or with one older than 2.58, has those routes Missing, their rows saying why.
rsvg-convert's row in `Set.Tools` carries its minimum, and `Options.Timeout` bounds its runs.
- `stages.Options.LibreOfficeExec`, which runs soffice on the host through the exec runner, found
through the lookup as `soffice`, under `stages.Options.LibreOfficeMemory`, the run's own
directory, and the fixed environment every exec-run tool runs under; docker is never looked up
for it, and soffice's row in `Set.Tools` names its path. False, its zero value, runs soffice in
`picture.LibreOfficeImage` through the container runner, found through the lookup as `docker`,
under `Options.Memory`, as before.
- `stages.Options.LibreOfficeMemory`, soffice's memory bound in bytes when `LibreOfficeExec` is set,
its RLIMIT_AS in place of `Options.Memory`, since soffice needs a far larger RLIMIT_AS than the
other tools. It has no default: zero is none, and `stages.Build` refuses one below zero with an
error matching `stages.ErrRequest`. A soffice run killed by a signal under it is recorded with
this bound.
- The `settings` key `soffice_memory`, whole bytes, zero or more, assembled into
`stages.Options.LibreOfficeMemory`, and its field `settings.Settings.SofficeMemory`. It is
optional: unset, it assembles to `tool_memory`'s value, so soffice keeps the bound it had before
the key existed, and one below zero is refused by name with a `settings.KeyError`. `cmd/docproc`,
which runs soffice in its container, doesn't read it.

### Changed

- An SVG is rendered through rsvg-convert, `--zoom=<density/96> --background-color=white
--format=png`, never through magick's `rsvg:` coder, which a magick built without librsvg, as
Debian 13's is, reads through ImageMagick's own MSVG renderer, following an `<image href>` to a
local file or a URL. The PNG is the same size at the same `Density`, opaque on white, and the same
bytes each time it is converted. An rsvg-convert run carries none of `picture.Limits`; the Tool's
memory bound and timeout hold it. A failed run's error names rsvg-convert, `picture:
rsvg-convert: <copy>: ...`, where it named magick.
- Each package's unit tests sit in its `test/` directory as an external test package
(`<pkg>/test/*_test.go`), the helper packages `dispatch/dispatchtest`, `internal/tooltest`, and
`internal/goldentest` included, with each package's fixtures in `<pkg>/test/testdata/`. A test
Expand Down Expand Up @@ -676,7 +721,8 @@ fixtures scripts stay in the spike.
The [limits page](docs/limits.md) states them: each stage's tool's limits, docproc-ooxml's
behavior under a memory bound, the Threader's memory, and the formats no stage reads.

[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.11.0...HEAD
[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.12.0...HEAD
[v0.12.0]: https://github.com/standards-lab/docproc/compare/v0.11.0...v0.12.0
[v0.11.0]: https://github.com/standards-lab/docproc/compare/v0.10.0...v0.11.0
[v0.10.0]: https://github.com/standards-lab/docproc/compare/v0.9.0...v0.10.0
[v0.9.0]: https://github.com/standards-lab/docproc/compare/v0.8.0...v0.9.0
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tags.
## Install

```sh
go get github.com/standards-lab/docproc@v0.11.0
go get github.com/standards-lab/docproc@v0.12.0
```

The module's releases are tagged `vX.Y.Z`, and [`CHANGELOG.md`](CHANGELOG.md) states what each
Expand Down Expand Up @@ -100,15 +100,30 @@ made fails before the tool starts.
| `pdfinfo` | poppler-utils | 22.02 | document |
| `magick` | ImageMagick | 7.1 | office, picture, vision |
| `soffice` | LibreOffice | 24.2 | office, picture |
| `rsvg-convert` | librsvg | 2.58 | office, picture |
| `7zz` | 7-Zip | 26.06 | archive |
| `ffmpeg`, `ffprobe` | FFmpeg | 9.0 | audio, video |

7zz's minimum is its mise pin, 26.06: 25.00 fixes CVE-2025-53816 in RAR's decoder, 26.02 fixes
CVE-2026-14266 in xz's, and 26.03 through 26.06 fix vulnerabilities they don't name. The text stage
runs no tool.

The container runner runs a tool inside a digest-pinned image through the docker CLI, 20.10 or
later: `audio.FFmpegImage` for ffmpeg and ffprobe, `picture.LibreOfficeImage` for soffice.
rsvg-convert renders every SVG, never magick: a magick built without librsvg, as Debian 13's is,
renders SVG through ImageMagick's own MSVG renderer, which follows an SVG's references to files
and URLs. rsvg-convert's minimum, 2.58, is Ubuntu 24.04 LTS's version, after 2.56.3 fixed
CVE-2023-38633, a path traversal through an SVG's reference. The office stage runs no
rsvg-convert, since it hands an Office document's SVGs on as stored, but it requires one, because
it shares the picture package's Converter.

`stages.Build` runs soffice by default inside `picture.LibreOfficeImage`, a digest-pinned image,
through the container runner and the docker CLI, 20.10 or later, which it finds through the lookup
as `docker`. With `stages.Options.LibreOfficeExec` set, it runs soffice on the host through the
exec runner instead and never looks up docker: it finds soffice through the lookup as `soffice`,
runs it under every exec-run tool's bounds except the memory bound, which
`stages.Options.LibreOfficeMemory` sets, and names soffice's path in its row in `Set.Tools`.
`stages.Build` runs every other tool, ffmpeg and ffprobe among them, through the exec runner alone.
`audio.FFmpegImage` is the image for a host that builds ffmpeg and ffprobe itself through
`tool.NewContainer`.

### The memory bound

Expand All @@ -119,4 +134,10 @@ runs: `prlimit` must then be on PATH, and `tool.NewExec` refuses a bounded tool
tool that dies by a signal under the bound is recorded with both, as in "killed by SIGABRT under a
256 MiB memory bound".

Run through the exec runner, soffice takes its own bound, `stages.Options.LibreOfficeMemory`, in
place of `Memory`. It has no default either: zero runs soffice with no bound. soffice needs a far
larger RLIMIT_AS than the other tools: soffice 26.8 fails to write its output under 4 GiB on a
host where it converts under 8 GiB. Run in the container, soffice stays under `Memory`, the
container's `--memory`.

Apache-2.0.
19 changes: 15 additions & 4 deletions context/bunrei.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Bunrei, the data-intelligence capstone's processing service, is planned. It runs docinfer's jobs
over docproc's dispatcher, stages, and stores, which it wires, and builds the go-ai clients docinfer
calls. The capstone root's notes hold its contracts; this note holds what Bunrei keeps to itself:
its input, its jobs and their fencing, and its state, which the `state` task settles
(`standards-lab/context/data-intelligence.md`, "Design").
its input, its jobs and their fencing, its tools and routes, and its state, which the `state` task
settles (`standards-lab/context/data-intelligence.md`, "Design").

## Queries and Commands

Expand All @@ -31,6 +31,19 @@ subject under the expected-last-subject-sequence check, which is its transaction
refused append reads the subject's tail and acts on either alike.
- **The profile** resolves to a `docinfer.Pipeline`, one per profile.

## Tools and routes

Bunrei wires docproc's `stages` and `dispatch` from a `settings.Run` assembled from its `docproc`
block, as `cmd/docproc` does, and its dispatcher works under `work_dir`, one volume per replica that
the deployment mounts. Bunrei's service image holds every tool docproc's routes run, and Bunrei
builds its stages with `stages.Options.LibreOfficeExec` set, so every tool, soffice included, runs
through the exec runner. soffice runs under the `soffice_memory` settings key's bound, every other
tool under `tool_memory`'s. rsvg-convert renders SVG, from Debian's librsvg2-bin. Startup requires
every route not in Bunrei's `jobs.exclude` and refuses to run while one has no processor, naming its
stage row's reason. Bunrei's
[`docs/image.md`](https://github.com/JaimeStill/capstone-bunrei/blob/main/docs/image.md) describes
the image.

## State and subjects

Bunrei holds only its jobs, its uploads, and each job's event stream. docproc's index and content
Expand Down Expand Up @@ -76,8 +89,6 @@ data-intelligence.md queues these asks of go-messaging's NATS provider, sized by

## Assumptions

- Assumes Bunrei wires docproc's `stages` and `dispatch` from a `settings.Run`, as `cmd/docproc`
does.
- Assumes one `docinfer.Bounds` per replica, shared by its pipelines, one per profile.
- Assumes Bunrei speaks Chat Completions to the gateway, its consumer key the bearer token.
- Assumes the consumer stores chunks by their identity, so a batch a redelivered job repeats changes
Expand Down
57 changes: 40 additions & 17 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ How `office` converts through LibreOffice, and why:
`.tif` and `.tiff` of one stem are each swapped whole, and a swapped-in name is never swapped
again.

How `picture` runs magick and soffice, and why:
How `picture` runs magick, soffice, and rsvg-convert, and why:

- An output stem is ASCII letters, digits, `.`, `-`, and `_`, beginning with a letter or digit, so
magick reads no part of a name made from it as a format prefix, a frame suffix, or a pattern.
Expand Down Expand Up @@ -371,6 +371,18 @@ How `picture` runs magick and soffice, and why:
picture at its own size at its center, so rendering the page at a scale renders the picture at
that scale; a page of another shape than the pixel size would stretch it. `-trim` then crops to
what differs from the corners' color and `+repage` drops the crop's offset, PNG in and out.
- An SVG is rendered by librsvg's own command, rsvg-convert, never by magick: a magick built
without librsvg, as Debian 13's is, reads an SVG named `rsvg:` through its own MSVG renderer,
which follows an `<image href>` to a local file or a URL. librsvg runs no script, fetches no URL,
and loads only a file beside the SVG or below its directory, which holds the copy alone. The run
is `--zoom=<density/96> --background-color=white --format=png --output=<png> <copy>`: the zoom
scales the SVG's CSS pixels, a 96th of an inch, to the density, as magick's `-density` did, and
leaves its physical units true, a fractional size rounded up where magick rounded down; the
white background leaves no transparent pixel, and librsvg writes no time chunk, so the PNG is
the same bytes each time. It works in the batch's `picture-*` directory, its HOME under the exec
runner, so fontconfig's cache is removed with it and never lands in the caller's directory.
`--unlimited` is never passed, so librsvg's own bounds on the XML it parses hold; magick's limits
don't apply, and the tool's memory bound and timeout do.

How `audio` and `media` run ffmpeg, and why:

Expand Down Expand Up @@ -792,11 +804,17 @@ type Options struct { // the zero value wires every route, with no bound
Exclude []route.Route
Inspect inspect.Options // validated once; the archive and document stages' bomb rule
Timeout time.Duration // Spec.Timeout of the unit tools: gs, qpdf, pdfdetach,
// pdftotext, pdfinfo, magick, soffice, docproc-ooxml, ffprobe
// pdftotext, pdfinfo, magick, soffice, rsvg-convert,
// docproc-ooxml, ffprobe
Idle time.Duration // Spec.Idle of the stream tools: ffmpeg, docproc-mail,
// docproc-onenote, 7zz
Memory int64 // tool.Spec.MemoryLimit for every Spec Build builds
Memory int64 // tool.Spec.MemoryLimit for every Spec Build builds, but
// soffice's under LibreOfficeExec
Env []string // tool.Spec.Env
LibreOfficeExec bool // soffice on the host through the exec runner, found as soffice;
// false runs it in picture.LibreOfficeImage, found as docker
LibreOfficeMemory int64 // soffice's tool.Spec.MemoryLimit under LibreOfficeExec; zero
// is none, below zero matches ErrRequest
Concurrency int // a PDF's pages and an audio part's windows held; zero is one
Document document.ImagesRequest // each stage's request, its own defaults where zero;
Picture picture.Request // a part's own fields (Dir, Path, Kind, Stem) are the
Expand Down Expand Up @@ -1053,13 +1071,14 @@ How the stages are built, and why:
`settings` holds a run's settings as one flat JSON object, so a host that takes its bounds as
JSON, rather than as `cmd/docproc`'s `DOCPROC_` variables, reads and validates them in one step
and hands them to `stages.Build` and `dispatch.New` as they are. Each key is named for the
variable `cmd/docproc` reads it from, without the prefix and in snake case. It imports the
standard library and docproc's own packages alone.
variable `cmd/docproc` reads it from, without the prefix and in snake case, except
`soffice_memory`, which `cmd/docproc` doesn't read, since it runs soffice in its container. It
imports the standard library and docproc's own packages alone.

```go
package settings
type Settings struct { // one pointer field per key, nil when unset; the json tags are the keys
ToolMemory *int64; UnitTimeout, StreamIdle *time.Duration
ToolMemory, SofficeMemory *int64; UnitTimeout, StreamIdle *time.Duration
MaxParts *int; MaxBytes *int64; MaxDepth *int
BombRatio *float64; BombSize *uint64; ArchiveEntries *int
ClaimRelease *time.Duration; Concurrency, PDFDPI *int; PDFText *bool; PDFMaxPixels *int64
Expand Down Expand Up @@ -1089,6 +1108,7 @@ The keys, their formats, where each lands, and whether it is required:
```text
key JSON field required
tool_memory whole bytes stages.Options.Memory yes
soffice_memory whole bytes stages.Options.LibreOfficeMemory no, tool_memory
unit_timeout duration stages.Options.Timeout yes
stream_idle duration stages.Options.Idle yes
max_parts whole number dispatch.Limits.Parts yes
Expand All @@ -1111,23 +1131,26 @@ audio_limit duration, over 4s audio.Request.Limit no,
output_writes whole number, from 1 dispatch.Config.Puts no, 1
```

The library ships no policy, so every key but four is required, and zero is no bound: a required
key left unset is refused, never defaulted. The four optional keys are the ones whose library value
already has a default: an unset `pdf_dpi` assembles to `document.DefaultDPI`, 150; an unset
`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `output_writes`,
the most outputs one part writes to the content store at once, to 1. A set `pdf_dpi`,
The library ships no policy, so every key but five is required, and zero is no bound: a required
key left unset is refused, never defaulted. An unset `soffice_memory` assembles to `tool_memory`'s
value, so soffice runs under the bound the host already chose for every tool; set, it is zero or
more, soffice's own bound when `LibreOfficeExec` runs it through the exec runner. The other four
optional keys are the ones whose library value already has a default: an unset `pdf_dpi`
assembles to `document.DefaultDPI`, 150; an unset `audio_limit` to `audio.DefaultWindowLimit`,
30s; and an unset `concurrency` or `output_writes`, the most outputs one part writes to the
content store at once, to 1. A set `pdf_dpi`,
`concurrency`, or `output_writes` is at least 1, and a set `audio_limit` is over 4s, twice
`audio.DefaultOverlap`, the shortest window the audio cutter takes. A duration is a Go duration
string, such as `"90s"` or `"10m"`, as `time.ParseDuration` reads it, and a number in its place is
refused; every value is zero or more, and `bomb_ratio` and `bomb_size` are both zero, for no bomb
rule, or both above it.

`Run.Stages` sets only the fields the table names. `Exclude`, `Env`, `Inspect.Policy`, `Picture`,
`Document.PagesPerProcess`, and every other field of the video, audio, and ImageMagick requests
stay the zero value, each host's own to set before `Build`. A host passes `Run.Limits` and
`Release` to `dispatch.New` in its `Config`, and `OutputWrites` as its `Puts`, with the
`stages.Set`'s `Inspect` as its `Inspect`, so the dispatcher and the stages share one validated
value of the inspection options.
`Run.Stages` sets only the fields the table names. `Exclude`, `Env`, `LibreOfficeExec`,
`Inspect.Policy`, `Picture`, `Document.PagesPerProcess`, and every other field of the video, audio,
and ImageMagick requests stay the zero value, each host's own to set before `Build`. A host
passes `Run.Limits` and `Release` to `dispatch.New` in its `Config`, and `OutputWrites` as its
`Puts`, with the `stages.Set`'s `Inspect` as its `Inspect`, so the dispatcher and the stages share
one validated value of the inspection options.

## Content

Expand Down
4 changes: 2 additions & 2 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ tool under `tools/` pins its own. Tasks run from the repository root, `mise run
run directory it writes, read back through `rundir`; and `integration`, below. Run it on your
machine before each Go tag; CI doesn't. The other programs come from the host, each at its
minimum or later: `gs`, `qpdf`, `pdfdetach`, `pdftotext`, `pdfinfo`, `ffmpeg`, `ffprobe`,
`magick`, `soffice`, util-linux's `prlimit`, and `docker`, which runs the compose harness and
pulls `audio.FFmpegImage` and `picture.LibreOfficeImage` for the tools tier.
`magick`, `soffice`, `rsvg-convert`, util-linux's `prlimit`, and `docker`, which runs the compose
harness and pulls `audio.FFmpegImage` and `picture.LibreOfficeImage` for the tools tier.
- `integration`: the providers' live tiers, `integration:postgres` then `integration:storage`, every
one even after one fails; CI runs it on a push to main that needs it and on demand.
`integration:postgres` runs the postgres module's suite against the harness's PostgreSQL, and
Expand Down
Loading