sherodbuilds
sherodbuilds5mo ago

Invalid Session for create_asgi_app deployed across 4 different machines

File "/bb/libexec/workflow-metrics-notebooks/python/lib/python3.10/site-packages/marimo/_server/api/deps.py", line 135, in require_current_session
raise ValueError(f"Invalid session id: {session_id}")
ValueError: Invalid session id: s_p41hf3
File "/bb/libexec/workflow-metrics-notebooks/python/lib/python3.10/site-packages/marimo/_server/api/deps.py", line 135, in require_current_session
raise ValueError(f"Invalid session id: {session_id}")
ValueError: Invalid session id: s_p41hf3
11 Replies
sherodbuilds
sherodbuildsOP5mo ago
import argparse
import logging
from typing import Any

import marimo
from fastapi import FastAPI
import uvicorn



LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

def parse_args(args: list[str] | None = None) -> dict[str, Any]:
parser = argparse.ArgumentParser()
parser.add_argument("--log-file", "-l")
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--log-level", default="INFO", choices=LOG_LEVELS)
parser.add_argument("--dir", default="./notebooks")
parsed_args, unknown = parser.parse_known_args(args=args)
logging.info(f'unknown args - {unknown}')
return vars(parsed_args)



def start_server(host: str, dir: str) -> None:

server = (
marimo.create_asgi_app()
.with_app(path="", root=f'{dir}/workflow-metrics.py')
)

# Create a FastAPI app
app = FastAPI(host=host)
app.mount("/", server.build())

uvicorn.run(app, host=host, port=8080)


def main() -> None:
args = parse_args()
start_server(args.pop("host"), args.pop("dir"))


if __name__ == "__main__":
main()
import argparse
import logging
from typing import Any

import marimo
from fastapi import FastAPI
import uvicorn



LOG_LEVELS = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]

def parse_args(args: list[str] | None = None) -> dict[str, Any]:
parser = argparse.ArgumentParser()
parser.add_argument("--log-file", "-l")
parser.add_argument("--host", default="0.0.0.0")
parser.add_argument("--log-level", default="INFO", choices=LOG_LEVELS)
parser.add_argument("--dir", default="./notebooks")
parsed_args, unknown = parser.parse_known_args(args=args)
logging.info(f'unknown args - {unknown}')
return vars(parsed_args)



def start_server(host: str, dir: str) -> None:

server = (
marimo.create_asgi_app()
.with_app(path="", root=f'{dir}/workflow-metrics.py')
)

# Create a FastAPI app
app = FastAPI(host=host)
app.mount("/", server.build())

uvicorn.run(app, host=host, port=8080)


def main() -> None:
args = parse_args()
start_server(args.pop("host"), args.pop("dir"))


if __name__ == "__main__":
main()
Myles Scolnick
Myles Scolnick5mo ago
marimo is stateful so it doesn’t support multiple instances at once. You will need to build a layer on top to manage this
sherodbuilds
sherodbuildsOP5mo ago
i see
Myles Scolnick
Myles Scolnick5mo ago
(or drop to one machine if you can)
sherodbuilds
sherodbuildsOP5mo ago
where would you start i'm deploying in my companies which is using kubernetes so multiple containers w/ no control over it
Myles Scolnick
Myles Scolnick5mo ago
it’s a concept called Session Affinity on most cloud providers. If you have a load balancer between your Kubernetes - you could enable it. Usually you can set the scale factor or turn off autoscaling for k8s. Do you not have access to that? Can you ask?
sherodbuilds
sherodbuildsOP5mo ago
yeah our kaas doesn't support it and requires us to be stateless.... its an internally managed and built tool is there a way to manage the state via redis or something?
Myles Scolnick
Myles Scolnick5mo ago
not at the moment - it’s quick difficult since there is a lot of runtime state (not all serializable)
sherodbuilds
sherodbuildsOP4mo ago
btw just created an issue if thats okay it seems like a fair ask whether prioritized soon or not
sherodbuilds
sherodbuildsOP4mo ago
GitHub
Support stateless deployment · Issue #1831 · marimo-team/marimo
Description I have a custom kubernetes deployment that requires stateless applications which has been a standard for a long time. Suggested solution I'd like to be able to deploy the app and an...
Myles Scolnick
Myles Scolnick4mo ago
This will be extremely difficult since not everything is serializable so can’t be stateless. These are running programs that inherently have state. Even if we made marimo stateless, your code may not be (e.g threads, db connections, etc) I think a better request would be a load balancer that can manage multiple instance