Skip to content

feat(agent-session): refuse a command whose session_id is not the session of now - #827

Open
hongquanli wants to merge 4 commits into
feat/agent-sessionfrom
feat/agent-session-id-check
Open

hongquanli wants to merge 4 commits into
feat/agent-sessionfrom
feat/agent-session-id-check

Conversation

@hongquanli

Copy link
Copy Markdown
Contributor

What this does

A client of the control server can put the identifier of its agent session next to command and params:

{"command": "move_to", "params": {"x_mm": 20.0}, "session_id": "5f0c..."}

Squid then serves the request only when that session is the session of now. If the session ended, and also if a different session began after it, the answer is the error this is not the agent session of now, and nothing changes.

Why

A program that drives the microscope reads the session state at intervals. Between two reads, a human can end its session, and a different program can begin one. Without the identifier, the next command of the first program goes to the session of the second program.

Behaviour that does not change

A request with no session_id works as before. No client must change.

How it works

  • The session (control/core/agent_session.py). The check is in the same locked block as the change:
    • an action command, at its admission (admit);
    • take over and end (request_stop, end);
    • hand back (hand_back).
  • The control server. _execute gets the session_id of the request. The handlers of the session commands read it from a context variable, so their signatures and their schemas stay as they are.
  • The window. A hand back goes through the GUI thread. The identifier goes with it, so a refused hand back does not put the input shield on and does not lock the control panel.
  • ping and the get_* commands are served with any identifier: they change nothing.
  • begin_agent_session with an identifier is refused: a session that begins has no identifier yet.
  • send_command() has an optional session_id.
  • docs/agent-session.md has a new part, "A command for one session: session_id".

Tests

  • New tests for each change with the identifier of an earlier session, for a request with an identifier and no session, for the path through the control server and through a real socket, and for the path through the window thread.
  • The agent session test files: 79 passed.
  • tests/control/test_HighContentScreeningGui.py, whole, in one process: 59 passed.
  • In simulation, with the window and the control server, a client sent commands over TCP: 25 of 25 checks passed (a wrong identifier is refused for a move, a take over, a hand back and an end; the right one is served; a second session has a new identifier, and the first one is then refused). No dialog opened.

Order

This pull request is on top of #823, and its base is the branch of #823. Merge #823 first.

🤖 Generated with Claude Code

https://claude.ai/code/session_0152Tv36aY3Whyz7ATrKcZX3

hongquanli and others added 2 commits November 15, 2026 06:15
… not the session of now

A client of the control server can put the identifier of its agent session
next to command and params. Squid then serves the request only when that
session is the session of now. The check is in the same locked block as the
change: for an action command at its admission, and for take over, hand back
and end in the call that changes the session. A hand back carries the
identifier to the window, so the input shield and the panel lock are not
touched for a refused request. A begin with an identifier is refused. A read
is served with any identifier. A request with no identifier works as before.

This is for a program that reads the session state at intervals: between two
reads, a human can end its session and a different program can begin one.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0152Tv36aY3Whyz7ATrKcZX3
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Team
  • Run ID: cc01915e-ee32-49c2-9ab7-d8ea2b644cfa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

hongquanli and others added 2 commits November 15, 2026 09:05
…long limit

The test of a hand back with the wrong session id waited 2 s for the answer of
a server thread and did not join the thread when the wait ran out. It now
waits up to 10 s for the end of the thread, and the thread is a daemon, so a
thread that a failed test leaves behind does not keep the tests from ending.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0152Tv36aY3Whyz7ATrKcZX3
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.

1 participant