Skip to content

feat(harness): coordinate Assistant lifecycle and execution leases [SAP-3292] - #996

Closed
ynadge wants to merge 1 commit into
terminal-end-admissionfrom
assistant-lifecycle-admission
Closed

ynadge wants to merge 1 commit into
terminal-end-admissionfrom
assistant-lifecycle-admission

Conversation

@ynadge

@ynadge ynadge commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Feature

Problem and motivation

A stale pane must not obtain execution after End or same-ID restoration. Context preparation can also ignore cancellation and leave old dispatch admission or recovery locks blocking the replacement runtime.

Summary and scope

Add a durable lifecycle coordinator with expected revisions, exact runtime leases, paused restoration, and an immediate End fence. Isolate in-memory dispatch admission by hosted runtime while preserving durable replay fences. Cancel pre-dispatch provider waits so late preparation results cannot submit work or hold the recovery lock. The next increment pairs these contracts with the router and browser.

Related work

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

Native stack target: main. Depends on the preceding branch, preserving Epic 2 dependency ancestry through #987. Depends on #995. Shared context types and dispatch ownership retain the fixed Epic 2 ancestry; production activation/pin remains with that owner.

Validation

pnpm --filter @sapiom/harness exec vitest run src/core/assistant-lifecycle.test.ts src/core/assistant-session-store.test.ts src/shared/opencode-errors.test.ts src/core/opencode-final-response.test.ts src/core/studio-assistant-delivery.test.ts — 52 passed
pnpm --filter @sapiom/harness exec tsc --noEmit — passed
pnpm exec eslint (changed production files) — passed
Send cancellation guard mutation — failed as expected; restored sources passed

Independent review reproduced the stale durable-revision, hung-attach, cross-runtime admission, and held recovery-lock cases before correction. Browser/production wiring is delivered in the dependent increment; this PR changes server primitives and cancellation only.

pr:size is absent in sapiom-js; incremental git diff --numstat measures 812 changed lines, including tests.

Tests and documentation

Regression tests cover durable End, stale leases, paused restart, access change, old attach completion, ignored cancellation, recovery lock release, and durable replay-fence preservation. The End orchestration caller must coalesce requests through Terminal/native cleanup and persistence.

Compatibility and release impact

  • Breaking or externally visible changes: cancelled provider waits no longer retain dispatch admission or recovery locks; new lifecycle APIs are internal until paired transport activation.
  • Changeset: added for @sapiom/harness.
  • Fix-forward: correct startup/cleanup in a follow-up while retaining process guards and proof; never delete guards to bypass uncertain cleanup.

Security

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

AI assistance

  • AI assistance used: Codex implemented the modules/tests; a separate agent reviewed their integration contracts and the root agent reran validation and reviewed the incremental diff.

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: bcbc9fb3-5a7d-4b2f-83d2-994a42bad154

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

Comment on lines +127 to +131
const pending = this.pending.get(id);
if (pending)
return pending.revision === expectedRevision
? pending.promise
: Promise.reject(failure("lifecycle_changed"));

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.

🟡 Shutdown reuses stale attach admission

After shutdown, attach returns an existing pending attachment before checking closed admission. Cancellation-ignoring association work leaves same-session callers hanging instead of receiving lifecycle_changed.

Suggested change
const pending = this.pending.get(id);
if (pending)
return pending.revision === expectedRevision
? pending.promise
: Promise.reject(failure("lifecycle_changed"));
if (this.closed) return Promise.reject(failure("lifecycle_changed"));
const pending = this.pending.get(id);
if (pending)
return pending.revision === expectedRevision
? pending.promise
: Promise.reject(failure("lifecycle_changed"));
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