Skip to content

feat(harness): bind Assistant transport to lifecycle leases [SAP-3292] - #997

Closed
ynadge wants to merge 1 commit into
assistant-lifecycle-admissionfrom
assistant-lifecycle-transport
Closed

ynadge wants to merge 1 commit into
assistant-lifecycle-admissionfrom
assistant-lifecycle-transport

Conversation

@ynadge

@ynadge ynadge commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Feature

Problem and motivation

An old Assistant pane can otherwise recreate a runtime after End or recover paused work after Studio restarts. Requests need to identify the exact admitted runtime and lifecycle revision.

Summary and scope

Add revision-checked attach and lifecycle inspection routes, require the issued lease on bound native requests, and enforce paused recovery in the server. Explicit Send composes context through the existing delivery owner and enables execution only after preparation. Keep the legacy router adapter for the fixed Epic 2 base until the dependent production/browser wiring lands.

Related work

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

Depends on #996. Native stack target: main; fixed Epic 2 ancestry through #987. Production context activation and the verified runtime pin remain with their existing owner.

Validation

pnpm --filter @sapiom/harness exec vitest run src/server/opencode.test.ts src/core/assistant-lifecycle.test.ts src/core/opencode-final-response.test.ts — 46 passed
pnpm --filter @sapiom/harness exec tsc --noEmit — passed
pnpm exec eslint packages/harness/src/server/opencode.ts — passed
git diff --check — passed

Tests and documentation

HTTP composition tests cover stale attach, ended sessions, foreign runtime leases, paused recovery, and explicit Send with persisted context acknowledgement. Browser pairing follows in the dependent increment. The repository has no pr:size script; measured incremental additions plus deletions: 329 lines, including tests.

Compatibility and release impact

  • Breaking or externally visible changes: the optional lifecycle-enabled router requires X-Assistant-Lease; the existing caller remains on the compatible adapter in this increment.
  • Changeset: N/A until the dependent production/browser activation enables this optional adapter.
  • Fix-forward: correct lifecycle admission in a follow-up while retaining durable replay fences and exact runtime ownership.

Security

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

AI assistance

  • AI assistance used: Codex implemented and reviewed the adapter and HTTP tests; checks above verify the composition with the actual coordinator and dispatch owner.

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: 9a83378d-3e5f-4ea9-94e9-86d6407f5b59

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

Devin Review

Comment on lines +38 to +47
const dispatch =
finalResponse ??
new OpenCodeFinalResponse({
assertCurrent: async (hosted) => {
await lifecycle?.assertRuntime(hosted, true);
await host.assertCurrent?.(hosted);
},
...(typeof context === "function"
? {}
: { recoverPrompt: context.recover }),

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.

🟡 Custom dispatch breaks context recovery

With lifecycle mode and a supplied finalResponse, accepted-v2 turns cannot recover. dispatch lacks context.recover, so recovery uses the incompatible legacy parser.

Learn more

A lifecycle-enabled router composes new prompts through AssistantContextDelivery, which writes accepted-v2 systems. OpenCodeFinalResponse can recover those systems only when its recoverPrompt option points to context.recover; otherwise it calls the legacy recoverAssistantPrompt. The nullish selection of finalResponse skips both that callback and the new runtime assertion whenever a caller supplies a dispatcher. This combination is necessary for callers that also need options such as onPersisted.

Example: A caller passes its existing new OpenCodeFinalResponse({ onPersisted }), an AssistantContextDelivery, and a lifecycle coordinator. A Send persists an accepted-v2 system. Recovering its interrupted response reaches the legacy parser, rejects that system, and returns HTTP 503 instead of continuing the turn.

Recommended fix: Configure one OpenCodeFinalResponse with context.recover, lifecycle/host assertions, and caller-specific hooks. Replace the prebuilt-instance parameter with delivery options or a factory if the existing instance cannot safely receive those callbacks.

Devin Review

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

Comment on lines 25 to +35
export function createOpenCodeRouter(
host: Pick<OpenCodeHost, "ensure" | "observe">,
host: Pick<OpenCodeHost, "ensure" | "observe"> &
Partial<Pick<OpenCodeHost, "assertCurrent">>,
bootToken: string,
resolveContext: ResolveAssistantContext,
context: ResolveAssistantContext | AssistantContextDelivery,
associations = new OpenCodeAssociations(),
finalResponse = new OpenCodeFinalResponse(),
finalResponse?: OpenCodeFinalResponse,
lifecycle?: Pick<
AssistantLifecycleCoordinator,
"describe" | "attach" | "use" | "enable" | "assertRuntime"
>,

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 mode has no production caller

The production router still uses the legacy adapter. Revision-bound attach, leases, paused recovery, and lifecycle inspection remain unreachable outside tests.

Devin Review

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

Comment on lines 25 to +35
export function createOpenCodeRouter(
host: Pick<OpenCodeHost, "ensure" | "observe">,
host: Pick<OpenCodeHost, "ensure" | "observe"> &
Partial<Pick<OpenCodeHost, "assertCurrent">>,
bootToken: string,
resolveContext: ResolveAssistantContext,
context: ResolveAssistantContext | AssistantContextDelivery,
associations = new OpenCodeAssociations(),
finalResponse = new OpenCodeFinalResponse(),
finalResponse?: OpenCodeFinalResponse,
lifecycle?: Pick<
AssistantLifecycleCoordinator,
"describe" | "attach" | "use" | "enable" | "assertRuntime"
>,

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.

🔍 New transport contract is undocumented

Lifecycle mode adds routes, required headers, response fields, and 409 failures without API documentation. The repository requires documenting externally visible behavior.

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