8000 feat(sessions): update session status by evanspearman · Pull Request #597 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

feat(sessions): update session status - #597

Merged
evanspearman merged 2 commits into
mainfrom
evan/updatesession
Jun 29, 2026
Merged

evanspearman merged 2 commits into
mainfrom
evan/updatesession

Conversation

@evanspearman
@evanspearman evanspearman commented Jun 29, 2026 •
Copy link
Copy Markdown
Member

Storage scaffolding for the daemon-side draft-session flow.

  • New SessionStatus { Draft, Active } on Record (defaults to
    Active, #[serde(default)] for backward-compat with on-disk
    records predating the field). Store records the value verbatim;
    state-machine rules belong to higher layers.
  • New Loader::save(&mut self, key, record). Overwrites the row
    in place; refuses id changes (InvalidInput), stale keys
    (NotFound), and real name collisions (AlreadyExists).
    Same-name re-save is a no-op. Atomic via the existing
    temp + renameat2 plumbing.
  • Loader::rename is now sugar over save (one write path).
  • Record derives PartialEq + Eq; trivially supported by
    every field.

Summary by CodeRabbit

  • New Features

    • Sessions now have a persisted lifecycle state (draft/active) that is saved and restored across reloads.
    • For older saved sessions that don’t include this field, the lifecycle state automatically defaults to active.
  • Bug Fixes

    • Session creation/activation requests now include the lifecycle state consistently across exec/SFTP/RPC flows.
    • Session save/rename now applies stricter validation to prevent stale data “resurrection,” handle overwrites correctly, and resolve duplicate-name collisions consistently.

@coderabbitai
coderabbitai Bot commented Jun 29, 2026 •
Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5806eab6-2368-4879-b189-dd73fd8ded67

📥 Commits

Reviewing files that changed from the base of the PR and between c308c6a and 32a5a8e.

📒 Files selected for processing (10)
  • crates/minimal2/src/main.rs
  • crates/minimald/src/exec.rs
  • crates/minimald/src/rpc.rs
  • crates/minimald/src/session.rs
  • crates/minimald/src/sessions.rs
  • crates/minimald/src/sftp.rs
  • crates/minvmd/examples/exec.rs
  • crates/minvmd/tests/minimald_session_e2e.rs
  • crates/sessions/src/lib.rs
  • crates/sessions/src/store.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/minimald/src/sessions.rs
🚧 Files skipped from review as they are similar to previous changes (9)
  • crates/minimald/src/exec.rs
  • crates/minvmd/examples/exec.rs
  • crates/minimal2/src/main.rs
  • crates/minimald/src/session.rs
  • crates/minimald/src/sftp.rs
  • crates/minvmd/tests/minimald_session_e2e.rs
  • crates/minimald/src/rpc.rs
  • crates/sessions/src/lib.rs
  • crates/sessions/src/store.rs

📝 Walkthrough

Walkthrough

Adds SessionStatus to sessions::Record, updates store save/rename behavior, and sets status on session creation request payloads and test fixtures.

Changes

Session status field and store validation

Layer / File(s) Summary
SessionStatus enum and Record field
crates/sessions/src/lib.rs
Defines SessionStatus with Draft and Active, sets Active as the default, adds status: SessionStatus to Record with #[serde(default)], and updates schema tests and helpers.
DiskLoader::save validation and rename behavior
crates/sessions/src/store.rs
Updates Loader::save and Loader::rename documentation, rewrites DiskLoader::save to enforce id matching, stale-key rejection, collision handling, and atomic persistence, and adds save-path tests for overwrite, status changes, stale keys, collisions, and name clearing.
Populate status at session creation call sites
crates/minimal2/src/main.rs, crates/minimald/src/..., crates/minvmd/...
Adds status: Default::default() to sessions::Record construction in cmd_activate, minimald RPC and subsystem helpers, the minvmd example, and the session-create e2e test.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • gominimal/minimal#436: Shares the Loader and DiskLoader session-store save/rename path that this PR rewrites.
  • gominimal/minimal#507: Also updates sessions::Record construction sites in session-creation flows and test helpers.
  • gominimal/minimal#581: Also changes the cmd_activate session creation request built in crates/minimal2/src/main.rs.

