Run OpenCode stages on a Pipelines-owned stage service with their own limits
Stages now run on a detached Pipelines-owned opencode serve started with OPENCODE_CONFIG_CONTENT carrying stage tool_output (16384 bytes / 400 lines) and compaction.auto defaults, configurable through PIPELINES_OPENCODE_STAGE_*. Chats keep their existing service and configuration; a server-spawned chat serve can take PIPELINES_OPENCODE_CHAT_CONFIG. The service shares the user's OpenCode config, credentials and session database, keeps a stable private registration so retained references (recovery, interrupt, export) stay valid, revives on the same port after a crash, replaces itself when idle after a settings change, and is stopped on shutdown only when idle. PIPELINES_OPENCODE_STAGE_SERVICE=shared restores the previous behaviour.
This commit is contained in:
@@ -36,6 +36,74 @@ provider spending limits separate. Existing definitions, defaults and published
|
||||
versions are never rewritten. Editing the setting requires publishing a new
|
||||
pipeline version as usual.
|
||||
|
||||
## OpenCode limits for stages and chats
|
||||
|
||||
OpenCode reads its tool-output and compaction limits only from configuration;
|
||||
there is no per-session or per-agent setting. Pipeline stages therefore run on
|
||||
their own OpenCode process, the **stage service**, so stages and chats can use
|
||||
different limits:
|
||||
|
||||
- **Stages** run on a Pipelines-owned `opencode serve` on `127.0.0.1`, started
|
||||
lazily by the first stage with `OPENCODE_CONFIG_CONTENT` holding the stage
|
||||
limits merged over any inherited `OPENCODE_CONFIG_CONTENT`. It is the same
|
||||
binary, user and XDG directories as your normal OpenCode, so it reads your
|
||||
configuration, directory `opencode.json` files and provider credentials, and
|
||||
writes sessions to the same OpenCode database (SQLite WAL; OpenCode sets a
|
||||
busy timeout). Stage sessions stay visible to `opencode --session <id>`.
|
||||
- **Chats** keep the OpenCode service they already use and its configuration.
|
||||
Pipelines never writes `~/.config/opencode`. `PIPELINES_OPENCODE_CHAT_CONFIG`
|
||||
(a JSON object) applies only when the server spawns its own chat
|
||||
`opencode serve`. A shared or `-opencode-endpoint` service keeps the limits in
|
||||
your OpenCode configuration (`tool_output`, `compaction`).
|
||||
|
||||
Server environment settings (add them to `opencode_env` in the install
|
||||
manifest, or the server's environment):
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `PIPELINES_OPENCODE_STAGE_TOOL_OUTPUT_MAX_BYTES` | `16384` | stage `tool_output.max_bytes`; `0` keeps OpenCode's default (51200) |
|
||||
| `PIPELINES_OPENCODE_STAGE_TOOL_OUTPUT_MAX_LINES` | `400` | stage `tool_output.max_lines`; `0` keeps OpenCode's default (2000) |
|
||||
| `PIPELINES_OPENCODE_STAGE_COMPACTION` | `on` | `on`/`off` set `compaction.auto`; `opencode` leaves it unset |
|
||||
| `PIPELINES_OPENCODE_STAGE_CONFIG` | none | JSON object merged last, e.g. `{"compaction":{"keep":{"tokens":20000}}}` |
|
||||
| `PIPELINES_OPENCODE_STAGE_SERVICE` | `owned` | `shared` runs stages on the CLI-managed service again, without stage limits |
|
||||
| `PIPELINES_OPENCODE_CHAT_CONFIG` | none | JSON object for a server-spawned chat `opencode serve` only |
|
||||
|
||||
Over-limit tool output is truncated by OpenCode itself. Bash keeps the tail
|
||||
with a `[showing lines X-Y of N; full output saved to <file>]` note, so the
|
||||
model can still read the full file.
|
||||
|
||||
How the stage service behaves:
|
||||
|
||||
- **Registration.** Its URL, password and pid are in the owner-only file
|
||||
`opencode-stage-service.json` (log: `opencode-stage-service.log`) under the
|
||||
user cache directory's `pipelines/private`. A stage's retained reference
|
||||
points at this file, so restart recovery, interruption and `session.html`
|
||||
export reach the same service. References made before this change still point
|
||||
at the CLI-managed service and keep working.
|
||||
- **Health and restarts.** Every stage admission checks it with the
|
||||
authenticated `/api/info`. A crashed service is started again on the same
|
||||
port and password, also when a retained reference is used after it exited.
|
||||
Start-up is bounded (20 s per attempt, 3 attempts). If it cannot start, the
|
||||
stage fails with `OpenCode stage service exited before becoming ready (see
|
||||
<log>)` or a timeout error. It never falls back to the shared service, because
|
||||
that would silently drop the stage limits. Use
|
||||
`PIPELINES_OPENCODE_STAGE_SERVICE=shared` to opt out deliberately.
|
||||
- **Changed settings or an upgraded OpenCode** restart the service when no
|
||||
session is active on it. A busy service keeps its old limits until it is idle.
|
||||
- **Lifetime.** It runs detached in its own process session, so a stopping
|
||||
Pipelines service does not take active stage work with it. On server shutdown
|
||||
it is stopped only when no session is active on it. Otherwise restart
|
||||
recovery interrupts the retained sessions through it, as before.
|
||||
- `pipelines debug` is unchanged: it opens a fresh interactive harness
|
||||
conversation, not the stage session.
|
||||
|
||||
Claude Code and Codex are chat-only harnesses (stages accept only
|
||||
`harness=opencode` or `harness=pi`), so they need no stage limit. Their chats
|
||||
keep their own defaults. Claude Code has `BASH_MAX_OUTPUT_LENGTH` and
|
||||
`MAX_MCP_OUTPUT_TOKENS` (environment or `--settings`). Codex has
|
||||
`tool_output_token_limit` (config override `-c`). Pi stages keep Pi's built-in
|
||||
tool-output truncation; Pipelines sets no Pi limit.
|
||||
|
||||
## Harness defaults
|
||||
|
||||
Configure two independent model defaults:
|
||||
|
||||
+7
-5
@@ -131,11 +131,13 @@ new`, `edit` and `debug` sessions.
|
||||
`/usr/local/bin`, `/usr/bin`, `~/.local/bin`. `./install` requires `opencode`
|
||||
on `PATH` and records its absolute path.
|
||||
|
||||
**Launched as:** the server starts its own loopback `opencode serve` for chat
|
||||
and for stage sessions, using your normal OpenCode configuration and login.
|
||||
A server started with `-opencode-endpoint URL` (or
|
||||
`PIPELINES_OPENCODE_ENDPOINT`) attaches chat to that service instead; the
|
||||
native installer does not set this.
|
||||
**Launched as:** chat uses the OpenCode service the server attached to (an
|
||||
endpoint from `-opencode-endpoint URL` / `PIPELINES_OPENCODE_ENDPOINT`, or a
|
||||
loopback `opencode serve` the server spawns). Stage sessions run on a separate
|
||||
Pipelines-owned loopback `opencode serve`, the *stage service*, which uses your
|
||||
normal OpenCode configuration, login and session database but adds the stage
|
||||
tool-output and compaction limits. See "OpenCode limits for stages and chats"
|
||||
in [harnesses-and-control.md](harnesses-and-control.md).
|
||||
|
||||
**Install and sign in:** `pipelines harness setup opencode` (runs
|
||||
`opencode auth login` when no provider is connected). Pipelines reads the
|
||||
|
||||
Reference in New Issue
Block a user