fix(server): persist delivered ACP instructions across reconnects #40876
Closedzaidsulthan02-wq(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/40876/headopened View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -2352,0 +2389,21 @@2389+ };2390+ return [cleared, new Map(current).set(sessionId, cleared)] as const;2391+ });2392+ const active = yield* Ref.get(activeTurn);2393+ if (active?.nativeThreadId === sessionId) {2394+ if (clearedMetadata !== undefined) {2395+ active.nativeMetadata = clearedMetadata;2396+ } else if (active.nativeMetadata?.acpDeliveredInstructions != null) {2397+ active.nativeMetadata = {2398+ ...active.nativeMetadata,2399+ acpDeliveredInstructions: null,2400+ };2401+ }2402+ } else {2403+ const knownProviderThread = (yield* Ref.get(providerThreadByNativeSessionId)).get(2404+ sessionId,2405+ );2406+ if (2407+ knownProviderThread !== undefined &&2408+ (clearedMetadata !== undefined ||2409+ knownProviderThread.nativeMetadata?.acpDeliveredInstructions != null)@@ -8258,3 +8342,4 @@82588342 option.type === "select" &&82598343 typeof selection.value === "string"82608344 ) {8345+ if (option.currentValue === selection.value) continue;@@ -8705,3 +8797,4 @@87058797 threadId: context.input.threadId,87068798 providerTurn: turn,87078799 });8800+ const deliveredInstructionState = (yield* Ref.get(promptInstructionStates)).get(@@ -8705,3 +8797,13 @@87058797 threadId: context.input.threadId,87068798 providerTurn: turn,87078799 });8800+ const deliveredInstructionState = (yield* Ref.get(promptInstructionStates)).get(8801+ context.nativeThreadId,8802+ );8803+ const deliveredRuntimeDigest = (yield* Ref.get(promptRuntimeInstructions)).get(8804+ context.nativeThreadId,8805+ );8806+ const sessionPendingCompaction = (yield* Ref.get(compactionMarkers)).has(8807+ context.nativeThreadId,8808+ );8809+ if (settledStatus === "completed" && !sessionPendingCompaction) {
Pushedeb9e386
zaidsulthan02-wq(GitHub profile, opens in a new tab) linked this to fix #24465
- @@ -2351,0 +2380,21 @@2380+ completedCompactionIds,2381+ (current): [boolean, Set<string>] =>2382+ current.has(key) ? [true, current] : [false, new Set(current).add(key)],2383+ );2384+ if (alreadyMarked) return;2385+ }2386+ yield* Ref.update(compactionMarkers, (current) =>2387+ new Map(current).set(sessionId, Symbol()),2388+ );2389+ const clearedMetadata = yield* Ref.modify(nativeMetadataBySessionId, (current) => {2390+ const existing = current.get(sessionId);2391+ if (existing?.acpDeliveredInstructions == null)2392+ return [undefined, current] as const;2393+ const cleared: OrchestrationV2ProviderThreadNativeMetadata = {2394+ ...existing,2395+ acpDeliveredInstructions: null,2396+ };2397+ return [cleared, new Map(current).set(sessionId, cleared)] as const;2398+ });2399+ const active = yield* Ref.get(activeTurn);2400+ if (active?.nativeThreadId === sessionId) {@@ -9160,8 +9297,13 @@9160- observedMarker === undefined ||9161- current.get(context.nativeThreadId) !== observedMarker9162- )9163- return current;9164- const updated = new Map(current);9165- updated.delete(context.nativeThreadId);9166- return updated;9167- });9297+ yield* instructionMetadataPermit.withPermit(9298+ Effect.gen(function* () {9299+ yield* Ref.update(promptInstructionStates, (current) => {9300+ if (promptParts?.instructionState === undefined) return current;9301+ const updated = new Map(current);9302+ updated.set(context.nativeThreadId, promptParts.instructionState);9303+ return updated;9304+ });9305+ yield* Ref.update(promptRuntimeInstructions, (current) => {9306+ if (promptParts?.runtimeInstructions === undefined) return current;9307+ const updated = new Map(current);9308+ updated.set(context.nativeThreadId, promptParts.runtimeInstructions);9309+ return updated;@@ -10066,10 +10280,9 @@1006610280 yield* Ref.set(activeSelection, nextSelection);1006710281 yield* Ref.set(activeInteractionMode, nextRuntimePolicy.interactionMode);1006810282 }10069- const now = yield* DateTime.now;10070- return {10071- ...threadInput.providerThread,10072- providerSessionId: input.providerSessionId,10073- status: "idle" as const,10074- updatedAt: now,10075- };10283+ return yield* instructionMetadataPermit.withPermit(10284+ Effect.gen(function* () {10285+ const compactedDuringActivation = (yield* Ref.get(compactionMarkers)).has(10286+ sessionId,10287+ );10288+ const baseMetadata = threadInput.providerThread.nativeMetadata ?? null;
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
github-actions[bot](GitHub profile, opens in a new tab) removed labelsneeds-rebase
Sign in to join this conversation.
Walkthrough
The ACP adapter now persists delivered-instruction metadata across thread resumes and uses a runtime-instruction digest to decide when to send instructions. It clears that metadata for compaction and rollback. Configuration updates skip model, select, and boolean options that already match the requested values.
Changes: ACP instruction delivery
packages/contracts/src/orchestrationV2.ts,packages/provider-acp/src/server/adapter.tspackages/provider-acp/src/server/adapter.ts,apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsACP configuration selection
packages/provider-acp/src/server/adapter.ts,apps/server/src/provider/acp/AntigravityAcpSupport.ts,apps/server/src/provider/acp/AntigravityAcpSupport.test.tsEstimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix
Sequence Diagram(s)#
Possibly related issues
Suggested labels:
bugfixSuggested reviewers:
juliusmarminge,charlesbine,shivamhwpMerge Risk:
Moderate · up to
eb9e3Instruction-delivery state now survives reconnects, which avoids re-sending instructions, and the earlier early-completion and stale-config issues are fixed. A late prompt response can still overwrite a newer turn's recorded mode, so a later reconnect may skip instructions the session needs. Two narrower metadata-staleness gaps also remain. These issues should be addressed or explicitly accepted before merging.
Pre-merge checks:
4
Full details: Title check
Explanation
The title "fix(server): persist delivered ACP instructions across reconnects" is a conventional commit that names the primary change: delivered ACP instruction state is now persisted across session reconnects. The changeset matches this, adding acpDeliveredInstructions metadata in contracts and the ACP adapter, plus reconnect tests. The title does not cover the model/config write skipping, but that is a secondary aspect and the title does not need to cover every detail.
Full details: Description check
Explanation
The description follows the repository template closely. It has Problem, Change (labeled Fix), Scope, and Verification sections. The Problem section explains the bug: delivery tracking for ACP instructions lives only in process-local memory, so resuming a native thread re-injects the instruction blocks. It also describes the redundant model and config writes on resume. The Fix section lists the persisted metadata, the clearing rules for compaction and rollback, and the skipped setModel and setConfigOption calls. Scope links issue
#24465and classifies the change as a bug fix. Verification lists the focused tests added, the commands run, and the reported results, and the author notes the work was built with an agent model. The template's trailing agent-attribution line is present. Minor gaps: the Change section uses the label Fix rather than Change, and the Verification section reports results that the PR objectives describe as author-reported outcomes. The Verification section does not explicitly state anything that could not be checked. Overall the description is complete and specific.Finishing Touches
Generate unit tests (beta)