Repository navigation
feat(harness): fence paused continuation preparation [SAP-3292] #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@sapiom/harness": patch | ||
| --- | ||
|
|
||
| Reserve exclusive paused Assistant continuation preparation and reject retries that lose committed accepted material. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -240,14 +240,35 @@ export class AssistantLifecycleCoordinator { | |||||||||||||||||||||||||
| return { conversationId, lease, lifecycle: { ...lifecycle } }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** Exclusive temporary ownership, shared with Attach and future Resume. Never | ||||||||||||||||||||||||||
| /** Exclusive temporary ownership, shared with Attach, Continue and Resume. Never | ||||||||||||||||||||||||||
| * creates an association or grants execution. Callback results stay private; | ||||||||||||||||||||||||||
| * the caller revalidates its saved binding after provisional cleanup. */ | ||||||||||||||||||||||||||
| async inspect<T>( | ||||||||||||||||||||||||||
| inspect<T>( | ||||||||||||||||||||||||||
| id: string, | ||||||||||||||||||||||||||
| expectedRevision: number, | ||||||||||||||||||||||||||
| read: (hosted: HostedOpenCode, signal: AbortSignal) => Promise<T>, | ||||||||||||||||||||||||||
| callerSignal?: AbortSignal, | ||||||||||||||||||||||||||
| ): Promise<T> { | ||||||||||||||||||||||||||
| return this.prepareRuntime(id, expectedRevision, read, false, callerSignal); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** Trusted Continue preparation owns an open child before its receipt permits | ||||||||||||||||||||||||||
| * Attach. Keep the exact runtime on success, but grant no lease or execution. */ | ||||||||||||||||||||||||||
| prepareContinuation<T>( | ||||||||||||||||||||||||||
| id: string, | ||||||||||||||||||||||||||
| expectedRevision: number, | ||||||||||||||||||||||||||
| prepare: (hosted: HostedOpenCode, signal: AbortSignal) => Promise<T>, | ||||||||||||||||||||||||||
| callerSignal?: AbortSignal, | ||||||||||||||||||||||||||
| ): Promise<T> { | ||||||||||||||||||||||||||
| return this.prepareRuntime(id, expectedRevision, prepare, true, callerSignal); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| private async prepareRuntime<T>( | ||||||||||||||||||||||||||
| id: string, | ||||||||||||||||||||||||||
| expectedRevision: number, | ||||||||||||||||||||||||||
| read: (hosted: HostedOpenCode, signal: AbortSignal) => Promise<T>, | ||||||||||||||||||||||||||
| retain: boolean, | ||||||||||||||||||||||||||
| callerSignal?: AbortSignal, | ||||||||||||||||||||||||||
| ): Promise<T> { | ||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||
| this.closed || | ||||||||||||||||||||||||||
|
|
@@ -276,7 +297,11 @@ export class AssistantLifecycleCoordinator { | |||||||||||||||||||||||||
| check(); | ||||||||||||||||||||||||||
| const state = await awaitAssistantInspection(this.describe(id), signal); | ||||||||||||||||||||||||||
| check(); | ||||||||||||||||||||||||||
| if (state.revision !== expectedRevision || state.lifecycle === "ending") | ||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||
| state.revision !== expectedRevision || | ||||||||||||||||||||||||||
| state.lifecycle === "ending" || | ||||||||||||||||||||||||||
| (retain && state.lifecycle !== "open") | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
Comment on lines
+300
to
+304
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Active leases survive continuation preparation
Learn moreContinuation preparation uses the same admission slot as attachment and inspection, but the slot only prevents new operations from starting. An attachment completed before preparation leaves a lease in Example: A child is attached and receives a paused lease. Before or during enablement, a continuation retry calls Recommended fix: Reject retained preparation when the session has a current lease. Permit an obsolete lease whose host is no longer current, since the retained path can safely allocate a replacement.
Suggested change
Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||||||||||||||||||||||
| throw failure("lifecycle_changed"); | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| let hosted: HostedOpenCode | undefined; | ||||||||||||||||||||||||||
|
|
@@ -322,7 +347,7 @@ export class AssistantLifecycleCoordinator { | |||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| if (provisional && started) { | ||||||||||||||||||||||||||
| if (provisional && started && !(complete && retain)) { | ||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||
| this.inspections.get(id) === controller && | ||||||||||||||||||||||||||
| this.generation(id) === fence.generation | ||||||||||||||||||||||||||
|
|
@@ -334,7 +359,7 @@ export class AssistantLifecycleCoordinator { | |||||||||||||||||||||||||
| void this.options.host.retireExact(hosted).catch(() => {}); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| if (complete) await revision(); | ||||||||||||||||||||||||||
| if (complete && !retain) await revision(); | ||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||
| clearTimeout(timer); | ||||||||||||||||||||||||||
| if (this.inspections.get(id) === controller) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Continuation fencing remains unwired
Production constructs the coordinator without
canAttach, and only tests callprepareContinuation. Continue operations remain unchanged until the planned consumer wiring lands.Was this helpful? React with 👍 or 👎 to provide feedback.