Suggested reviewers

  • twitchyliquid64
  • norrietaylor

🐇 I hopped through records, both old and new,
With Draft and Active in tidy view.
The store kept its names and ids in line,
And status joined the session design.
A whisker twitch, a carrot cheer,
The bunnies say: “defaults are here!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding session status support to sessions records.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/sessions/src/store.rs`:
- Around line 92-96: Update the error documentation for Store::save and
Store::rename to include the stale-key case that returns ErrorKind::NotFound.
The current docs for save only mention InvalidInput, AlreadyExists, and I/O
errors, so add NotFound with a brief description that it occurs when the
provided key is stale; make sure rename’s docs (or its shared trait/docs block)
reflect the same inherited behavior from save.
- Around line 756-767: The current guard in save only checks that short exists
in index, but it must also verify that the stored session id matches the key’s
id before writing. Update the check around short_to_id in store.rs so save
compares the resolved id for short against key.id() and returns NotFound if they
differ, preventing stale keys from overwriting a reused short. Use the save path
and the short_to_id lookup in SessionStore as the main place to enforce this
ownership check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c1cb62f-a4a7-4c2f-9411-414b9555c761

📥 Commits

Reviewing files that changed from the base of the PR and between 94da592 and 145ceb0.

📒 Files selected for processing (10)
  • crates/minimal2/src/main.rs
  • crates/minimald/src/exec.rs
  • crates/minimald/src/rpc.rs
  • crates/minimald/src/session.rs
  • crates/minimald/src/sessions.rs
  • crates/minimald/src/sftp.rs
  • crates/minvmd/examples/exec.rs
  • crates/minvmd/tests/minimald_session_e2e.rs
  • crates/sessions/src/lib.rs
  • crates/sessions/src/store.rs

Comment thread crates/sessions/src/store.rs Resolved
Comment thread crates/sessions/src/store.rs Resolved
}
}

/// Lifecycle status of a [`Record`].
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SessionStatus implies its the state machine for the session- given its more the loadout vibes, do we want to call it Loadout or LoadoutStatus ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it is actually part of the session lifecycle itself. A session is created as a Draft once the client sends the CreateSession request, along with the loadout information, and then it becomes active once the client gets back to it with the verdict on package and project contributions. It's not really a loadout specific thing.

@coderabbitai coderabbitai Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
crates/sessions/src/store.rs (1)

95-97: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Document the reused-short NotFound case.

Line 95 says stale keys are only when the short is no longer in the index, but save also returns NotFound when that short now maps to a different session id.

Suggested doc update
-    /// - `NotFound` if `key` is stale — its short is no longer in the
-    ///   index (e.g. the session was deleted after the caller obtained
-    ///   the key). Prevents silent resurrection of removed sessions.
+    /// - `NotFound` if `key` is stale — its short is no longer in the
+    ///   index, or it now maps to a different session id (e.g. after
+    ///   deletion and short reuse). Prevents silent resurrection or
+    ///   overwriting an unrelated session.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/sessions/src/store.rs` around lines 95 - 97, Update the
`SessionStore::save` docs to cover the reused-short `NotFound` case as well as
stale keys. The current comment only mentions the key being stale when its short
is missing from the index, but `save` can also return `NotFound` when the short
exists and now points to a different session id. Adjust the doc comment near
`save` and the `NotFound` bullet so both conditions are clearly described.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@crates/sessions/src/store.rs`:
- Around line 95-97: Update the `SessionStore::save` docs to cover the
reused-short `NotFound` case as well as stale keys. The current comment only
mentions the key being stale when its short is missing from the index, but
`save` can also return `NotFound` when the short exists and now points to a
different session id. Adjust the doc comment near `save` and the `NotFound`
bullet so both conditions are clearly described.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2a08f8f-834a-40e4-82a3-87420c64a94e

📥 Commits

Reviewing files that changed from the base of the PR and between 145ceb0 and c308c6a.

📒 Files selected for processing (1)
  • crates/sessions/src/store.rs

@evanspearman
evanspearman merged commit d15539a into main Jun 29, 2026
41 checks passed
@evanspearman
evanspearman deleted the evan/updatesession branch June 29, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0