Skip to content

fix(harness): preserve Terminal retirement ownership through shutdown [SAP-3292] - #1004

Closed
ynadge wants to merge 1 commit into
assistant-end-controlsfrom
terminal-retirement-followup
Closed

ynadge wants to merge 1 commit into
assistant-end-controlsfrom
terminal-retirement-followup

Conversation

@ynadge

@ynadge ynadge commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Bug fix

Problem and motivation

Shutdown omitted PTYs retained after unconfirmed cleanup. End could also delete a delegated-session binding while an older restart later recreated its marker.

Summary and scope

Retry termination of exact retained PTY handles during bounded shutdown without republishing them as live. Recheck End generations after restart probes and binding persistence, repairing only the authoritative marker state. Document that bounded registry retirement is distinct from process-exit proof.

Related work

Related issue: https://linear.app/sapiom/issue/SAP-3292

Depends on #1003; addresses review of #995. Native stack target: main.

Validation

SessionManager focused and regression suite — 264 passed
New retirement review suite — 8 passed
Regression red run with old behavior — 7 of 8 failed as expected
pnpm --filter @sapiom/harness exec tsc --noEmit — passed
pnpm --filter @sapiom/harness build:server — passed
Scoped ESLint, new-test Prettier, git diff --check — passed

Tests and documentation

Regression gates cover retained-process liveness and signal failure, replacement races, End during vendor/history probes, delayed marker writes, and authority resolution. JSDoc records cleanup result semantics. Incremental size: 318 changed lines including tests; pr:size is absent.

Compatibility and release impact

  • Breaking or externally visible changes: shutdown now retries retained handles, and stale restarts cannot recreate deleted binding markers.
  • Changeset: covered by the unreleased Terminal cleanup feature's existing package changeset.
  • Fix-forward: correct retirement in a follow-up while preserving unknown process ownership and refusing replacement without proof.

Security

  • No secrets, credentials, private data, or unsanitized logs included.
  • No suspected vulnerability disclosed publicly.

AI assistance

  • AI assistance used: Codex implemented fixes and meaningful race tests; root reviewed the isolated patch and existing callers. Restoring old behavior demonstrated regression failures.

Checklist

  • CONTRIBUTING.md read; maintainer-authorized issue work.
  • One focused increment, tests, relevant checks, documentation, and release impact addressed above.
  • I can explain and maintain the submitted changes.

Devin Review

@coderabbitai

coderabbitai Bot commented Sep 14, 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

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 9f31d057-1c65-4a62-828c-be65473dc00a

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

this.subsessionBindings.get(id) === next
)
this.subsessionBindings.set(id, current);
await this.persistSubsessionBindings().catch(() => {});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Failed repair resurrects ended binding

When End overtakes the marker write, persistSubsessionBindings ignores a failed repair. Restarting can reload the stale binding and recover the ended session.

Learn more

The delayed restart write can finish after close() has durably removed the binding. The cancellation path then writes the current in-memory state again to repair that stale disk state. If this repair fails, the catch suppresses the only evidence that disk still contains the obsolete open marker. A later process start loads that marker without the End tombstone and can treat the delegated session as recoverable.

Example: Restart writes incarnation 2 after End has persisted an empty registry. The repair then fails with ENOSPC. End already returned successfully, but the next launch reads incarnation 2 as open.

Recommended fix: Do not suppress the compensating persistSubsessionBindings() failure. Propagate it, or serialize binding writes so the stale restart write cannot complete after End's authoritative deletion. Preserve the cancellation error only after durable state is known correct.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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