Skip to content

feat(exec): write background exec output to a file named in the exit wake - #199992

Merged
obviyus merged 2 commits into
mainfrom
exec-output-file
Nov 16, 2026
Merged

obviyus merged 2 commits into
mainfrom
exec-output-file

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

A background exec now writes its full output to a file. The exit wake gives the agent the file path, so the agent can read only the part that it needs with read. No output is lost at the 200k in-memory cap.

  • A Gateway-host exec writes stdout and stderr, in arrival order, to one owner-only file while it runs.
  • The exit wake ends with Full output: <path> (<N> bytes) when it omits output. The wake no longer says "process log has the rest" for these commands.
  • A foreground result or a process poll/log result that lost output at the in-memory cap names the same file, instead of "earlier output was discarded".
  • The in-memory window and tail for process poll/log do not change.

Design: reuse the existing spill storage

  • The file uses the web_fetch record-time spill location: private-temp-file.ts, OS temp directory, 0600, random name, exclusive create. openPrivateTempFileStream is a streamed variant beside writePrivateTempFile.
  • Retention is the same as for web_fetch spill files: the OS temp-directory cleanup. The file survives a Gateway restart.
  • The footer is the shared formatFullOutputFooter, and foreground results set details.fullOutputPath. Thus the existing record-time truncation in tool-result-truncation.ts keeps the path visible when it cuts the result.
  • One render function (renderExecOutputFile) owns the path text for the wake, the foreground result and the process log.
  • Hard limit: 64 MiB per file (EXEC_OUTPUT_FILE_MAX_BYTES). Later output is discarded and the footer says so. Documented in docs/tools/exec.md.
  • OpenClaw keeps the file only when a result or wake omits some of its output. Otherwise the file is removed at exit.
  • No DB table, no schema or stored-row change, no protocol change.

