Skip to content

Shell: "Fix" non-interactive shell stdout - #9258

Closed
sourishkrout wants to merge 2 commits into
dagger:mainfrom
stateful:seb/shell-stdout-non-tty
Closed

sourishkrout wants to merge 2 commits into
dagger:mainfrom
stateful:seb/shell-stdout-non-tty

Conversation

@sourishkrout

@sourishkrout sourishkrout commented Dec 19, 2024 •

Copy link
Copy Markdown
Contributor

Problem

  1. The shell and CLI behave differently when it comes to stdout handling with TTY attached.
  2. The response payload does not include the _type.

This PR is attempt to produce a pragmatic fix. However, any reviews/pointers are welcome if the code's not up to standard. I found it quicker to fix the issues than to merely describe the problems.

PS: This is required to preserve Runme's existing Notebook UX/UI integration.

In a nutshell this PR fixes

  • Writes payload response to stdout when no TTY is attached to stdout.
  • The response payload includes _type in response as per dagger call.

However, is the stdout fixed in the right place? I see several ways to resolve this issue; however, I am not clear about the side effects. Are there tests to write?

Shell stdout always goes to stderr

The Dagger shell always writes to stderr, even the response payload. Following command should discard stdout but doesn't.

dagger shell -c 'cli | binary' 1> /dev/null

# Ran on 2024-12-19 11:17:59-08:00 for 24.308s exited with 0
 
[...]
{
    "digest": "sha256:ff24da1f384a60498acdbbb9d6203cb19faa607b96d0d22f8d4d0b71fc3f5d93",
    "name": "dagger",
    "size": 29229208
}

 

 
✔ connect 0.2s
✔ load module 7.4s

✔ daggerDev: DaggerDev! 8.6s
✔ .cli: DaggerDevCli! 0.4s
$ .binary: File! 7.1s CACHED

✔ File.digest: String! 0.0s

✔ File.name: String! 0.0s

✔ File.size: Int! 0.0s

Unlike the Dagger CLI which does discard stdout correctly.

dagger call cli binary 1> /dev/null

# Ran on 2024-12-19 11:18:01-08:00 for 29.303s exited with 0

[...]

 
✔ connect 0.4s
✔ load module 11.9s

✔ daggerDev: DaggerDev! 6.1s
✔ .cli: DaggerDevCli! 0.5s
$ .binary: File! 9.5s CACHED

✔ File.digest: String! 0.0s

✔ File.name: String! 0.0s

✔ File.size: Int! 0.0s

✔ parsing command line arguments 0.0s

Now with this PR's branch build

It redirects it correctly.

rm -f /tmp/dagger-shell-stdout
./bin/dagger shell -c 'cli | binary' 1> /tmp/dagger-shell-stdout

# Ran on 2024-12-19 11:18:02-08:00 for 27.696s exited with 0
 
✔ connect 0.5s
✔ load module 11.5s

✔ daggerDev: DaggerDev! 7.0s
✔ .cli: DaggerDevCli! 1.0s
✔ .binary: File! 6.7s

✔ File.digest: String! 0.0s

✔ File.name: String! 0.0s

✔ File.size: Int! 0.0s

Redirected stdout works and matches CLI

Here we go! Please note that the response payload now matches the CLI's with the _type included. The missing _type is a spearate issue.

cat /tmp/dagger-shell-stdout

# Ran on 2024-12-19 11:18:38-08:00 for 747ms exited with 0
{
    "_type": "File",
    "digest": "sha256:ff24da1f384a60498acdbbb9d6203cb19faa607b96d0d22f8d4d0b71fc3f5d93",
    "name": "dagger",
    "size": 29229208
}

@shykes
shykes requested review from helderco and jedevc December 20, 2024 00:56
@shykes

shykes commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

Pinging @helderco and @jedevc who are the most active no this part of the code

@helderco

Copy link
Copy Markdown
Contributor

Hey, the _Type field was removed on purpose, as a first step towards:

To print the contents, .print. Note the absence of _Type field, another hack we no longer need:

⋈ .http https://dagger.io | .print
digest: sha256:e37c20d68d9cf63cd164ef06220b6b7b6ea4bc98aed5cc982e3de09c2622c028
name: 78c79fe99761c116238476f0b5a6a528b621e80398bfbaaa991abe41c4942a0d
size: 838056

Let's discuss (in #8990) first why you need it and see if there's a better solution or if bringing that back is the best long term.

@github-actions

github-actions Bot commented Jan 4, 2025

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

Include _type in response

Signed-off-by: Sebastian (Tiedtke) Huckleberry <[email protected]>
Signed-off-by: Sebastian (Tiedtke) Huckleberry <[email protected]>
@sourishkrout
sourishkrout force-pushed the seb/shell-stdout-non-tty branch from 3aba7af to 16adf9d Compare January 8, 2025 16:27
@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants