livebook-dev / livebook

Automate code & data workflows with interactive Elixir notebooks
https://livebook.dev
Apache License 2.0
5k stars 428 forks source link

Bug with Kino.Input.audio when inside a Livebook app #2627

Closed hugobarauna closed 6 months ago

hugobarauna commented 6 months ago

Environment:

Using the Kino.Input.audio to record and play audio works just fine inside a regular notebook.

For example, a notebook with just that code:


# Untitled notebook

```elixir
Mix.install(
  [
    {:kino, github: "livebook-dev/kino"},
  ]
)

Section

Kino.Input.audio("Audio")

The app crashes.

Here's a video showing the bug: https://share.cleanshot.com/zbPXFVPc

Here's some part of the error logs:

[error] GenServer #PID<0.2108.0> terminating
** (UndefinedFunctionError) function LivebookWeb.AppSessionLive.handle_call/3 is undefined or private
    (livebook 0.13.0-dev) LivebookWeb.AppSessionLive.handle_call({:get_input_value, "79849145"}, {#PID<0.2109.0>, [:alias | #Reference<0.0.269955.1715863608.3448307713.126424>]}, #Phoenix.LiveView.Socket<id: "phx-F9QRC91P64RmI6XB", endpoint: LivebookWeb.Endpoint, view: LivebookWeb.AppSessionLive, parent_pid: nil, root_pid: #PID<0.2108.0>, router: LivebookWeb.Router, assigns: %{session: %Livebook.Session{id: "urtwryjhsqziyblupaded3z5vft77dyvem47bnqt4jjqd2ht", pid: #PID<0.1999.0>, origin: nil, notebook_name: "Untitled notebook", file: nil, mode: :app, files_dir: %Livebook.FileSystem.File{file_system_id: "local", file_system_module: Livebook.FileSystem.Local, path: "/Users/hugobarauna/src/tmp/livebook_data_paths/test/prod-livebook/autosaved/2024_05_29/20_54_d2ht/files/", origin_pid: #PID<0.1999.0>}, created_at: ~U[2024-05-29 20:54:59.363802Z], memory_usage: %{runtime: %{atom: 680161, binary: 573360, code: 13336884, ets: 1030000, processes: 8848376, total: 38004910, other: 13536129}, system: %{free: 47513600, total: 17179869184}}}, __changed__: %{}, page_title: "Livebook - Untitled notebook", flash: %{}, confirm_state: nil, slug: "test", app_settings: %Livebook.Notebook.AppSettings{slug: "test", multi_session: false, zero_downtime: false, show_existing_sessions: false, auto_shutdown_ms: nil, access_type: :public, password: "cuaxxprz5pn64l2s", show_source: false, output_type: :all}, live_action: :page, current_user: %Livebook.Users.User{id: "uyie6ljrsj35mozjvcbprxnh2obaugv7", name: "Hugo Baraúna", email: nil, payload: nil, hex_color: "#F472B6"}, confirm_opt_out_ids: MapSet.new(["delete-cell", "hide-notebook"]), client_id: "rrp4k5rq2l6c5azj", data_view: %{app_status: %{execution: :executed, lifecycle: :active}, slug: "test", multi_session: false, notebook_name: "Untitled notebook", show_source: false, cell_views: [%{id: "setup", outputs: [{28, %{type: :terminal_text, chunk: false, text: "\e[34m:ok\e[0m"}}], outputs_batch_number: 1, input_views: %{}}, %{id: "3noodqxzbbkpprso", outputs: [{29, %{id: "79849145", type: :input, destination: {Kino.SubscriptionManager, :"name--262qqw7j@hugo"}, ref: "yqfp456xzkulp6pcacxmex2va665w3pv", attrs: %{default: nil, label: "Audio", type: :audio, format: :pcm_f32, sampling_rate: 48000}}}], outputs_batch_number: 1, input_views: %{"79849145" => %{value: %{format: :pcm_f32, file_ref: {:file, "yjshv4heraioyfu3"}, sampling_rate: 48000, num_channels: 1}, changed: false}}}], any_stale?: false, errored_cell_id: nil}, app_authenticated?: true, livebook_authenticated?: true}, transport_pid: #PID<0.2029.0>, ...>)
    (phoenix_live_view 1.0.0-rc.0) lib/phoenix_live_view/channel.ex:411: Phoenix.LiveView.Channel.handle_call/3
    (stdlib 5.2.1) gen_server.erl:1131: :gen_server.try_handle_call/4
    (stdlib 5.2.1) gen_server.erl:1160: :gen_server.handle_msg/6
    (stdlib 5.2.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.2109.0>): {:get_input_value, "79849145"}
State: %{socket: #Phoenix.LiveView.Socket<id: "phx-F9QRC91P64RmI6XB", endpoint: LivebookWeb.Endpoint, view: LivebookWeb.AppSessionLive, parent_pid: nil, root_pid: #PID<0.2108.0>, router: LivebookWeb.Router, assigns: %{session: %Livebook.Session{id: "urtwryjhsqziyblupaded3z5vft77dyvem47bnqt4jjqd2ht", pid: #PID<0.1999.0>, origin: nil, notebook_name: "Untitled notebook", file: nil, mode: :app, files_dir: %Livebook.FileSystem.File{file_system_id: "local", file_system_module: Livebook.FileSystem.Local, path: "/Users/hugobarauna/src/tmp/livebook_data_paths/test/prod-livebook/autosaved/2024_05_29/20_54_d2ht/files/", origin_pid: #PID<0.1999.0>}, created_at: ~U[2024-05-29 20:54:59.363802Z], memory_usage: %{runtime: %{atom: 680161, binary: 573360, code: 13336884, ets: 1030000, processes: 8848376, total: 38004910, other: 13536129}, system: %{free: 47513600, total: 17179869184}}}, __changed__: %{}, page_title: "Livebook - Untitled notebook", flash: %{}, confirm_state: nil, slug: "test", app_settings: %Livebook.Notebook.AppSettings{slug: "test", multi_session: false, zero_downtime: false, show_existing_sessions: false, auto_shutdown_ms: nil, access_type: :public, password: "cuaxxprz5pn64l2s", show_source: false, output_type: :all}, live_action: :page, current_user: %Livebook.Users.User{id: "uyie6ljrsj35mozjvcbprxnh2obaugv7", name: "Hugo Baraúna", email: nil, payload: nil, hex_color: "#F472B6"}, confirm_opt_out_ids: MapSet.new(["delete-cell", "hide-notebook"]), client_id: "rrp4k5rq2l6c5azj", data_view: %{app_status: %{execution: :executed, lifecycle: :active}, slug: "test", multi_session: false, notebook_name: "Untitled notebook", show_source: false, cell_views: [%{id: "setup", outputs: [{28, %{type: :terminal_text, chunk: false, text: "\e[34m:ok\e[0m"}}], outputs_batch_number: 1, input_views: %{}}, %{id: "3noodqxzbbkpprso", outputs: [{29, %{id: "79849145", type: :input, destination: {Kino.SubscriptionManager, :"name--262qqw7j@hugo"}, ref: "yqfp456xzkulp6pcacxmex2va665w3pv", attrs: %{default: nil, label: "Audio", type: :audio, format: :pcm_f32, sampling_rate: 48000}}}], outputs_batch_number: 1, input_views: %{"79849145" => %{value: %{format: :pcm_f32, file_ref: {:file, "yjshv4heraioyfu3"}, sampling_rate: 48000, num_channels: 1}, changed: false}}}], any_stale?: false, errored_cell_id: nil}, app_authenticated?: true, livebook_authenticated?: true}, transport_pid: #PID<0.2029.0>, ...>, components: {%{1 => {LivebookWeb.AppSessionLive.CellOutputsComponent, "outputs-setup", %{id: "outputs-setup", session: %Livebook.Session{id: "urtwryjhsqziyblupaded3z5vft77dyvem47bnqt4jjqd2ht", pid: #PID<0.1999.0>, origin: nil, notebook_name: "Untitled notebook", file: nil, mode: :app, files_dir: %Livebook.FileSystem.File{file_system_id: "local", file_system_module: Livebook.FileSystem.Local, path: "/Users/hugobarauna/src/tmp/livebook_data_paths/test/prod-livebook/autosaved/2024_05_29/20_54_d2ht/files/", origin_pid: #PID<0.1999.0>}, created_at: ~U[2024-05-29 20:54:59.363802Z], memory_usage: %{runtime: %{atom: 680161, binary: 573360, code: 13336884, ets: 1030000, processes: 8848376, total: 38004910, other: 13536129}, system: %{free: 47513600, total: 17179869184}}}, __changed__: %{}, flash: %{}, myself: %Phoenix.LiveComponent.CID{cid: 1}, streams: %{outputs: %Phoenix.LiveView.LiveStream{name: :outputs, dom_id: #Function<3.112696910/1 in Phoenix.LiveView.LiveStream.new/4>, ref: "1-0", inserts: [], deletes: [], reset?: false, consumable?: false}, __changed__: MapSet.new([]), __configured__: %{}, __ref__: 1}, client_id: "rrp4k5rq2l6c5azj", cell_view: %{id: "setup", outputs: [{28, %{type: :terminal_text, chunk: false, text: "\e[34m:ok\e[0m"}}], outputs_batch_number: 1, input_views: %{}}}, %{live_temp: %{}, lifecycle: %Phoenix.LiveView.Lifecycle{after_render: [%{function: #Function<2.3491208/1 in Phoenix.LiveView.assign_stream/4>, id: :outputs, stage: :after_render}], handle_async: [], handle_event: [], handle_info: [], handle_params: [], mount: []}, root_view: LivebookWeb.AppSessionLive, children_cids: [3]}, {215621192555149934640689716936343083061, %{2 => 313021271637941463070270220817581425837}}}, 2 => {LivebookWeb.AppSessionLive.CellOutputsComponent, "outputs-3noodqxzbbkpprso", %{id: "outputs-3noodqxzbbkpprso", session: %Livebook.Session{id: "urtwryjhsqziyblupaded3z5vft77dyvem47bnqt4jjqd2ht", pid: #PID<0.1999.0>, origin: nil, notebook_name: "Untitled notebook", file: nil, mode: :app, files_dir: %Livebook.FileSystem.File{file_system_id: "local", file_system_module: Livebook.FileSystem.Local, path: "/Users/hugobarauna/src/tmp/livebook_data_paths/test/prod-livebook/autosaved/2024_05_29/20_54_d2ht/files/", origin_pid: #PID<0.1999.0>}, created_at: ~U[2024-05-29 20:54:59.363802Z], memory_usage: %{runtime: %{atom: 680161, binary: 573360, code: 13336884, ets: 1030000, processes: 8848376, total: 38004910, other: 13536129}, system: %{free: 47513600, total: 17179869184}}}, __changed__: %{}, flash: %{}, myself: %Phoenix.LiveComponent.CID{cid: 2}, streams: %{ou (truncated)
[error] GenServer #PID<0.2109.0> terminating
** (stop) exited in: GenServer.call(#PID<0.2108.0>, {:get_input_value, "79849145"}, 5000)
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function LivebookWeb.AppSessionLive.handle_call/3 is undefined or private
            (livebook 0.13.0-dev) LivebookWeb.AppSessionLive.handle_call({:get_input_value, "79849145"}, {#PID<0.2109.0>, [:alias | #Reference<0.0.269955.1715863608.3448307713.126424>]}, #Phoenix.LiveView.Socket<id: "phx-F9QRC91P64RmI6XB", endpoint: LivebookWeb.Endpoint, view: LivebookWeb.AppSessionLive, parent_pid: nil, root_pid: #PID<0.2108.0>, router: LivebookWeb.Router, assigns: %{session: %Livebook.Session{id: "urtwryjhsqziyblupaded3z5vft77dyvem47bnqt4jjqd2ht", pid: #PID<0.1999.0>, origin: nil, notebook_name: "Untitled notebook", file: nil, mode: :app, files_dir: %Livebook.FileSystem.File{file_system_id: "local", file_system_module: Livebook.FileSystem.Local, path: "/Users/hugobarauna/src/tmp/livebook_data_paths/test/prod-livebook/autosaved/2024_05_29/20_54_d2ht/files/", origin_pid: #PID<0.1999.0>}, created_at: ~U[2024-05-29 20:54:59.363802Z], memory_usage: %{runtime: %{atom: 680161, binary: 573360, code: 13336884, ets: 1030000, processes: 8848376, total: 38004910, other: 13536129}, system: %{free: 47513600, total: 17179869184}}}, __changed__: %{}, page_title: "Livebook - Untitled notebook", flash: %{}, confirm_state: nil, slug: "test", app_settings: %Livebook.Notebook.AppSettings{slug: "test", multi_session: false, zero_downtime: false, show_existing_sessions: false, auto_shutdown_ms: nil, access_type: :public, password: "cuaxxprz5pn64l2s", show_source: false, output_type: :all}, live_action: :page, current_user: %Livebook.Users.User{id: "uyie6ljrsj35mozjvcbprxnh2obaugv7", name: "Hugo Baraúna", email: nil, payload: nil, hex_color: "#F472B6"}, confirm_opt_out_ids: MapSet.new(["delete-cell", "hide-notebook"]), client_id: "rrp4k5rq2l6c5azj", data_view: %{app_status: %{execution: :executed, lifecycle: :active}, slug: "test", multi_session: false, notebook_name: "Untitled notebook", show_source: false, cell_views: [%{id: "setup", outputs: [{28, %{type: :terminal_text, chunk: false, text: "\e[34m:ok\e[0m"}}], outputs_batch_number: 1, input_views: %{}}, %{id: "3noodqxzbbkpprso", outputs: [{29, %{id: "79849145", type: :input, destination: {Kino.SubscriptionManager, :"name--262qqw7j@hugo"}, ref: "yqfp456xzkulp6pcacxmex2va665w3pv", attrs: %{default: nil, label: "Audio", type: :audio, format: :pcm_f32, sampling_rate: 48000}}}], outputs_batch_number: 1, input_views: %{"79849145" => %{value: %{format: :pcm_f32, file_ref: {:file, "yjshv4heraioyfu3"}, sampling_rate: 48000, num_channels: 1}, changed: false}}}], any_stale?: false, errored_cell_id: nil}, app_authenticated?: true, livebook_authenticated?: true}, transport_pid: #PID<0.2029.0>, ...>)
            (phoenix_live_view 1.0.0-rc.0) lib/phoenix_live_view/channel.ex:411: Phoenix.LiveView.Channel.handle_call/3
            (stdlib 5.2.1) gen_server.erl:1131: :gen_server.try_handle_call/4
            (stdlib 5.2.1) gen_server.erl:1160: :gen_server.handle_msg/6
            (stdlib 5.2.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
    (elixir 1.16.2) lib/gen_server.ex:1114: GenServer.call/3
    (livebook 0.13.0-dev) lib/livebook_web/controllers/session_controller.ex:179: LivebookWeb.SessionController.show_input_audio/2
    (livebook 0.13.0-dev) lib/livebook_web/controllers/session_controller.ex:1: LivebookWeb.SessionController.action/2
    (livebook 0.13.0-dev) lib/livebook_web/controllers/session_controller.ex:1: LivebookWeb.SessionController.phoenix_controller_pipeline/2
    (phoenix 1.7.12) lib/phoenix/router.ex:484: Phoenix.Router.__call__/5
    (livebook 0.13.0-dev) lib/livebook_web/endpoint.ex:1: LivebookWeb.Endpoint.plug_builder_call/2
    (livebook 0.13.0-dev) deps/plug/lib/plug/debugger.ex:136: LivebookWeb.Endpoint."call (overridable 3)"/2
    (livebook 0.13.0-dev) lib/livebook_web/endpoint.ex:1: LivebookWeb.Endpoint.call/2
    (phoenix 1.7.12) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
    (bandit 1.5.0) lib/bandit/pipeline.ex:124: Bandit.Pipeline.call_plug!/2
    (bandit 1.5.0) lib/bandit/pipeline.ex:36: Bandit.Pipeline.run/4
    (bandit 1.5.0) lib/bandit/http1/handler.ex:12: Bandit.HTTP1.Handler.handle_data/3
    (bandit 1.5.0) lib/bandit/delegating_handler.ex:18: Bandit.DelegatingHandler.handle_data/3
    (bandit 1.5.0) /Users/hugobarauna/src/livebook/deps/thousand_island/lib/thousand_island/handler.ex:411: Bandit.DelegatingHandler.handle_continue/2
    (stdlib 5.2.1) gen_server.erl:1085: :gen_server.try_handle_continue/3
    (stdlib 5.2.1) gen_server.erl:995: :gen_server.loop/7
    (stdlib 5.2.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:continue, :handle_connection}
State: {%ThousandIsland.Socket{socket: #Port<0.407>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.1715863608.3448242177.125256>, start_time: -576459379716551157, start_metadata: %{remote_port: 61323, remote_address: {127, 0, 0, 1}, telemetry_span_context: #Reference<0.1715863608.3448242177.125256>, parent_telemetry_span_context: #Reference<0.1715863608.3447980035.251892>}}}, %{opts: %{http: [], websocket: [], http_1: [max_header_length: 32768], http_2: []}, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {LivebookWeb.Endpoint, []}}, handler_module: Bandit.InitialHandler, http_1_enabled: true, http_2_enabled: true}}
jonatanklosko commented 6 months ago

Fixed in 52240a167738f16a38d527f0bb0c571426c8b677.