Skip to content

fix(gateway): make CLI shutdown prompt#1215

Open
ymote wants to merge 1 commit into
mainfrom
fix/gateway-cli-shutdown-381
Open

fix(gateway): make CLI shutdown prompt#1215
ymote wants to merge 1 commit into
mainfrom
fix/gateway-cli-shutdown-381

Conversation

@ymote

@ymote ymote commented May 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Recognize quit and exit as gateway CLI exit commands alongside /quit, /exit, and :q, so bare exit words are not dispatched as chat.
  • Wire the CLI channel to the gateway shutdown Notify so Ctrl-C/runtime shutdown wakes the stdin loop promptly.
  • Bound CLI actor shutdown to the prompt timeout path and exit after successful run_async() return to avoid Tokio stdin teardown holding the terminal.

Closes #381

Current-main refresh

  • Refreshed onto origin/main f6936c452389c5172496ee0c3e13393956086d92.
  • Head: a9fb8c6787605ac13d8cdc368ab90c9264bbdf12.
  • Isolated checkout: /private/tmp/octos-1393-f693.c8Xuzv/octos.
  • Root dirty checkout preserved; all branch work stayed in the isolated clone.
  • Environment: rustc 1.95.0 (59807616e 2026-04-14), cargo 1.95.0 (f2d3ce0bd 2026-03-21), Darwin 25.5.0 arm64.
  • Artifacts: Cargo/build output and smoke runtime dirs only under /private/tmp; git ls-files --others --exclude-standard was empty in the isolated checkout.

Validation

  • git diff --check origin/main...HEAD passed.
  • cargo fmt --all -- --check passed.
  • touched-file rustfmt --check passed.
  • touched-file typos passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-f693-target-bus CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo test -p octos-bus --lib recognizes_gateway_exit_commands -- --nocapture passed: 1/1.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-f693-target-cli CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo test -p octos-cli --features api --lib cli_shutdown_timeout_stays_prompt -- --nocapture passed: 1/1.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-f693-target-clippy CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo clippy --workspace --all-targets -- -D warnings passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-f693-target-cli CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo build -p octos-cli --features api --bin octos passed.
  • PTY smoke, bare quit: /usr/bin/expect spawned octos gateway --cwd /private/tmp/... --data-dir /private/tmp/... --provider ollama --model llama3.2, waited for Gateway ready, sent quit, observed Gateway stopped., and reached EOF within a 10s timeout.
  • PTY smoke, Ctrl-C: /usr/bin/expect spawned the same non-production gateway path, waited for Gateway ready, sent Ctrl-C, observed Shutting down gateway..., observed Gateway stopped., and reached EOF within a 10s timeout.

CI / merge status

  • GitHub CI is green on refreshed head a9fb8c6787605ac13d8cdc368ab90c9264bbdf12: check, check-matrix, dashboard, swarm-app, test-octos-agent (lib), test-octos-agent (integration), test-octos-cli, typos, and author-email passed. Optional expansion jobs were skipped.
  • Merge remains branch-protection blocked by required review (reviewDecision=REVIEW_REQUIRED).

@ymote ymote requested a review from bobdingAI May 28, 2026 11:34
@ymote

ymote commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Current-main validation refresh for #381.

Scope validated:

  • Base/current main: 1fb4c88e020242d82cee245b331798ed6dc551e7
  • PR head: 739a9c165c45ee99db6e3e9608986b937f1398e3
  • Local rehearsal merge: c26a3db7fbe378af95a6c32e8591e9a49afcb6af
  • Rehearsal clone: /private/tmp/octos-1215-current-e1Tm5m (standalone clone; root checkout left untouched)
  • Changed files: crates/octos-bus/src/cli_channel.rs, crates/octos-cli/src/commands/gateway/adapters/cli.rs, crates/octos-cli/src/commands/gateway/adapters/mod.rs, crates/octos-cli/src/commands/gateway/gateway_runtime.rs, crates/octos-cli/src/commands/gateway/mod.rs

