-
Notifications
You must be signed in to change notification settings - Fork 590
[feat] Reuse Daytona sandboxes across turns instead of deleting them every turn #5225
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a3bbcb9
feat(runner): warm daytona sessions slice 1 - provider pause/reconnec…
mmabrouk 51b18fb
feat(runner): warm daytona sessions, slices 2-5 - park-to-stopped, pr…
mmabrouk 20dbabb
feat(runner): drop sandbox fingerprint, converge network policy at re…
59e49b9
fix(runner): service CodeRabbit review on warm daytona sessions
a588b08
fix(hosting): restore the MCP gate default to off
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
28 changes: 28 additions & 0 deletions
28
...stgres/migrations/core_oss/versions/oss000000011_add_session_state_sandbox_fingerprint.py
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,28 @@ | ||
| """add session state sandbox fingerprint | ||
|
|
||
| Revision ID: oss000000011 | ||
| Revises: oss000000010 | ||
| Create Date: 2026-07-11 00:00:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| revision: str = "oss000000011" | ||
| down_revision: Union[str, None] = "oss000000010" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "session_states", | ||
| sa.Column("sandbox_fingerprint", sa.String(), nullable=True), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("session_states", "sandbox_fingerprint") |
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 |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| import uuid_utils.compat as uuid_utils | ||
|
|
||
| from sqlalchemy import select | ||
| from sqlalchemy import Integer, case, cast, func, select | ||
| from sqlalchemy.dialects.postgresql import insert | ||
|
|
||
| from oss.src.utils.logging import get_module_logger | ||
|
|
@@ -78,6 +78,7 @@ async def set_session_state( | |
| "session_id": session_id, | ||
| "data": data_json, | ||
| "sandbox_id": upsert.sandbox_id, | ||
| "sandbox_fingerprint": upsert.sandbox_fingerprint, | ||
| "flags": SessionStateFlags().model_dump(mode="json"), | ||
| "created_at": now, | ||
| "updated_at": None, | ||
|
|
@@ -94,8 +95,33 @@ async def set_session_state( | |
| } | ||
| if "data" in upsert.model_fields_set: | ||
| update_values["data"] = stmt.excluded.data | ||
| if "sandbox_id" in upsert.model_fields_set: | ||
| guarded_pointer_write = ( | ||
| "sandbox_id" in upsert.model_fields_set | ||
| and upsert.sandbox_turn_index is not None | ||
| ) | ||
| if guarded_pointer_write: | ||
| pointer_write_allowed = ( | ||
| func.coalesce( | ||
| cast(SessionStateDBE.data["latest_turn_index"].astext, Integer), | ||
| -1, | ||
| ) | ||
| <= upsert.sandbox_turn_index | ||
| ) | ||
| update_values["sandbox_id"] = case( | ||
| (pointer_write_allowed, stmt.excluded.sandbox_id), | ||
| else_=SessionStateDBE.sandbox_id, | ||
| ) | ||
| elif "sandbox_id" in upsert.model_fields_set: | ||
| update_values["sandbox_id"] = stmt.excluded.sandbox_id | ||
|
Member
Author
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. Kept: the turn-index compare-and-set on sandbox_id (guarded_pointer_write above). This is the multi-runner safety mechanism and it uses only pre-existing columns. Only the fingerprint branch was removed here, so a stale write still cannot overwrite a newer pointer. |
||
| if "sandbox_fingerprint" in upsert.model_fields_set: | ||
| update_values["sandbox_fingerprint"] = ( | ||
| case( | ||
| (pointer_write_allowed, stmt.excluded.sandbox_fingerprint), | ||
| else_=SessionStateDBE.sandbox_fingerprint, | ||
| ) | ||
| if guarded_pointer_write | ||
| else stmt.excluded.sandbox_fingerprint | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| stmt = stmt.on_conflict_do_update( | ||
| constraint="uq_session_states_project_session_id", | ||
|
|
||
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
Oops, something went wrong.
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.
🤖 The pointer guard: when the writer supplies
sandbox_turn_index,sandbox_idandsandbox_fingerprintupdate only under this CASE compare-and-set against the row'slatest_turn_index; a tokenless write behaves exactly as before, so existing callers are untouched. SQL note: insideON CONFLICT DO UPDATE, the table-qualified column refers to the EXISTING row andexcludedto the proposed one. The insert path (no existing row) applies unconditionally.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.
we removed sandbox_fingerprint is this still relevant
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.
The fingerprint is gone but this guard stays relevant: it is the turn-index compare-and-set on sandbox_id itself, the multi-runner safety mechanism. It uses only pre-existing columns. Commit 20dbabb removed the fingerprint branch below it.