## ADDED Requirements ### Requirement: Live terminal follows the current supervised process session The system SHALL identify each newly started Run-supervised process generation with a durable logical session ID, and SHALL associate its plugin-declared `process.stdout` and `process.stderr` streams with that session. A Run restart that resumes the same running process SHALL retain that session ID. #### Scenario: Process output is collected independently of the terminal - **WHEN** a plugin-declared supervised process writes stdout or stderr while no browser terminal is open - **THEN** Run SHALL durably spool and upload that output under the process's logical session without opening an RCON connection or depending on browser state #### Scenario: Run resumes a running process after restart - **WHEN** Run restarts while its persisted supervised process is still running - **THEN** Run SHALL resume collecting output with the persisted process session ID and the terminal SHALL continue following that session #### Scenario: Run crashes between durable append and output checkpoint - **WHEN** a process line is already durable in the local spool but Run restarts before its output-file offset checkpoint is persisted - **THEN** Run SHALL recognize the repeated source cursor and SHALL NOT allocate or upload a duplicate log entry #### Scenario: A replacement starts before the prior output drain completes - **WHEN** Run starts a replacement process while the prior generation still has unread stdout or stderr - **THEN** Run SHALL retain and resume the prior generation's drain state independently of the replacement generation #### Scenario: Existing process journal predates session metadata - **WHEN** an upgraded Run loads a legacy journal for a supervised process that is still alive - **THEN** Run SHALL assign and persist a session for that same process without requiring the game process to restart ### Requirement: Live SSE exposes only the active supervised session The server log SSE endpoint SHALL select the supervised-process session named by the current `running` process fact from an online bound Run endpoint, publish an explicit session boundary, and replay only a bounded set of entries from that selected session. The process fact SHALL identify the generation as `log-session:`. The endpoint SHALL exclude legacy, completed-job, file-tail, management-program, unbound, and older supervised-session entries from the default live feed. #### Scenario: Terminal opens after prior process generations - **WHEN** an instance has historical job streams and older process sessions and an operator opens the terminal - **THEN** the endpoint SHALL publish only the active session metadata and its bounded recent output before live appends #### Scenario: No current session exists - **WHEN** no session-scoped supervised process stream has been accepted for an instance - **THEN** the endpoint SHALL publish a ready empty live session and SHALL NOT replay unrelated historical streams #### Scenario: Persisted session belongs to a stopped process - **WHEN** the newest persisted session belongs to a process that Run reported stopped, exited, or failed - **THEN** a newly opened terminal SHALL receive an empty live session and SHALL expose the persisted output only through history #### Scenario: Output arrives before its generation observation - **WHEN** session-scoped process output is accepted before Run reports a matching `log-session:` running observation - **THEN** the endpoint SHALL retain the output as history and SHALL NOT select it as the current live session until that matching observation arrives #### Scenario: A new start is dispatched from a stopped instance - **WHEN** Platform accepts a new start request for an instance with a previous process-session binding - **THEN** Platform SHALL clear the previous binding before dispatch so historical output cannot become current while the replacement generation is unobserved ### Requirement: Open terminal changes session without reconnection The SSE endpoint SHALL detect a newer supervised-process session on accepted process output and SHALL emit a new session boundary, its stream metadata, and the new session replay to existing subscribers before sending subsequent output for that session. #### Scenario: Process restarts while terminal is open - **WHEN** a replacement supervised process writes its first stdout or stderr entry while an operator's terminal is open - **THEN** the terminal SHALL discard the old live buffer, label the new current session, and display the new generation's output without the operator reopening the terminal #### Scenario: Current process exits while terminal is open - **WHEN** Run reports that the current supervised process stopped, exited, or failed - **THEN** the same SSE connection SHALL emit an empty session boundary and the terminal SHALL remove the ended session from its live buffer #### Scenario: Run reconnects to a surviving process - **WHEN** a Run endpoint reconnects and reports that its persisted supervised process is still running - **THEN** the same SSE connection SHALL reselect that process's existing session without creating a replacement session ### Requirement: Historical logs remain explicit and separate The system SHALL retain persisted log streams and cursor queries for historical inspection. The terminal SHALL expose history only through an explicit operator action or view and SHALL NOT merge it into the current live buffer. #### Scenario: Operator reviews an older stream - **WHEN** an operator explicitly selects a historical log stream - **THEN** the terminal SHALL fetch and display that stream's retained cursor entries separately from the live session ### Requirement: Command transports are not log sources The system SHALL use RCON or another plugin-declared command transport only to execute a requested command. It SHALL collect live terminal output only through plugin-declared log sources, prioritizing the supervised process stdout/stderr channels. #### Scenario: Operator sends an RCON command - **WHEN** an operator submits a SCUM management command - **THEN** the command SHALL use the protected RCON command path while live terminal output continues to arrive independently from the supervised process stream