Commands run:

  • git fetch https://github.com/octos-org/octos.git pull/1215/head
  • git merge --no-edit FETCH_HEAD clean on current local main
  • git diff --check origin/main...HEAD
  • rustfmt --check crates/octos-bus/src/cli_channel.rs crates/octos-cli/src/commands/gateway/adapters/cli.rs crates/octos-cli/src/commands/gateway/adapters/mod.rs crates/octos-cli/src/commands/gateway/gateway_runtime.rs crates/octos-cli/src/commands/gateway/mod.rs
  • cargo fmt --all -- --check
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-bus-target CARGO_INCREMENTAL=0 cargo test -p octos-bus --lib recognizes_gateway_exit_commands -- --nocapture
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-cli-target CARGO_INCREMENTAL=0 cargo test -p octos-cli --lib cli_shutdown_timeout_stays_prompt -- --nocapture
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-bus-target CARGO_INCREMENTAL=0 cargo test -p octos-bus --lib
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-cli-target CARGO_INCREMENTAL=0 cargo test -p octos-cli --lib
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-bus-clippy-target CARGO_INCREMENTAL=0 cargo clippy -p octos-bus --lib --no-deps
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-cli-clippy-target CARGO_INCREMENTAL=0 cargo clippy -p octos-cli --features "api,telegram,discord,whatsapp,feishu,twilio,wecom,wecom-bot,audio_mp3" --lib --no-deps
  • git ls-files --others --exclude-standard

Results:

  • Rehearsal merge was clean.
  • git diff --check passed.
  • Touched Rust files passed rustfmt --check.
  • Focused tests passed: recognizes_gateway_exit_commands and cli_shutdown_timeout_stays_prompt.
  • Broad library tests passed: octos-bus 186/186; octos-cli 481/481 with 2 ignored macOS Keychain tests.
  • Both clippy commands exited 0 with existing warnings.
  • git ls-files --others --exclude-standard returned empty in the rehearsal clone.
  • Environment: Darwin 25.5.0 arm64, rustc 1.95.0, cargo 1.95.0.

Current-main blocker found:

  • Full cargo fmt --all -- --check fails outside this PR diff on current-main formatting drift in:
    • crates/octos-agent/src/agent/loop_runner.rs
    • crates/octos-agent/src/loop_detect.rs
    • crates/octos-cli/src/api/ui_protocol_ledger.rs
  • The touched files for this PR passed formatting.

Issue fit:

  • Bare quit and exit now match CLI exit commands alongside /quit, /exit, and :q.
  • CLI shutdown notification wakes the stdin path, and CLI shutdown uses the prompt timeout path instead of waiting on the full actor grace period.

Remaining gap:

  • GitHub reports this PR as MERGEABLE but REVIEW_REQUIRED / BLOCKED, so I did not merge.

@ymote

ymote commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Validation evidence for #1215 against current main.

Scope checked:

  • CliChannel::is_exit_command recognizes quit, exit, /quit, /exit, and :q, including trimmed/case-insensitive input.
  • CLI channel shutdown now stores the shutdown flag and notifies waiters so the stdin loop can break promptly when shutdown is requested elsewhere.
  • CLI adapter registration wires the shared shutdown Notify into the CLI channel.
  • Gateway shutdown uses a one-second CLI_SHUTDOWN_TIMEOUT for actor shutdown before forcing exit progress.
  • Successful octos gateway execution exits the process after run_async() returns, avoiding Tokio stdin runtime teardown holding the terminal open.

SHAs:

  • current main: 1fb4c88e020242d82cee245b331798ed6dc551e7
  • PR head: 739a9c165c45ee99db6e3e9608986b937f1398e3
  • local rehearsal merge: 8e0d269ad808795ab758738b8b690d9e37c8d61a

Environment:

  • rustc 1.95.0 (59807616e 2026-04-14)
  • cargo 1.95.0 (f2d3ce0bd 2026-03-21)
  • node v24.10.0
  • npm 11.6.0
  • Darwin 25.5.0 arm64

