Skip to content

feat!: add optional terminal and readiness callback to library run - #150

Merged
gautamsirdeshmukh merged 4 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/library-terminal-options
Oct 22, 2026
Merged

gautamsirdeshmukh merged 4 commits into
strands-agents:mainfrom
gautamsirdeshmukh:gsird-task/library-terminal-options

Conversation

@gautamsirdeshmukh

@gautamsirdeshmukh gautamsirdeshmukh commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Allow Rust applications to call strands_box::run() once while keeping their terminal UI responsive. The existing API lacks a separate workload terminal and a startup hook after signal registration, risking overlapping output and incomplete terminal cleanup.

Changes

  • Add RunOptions with an optional workload terminal and on_ready callback.
  • Invoke the callback after hardening and signal registration, before workload setup.
  • Existing callers must add Default::default() as the third argument.
  • Update the library example and test callback ordering/failure, terminal ownership, and signal cleanup.

Testing

  • Local macOS tests, Clippy, and formatting passed; tests caught five deliberately introduced regressions.
  • CI passed at 850764b2: Linux/macOS workspace tests, lint, containment, and native filesystem checks.

@gautamsirdeshmukh gautamsirdeshmukh changed the title Add optional terminal and readiness callback to library run feat!: add optional terminal and readiness callback to library run Oct 22, 2026
@gautamsirdeshmukh
gautamsirdeshmukh marked this pull request as ready for review October 22, 2026 14:48
Comment thread crates/box/src/command/mod.rs Resolved
Comment thread crates/box/src/run/contain/supervise.rs Resolved
@github-actions

Copy link
Copy Markdown

Process note (interface-frozen surface): strands_box::run and the public RunOptions type are part of the frozen strands-box surface described in AGENTS.md/CONTRIBUTING.md. This PR changes run's signature and adds a new public type — both observable by external callers — which is a feat! breaking change.

Suggestion: Please confirm the explicit pre-approval the freeze requires was obtained, and that the PR carries the appropriate API-review label. The description already names the caller-visible break (callers must add Default::default()), which is good; a brief line on why RunOptions is the chosen shape (vs. e.g. a builder or separate run_with entry point) would help the API reviewer evaluate the abstraction and its future extensibility.

@github-actions

Copy link
Copy Markdown

Issue: The "Use Box as a Rust library" section in README.md (around line 82) still shows the old two-argument form:

let exit_code = strands_box::run("/absolute/box.toml".into(), Vec::new());

After this change that call no longer compiles, and the surrounding prose ("It uses the process's terminal") no longer describes the new RunOptions { terminal, on_ready } behavior.

Suggestion: Update the README example to pass the third argument (e.g. Default::default()) and add a short note documenting RunOptions — what terminal and on_ready do and when a caller would supply them. The public library surface is the user-facing contract, so the docs should move with it.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Assessment: Request Changes

The core mechanism — gating signal registration/on_ready before workload setup, and handing the workload a caller-owned terminal via setsid+TIOCSCTTY while suppressing Box's own foreground claim and signal-disposition reset — is coherent and the isolate/die_with_parent refactor is clean. The blocking gaps are documentation and test coverage for a breaking change to a frozen surface.

Review themes
  • Docs drift: the README library example and prose still describe the old two-argument run and the old terminal behavior; they must move with the public API.
  • Test coverage: the new on_ready ordering/error-abort, terminal attachment, and restore_default = false paths are unverified in the suite — only manual host application checks are cited.
  • Safety documentation: the new unsafe pre_exec block breaks the file's convention of a // SAFETY: note, and its fd-0/ordering assumptions are implicit.
  • Process: confirm the frozen-interface approval and API-review label for the run signature change and new RunOptions type; a one-line rationale for the chosen shape would aid the API reviewer.
  • Minor: the on_ready failure message hardcodes "host terminal setup failed".

Nice refactor extracting die_with_parent so the terminal and isolation paths share the parent-death wiring.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Assessment: Comment (code findings resolved; one process item for a human to confirm)

Re-reviewed at d94e27d. The follow-up commit addresses every actionable item from the previous review:

Resolved
  • Docs: the README library example now passes the third argument and documents RunOptions::terminal / RunOptions::on_ready.
  • Safety docs: the new pre_exec block carries a // SAFETY: comment covering the stdio-before-hook and setsid→TIOCSCTTY ordering.
  • Error wording: now "on_ready callback failed: {source}".
  • Tests: box_library.rs gains real coverage — a --callback-error probe proves an Err from on_ready aborts with FAILURE before the config is read, and the in-callback assertions pin that hardening (core-dump limits 0,0) and signal registration (SIGINT/SIGTERM not SIG_DFL/SIG_IGN) have already run and that the callback precedes dispatch. That pins all three ordering claims.

Remaining, not blocking from a code standpoint:

  • The terminal attachment and restore_default = false paths still rely on manual host application verification (they need a real tty), which is reasonable to leave to manual testing; worth a one-line note in the PR as a deferred follow-up.
  • Process: the run signature change and new RunOptions type are on the frozen strands-box surface — a maintainer still needs to confirm the freeze approval and API-review label. This is a human gate, not something the diff can satisfy.

Nice work turning the ordering guarantees into executable assertions rather than prose.

gsird added 4 commits October 22, 2026 09:16
The host application must keep its banner responsive during one in-process Box run. The inherited terminal and blocking call do not provide the terminal routing or post-hardening startup point that its UI needs.

Add RunOptions with optional terminal and on_ready fields. Route the supplied terminal to the workload and invoke the callback after hardening and signal registration. Preserve parent-death protection and let the host finish terminal restoration after runtime teardown. Existing Rust callers must pass a third argument; default options preserve inherited stdio. The CLI flags and configuration schema do not change.

The host application build and all-features compilation passed on macOS. External terminal probes passed interactive shell and session launches, input, resizing, policy denial, shutdown, output draining, and terminal restoration. Headless input/output and a library callback-order probe passed. Changed-file formatting checks passed. No tests or comments are modified by request. Existing library test callers still use the old signature; full repository gates and Linux coverage remain deferred in this draft.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants