Skip to content

Add terminal snapshot freshness contract gate - #7005

Closed
brennanb2025 wants to merge 1 commit into
brennanb2025/fix-terminal-reliabilityfrom
brennanb2025/reliability-snapshot-integration
Closed

brennanb2025 wants to merge 1 commit into
brennanb2025/fix-terminal-reliabilityfrom
brennanb2025/reliability-snapshot-integration

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Added a deterministic terminal snapshot freshness contract harness with a deferred listSessions provider and mutable visible/hidden pane bindings.
  • Covered the escaped race where a snapshot requested before a PTY rebind resolves stale without the newer PTY id, and verified a later post-bind snapshot still tears down genuinely dead local bindings.
  • Updated only the terminal-session.snapshot-freshness gate metadata to describe the renderer provider-contract layer and unchanged soak maturity.

ELI5

The app sometimes asks, "which terminal sessions are alive?" That answer can arrive late. If a terminal reconnects while we are waiting, the old answer must not close the new terminal by mistake. This PR adds a test that freezes that timing problem and proves old answers cannot kill newer terminal bindings.

Why We Need This

This covers the stale terminal-liveness snapshot class. Orca can ask the provider which PTY sessions are alive, but that answer may arrive after a pane has already rebound to a newer PTY. Without a freshness invariant, an old answer can close a valid newer terminal.

Product Code vs Gate Coverage

This PR is gate coverage, not a runtime rewrite. It adds a deterministic provider-contract harness around the existing dead-session reconciliation behavior and updates the manifest metadata. The gate proves that stale pre-bind snapshots cannot tear down newer bindings, while fresh post-bind snapshots still close genuinely dead local bindings.

Red/Green

  • Red: removing the ptyBoundAt >= snapshotRequestedAt freshness guard, or moving requestedAt capture until after listSessions resolves, makes the new provider-contract test close pty-visible-new and pty-hidden-new from the stale snapshot.
  • Green: with the guard and request-time capture in place, stale pre-bind snapshots do not teardown newer bindings, while fresh post-bind snapshots still close genuinely absent local bindings.

Performance

  • The change adds only an in-memory Vitest harness and does not add production polling, hidden-pane scans, or provider calls.
  • Production behavior remains one listSessions request per existing visibility/input-triggered reconciliation pass.

Merge Order

Requires #7001 first because this PR updates the reliability gate manifest introduced there.

After #7001 lands, this PR can merge independently of #7004, #7006, #7007, and #7008. No other child PR must merge before this one. Later child PRs may need a normal manifest rebase if this one lands first.

Why These Tests Stay Useful

  • Invariant protected: a liveness snapshot requested before a pane binds a newer PTY cannot close that newer binding when the old provider answer arrives late.
  • Right layer: this is a renderer/provider-contract race, so a deterministic deferred listSessions harness proves the failure more directly than a broad Electron flow. A full UI test would add timing noise without improving the core oracle.
  • Stable oracle: the test controls exactly when the provider snapshot resolves and exactly when visible/hidden pane bindings change. It asserts teardown decisions and surviving bindings directly, with no sleeps, real terminals, shared profiles, or platform timing dependencies.
  • How we know it works: the red case is concrete: remove the freshness guard or capture requestedAt after listSessions resolves and the stale snapshot closes the newly bound PTYs. With the guard intact, stale pre-bind snapshots are ignored while fresh post-bind misses still close genuinely dead local bindings.
  • Why it stays useful: the test encodes the class-level inverse property, not just one bug path: old observations cannot tear down newer ownership. The manifest keeps SSH/remote and full Electron tab-survival/input echo as explicit gaps instead of pretending this lower-layer gate proves them.
  • Anti-flake policy: the gate stays at soak; promotion requires recorded runtime, flake history, and saved red/green evidence before it can become blocking.

Validation

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-dead-session-reconcile.test.ts
  • pnpm run check:reliability-gates
  • pnpm exec oxlint src/renderer/src/components/terminal-pane/terminal-snapshot-freshness-contract.ts src/renderer/src/components/terminal-pane/terminal-dead-session-reconcile.test.ts config/reliability-gates.jsonc
  • git diff --check

Notes

  • SSH liveness remains unknown in the contract harness: a fresh local snapshot miss does not close an SSH-bound pane.
  • Manifest maturity did not change; terminal-session.snapshot-freshness remains soak.
  • Residual risk: this is deterministic renderer/provider-contract coverage, not a full Electron tab-survival/input echo fixture.

Made with Orca 🐋


Open in Stage

Post-PR Stabilization

  • CI checks pass after the post-PR wait.
  • PR comments and review-comment surfaces were checked; no actionable automated review comments remain.

@ghost

ghost commented Jul 1, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 3 individual chapters for you:

Title
1 Define terminal snapshot freshness contract harness
2 Verify snapshot freshness and SSH liveness contracts
3 Update reliability gate metadata for provider contract
Open in Stage

Chapters generated by Stage for commit 3542334 on Jul 1, 2026 8:22am UTC.

@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-01T23:22:55Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Fixed on main by #6801; this PR only adds tests.

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.

2 participants