Skip to content

feat: require restart approval when agents are running - #4

Open
ivanmilevtues wants to merge 6 commits into
devfrom
restart-approval
Open

ivanmilevtues wants to merge 6 commits into
devfrom
restart-approval

Conversation

@ivanmilevtues

@ivanmilevtues ivanmilevtues commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Demonstrates a real cross-component feature from upstream anomalyco/opencode#55967, addressing upstream #43415 and #46322: restarting the background service can interrupt running agents without approval.

This is a runnable demo port for the CodeBoarding fork, not a claim of original authorship or a request to merge upstream work. Leave open for the architecture demo. Upstream is still under review.

Type of change

  • New feature
  • Bug fix
  • Documentation

What does this PR do?

Ask before restarting a server with active agents. The CLI requests approval, the server coordinates the decision, and the TUI offers Restart now, When idle, or Cancel restart. First resolution wins; unanswered requests expire so dialogs do not remain stuck. The CLI retains an explicit --force option.

Why this makes a useful architecture demo

19 files, +1,346 / −16, including 674 lines of tests. No dependency, lockfile, workflow, or baseline changes.

Verified generated result: open the architecture diff. CodeBoarding analysis succeeded.

Five top-level components are modified (10 components counting their five changed children):

Component Role in the feature
CLI Application and Scripts Requests approval and waits for the selected outcome
Terminal User Interface Presents active sessions and the approval choices
Server and Plugin Runtime Services Exposes restart endpoints and owns intent settlement/expiry
Protocol Route Specifications Defines the typed request/resolve contract
Frontend Applications and UI Clients Generated clients expose the new contract to callers

Comparing the exact base and head artifacts confirms two affected component relationships, both inside TUI:

  • New: Context Providers → Session & Home Routes, from RestartApprovalDialog calling the existing SessionQuestion UI.
  • Changed: App & Feature Plugins → Context Providers, with changed call evidence for event subscription.

There are no added or removed component boxes. New modules include server/src/restart-intent.ts, tui/src/context/restart-approval.tsx, and schema/src/service-event.ts, but CodeBoarding groups them within existing responsibilities. This is a cross-component change demo, not a new-component demo.

Demo walkthrough: start with the cross-component diff, follow the CLI request into the server's new intent service, inspect the TUI approval dependency, and explain how the selected decision returns through the shared API/events. Drill into the server and TUI rather than displaying every unrelated component.

Provenance

All six commits from upstream anomalyco#55967 were replayed with git cherry-pick -x, preserving @agustif's authorship and original commit references. Includes the upstream location-error prerequisite and follow-up expiry/race fixes. The patch applies cleanly to this fork's existing dev; no base-branch update is needed.

How did you verify your code works?

  • Installed with the repository-pinned Bun 1.4.2 and frozen lockfile.
  • bun run check: lint passed (warnings, no errors), all 36 typecheck tasks passed.
  • Server restart-intent tests: 6 passed.
  • CLI restart-approval tests: 12 passed.
  • TUI restart-approval and location-error tests: 6 passed.
  • Server auth, HTTP routing, event-feed, and session-create regression tests: 22 passed.
  • Regenerated clients with bun run generate in packages/client: no changes, confirming the checked-in generated contract matches.
  • git diff --check: passed.

Broader client tests (bun test test/effect.test.ts test/promise.test.ts) produce 46 passed / 3 failed, identically on unchanged origin/dev and this branch. The existing failures concern the Effect idle-date fixture, the integration API group inventory, and the session interrupt URL expectation. They are not introduced by this port; this PR does not claim the full test suite is green.

Tests exercise first-wins settlement, expiry, stale expiry tokens, cancellation, force bypass, waiting for idle, excluding the requesting session from the idle wait, disconnects during idle polling, and remote dismissal of TUI approval.

Screenshots / recordings

The production TUI dialog was rendered through the upstream fixture harness at 100×30 and 60×24 terminal sizes. This is fixture validation, not a claim of a live-server end-to-end restart test.

Checklist

  • I have tested my changes locally
  • Preserved upstream provenance
  • I have not included unrelated changes in this PR
  • Confirm final CodeBoarding component and edge counts after analysis

agustif and others added 6 commits November 5, 2026 20:31
(cherry picked from commit b68002d)
Co-authored-by: Ivan Milev <[email protected]>
(cherry picked from commit 9152632)
Co-authored-by: Ivan Milev <[email protected]>
- Release pending intents: CLI posts cancel on timeout and disconnect so
  connected TUIs never stay stuck on a dead request.
- Resolve only broadcasts on a fresh settlement; late resolvers replay the
  winner without re-emitting, and nothing pending returns 400.
- Subscribe to the resolved event before requesting an intent in both the
  CLI and the TUI, so a fast decision cannot be missed.
- Exclude the requesting session from the idle wait; it blocks on this
  command and could never drain.
- Keep the --force hint out of the non-interactive path so a blocked agent
  is not handed its own bypass.

(cherry picked from commit 80b3628)
Co-authored-by: Ivan Milev <[email protected]>
A requester that is interrupted or SIGKILLed (for example by the agent
shell tool's own timeout) never reaches its release path, so the pending
intent lived forever and every approver dialog stayed open, with a later
decision broadcast to nobody.

The server now owns release: each request schedules a detached expiry that
clears the intent and emits server.restart.expired, which approvers treat
as a dismissal. Generation tokens keep a stale timer from expiring a newer
request.

The CLI no longer posts its own cancel; expiry is the single release path,
and its local wait is longer than the server TTL so the server always ends
an unanswered wait.

(cherry picked from commit 8a5d47c)
Co-authored-by: Ivan Milev <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-05T20:34:25.349279Z
We couldn’t complete this review. Comment @codex review to try again.
57f3ddf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

CodeBoarding review

Status: 10 changed components

See the full change in CodeBoarding.

graph LR
    n_Frontend_Applications_and_UI_Clients["Frontend Applications and UI Clients"]
    n_Core_Agent_Engine_and_Runtime["Core Agent Engine and Runtime"]
    n_Terminal_User_Interface["Terminal User Interface"]
    n_AI_Provider_Integrations_and_Protocols["AI Provider Integrations and Protocols"]
    n_CLI_Application_and_Scripts["CLI Application and Scripts"]
    n_Server_and_Plugin_Runtime_Services["Server and Plugin Runtime Services"]
    n_Domain_Schemas_and_Data_Models["Domain Schemas and Data Models"]
    n_Protocol_Route_Specifications["Protocol Route Specifications"]
    n_Infrastructure_and_Cloud_Services["Infrastructure and Cloud Services"]
    n_Web_Share_Viewer["Web Share Viewer"]
    n_Provider_and_UI_Simulation["Provider and UI Simulation"]
    n_LaTeX_Parser_and_Renderer["LaTeX Parser and Renderer"]
    n_Terminal_UI_Themes["Terminal UI Themes"]
    n_Storybook_and_Package_Utilities["Storybook and Package Utilities"]
    n_Frontend_Applications_and_UI_Clients -- "utilizes core utility helpers" --> n_Core_Agent_Engine_and_Runtime
    n_Frontend_Applications_and_UI_Clients -- "imports session transfer schema" --> n_Domain_Schemas_and_Data_Models
    n_Frontend_Applications_and_UI_Clients -- "proxies browser network calls" --> n_Server_and_Plugin_Runtime_Services
    n_CLI_Application_and_Scripts -- "renders overlay and dialog UI" --> n_Terminal_User_Interface
    n_Protocol_Route_Specifications -- "references schema types in protocol definitions" --> n_Domain_Schemas_and_Data_Models
    classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
    classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
    classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
    class n_Frontend_Applications_and_UI_Clients,n_Terminal_User_Interface,n_CLI_Application_and_Scripts,n_Server_and_Plugin_Runtime_Services,n_Protocol_Route_Specifications modified;
Loading

download artifacts · run 42104631025

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.

2 participants