File size: 6,975 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | # Stack Logs
Reference for the Stack Logs tool: compose-stack log discovery and bounded retrieval for top-level agents.
## Purpose
- Give the top-level agent a safe way to read logs of the entire Docker Compose stack without direct Docker socket access from the `oxide_agent` process.
- Return bounded JSON instead of raw log dumps, so memory and progress UI are not inflated.
- Support service selection, time windows, and cursor-based line-by-line pagination.
## Tools
Two tools with separate semantics:
| Tool | Purpose |
|------|---------|
| `stack_logs_list_sources` | List available services and containers in the selected compose stack. |
| `stack_logs_fetch` | Fetch a bounded, normalized log stream by time window or cursor. |
### `stack_logs_list_sources`
Arguments:
```json
{
"selector": {
"compose_project": "oxide-agent"
},
"services": ["oxide_agent", "crw"],
"include_stopped": false
}
```
- `selector` — optional; `compose_project` overrides the stack selection for this call.
- `services` — optional; when omitted, all services in the selected stack are returned.
- `include_stopped` — default `false`.
Response:
```json
{
"stack_selector": {
"compose_project": "oxide-agent"
},
"containers": [
{
"service": "oxide_agent",
"container_name": "oxide_agent",
"container_id": "abc123def456",
"state": "running",
"started_at": "2026-04-02T10:11:12Z"
}
]
}
```
### `stack_logs_fetch`
Arguments:
```json
{
"selector": {
"compose_project": "oxide-agent"
},
"services": ["oxide_agent", "sandboxd"],
"since": "2026-04-02T10:00:00Z",
"until": "2026-04-02T10:10:00Z",
"cursor": {
"ts": "2026-04-02T10:03:04.500Z",
"service": "oxide_agent",
"stream": "stdout",
"ordinal": 17
},
"max_entries": 200,
"include_noise": false,
"include_stderr": true
}
```
- `selector` — optional; same as in `list_sources`.
- `services` — optional; when omitted, all services in the selected stack are read.
- `since` / `until` — RFC3339 timestamps. If both are set, `since` must be ≤ `until`.
- `cursor` — optional; returned by a previous `fetch` call for continuation without duplicates.
- `max_entries` — default `200`, hard max `500`. Values of `0` are clamped to `1` with a warning.
- `include_noise` — default `false`.
- `include_stderr` — default `true`.
Response:
```json
{
"window": {
"since": "2026-04-02T10:00:00Z",
"until": "2026-04-02T10:10:00Z"
},
"entries": [
{
"ts": "2026-04-02T10:03:04.500Z",
"service": "oxide_agent",
"container_name": "oxide_agent",
"stream": "stdout",
"ordinal": 17,
"message": "retrying LLM request after rate limit"
}
],
"suppressed": [
{
"reason": "exact_duplicate_burst",
"count": 12
}
],
"truncated": false,
"next_cursor": {
"ts": "2026-04-02T10:03:04.500Z",
"service": "oxide_agent",
"stream": "stdout",
"ordinal": 18
},
"warnings": []
}
```
## Stack selector
Three-level resolution, in priority order:
1. **Per-request override** — `selector.compose_project` in the tool arguments.
2. **Environment variable** — `STACK_LOGS_PROJECT`.
3. **Runtime detection** — the sandboxd container's `com.docker.compose.project` Docker label, looked up via `HOSTNAME` → `inspect_container`.
If none resolve, the call fails with an error (see Error handling).
Docker Compose wiring sets `STACK_LOGS_PROJECT=${COMPOSE_PROJECT_NAME:-oxide-agent}` in `docker-compose.yml`.
Arbitrary label selectors are not supported.
## Cursor contract
Cursor key: `ts`, `service`, `stream`, `ordinal` — all required.
Merge order for cross-container pagination:
1. `ts`
2. `service`
3. `stream`
4. `ordinal`
Timestamp alone does not guarantee stable pagination when log timestamps collide. Ordinals are assigned per `(service, stream)` after sorting and noise filtering, making the cursor unambiguous.
## Noise policy
When `include_noise=false`, three classes are suppressed:
- **Empty lines** — `reason: "empty_line"`.
- **Health/readiness probe chatter** — messages mentioning endpoints (`/health`, `/healthz`, `/ready`, `/readyz`, `/readiness`, `/live`, `/livez`) alongside keywords (`get`, `head`, `healthcheck`, `kube-probe`, `probe`). `reason: "health_probe_chatter"`.
- **Exact duplicate bursts** — same `service`, `container_name`, `stream`, and `message` within 1 second of the previous kept entry. `reason: "exact_duplicate_burst"`.
Suppressed entries are never lost silently: the tool always returns `suppressed` counters with reasons and counts. Semantic summarization, clustering, and LLM rewrite are not performed.
## Access policy
- **Top-level agents** — full access.
- **Sub-agents** — blocked; both tool names are always unavailable to sub-agents.
- **Topic agents** — blocked by default; can be enabled explicitly through the manager control plane using the provider alias `"stack_logs"` or `"logs"`.
Prompt composer exposes a guidance group under alias `"stack_logs"` instructing the agent to call `list_sources` before `fetch`.
## Error handling
The provider does not fail tool calls on backend errors. Instead, it returns a JSON object:
```json
{ "error": "Unable to resolve compose project for stack log discovery; set STACK_LOGS_PROJECT or run sandboxd inside a Docker Compose deployment" }
```
Key error conditions:
| Condition | Message |
|-----------|---------|
| Unresolvable compose project | `Unable to resolve compose project for stack log discovery; set STACK_LOGS_PROJECT or run sandboxd inside a Docker Compose deployment` |
| `HOSTNAME` unavailable for runtime detection | `Unable to resolve compose project for stack log discovery automatically: HOSTNAME is unavailable; set STACK_LOGS_PROJECT` |
| Container missing compose label | `Unable to resolve compose project for stack log discovery automatically: current sandboxd container is missing label '...'; set STACK_LOGS_PROJECT` |
| Inverted time window | `Invalid stack log time window: 'since' must be earlier than or equal to 'until'` |
| All sources failed, no entries | `Failed to fetch logs for {service} ({container_name}): {error}` (joined with `; `) |
Warnings (non-fatal, returned in the `warnings` array):
- `max_entries=0` clamped to `1`: `Requested max_entries=0 is invalid; using 1`
- `max_entries>500` clamped to `500`: `Requested max_entries={n} exceeds hard limit 500; using 500`
- Unparsable log lines: `Skipped {n} unparsable timestamped log lines from {service} ({container_name})`
- Per-source fetch failures (when at least some entries were still collected from other sources)
## Configuration
| Variable | Purpose |
|----------|---------|
| `STACK_LOGS_PROJECT` | Optional compose project name override. Set in Docker Compose files to `${COMPOSE_PROJECT_NAME:-oxide-agent}`. |
No YAML config keys. Stack selection is purely env + per-request `selector.compose_project`.
|