Skip to content

Commit c7402aa

Browse files
committed
Preserve provider refs across task lifecycle
1 parent 59a7b1e commit c7402aa

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/runtime.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class RuntimeService {
179179

180180
await this.store.updateTask(task.id, {
181181
status: "running",
182-
providerRefs: { ...task.providerRefs, ...started.providerRefs },
182+
providerRefs: { ...(await this.latestProviderRefs(task.id)), ...started.providerRefs },
183183
updatedAt: nowIso()
184184
});
185185
for (const artifact of started.artifacts ?? []) {
@@ -245,6 +245,10 @@ export class RuntimeService {
245245
};
246246
}
247247

248+
private async latestProviderRefs(taskId: string): Promise<Record<string, unknown>> {
249+
return (await this.store.getTask(taskId))?.providerRefs ?? {};
250+
}
251+
248252
private selectAdapter(request: DispatchRequest): BackendAdapter {
249253
const backendName = request.backend ?? this.defaultBackendFor(request);
250254
if (backendName) {

test/runtime.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ describe("RuntimeService", () => {
142142
cleanupStatus: "pending",
143143
createdAt: timestamp,
144144
updatedAt: timestamp
145-
}
146-
})
145+
},
146+
providerRefs: { runtimeId: "provider_runtime_1" }
147+
}),
148+
startTask: async () => ({ providerRefs: { runtimeSessionId: "agentcore_session_1" }, result: { ok: true } })
147149
};
148150
const service = new RuntimeService({
149151
config: { accounts: { "dev-aws": { provider: "aws", credentialSource: "aws-sdk-default" } }, backends: {} },
@@ -159,6 +161,12 @@ describe("RuntimeService", () => {
159161
cleanupStatus: "completed",
160162
providerRefs: { runtimeId: "provider_runtime_1", cleanupId: "cleanup_1" }
161163
});
164+
expect(store.tasks.get(handle.taskId)).toMatchObject({
165+
providerRefs: {
166+
runtimeId: "provider_runtime_1",
167+
runtimeSessionId: "agentcore_session_1"
168+
}
169+
});
162170
});
163171

164172
it("persists failed runtime cleanup without changing succeeded task result", async () => {

0 commit comments

Comments
 (0)