Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/plugins/runner-acp.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Loop checks `runners.acp` against the profile and `AcpRunnerProvider.validate` o

- **Launch:** argv words run in the workspace working directory inside an isolated process group (`ProcessGroupLauncher`) with no shell. Under `preset: agy`, Loop sweeps stale isolated folders and appends `--disable-telemetry`, `--sandbox`, and `--gemini-dir <relative-under-HOME>` pointing to an isolated folder containing `antigravity-cli/settings.json` (`{"toolPermission": "strict", "allowNonWorkspaceAccess": false}`). The folder is `$LOOP_HOME/agy/<attempt>-<id>` when `LOOP_HOME` lies under `$HOME`, else `$HOME/.loop-agy/<attempt>-<id>`, never in the attempt folder, which Loop deletes when the attempt ends. See [Isolated folder lifetime](#isolated-folder-lifetime). Loop never passes `--dangerously-skip-permissions`, `--effort`, `--remote-agent`, or `--remote-control`.
- **Loop MCP server:** when the attempt environment provides `LOOP_LAUNCHER` and `LOOP_TOOL_CONFIG`, `session/new` and `session/load` pass Loop's stdio MCP server (`name: "loop"`, `command: <LOOP_LAUNCHER>`, `args: ["tool", "mcp"]`) with only the 8 Loop environment variables (`LOOP_TOOL_CONFIG`, `LOOP_ATTEMPT_ID`, `LOOP_ISSUE_ID`, `LOOP_ISSUE_IDENTIFIER`, `LOOP_TRACKER_ID`, `LOOP_HOME`, `LOOP_SESSION_ID`, `LOOP_TURN_ID`). `LOOP_SESSION_ID` and `LOOP_TURN_ID` stay fixed at the values of the turn that opened the session. A respawn or a resume under `preset: agy` passes the `mcpServers` again in `session/load`.
- **Stdout:** newline delimited JSON-RPC 2.0 messages, bounded to 10 MB per line (`ProcessGroupLauncher.MAX_LINE_BYTES`). Malformed lines are logged on stderr with a fixed reason (never quoting the line) and skipped.
- **Stdout:** newline delimited JSON-RPC 2.0 messages, bounded to 10 MB per line (`ProcessGroupLauncher.MAX_LINE_BYTES`). Malformed lines are logged on stderr with a fixed reason (never quoting the line) and skipped. Each line is kept as runner output as read, except an error response, echoed with its `jsonrpc`, `id`, `code` and `message` and a `[error data omitted, N chars]` marker in place of its data, which can hold account fields (bl-240). The runner still reads the whole error.
- **Stderr:** kept apart from the protocol stream as diagnostic output.
- **Stop:** closing a session closes stdin and waits up to 5 seconds (`STOP_GRACE`) for the process to exit. When the grace expires, Loop kills the process group and reports `stop_grace_expired` through `AgentSession.stop(report)`. Under `preset: agy`, the isolated `--gemini-dir` folder of a session that reported its runtime session id is kept after the process exits, since it holds `agy`'s session store, and the folders earlier sessions of the same issue kept are removed; any other folder, and the folder of a session a guard ended, is removed (logging any removal failure).

Expand Down Expand Up @@ -141,7 +141,7 @@ Loop ships default context windows of `1048576` tokens in `ContextConfig.DEFAULT
- **Hard-limit interrupt:** `AgentSession.interrupt()` sends a `session/cancel` notification, answers any pending `session/request_permission` with `cancelled`, preserves `result.usage` on `stopReason: "cancelled"`, and ends the turn cleanly so Loop rotates onto a fresh session.
- **Error mapping:** structured JSON-RPC errors reporting authentication or eligibility failure (401, 403, expired login, `IneligibleTierError`), rate limit or overload (429, 503, 529), model refusal (`-32602 Unknown model ID` or `modelNotFound`), or runtime-reported network transport failure with no HTTP status map to `runner_unavailable`, as does an `agy` of another major or older than the minimum at `initialize` under `preset: agy`. All other errors, exits, and malformed lines are ordinary failures. A Google error object anywhere in the error data, nested in a string field included, maps to `runner_unavailable` when its `status` is `RESOURCE_EXHAUSTED` or an `ErrorInfo` `reason` is `QUOTA_EXHAUSTED`. The quota message text alone is free text and maps nothing.
- **Retry time and quota reset (bl-215):** a `runner_unavailable` with a status or a rate limit code sets `retryAfter`, which the run level hold uses as its period when it is longer than the backoff, so one probe runs at the reset instead of one every 1 to 15 minutes. An explicit `retryAfterMs`, `retry_after_ms`, `retryAfterSeconds`, `retry_after_seconds`, `retryAfter` or `retry_after` key of the error data comes first. Else the wait is the first valid positive value of, in order: `quotaResetTimeStamp` (RFC 3339) minus now, `quotaResetDelay`, a `RetryInfo` `retryDelay`, each searched at any depth of the error data, a JSON body inside a string field included, then `Your quota will reset after <duration>` in the error message or a string of the data. Durations use Google's format (`4h23m27.716645894s`, `27s`, `850ms`). A past timestamp or an unparsable value is skipped, never a failure, and nothing found leaves `retryAfter` empty as before.
- **`rate_limit` event:** with a quota reset found, the turn emits `rate_limit` before `turn_failed`, with `limit_id` `gemini`, the error's `metadata.model` as `limit_name` (else `runners.acp.model`), and `reached` `quota_exhausted`. It carries no window, since a window needs a used percent that `agy` never reports, so the reset time is in the `turn_failed` reason instead: `turn_failed: <message> (code <code>); the quota resets at <instant>`. `loop trace` prints it as `rate_limit limit=gemini name=<model> reached=quota_exhausted`. Only the reset time and a plain model id are read from the error: no account id, email or token reaches the event or the reason. The JSON-RPC line itself is still echoed as runner output, like every protocol line. The decisions are in [The acp runner holds until an exhausted Gemini quota resets](../spec-decisions.md#the-acp-runner-holds-until-an-exhausted-gemini-quota-resets-extension-bl-215).
- **`rate_limit` event:** with a quota reset found, the turn emits `rate_limit` before `turn_failed`, with `limit_id` `gemini`, the error's `metadata.model` as `limit_name` (else `runners.acp.model`), and `reached` `quota_exhausted`. It carries no window, since a window needs a used percent that `agy` never reports, so the reset time is in the `turn_failed` reason instead: `turn_failed: <message> (code <code>); the quota resets at <instant>`. `loop trace` prints it as `rate_limit limit=gemini name=<model> reached=quota_exhausted`. Only the reset time and a plain model id are read from the error: no account id, email or token reaches the event or the reason. The JSON-RPC line is echoed as runner output without its error data (bl-240), see [error responses in runner output](../spec-decisions.md#error-responses-in-runner-output-extension-bl-240). The decisions are in [The acp runner holds until an exhausted Gemini quota resets](../spec-decisions.md#the-acp-runner-holds-until-an-exhausted-gemini-quota-resets-extension-bl-215).
- **Startup preflight (`preset: agy`):** verifies the `agy` binary is reachable, on pinned major version `1` and no older than `1.5.18`, reading the version from the line of `agy --version` that is only a version, else its last version token, so a banner such as `new version 1.6.0 available` printed before it never decides it (errors stop startup; 1.5.18 is the first version that applies permission prompts to files read or edited through `file:///` URIs, which the guards above rely on), and runs `agy models` to warn on login problems, offline failures, or a configured model not listed.

## Capabilities
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/runner-codex-app-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The merge risk reviewer follows the model of `kinds.code.delivery.risk.reviewer`

- **Launch:** the words of `command` as the argv, with the workspace as its working directory, in its own process group, with the agent env of the shared policy (`agent.env` added, removed names taken out). Cancelling the attempt kills the group. No shell runs it, unlike the spec's `bash -lc`: a login shell reads the user's profile after the env policy built the env, and a profile export would bring back a name the policy removed, such as `GH_TOKEN` or `LOOP_HOLDOUT` (m3-20).
- **The agent's commands:** every `thread/start` sets `allow_login_shell` to false in its `config`, so Codex runs each command of the agent with `zsh -c` or `bash -c`, not `-lc`, and the same profile export does not reach them either. A command the model asks to run in a login shell is refused by Codex. Not covered: `zsh` reads `~/.zshenv` for every shell, login or not, so an export there still reaches the agent's commands when the user's shell is zsh.
- **Stdout** is the protocol stream: one JSON object per line, the framing of the pinned app server. Each line is kept as output. A line split across reads is read whole once its line break arrives. A line that is not a protocol message is logged as `loop: an app server stdout line is not a protocol message (<reason>), skipped`, the reason a fixed phrase such as `not JSON`, never the line, and reading goes on. A line longer than 10 MB, the max line size of spec 10.1, is dropped by the launcher, never held whole in memory, and a `loop: a stdout line of <n> bytes was dropped, longer than the maximum of 10485760 bytes` line on stderr takes its place (bl-128).
- **Stdout** is the protocol stream: one JSON object per line, the framing of the pinned app server. Each line is kept as output as read, except an error response, echoed with its `id`, `code` and `message` and a `[error data omitted, N chars]` marker in place of its data (bl-240), see [error responses in runner output](../spec-decisions.md#error-responses-in-runner-output-extension-bl-240). A line split across reads is read whole once its line break arrives. A line that is not a protocol message is logged as `loop: an app server stdout line is not a protocol message (<reason>), skipped`, the reason a fixed phrase such as `not JSON`, never the line, and reading goes on. A line longer than 10 MB, the max line size of spec 10.1, is dropped by the launcher, never held whole in memory, and a `loop: a stdout line of <n> bytes was dropped, longer than the maximum of 10485760 bytes` line on stderr takes its place (bl-128).
- **Stderr** is kept apart, as diagnostics: each line is kept as stderr output and never read as protocol.
- **Stdin** carries the client's messages, one JSON object per line. It stays open across the turns of a session and is closed when the session stops.
- **Failures:** `invalid_workspace_cwd` (the workspace is not a directory, nothing starts), `agent_not_found` (the process cannot be spawned, or the launcher exits 127 because it could not run the command, before any stdout line), `response_error` (the start or a `turn/start` failed, see below), `response_timeout` and `turn_timeout` (see [timeouts](#turns-timeouts-and-continuation)), `turn_failed` and `turn_cancelled` (the turn's own end), `port_exit: exit code N, before the <method> response` (the server exited while a request waited for its answer), `port_exit: exit code N, no turn result` (it exited during the turn) and `port_exit: the app server of this session is gone, turn N cannot start on thread <id>`.
Expand Down
15 changes: 14 additions & 1 deletion docs/spec-decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3143,10 +3143,23 @@ A `runner_unavailable` from an exhausted Gemini quota carried no retry key Loop
- **Classified on structured fields.** A Google error object anywhere in the error data, a JSON body inside a string field included, maps to `runner_unavailable` when its `status` is `RESOURCE_EXHAUSTED` or an `ErrorInfo` reason is `QUOTA_EXHAUSTED`. The quota message alone is free text and classifies nothing, as since `m4-08`.
- **Wait.** An explicit retry key of the error data comes first, as before. Else the first valid positive value of `quotaResetTimeStamp` minus now, `quotaResetDelay`, `retryDelay` (any depth), then the message text, becomes `TurnFailed.retryAfter`, in Google's duration format. A past timestamp or an unparsable value is skipped. `RunnerHold` is unchanged: it already takes a `retryAfter` longer than its backoff as the period, so one probe runs at the reset.
- **Telemetry.** The turn emits the `rate_limit` event of the Codex runner with `limit_id` `gemini`, the model as `limit_name` and `reached` `quota_exhausted`. `RunnerEvent.RateLimit.Window` needs a used percent that `agy` never reports, so the event carries no window and the reset instant goes in the `turn_failed` reason, `...; the quota resets at <instant>`, rather than a `plugin-api` change.
- **Redaction.** Only the reset time and a plain model id are read from the error, so no account id, email or token reaches the event or the reason. The raw JSON-RPC line is still echoed as runner output, like every protocol line.
- **Redaction.** Only the reset time and a plain model id are read from the error, so no account id, email or token reaches the event or the reason. The JSON-RPC line is echoed as runner output without its error data since [bl-240](#error-responses-in-runner-output-extension-bl-240).

Tests: `plugins/runner-acp/src/test/kotlin/loop/runner/acp/AcpQuotaResetTest.kt` (from the logged 429 body: details in the error data, the body nested in a string, an array body in a string, the message text only, a past timestamp, an unparsable value, no reset at all, an explicit retry key first, the duration format, and through the fake server the `rate_limit` event and `retryAfter` of a prompt error), `spec-core/src/test/kotlin/loop/core/orchestrator/RunnerHoldTest.kt` (`bl-215 an exhausted Gemini quota holds until its reset time, not the 1 minute backoff`).

### Error responses in runner output (extension, bl-240)

The acp and codex-app-server runners echoed every stdout line as runner output before decoding it, and the orchestrator's `SecretRedactor` knows only learned env secrets and token patterns. So the `data` of a JSON-RPC error response, such as the Google body of an exhausted Gemini quota with its `consumer` account id and an email, reached the event store, the attempt record file, `loop show` and the run observer. The decisions (`AcpFraming.echo` in `plugins/runner-acp`, `ProtocolFraming.echo` in `plugins/runner-codex-app-server`):

- **Rule.** A stdout line that decodes as an error response is echoed as its `jsonrpc` and `id` members (each only when the line has it), its `code` and `message`, and `"data":"[error data omitted, N chars]"`, N the length of the omitted values as compact JSON. Omitted means the error's `data` and any other member of the error besides `code` and `message`, and any member of the envelope besides `jsonrpc`, `id` and `error`, since a provider body can sit there too. An error with nothing else, or only null members, is echoed as read.
- **The frame keeps the data.** Only the echo is rewritten: the decoded frame the runner reads keeps the whole error, so bl-215's `rate_limit` event, `retryAfter` and `turn_failed` reason are read as before. The `turn_failed` reason already names only the code and the message.
- **Every other line is echoed as read,** byte for byte: requests, notifications, success responses, a line that is not a protocol message and every stderr line. A line drained after a kill follows the same rule.
- **One function per runner.** The two runners share only `plugins/runner-process`, which has no JSON dependency, so each framing has its own small `echo` with the same rule rather than a JSON dependency on the process launcher.
- **Not the claude-code runner.** Claude Code's stream-json carries no JSON-RPC frames. A failed API call is a `result` line with `is_error` whose `result` text quotes the Anthropic error body, `{"type":"error","error":{"type":...,"message":...}}`, and its `rate_limit_event` lines carry windows, statuses and reset times: neither has an account id or an email field, so its lines stay echoed as read and it has no test of its own. A runner whose provider bodies gain account fields takes the same rule.
- **Not the redactor.** A general email or account id pattern in `SecretRedactor` would touch every writer, git output included, so the runners leave the data out instead.

Tests: `plugins/runner-acp/src/test/kotlin/loop/runner/acp/AcpFramingTest.kt` and `plugins/runner-codex-app-server/src/test/kotlin/loop/runner/codex/ProtocolFramingTest.kt` (the `bl-240` tests: the data and the extra members omitted, every other line echoed byte for byte), `AcpQuotaResetTest.kt` (`bl-240 the echo of the quota error omits its data, the frame still gives rate_limit and the reason`), `CodexAppServerRunnerTest.kt` (`bl-240 the echo of an error answer omits its data, other lines are echoed as read`).

### Claude Code rate limits (extension, bl-209)

Conformance 17.5 item 13 asks a runner to extract rate limit telemetry; the Codex runner did since [m3-21](#codex-runner-usage-rate-limits-and-cost-m3-21), the Claude Code runner dropped its rate limit lines. Claude Code writes `{"type":"rate_limit_event","rate_limit_info":{...}}` lines in its stream: a `status` (`allowed`, `allowed_warning`, `rejected`), the `rateLimitType` and `resetsAt` of the window that status is about, the overage fields, and `unifiedWindows`, each window by name with its `utilization` (0 to 1), `resetsAt` (Unix seconds) and `status`. The recorded lines of `real_two_turns_one_process.jsonl` and `wake_turns_10c2f759.jsonl` name only `seven_day`. The decisions (`ClaudeRateLimits` in `plugins/runner-claude-code`):
Expand Down
33 changes: 33 additions & 0 deletions plugins/runner-acp/src/main/kotlin/loop/runner/acp/AcpFraming.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,36 @@ object AcpFraming {
return AcpFrame.Malformed(line, "not a JSON-RPC message")
}

/**
* The text runner output echoes for the stdout line of [frame] (bl-240). An error response's `data`, and any member
* besides `code` and `message` in its error or besides `jsonrpc`, `id` and `error` in its envelope, can hold a
* provider's error body with account fields, so it is echoed as `jsonrpc` and `id` (as the line had them), `code`,
* `message` and a `data` marker, `[error data omitted, N chars]`, N the length of the omitted values as compact JSON.
* Every other line, an undecodable one included, is echoed as read. The frame itself keeps the data.
*/
fun echo(frame: AcpFrame): String {
if (frame !is AcpFrame.Error) return frame.line
val envelope = json.parseToJsonElement(frame.line) as JsonObject
val error = envelope.getValue("error") as JsonObject
// A null member carries nothing to omit.
val omitted =
(envelope.filterKeys { it !in ENVELOPE_KEPT }.values + error.filterKeys { it !in ERROR_KEPT }.values)
.filterNot { it is JsonNull }
if (omitted.isEmpty()) return frame.line
return buildJsonObject {
envelope["jsonrpc"]?.let { put("jsonrpc", it) }
envelope["id"]?.let { put("id", it) }
put(
"error",
buildJsonObject {
put("code", error.getValue("code"))
put("message", error.getValue("message"))
put("data", "[error data omitted, ${omitted.sumOf { it.toString().length }} chars]")
},
)
}.toString()
}

/** Encodes a JSON-RPC 2.0 request line, terminated with `\n`. */
fun request(
id: Long,
Expand Down Expand Up @@ -197,6 +227,9 @@ object AcpFraming {
)
}.toString() + "\n"

private val ENVELOPE_KEPT = setOf("jsonrpc", "id", "error")
private val ERROR_KEPT = setOf("code", "message")

private fun isValidId(id: JsonElement): Boolean {
val primitive = id as? JsonPrimitive ?: return false
return primitive.isString || primitive.longOrNull != null
Expand Down
Loading