feat(system): fence terminal lifecycle generations - #74
Conversation
Initial independent high-risk reviewExact head reviewed: Scope and methodI inspected the complete pinned 15-file diff (871 additions, 108 deletions), then traced the changed paths through the surrounding stream dispatch, terminal session, reconnect, persistence HTTP, relay protocol, TUI, and tests. I compared the protocol rollout against the repository's known-good compatibility control in FindingsBLOCKING — V3 agent strands against the currently deployed V2/legacy relayRefs: This head unconditionally advertises Reachable scenario/material impact: install/update this agent while the hosted backend is still on its current main/deployed version (the normal mixed-version rollout), start it with a valid pairing token, and it remains offline indefinitely; existing users lose tunnel, proxy, and terminal access. This violates the repository's explicit rollout order (backend compatibility first, then agent) and the issue acceptance criterion that mixed-version deployment fail safely rather than strand Required acceptance criteria: either (1) land/deploy backend compatibility for V3 and the reset/terminal lifecycle routes before publishing this agent, with an enforced dependency/release gate, or (2) retain a mixed-version-compatible handshake/agent path that negotiates capabilities and does not require lifecycle endpoints against an older backend. Add an integration/compatibility test proving an old backend plus this agent remains usable for non-lifecycle operation and that the new lifecycle path is only enabled after V3/reset support is confirmed. DispositionNo other evidenced reachable material blockers were found in the pinned diff. The PTY normalization, generation checks, reconnect reconciliation ordering, input-worker accounting/cancellation, sealing/protocol framing, and TUI stale-message handling were traced and covered by the changed tests; the local full and race test runs above passed. Residual risk remains on cross-repository deployment sequencing and real backend/browser interoperability, which this repository's tests cannot establish. NEEDS ATTENTION |
Independent high-risk initial reviewGitHub refused Risk: high. This head changes host PTY lifecycle, reconnect ordering, background retry workers, and relay protocol compatibility (v3 record/generation fences). Pinned head reviewed: Method: Complete BLOCKING1. TUI can create and spawn a PTY before process-start reset; reset then exits that row and reconnect reconcile kills the shell
Backend reset is not “unused leftovers only”: it lists every non-exited row for the system and reports each exited. A reachable sequence:
The operator’s first shell dies, and the tab flips to exited. The window is one HTTP RTT on a healthy reset and seconds to minutes while reset 5xx/404 retries — the exact mixed-version startup this rollout uses. This is new versus Required fix: When 2. d.lifecycleMu.Lock()
defer d.lifecycleMu.Unlock()
d.terminalMu.Lock()
defer d.terminalMu.Unlock()
// ...
if h.TerminalRecordID != "" && d.cfg.RelayURL != "" {
ctx, cancel := context.WithTimeout(d.lifecycleContext(), terminalLocalActionTO)
rows, err := d.fetchTerminalSessions(ctx)
Reachable on any production agent (
Control: Required fix: Do not hold BLOCKING TEST GAP3. Claimed close / reset-before-publish invariants have no failing test This head adds TUI
Required tests: one close/reconcile test that starts a real mapped session, injects a non-running or absent authoritative row, and asserts process teardown + exact-generation FOLLOW-UP4.
Rationale: decoder inconsistency next to a new privileged restart. 5. Generation mismatch schedules close and fails the attach instead of replacing
Rationale: restart is specified to start one new shared PTY for the same tab. 6. TUI close/restart presentation is incomplete Exited Enter reuses Rationale: the PR claims truthful running/closing/exited/restart/close empty states. 7. Project delete still only hits HTTP
Rationale: leftover shells after project delete. Investigated and not blocking: v3 advertisement and missing-record/generation refusal before handshake ( Residual risk: I did not execute NEEDS ATTENTION |
Implements the agent/protocol layer for https://github.com/nicodes/ormos-be/issues/508.
Risk: high. This changes host PTY lifecycle, reconnect ordering, background retry workers, and relay protocol compatibility.
Summary
Verification
go test ./... -count=1go test -race ./... -count=1go vet ./...git diff --checkDeliberate gate proof: making initial reconnect reconciliation asynchronous caused
TestInitialReconnectReconciliationBlocksStreamAcceptanceto fail/hang; synchronous reconciliation was restored before the green runs.