Skip to content

feat(harness): reopen Assistant runtimes paused [SAP-3292] - #1000

Closed
ynadge wants to merge 1 commit into
assistant-history-checkpointsfrom
assistant-paused-restoration
Closed

ynadge wants to merge 1 commit into
assistant-history-checkpointsfrom
assistant-paused-restoration

Conversation

@ynadge

@ynadge ynadge commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Feature

Problem and motivation

Reopening Assistant history currently lets the browser request recovery of old unfinished work. An obsolete pane also needs to lose authority when its Studio session ends or its native runtime changes.

Summary and scope

Pair the browser's validated lifecycle handshake and runtime lease with production server admission. Restored runtimes remain paused until explicit Send, including both acknowledgment/history arrival orders. Publish lifecycle and native observation updates under one ordered state clock. Fence Terminal and Assistant admission together during shutdown, and reject new attaches while cancelled old association work is still pending.

Related work

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

Depends on #999; pairs the adapter in #997. Native stack target: main. Fixed Epic 2 context/runtime ancestry is preserved; its production activation and artifact pin remain separately owned.

Validation

pnpm --filter @sapiom/harness exec vitest run src/core/assistant-lifecycle.test.ts src/core/assistant-state-projection.test.ts src/server/opencode.test.ts src/server/events-ws.test.ts — 43 passed
pnpm --filter @sapiom/harness exec vitest run web/src/lib/assistant-state.test.ts web/src/lib/assistant-lifecycle-client.test.ts — 41 passed
pnpm --filter @sapiom/harness exec vitest run src/server/state-isolation.test.ts src/server/auth-mcp-wiring.test.ts — passed
pnpm --filter @sapiom/harness typecheck — passed
pnpm exec eslint (changed server files and explicit frontend project) — passed
Assistant browser suite — 52 passed; final seven lifecycle cases passed after tightening the recoverable-turn fixture and adding the second delivery-order case
Four negative mutations — failed as expected; final sources restored and focused suite passed

Tests and documentation

Tests cover paused recovery, both Send acknowledgment/history orders, exact lease headers, stale attachment disposal, End-before-attach, lifecycle snapshot validation, authority removal, and shutdown admission. Seven screenshots and command/mutation evidence are retained in the workspace handoff. Browser evidence uses deterministic HTTP/SSE fixtures; installed native acceptance remains a later integration gate. The repository has no pr:size script; measured increment: 833 changed lines including tests and changeset.

Compatibility and release impact

  • Breaking or externally visible changes: Assistant requests now require the current runtime lease; reopening restores paused history. Terminal remains the default view and the existing Assistant eligibility gate remains unchanged.
  • Changeset: added for @sapiom/harness.
  • Fix-forward: correct the handshake or pause projection in a follow-up while retaining server admission fences.

Security

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

AI assistance

  • AI assistance used: Codex implemented the browser and server pairing; the root agent reviewed the integration and reran server, decoder, and type checks. Browser mutations verify the guards affect behavior.

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

Review evidence

These images show disposable browser fixture states before and after an explicit user action, not a historical pre-implementation baseline. They do not establish native execution or an installed activated release.

Before action After action
Before action After action

@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: b7e3cc92-c149-4635-af45-f3f74dd538c5

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 2 potential issues.

Devin Review

const unsubscribeAssistant = openCodeHost.subscribeAssistantState(() =>
bus.publish({ type: "assistant.state", snapshot: getAssistantState() }),
const openCodeAssociations = new OpenCodeAssociations(assistantSessions);
const assistantLifecycle = new AssistantLifecycleCoordinator({ store: assistantSessions, host: openCodeHost, associations: openCodeAssociations });

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.

🔴 Closed sessions retain Assistant runtimes

Closing a Studio session never calls assistantLifecycle.beginEnd, so its lease and native runtime remain active. An open pane can continue Assistant requests after closure.

Learn more

The lifecycle coordinator owns the fence that invalidates leases, retires the native Assistant process, and persists ending then ended. Production creates this coordinator but never invokes that flow for a Studio session close. The deletion route still calls sessionManager.close directly, while Assistant request admission only consults the coordinator lease and durable lifecycle. Closing the Terminal therefore leaves the Assistant process and lease usable.

Example: Alice opens Assistant, receives a lease, then closes the Studio tab. The DELETE request closes the Terminal, but the mounted pane can still send a leased Assistant request. The expected result is immediate rejection and retirement of both runtimes.

Recommended fix: Add one close orchestration boundary used by the REST deletion route. It must call assistantLifecycle.beginEnd(id) synchronously, join sessionManager.closeWithResult(id), Assistant retirement, and lifecycle persistence, then call assistantLifecycle.finishEnd(fence) only after the required cleanup result. Coalesce concurrent close callers through the complete operation as required by beginEnd.

Devin Review

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

return {
...runtime,
revision,
lifecycles: runtime.enabled ? lifecycle.snapshot() : [],

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.

🔍 Lifecycle projection has no consumer

The server publishes lifecycles, but the SPA never reads them. Mounted panes therefore cannot react to ordered lifecycle changes without another request.

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