Skip to content

feat: add --session-ttl flag to marimo edit#7863

Merged
mscolnick merged 3 commits intomarimo-team:mainfrom
AnirudhDagar:add_session_ttl_edit
Jan 16, 2026
Merged

feat: add --session-ttl flag to marimo edit#7863
mscolnick merged 3 commits intomarimo-team:mainfrom
AnirudhDagar:add_session_ttl_edit

Conversation

@AnirudhDagar
Copy link
Contributor

📝 Summary

Fix #7834

🔍 Description of Changes

This PR adds the --session-ttl flag to marimo edit (extending the functionality from the run mode), enabling automatic cleanup of inactive sessions on multi-user edit servers.

When set, sessions are automatically closed after the specified number of seconds
following a websocket disconnect.

Usage:

marimo edit --session-ttl 300  # Close sessions 5 minutes after disconnect

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Tests have been added for the changes made.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Pull request title is a good summary of the changes - it will be used in the release notes.
@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jan 16, 2026 6:46pm

Request Review

Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice clean change! Just one comment on the test

_check_contents(p, b'"mode": "home"', contents)
finally:
p.kill()
p.wait(timeout=5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is super long, how long do we wait in other cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I also questioned this initially, but went with the same value used elsewhere for consistency. The timeout=5 is just a max wait/upper bound that should rarely get hit after p.kill(), the process should exit instantly, so wait() returns almost immediately. I guess the use of timeout is to prevent hanging forever if something goes wrong.

See other tests using the same pattern:

p.wait(timeout=5)

p.wait(timeout=5)

mscolnick
mscolnick previously approved these changes Jan 16, 2026
@mscolnick
Copy link
Contributor

looks like a single test is failign:

FAILED tests/_server/api/endpoints/test_ws.py::test_session_ttl_expiration[run-None] - assert SessionImpl(connection_state=ConnectionState.ORPHANED, room=<marimo._session.room.Room object at 0x1482f6440>) is None
@AnirudhDagar
Copy link
Contributor Author

Should be passing now, since RUN mode can only take in integer values for session-ttl, I updated the test to reflect the default value of 120.

@mscolnick mscolnick merged commit 2033b70 into marimo-team:main Jan 16, 2026
44 of 46 checks passed
botterYosuke pushed a commit to botterYosuke/marimo that referenced this pull request Jan 17, 2026
## 📝 Summary

Fix marimo-team#7834

## 🔍 Description of Changes
This PR adds the `--session-ttl` flag to `marimo edit` (extending the
functionality from the run mode), enabling automatic cleanup of inactive
sessions on multi-user edit servers.

When set, sessions are automatically closed after the specified number
of seconds
following a websocket disconnect.

Usage:

```bash
marimo edit --session-ttl 300  # Close sessions 5 minutes after disconnect
```

## 📋 Checklist

- [x] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [x] Tests have been added for the changes made.
- [x] Documentation has been updated where applicable, including
docstrings for API changes.
- [x] Pull request title is a good summary of the changes - it will be
used in the [release
notes](https://github.com/marimo-team/marimo/releases).
mscolnick pushed a commit that referenced this pull request Jan 19, 2026
## 📝 Summary

Fix #7834

## 🔍 Description of Changes
This PR adds the `--session-ttl` flag to `marimo edit` (extending the
functionality from the run mode), enabling automatic cleanup of inactive
sessions on multi-user edit servers.

When set, sessions are automatically closed after the specified number
of seconds
following a websocket disconnect.

Usage:

```bash
marimo edit --session-ttl 300  # Close sessions 5 minutes after disconnect
```

## 📋 Checklist

- [x] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [x] Tests have been added for the changes made.
- [x] Documentation has been updated where applicable, including
docstrings for API changes.
- [x] Pull request title is a good summary of the changes - it will be
used in the [release
notes](https://github.com/marimo-team/marimo/releases).
mscolnick added a commit that referenced this pull request Feb 27, 2026
Session cleanup for ASGI apps was broken after #7863 refactored session TTL handling. The `_on_disconnect` handler checked `manager.ttl_seconds` which is None by default for `create_asgi_app()`, causing sessions to never be closed on WebSocket disconnect.

This also forces a non-deafult for `create_asgi_app`'s session_ttl parameter, for another layer of safety.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

3 participants