Not covered (today's behavior stays)

  • Sandbox exec: a sandboxed read cannot reach host temp files. No file; the wake keeps today's text.
  • Node exec: runs on another machine through its own path. No file; the wake keeps today's text.
  • Durable exec: already keeps its own log artifact. No new file.
  • tools.fs.workspaceOnly: read cannot reach the temp directory. This is the same limit as for web_fetch spill files. The agent can read the file with exec.
  • Foreground output cut only by the model result budget (under 200k): no file. That cut happens at record time, after the process ends; adding it there is not trivial.

Proof

Tier: source (ocx src, scratch Gateway, scripted OpenAI-compatible model). A background command prints FIRST_LINE_MARKER, 500,000 x, then LAST_LINE_MARKER, and exits. The scripted model reacts to the exit wake: if it finds Full output: <path>, it calls read with limit: 1.

Base (e9c805458136, merge base):

-- model request: wake-without-path
Exec completed (…, code 0, 3s), last 2000 of 500036 output chars (process log keeps the last 200000; earlier output was discarded):
xxxx…
LAST_LINE_MARKER

Head:

-- model request: wake-with-path
Exec completed (…, code 0, 3s), last 2000 of 500036 output chars:
xxxx…
LAST_LINE_MARKER
Full output: <tmp>/openclaw-exec-7be8d1051799b5b6.log (500036 bytes)
-- model request: read-result
FIRST_LINE_MARKER

[2 more lines in file. Use offset=2 to continue.]
file: bytes=500036 first=FIRST_LINE_MARKER last=LAST_LINE_MARKER mode=600
  • The files of both head runs were still present after their scratch Gateways stopped.
  • Tier vitest-source (ocx test):
    • bash-tools.exec-background-followup.test.ts: the wake text and path, and a 500,010-char background output that is complete in the file.
    • bash-tools.exec-runtime.test.ts: a timeout wake after the 1,000-char cap; the file has all of the output.
    • session-tool-result-guard.test.ts, bash-tools.process.poll-timeout.test.ts: unchanged behavior.
  • pnpm tsgo:core, pnpm check:test-types, oxlint and oxfmt pass.
  • Tier full: ocx build --dts passes; node dist/entry.js --version prints OpenClaw 2026.11.3 (076dc6c).

…wake

A Gateway-host exec now writes all stdout and stderr, in order, to an
owner-only temp file (the web_fetch spill location and retention) up to a
64 MiB hard limit. The exit wake ends with 'Full output: <path> (<N> bytes)'
when it omits output, and a foreground result or process log that lost
output at the 200k in-memory cap names the same file. Sandbox, node and
durable commands keep today's behavior.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Nov 16, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Gateway-host exec commands save output in private temporary files and expose recovery paths when wakes or results omit output.

Example: A background command prints FIRST_LINE_MARKER, 500,000 characters, and LAST_LINE_MARKER.

  • Before: The wake includes the last 2,000 characters, while the 200,000-character memory cap permanently loses FIRST_LINE_MARKER.
  • After: The wake names a 500,036-byte file, and a subsequent read retrieves FIRST_LINE_MARKER.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Useful and supported by production-entry-point traces; both previous blockers are resolved, with broad validation still running.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The supplied isolated source-Gateway run uses a scripted provider to exercise background exec, exit-wake delivery, and a subsequent read of the saved first line; the follow-up changes preserve that capture path and repair wrapper closure and partial-file metadata.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: An agent cannot recover the beginning of a verbose background command after the in-memory retention cap discards it.
Reason: Recoverable output avoids rerunning commands, and the collaborator-authored direction reuses established artifact storage with documented limits.

Merge readiness

✅ Ready for maintainer review

This PR provides useful output recovery, fixes both earlier review findings, and has no new actionable defect identified; checks for the reviewed head remain pending.

Priority: P2
Reviewed head: 143113e4e00f885e73275bfe2cd88f5fd1fa1626

Before merge

None.

Findings

None.

Agent review details

How this fits together

The exec runtime captures command output, the process registry retains bounded memory windows, and completion notifications and process tools expose results to the agent.

flowchart TD
  A[Gateway exec command] --> B[Output capture]
  B --> C[Bounded process memory]
  B --> D[Private output file]
  C --> E[Exit settlement]
  D --> E
  E --> F[Wake or tool result]
  F --> G[Agent reads saved output]
Loading

Technical review

Best possible solution:

Keep streamed capture with the existing private-file owner and shared footer contract, preserving bounded memory and explicit partial-file disclosure.

Do we have a high-confidence way to reproduce the issue?

Current-main source retains only bounded output, and the supplied paired Gateway traces demonstrate loss and recovery of the first marker; no target code was executed during this review.

Is this the best way to solve the issue?

The change uses the existing process lifecycle, private temporary-file location, and spill-footer contract without adding another storage manager or changing sandbox and remote-node behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b3ee20852674.

Provenance checked

  • Exit-wake output rendering keeps the original intent (00636f0: Carry a bounded result in the completion wake so the resumed agent can act without polling.)
  • Retention-loss disclosure changes intended behavior with a stated reason (be67a8b: Lead with disclosure of irrecoverable output loss so later result caps cannot conceal it.)
  • Exit settlement ordering keeps the original intent (9ccfc7d: Settle process bookkeeping and notification work before releasing process-scope joins.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +120, Tests +48, Docs +2, Other +1. Total +171 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 143 23 +120
Tests 3 61 13 +48
Docs 2 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 16 209 38 +171

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +143/-23; tests +61/-13 Production growth implements bounded streaming, settlement, and shared recovery rendering within existing owners; tests extend output-recovery and partial-file coverage.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Recovering omitted background-command output is a useful, limited-scope improvement without an urgent runtime regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-16T06:03:44.516Z sha 076dc6c :: needs changes before merge. :: [P2] Include the new runtime dependency in the PR wrapper inventory | [P2] Preserve the partial-file flag in foreground result metadata

Reviewed November 16, 2026, 1:17 AM ET / 06:17 UTC (Revision 2).

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Review findings at 143113e:

  • Wrapper inventory: src/agents/sessions/tools/tool-contracts.ts is now in scripts/pr-lib/wrapper-components.txt (type-only imports, so the closure stays closed). test/scripts/eager-import-closure.test.ts passes. The exec-output.ts type import of the process registry is removed, which also clears the madge cycle.
  • Partial-spill elision (fix(agents): preserve spill-file pointers through elision and spill truncated web_fetch output #100135): a foreground result whose file reached the 64 MiB limit now sets the existing spillTruncated field. History elision keeps it marked partial and never calls it full output. New test in session-tool-result-guard.test.ts.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 16, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 16, 2026
@obviyus
obviyus merged commit 202514e into main Nov 16, 2026
136 checks passed
@obviyus
obviyus deleted the exec-output-file branch November 16, 2026 06:29
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 202514e. A background Gateway-host exec now writes its full output to a file. The exit wake names the file path and size, and read can return any part of it. Proof: a scratch Gateway with a scripted model, on the exact head. A 500,036-byte output gives a wake with Full output: <path> (500036 bytes), and read limit=1 returns the first line. On the base, that first line was lost at the 200k cap.

steipete added a commit that referenced this pull request Nov 16, 2026
Nested Vitest temp-path relocation could send the native-close capability probe outside the fixture guard. Its rejection disabled explicit close and caused hundreds of transcript-worker replacements during reload continuations. Select the owned temp root in the preload guard and remove the late reset.

Regression fails before the fix; 12 isolation tests, Node continuation/revocation product tests, and the exact Bun CI group pass at the unchanged timeout. check:changed passes except the exact-parent dead export introduced by #199992. Codex review is clean.
steipete added a commit that referenced this pull request Nov 16, 2026
…art (#200020)

* fix: recover saved Responses state and retry completion delivery after restart

* fix: preserve streamed replay bytes without repeated metadata parsing

* fix: scope saved argument replay to its source provider

* test: satisfy conditional braces in replay regression

* test(gateway): await steering admission before releasing tool

* fix(agents): retry returned saved-state delivery failures

* fix(agents): preserve delivery suppression before state repair

* fix(test): initialize guarded temp root before SQLite probes

Nested Vitest temp-path relocation could send the native-close capability probe outside the fixture guard. Its rejection disabled explicit close and caused hundreds of transcript-worker replacements during reload continuations. Select the owned temp root in the preload guard and remove the late reset.

Regression fails before the fix; 12 isolation tests, Node continuation/revocation product tests, and the exact Bun CI group pass at the unchanged timeout. check:changed passes except the exact-parent dead export introduced by #199992. Codex review is clean.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…wake (openclaw#199992)

## Summary

A background exec now writes its full output to a file. The exit wake gives the agent the file path, so the agent can read only the part that it needs with `read`. No output is lost at the 200k in-memory cap.

- A Gateway-host exec writes stdout and stderr, in arrival order, to one owner-only file while it runs.
- The exit wake ends with `Full output: <path> (<N> bytes)` when it omits output. The wake no longer says "process log has the rest" for these commands.
- A foreground result or a `process poll`/`log` result that lost output at the in-memory cap names the same file, instead of "earlier output was discarded".
- The in-memory window and tail for `process poll`/`log` do not change.

## Design: reuse the existing spill storage

- The file uses the `web_fetch` record-time spill location: `private-temp-file.ts`, OS temp directory, `0600`, random name, exclusive create. `openPrivateTempFileStream` is a streamed variant beside `writePrivateTempFile`.
- Retention is the same as for `web_fetch` spill files: the OS temp-directory cleanup. The file survives a Gateway restart.
- The footer is the shared `formatFullOutputFooter`, and foreground results set `details.fullOutputPath`. Thus the existing record-time truncation in `tool-result-truncation.ts` keeps the path visible when it cuts the result.
- One render function (`renderExecOutputFile`) owns the path text for the wake, the foreground result and the process log.
- Hard limit: 64 MiB per file (`EXEC_OUTPUT_FILE_MAX_BYTES`). Later output is discarded and the footer says so. Documented in `docs/tools/exec.md`.
- OpenClaw keeps the file only when a result or wake omits some of its output. Otherwise the file is removed at exit.
- No DB table, no schema or stored-row change, no protocol change.

## Not covered (today's behavior stays)

- **Sandbox exec:** a sandboxed `read` cannot reach host temp files. No file; the wake keeps today's text.
- **Node exec:** runs on another machine through its own path. No file; the wake keeps today's text.
- **Durable exec:** already keeps its own log artifact. No new file.
- **`tools.fs.workspaceOnly`:** `read` cannot reach the temp directory. This is the same limit as for `web_fetch` spill files. The agent can read the file with `exec`.
- **Foreground output cut only by the model result budget (under 200k):** no file. That cut happens at record time, after the process ends; adding it there is not trivial.

## Proof

Tier: **source** (`ocx src`, scratch Gateway, scripted OpenAI-compatible model). A background command prints `FIRST_LINE_MARKER`, 500,000 `x`, then `LAST_LINE_MARKER`, and exits. The scripted model reacts to the exit wake: if it finds `Full output: <path>`, it calls `read` with `limit: 1`.

Base (`2f1cec388d24`, merge base):

```text
-- model request: wake-without-path
Exec completed (…, code 0, 3s), last 2000 of 500036 output chars (process log keeps the last 200000; earlier output was discarded):
xxxx…
LAST_LINE_MARKER
```

Head:

```text
-- model request: wake-with-path
Exec completed (…, code 0, 3s), last 2000 of 500036 output chars:
xxxx…
LAST_LINE_MARKER
Full output: <tmp>/openclaw-exec-7be8d1051799b5b6.log (500036 bytes)
-- model request: read-result
FIRST_LINE_MARKER

[2 more lines in file. Use offset=2 to continue.]
file: bytes=500036 first=FIRST_LINE_MARKER last=LAST_LINE_MARKER mode=600
```

- The files of both head runs were still present after their scratch Gateways stopped.
- Exact head `143113e4` rerun: same result (`Full output: … (500036 bytes)`, `read` returns `FIRST_LINE_MARKER`).
- A foreground result whose file reached the 64 MiB limit sets `spillTruncated`, so history elision keeps it marked partial.
- Tier **vitest-source** (`ocx test`):
  - `bash-tools.exec-background-followup.test.ts`: the wake text and path, and a 500,010-char background output that is complete in the file.
  - `bash-tools.exec-runtime.test.ts`: a timeout wake after the 1,000-char cap; the file has all of the output.
  - `session-tool-result-guard.test.ts`, `bash-tools.process.poll-timeout.test.ts`: unchanged behavior.
- `pnpm tsgo:core`, `pnpm check:test-types`, oxlint and oxfmt pass.
- Tier **full**: `ocx build --dts` passes; `node dist/entry.js --version` prints `OpenClaw 2026.11.3` (first head).

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…art (openclaw#200020)

* fix: recover saved Responses state and retry completion delivery after restart

* fix: preserve streamed replay bytes without repeated metadata parsing

* fix: scope saved argument replay to its source provider

* test: satisfy conditional braces in replay regression

* test(gateway): await steering admission before releasing tool

* fix(agents): retry returned saved-state delivery failures

* fix(agents): preserve delivery suppression before state repair

* fix(test): initialize guarded temp root before SQLite probes

Nested Vitest temp-path relocation could send the native-close capability probe outside the fixture guard. Its rejection disabled explicit close and caused hundreds of transcript-worker replacements during reload continuations. Select the owned temp root in the preload guard and remove the late reset.

Regression fails before the fix; 12 isolation tests, Node continuation/revocation product tests, and the exact Bun CI group pass at the unchanged timeout. check:changed passes except the exact-parent dead export introduced by openclaw#199992. Codex review is clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant