Repository navigation
fix(runtime): explain harness-managed shell rejections #2544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aidandaly24
wants to merge
6
commits into
aws:refactor
Choose a base branch
from
aidandaly24:fix/runtime-shell-harness
base: refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
36ac173
fix(runtime): explain harness-managed shell rejections
aidandaly24 f66b9b3
fix(runtime): recommend harness shell for managed Runtimes
aidandaly24 81911ce
fix(shell): retain connection errors in the TUI
aidandaly24 5c3272b
fix(runtime): share conditional shell error guidance
aidandaly24 7d9677f
fix(runtime): separate shell rejection guidance from the error
aidandaly24 d2deecf
fix(tui): display harness shell guidance below connection errors
aidandaly24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { Text, useApp, useInput, useStderr, useStdin, useStdout } from "ink"; | ||
| import { useLocation, useNavigate } from "react-router"; | ||
| import { AgentCoreCLIError, SilentCLIError } from "../errors"; | ||
| import type { AppIO } from "../io"; | ||
| import { Layout } from "./Layout"; | ||
| import { Spinner } from "./ui/spinner"; | ||
|
|
||
| type ShellHandoffProps = { | ||
| label: string; | ||
| returnPath?: string; | ||
| run: (io: AppIO) => Promise<void>; | ||
| errorHint?: (error: Error) => string | undefined; | ||
| }; | ||
|
|
||
| export function ShellHandoff({ label, returnPath, run, errorHint }: ShellHandoffProps) { | ||
| const { exit, suspendTerminal } = useApp(); | ||
| const { stdin } = useStdin(); | ||
| const { stdout } = useStdout(); | ||
| const { stderr } = useStderr(); | ||
| const location = useLocation(); | ||
| const navigate = useNavigate(); | ||
| const requested = useRef(false); | ||
| const [error, setError] = useState<Error | null>(null); | ||
| const [attempt, setAttempt] = useState(0); | ||
|
|
||
| useInput( | ||
| (input, key) => { | ||
| if (key.ctrl && input === "c") exit(); | ||
| else if (key.escape) { | ||
| navigate(returnPath ?? location.pathname.slice(0, location.pathname.lastIndexOf("/")), { | ||
| replace: true, | ||
| }); | ||
| } else if (input === "r") { | ||
| requested.current = false; | ||
| setError(null); | ||
| setAttempt((current) => current + 1); | ||
| } | ||
| }, | ||
| { isActive: error !== null }, | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (requested.current) return; | ||
| requested.current = true; | ||
| void (async () => { | ||
| try { | ||
| await suspendTerminal(() => run({ stdin, stdout, stderr })); | ||
| } catch (caught) { | ||
| if (!(caught instanceof SilentCLIError)) { | ||
| setError(AgentCoreCLIError.fromError(caught)); | ||
| return; | ||
| } | ||
| if (returnPath === undefined) { | ||
| exit(caught); | ||
| return; | ||
| } | ||
| } | ||
| if (returnPath === undefined) exit(); | ||
| else navigate(returnPath, { replace: true }); | ||
| })(); | ||
| }, [attempt, exit, navigate, returnPath, run, stderr, stdin, stdout, suspendTerminal]); | ||
|
|
||
| if (error) { | ||
| const hint = errorHint?.(error); | ||
| return ( | ||
| <Layout | ||
| breadcrumb={location.pathname.split("/").filter(Boolean).map(decodeURIComponent)} | ||
| keyHints={[ | ||
| { key: "r", label: "retry" }, | ||
| { key: "esc", label: "back" }, | ||
| { key: "ctrl+c", label: "quit" }, | ||
| ]} | ||
| > | ||
| <Text color="red">Error: {error.message}</Text> | ||
| {hint && ( | ||
| <Text> | ||
| {"\n"} | ||
| {hint} | ||
| </Text> | ||
| )} | ||
| </Layout> | ||
| ); | ||
| } | ||
| return <Spinner label={label} />; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export function runtimeShellErrorHint(error: Error): string | undefined { | ||
| if (error.message !== "Server rejected WebSocket connection: HTTP 400") return undefined; | ||
| return ( | ||
| "If this Runtime is managed by a harness, open its shell with:\n" + | ||
| "agentcore harness shell --id <harness-id>" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this changes the exit code for failed shells. Before, any non-silent error went to
exit(error), sorenderTuiAtrejected and the CLI exited non-zero. Now we catch it, show it, and the only way out is ctrl+c, which callsexit()with no error (line 29). So e.g.agentcore runtime shell --id Xwith expired creds, or the very 400 this PR is about, ends up exiting 0, and telemetry logs it as a success.The test "renderTuiAt propagates unexpected shell failures" was removed too, so nothing catches this anymore.
Maybe hang on to the caught error and pass it through on quit, something like
if (key.ctrl && input === "c") exit(error ?? undefined), and the same for esc when there's noreturnPath? Would be good to bring back a version of that test as well.