Repository navigation
feat(mcp): watch and control agent sessions from the personal MCP - #77
Merged
Merged
Conversation
A session's terminal was only readable after it ended: logs are collected during the container workflow's cleanup phase, and the serving endpoint 404s anything that is not finished or failed. So an agent could not tell a working session from a wedged one, and could not do anything about it. Adds four personal-MCP tools over the seams that already existed: list_sessions, get_session_log (live `tmux capture-pane` read while the container is up, stored log once it is over, plus idle time and a quota verdict), stop_session and trigger_task_workflow — the last being the board card's Run workflow button, with a force that cancels the in-flight run first. Reads are gated by TerminalSession.readable_by + visible_to?, extracted so the tool and Api::V1::TerminalSessionsController share one rule. Writes go through SessionService/WorkflowService/TaskService only: a hand-rolled transition leaves the pod, Service and IngressRoute behind. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
alex-astafyev
pushed a commit
to alex-astafyev/flow
that referenced
this pull request
Aug 19, 2026
* origin/develop: feat(mcp): watch and control agent sessions from the personal MCP (AixleHQ#77)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
A session's terminal is only readable after it ends: logs are collected in the container workflow's cleanup phase, and
Api::V1::TerminalSessionsController#terminal_logdeliberately 404s anything notfinished/failed. The personal MCP had no session tool at all — so an agent could not tell a working session from a wedged one, and could not do anything about one that was stuck.Research:
docs/research/technical-agent-session-log-access-and-control-research-2026-08-10.md.Spec:
docs/implementation-artifacts/spec-session-observability-mcp-tools.md.What
Four personal-MCP tools, over seams that already existed:
list_sessionsget_session_logtmux capture-panewhile the container is up, the storedterminal_output.logonce it is over — plusidle_seconds,last_output_atand aQuotaErrorDetectorverdictstop_sessionSessionService.finish, orforce→fail_session(what unblocks a workflow step waiting on a wedged agent)trigger_task_workflowforce: truecancels the in-flight run firstSupporting changes:
Sessions::LiveLogReader— one exec that returns the log's mtime and the pane, so a read costs a single pod-exec upgrade. Same readScanQuotaErrorsActivityhas always done, factored out so the two cannot drift.TerminalSession.readable_by(user)— the reachability half of the read rule, now shared withTerminalSessionsController#find_readable_session.visible_to?is still applied per row.FakeRuntimegainsset_terminal_pane/unreachable_on_exec, so the live path is tested through the blessed container seam rather than per-test stubs.Decisions worth reviewing
truncatedflag.capture-paneread is already plain text; a stored log is stripped by default,raw: truereturns the bytes verbatim.SessionService/WorkflowService/TaskService. A hand-rolledsession.fail!leaves the pod, Service, IngressRoute and Middlewares behind (seesession_service.rb:66-85).Verified
docker compose exec -T web make check_all— all green (rails-test, rubocop, brakeman, system-test, eslint, typescript, fe-test, vite-build); backend line coverage 91.46%.WorkflowService#cancel_active_step_runs→SessionService.cancel→ Temporal cancellation →ContainerWorkflow#run_cleanup_detached(a freshCancellation, so the cleanup activity still runs) → pod reclaimed and the terminal log collected. Theforcetest exercises the realWorkflowService, not a mock of it.Noted, not fixed (pre-existing)
WorkflowService.cancelrecords a:workflow_cancelledboard activity, butBoardActivity'sevent_typeenum has no such value — the write fails validation and is swallowed by the rescue, so cancellations never appear on the board timeline. Out of scope here.🤖 Generated with Claude Code