Commands run:

  • git diff --check origin/main...HEAD passed.
  • rustfmt --check crates/octos-bus/src/cli_channel.rs crates/octos-cli/src/commands/gateway/adapters/cli.rs crates/octos-cli/src/commands/gateway/adapters/mod.rs crates/octos-cli/src/commands/gateway/gateway_runtime.rs crates/octos-cli/src/commands/gateway/mod.rs passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target CARGO_INCREMENTAL=0 cargo test -p octos-bus cli_channel::tests -- --nocapture passed: 1 passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target CARGO_INCREMENTAL=0 cargo test -p octos-cli --features api cli_shutdown_timeout_stays_prompt -- --nocapture passed: 1 passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target CARGO_INCREMENTAL=0 cargo check -p octos-bus passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target CARGO_INCREMENTAL=0 cargo check -p octos-cli --features api passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target CARGO_INCREMENTAL=0 cargo clippy -p octos-bus --lib --no-deps passed.
  • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-1fb4-test-target-cli-clippy CARGO_INCREMENTAL=0 cargo clippy -p octos-cli --features api --lib --no-deps exited 0; current warning-level clippy output remains non-fatal.
  • git status --short --branch in the rehearsal clone was clean apart from ## main...origin/main [ahead 2]; no untracked files.

Artifacts:

  • Cargo target dirs: /private/tmp/octos-1215-current-1fb4-test-target, /private/tmp/octos-1215-current-1fb4-test-target-cli-clippy
  • No generated artifacts were left untracked in the clone.

Remaining gaps / gates:

  • I did not run an interactive PTY smoke of octos gateway; validation here is unit/compile/code-inspection coverage for the CLI exit and shutdown paths.
  • cargo fmt --all -- --check still fails on current-main files outside this PR diff: crates/octos-agent/src/agent/loop_runner.rs, crates/octos-agent/src/loop_detect.rs, and crates/octos-cli/src/api/ui_protocol_ledger.rs.
  • GitHub reports mergeable: MERGEABLE, mergeStateStatus: BLOCKED, reviewDecision: REVIEW_REQUIRED; merge is branch-protection blocked until required review lands.

@ymote ymote force-pushed the fix/gateway-cli-shutdown-381 branch from 739a9c1 to f6d2ccd Compare May 30, 2026 20:38
@ymote

ymote commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed this #381 closure PR onto current origin/main.

Evidence:

  • base: 4b6d7218b14e91ece68ecde1ca10216975baea58
  • head: f6d2ccd38becf294a2831b8e448b1beefd9de7df
  • isolated checkout: /Users/yuechen/home/octos/target/octos-1215-refresh-current-wLfZI8/octos
  • diff shape: gateway CLI exit/shutdown fix plus shared current-main fmt/clippy cleanup; no generated artifacts
  • local validation passed:
    • git diff --check origin/main...HEAD
    • cargo fmt --all -- --check
    • git ls-files --others --exclude-standard (empty)
    • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-target CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo test -p octos-bus --lib recognizes_gateway_exit_commands -- --nocapture (1 passed)
    • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-target CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo test -p octos-cli --features api --lib cli_shutdown_timeout_stays_prompt -- --nocapture (1 passed)
    • CARGO_TARGET_DIR=/private/tmp/octos-1215-current-target CARGO_INCREMENTAL=0 CARGO_PROFILE_DEV_DEBUG=0 cargo clippy --workspace --all-targets -- -D warnings

The PR still carries Closes #381; closure should happen through merge after required review and refreshed CI.

@ymote

ymote commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed CI is green at head f6d2ccd38becf294a2831b8e448b1beefd9de7df on base 4b6d7218b14e91ece68ecde1ca10216975baea58.

Required jobs succeeded: dashboard, reject blocked author/committer emails, swarm-app, typos, check, test-octos-agent (lib), test-octos-agent (integration), test-octos-cli, and check-matrix. Conditional platform/package/e2e/security jobs were skipped by workflow conditions.

Merge remains blocked only by required review (mergeable=MERGEABLE, mergeStateStatus=BLOCKED, reviewDecision=REVIEW_REQUIRED). The PR still carries Closes #381, so #381 should close automatically after review and merge.

@ymote ymote force-pushed the fix/gateway-cli-shutdown-381 branch 2 times, most recently from 5744aec to 7b84f33 Compare June 2, 2026 04:16
@ymote ymote force-pushed the fix/gateway-cli-shutdown-381 branch from 7b84f33 to a9fb8c6 Compare June 2, 2026 13:03
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.

Gateway CLI hangs on exit after Ctrl-C

1 participant