Skip to content

[REA-6854] Close a session when it reaches its steps - #235

Merged
Dere-Wah merged 4 commits into
mainfrom
dere/rea-6854-close-the-session-at-steps
Oct 5, 2026
Merged

Dere-Wah merged 4 commits into
mainfrom
dere/rea-6854-close-the-session-at-steps

Conversation

@Dere-Wah

@Dere-Wah Dere-Wah commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

A session started with steps is meant to run that many steps and end, and there may be no client there to stop it. With step reports in place, the runtime can close the session itself.

What Changed

The step that brings a running session to its steps stops it with a normal stop: reason stopped and the close reason "Session ended: the requested steps are complete.", which connected clients are told before their connections close. The model keeps stepping until the session end reaches it, so a step reported after the stop is journalled with its number and stops nothing. A session without steps never stops on its own.

A step report carries the session it began in, as the model's count of session starts, and the runner keeps the same count of the starts it posts. A report from an earlier session, one that a model finishes after a quick stop and restart, is dropped: it is neither journalled nor counted, so it cannot close the session that followed.

The contract suite now runs the whole flow on a model with no client connected, with the orphan timeout set short so a client-less timeout would show up if it fired:

start_session       ready -> waiting
connection_opened   {"conn_id": 0, "system": true}
command             {"name": "set_speed", "args": {"speed": 2.0}, "conn_id": 0}
step_completed      {"step": 1, "saved": false, "error": null}
step_completed      {"step": 2, "saved": false, "error": null}
stop_session        {"reason": "stopped", "close_reason": "Session ended: the requested steps are complete."}
cleanup_complete    closing -> ready

A second contract test starts a session with steps: 2 whose starting input names an image the caller uploads 200 ms after the start. The journal shows the starting command before the first step_completed, so a session cannot reach its steps before its setup arrives.

The same flow against examples/starter with steps: 5 and no client ran five steps, stopped, and returned to ready; one more step was reported before the session end reached the model, and it was journalled without effect.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

[codex-review] - [P1] src/reactor_runtime/runner/runner.py: A late completion from the prior session can incorrectly count toward and stop the next session.

Scope: full (9af1f4c..dcb5538).

View workflow run.

Comment thread src/reactor_runtime/runner/runner.py

@tempusfrangit tempusfrangit 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.

Reviewed completion counting, stop notifications, and default-loop session stamping. The regression coverage verifies that an earlier session's report cannot stop a later session.

@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-close-the-session-at-steps branch from c0f4bc9 to 8c05792 Compare October 4, 2026 16:39
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-report-completed-steps branch 2 times, most recently from 2b9b4f5 to dc34d85 Compare October 4, 2026 18:28
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-close-the-session-at-steps branch from 8c05792 to b00b1d3 Compare October 4, 2026 18:28
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-report-completed-steps branch from dc34d85 to c52f4ed Compare October 4, 2026 23:47
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-close-the-session-at-steps branch from b00b1d3 to 686e937 Compare October 4, 2026 23:47
Comment thread src/reactor_runtime/runner/runner.py
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-close-the-session-at-steps branch from 686e937 to 7aaeb4d Compare October 5, 2026 17:58
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-report-completed-steps branch from c52f4ed to 91cdf36 Compare October 5, 2026 17:58

Dere-Wah commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Oct 5, 6:07 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 5, 6:21 PM UTC: Graphite rebased this pull request as part of a merge.
  • Oct 5, 6:22 PM UTC: @Dere-Wah merged this pull request with Graphite.

@Dere-Wah
Dere-Wah changed the base branch from dere/rea-6854-report-completed-steps to graphite-base/235 October 5, 2026 18:17
@Dere-Wah
Dere-Wah changed the base branch from graphite-base/235 to main October 5, 2026 18:19
Dere-Wah and others added 2 commits October 5, 2026 18:20
A session started with a step count is meant to run that many steps and
end, with no client there to stop it. The runtime counts the steps the
model reports, and the step that brings a running session to its count
stops it: a normal stop with the close reason "Session ended: the requested
steps are complete.", which connected clients are told before their
connections close.

The model keeps stepping until the session end reaches it, so a step
reported after the stop is journalled with its number and stops nothing. A
session without a step count never stops on its own. The contract suite
now runs the whole flow on a model with no client connected: the system
client opens, the starting command runs, two steps complete, and the
session closes itself back to ready.

Signed-off-by: Dere-Wah <derexcontact@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
A step report carried nothing that tied it to a session, and the step
count resets when a session starts. A model that finished a unit of work
just after a quick stop and restart therefore had that report counted
against the new session, and could close it early.

Each report now carries the session it belongs to: the number of session
starts the model had received, which the runner counts the same way as it
posts them. The default step loop stamps the session a step began in, so a
step that spans a restart is not credited to the next session. The runner
drops a report from any other session without journalling or counting it.

Signed-off-by: Dere-Wah <derexcontact@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Dere-Wah and others added 2 commits October 5, 2026 18:20
A session that starts with steps and a starting input naming an upload
the caller seeds only after the start must not count a step on the
defaults the starting input replaces, nor reach its steps before its
setup arrives. The contract suite now runs that flow end to end: the
image is uploaded 200 ms after the start, and the journal shows the
starting command before the first step_completed, then the stop.

Signed-off-by: Dere-Wah <derexcontact@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The README described a session with steps as streaming until it ends,
without saying the runtime ends it once the model has reported that many
steps. One sentence now says so, with the close reason clients are told.

Signed-off-by: Dere-Wah <derexcontact@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@Dere-Wah
Dere-Wah force-pushed the dere/rea-6854-close-the-session-at-steps branch from 7aaeb4d to 62019ed Compare October 5, 2026 18:20
@Dere-Wah
Dere-Wah merged commit 38b8f99 into main Oct 5, 2026
10 checks passed
@Dere-Wah
Dere-Wah deleted the dere/rea-6854-close-the-session-at-steps branch October 5, 2026 18:22
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.

3 participants