@nylorun/runtime 0.48.0-beta → 0.48.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.48.1-beta
4
+
5
+ ### Patch Changes
6
+
7
+ - f581772: An Agent created again under a deleted Agent's id no longer takes that Agent's state. Before, it read `failing` or `input_required` from sessions whose last turn ran on the deleted Agent, before it existed. Its `state` and `attention` now count a session only once that session takes a turn on the new Agent. The sessions still keep the id and can go on with the new Agent, as before, and they still appear in its `sessions`.
8
+
3
9
  ## 0.48.0-beta
4
10
 
5
11
  ### Minor Changes
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.2.0",
3
3
  "info": {
4
4
  "title": "Nylorun Management API",
5
- "version": "0.48.0-beta",
5
+ "version": "0.48.1-beta",
6
6
  "x-nylorun-protocol": {
7
7
  "min": 16,
8
8
  "max": 18,
package/dist/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.2.0",
3
3
  "info": {
4
4
  "title": "Nylorun Runtime API",
5
- "version": "0.48.0-beta",
5
+ "version": "0.48.1-beta",
6
6
  "x-nylorun-protocol": {
7
7
  "min": 16,
8
8
  "max": 18,
@@ -25,6 +25,14 @@ export declare function stateOf(agent: Pick<Environment, "desiredState" | "pod">
25
25
  state: AgentState;
26
26
  attention: AgentAttention[];
27
27
  };
28
+ /**
29
+ * The sessions whose latest turn ran on this Agent. A deleted Agent's sessions keep its id
30
+ * (`deleteAgent`), so an Agent created again under that id would otherwise read `failing` or
31
+ * `input_required` from turns it never ran. A session whose latest turn started before this Agent
32
+ * was created is left out of its state until it takes a turn here; one with no turn in the turn
33
+ * index (Host feature `turns`) is kept.
34
+ */
35
+ export declare function ranOnThisAgent<T extends Pick<Session, "id" | "activeTurnId" | "lastTurnId">>(t: Tx, environment: Pick<Environment, "createdAt">, sessions: readonly T[]): Promise<T[]>;
28
36
  /** How an Agent names its manifest: `name` when it tracks it, `name@n` when pinned. */
29
37
  export declare function manifestRefOf(agent: Pick<Environment, "manifestName" | "manifestVersion" | "manifestRef">): string;
30
38
  /**
@@ -141,7 +149,8 @@ export declare function refuseDiskCopy(environment: Environment): void;
141
149
  /**
142
150
  * `DELETE /v1/agents/{id}`: deletes the Environment, its vault and its workspace. Refused
143
151
  * while a session that names it has an active turn. Sessions keep its id: their next turn is
144
- * refused (`agent_unavailable`) unless an Environment with this id exists again.
152
+ * refused (`agent_unavailable`) unless an Environment with this id exists again. An Agent created
153
+ * again under the id does not take their state until they take a turn on it (`ranOnThisAgent`).
145
154
  */
146
155
  export declare function deleteAgent(ctx: TenantContext, id: string, scope: AuthScope): Promise<{
147
156
  id: string;
@@ -150,6 +150,24 @@ export function stateOf(agent, sessions, unsetSecrets = []) {
150
150
  attention.sort((a, b) => STATE_RANK.indexOf(a.state) - STATE_RANK.indexOf(b.state));
151
151
  return { state: attention[0]?.state ?? "sleeping", attention };
152
152
  }
153
+ /**
154
+ * The sessions whose latest turn ran on this Agent. A deleted Agent's sessions keep its id
155
+ * (`deleteAgent`), so an Agent created again under that id would otherwise read `failing` or
156
+ * `input_required` from turns it never ran. A session whose latest turn started before this Agent
157
+ * was created is left out of its state until it takes a turn here; one with no turn in the turn
158
+ * index (Host feature `turns`) is kept.
159
+ */
160
+ export async function ranOnThisAgent(t, environment, sessions) {
161
+ const kept = [];
162
+ for (const session of sessions) {
163
+ const turnId = session.activeTurnId ?? session.lastTurnId;
164
+ const turn = turnId ? await t.turn(session.id, turnId) : undefined;
165
+ if (turn !== undefined && Date.parse(turn.startedAt) < Date.parse(environment.createdAt))
166
+ continue;
167
+ kept.push(session);
168
+ }
169
+ return kept;
170
+ }
153
171
  /** How an Agent names its manifest: `name` when it tracks it, `name@n` when pinned. */
154
172
  export function manifestRefOf(agent) {
155
173
  return agent.manifestRef === "tracking" ? agent.manifestName : `${agent.manifestName}@${agent.manifestVersion}`;
@@ -161,7 +179,7 @@ async function viewOf(ctx, t, environment, owner) {
161
179
  : undefined;
162
180
  const pod = environment.pod;
163
181
  const visible = sessions.filter((session) => owner === undefined || session.ownerUserId === owner);
164
- const { state, attention } = stateOf(environment, visible, await unsetRequiredSecrets(t, environment));
182
+ const { state, attention } = stateOf(environment, await ranOnThisAgent(t, environment, visible), await unsetRequiredSecrets(t, environment));
165
183
  return {
166
184
  id: environment.id,
167
185
  manifest: manifestRefOf(environment),
@@ -898,7 +916,8 @@ async function deleteKeys(ctx, keys) {
898
916
  /**
899
917
  * `DELETE /v1/agents/{id}`: deletes the Environment, its vault and its workspace. Refused
900
918
  * while a session that names it has an active turn. Sessions keep its id: their next turn is
901
- * refused (`agent_unavailable`) unless an Environment with this id exists again.
919
+ * refused (`agent_unavailable`) unless an Environment with this id exists again. An Agent created
920
+ * again under the id does not take their state until they take a turn on it (`ranOnThisAgent`).
902
921
  */
903
922
  export async function deleteAgent(ctx, id, scope) {
904
923
  reachable(agentGrantsOf(scope), id);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const RUNTIME_VERSION = "0.48.0-beta";
1
+ export declare const RUNTIME_VERSION = "0.48.1-beta";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Kept in step with package.json by runtime/server/scripts/check-package.mjs, which runs in npm run check.
2
2
  // release:prepare also rewrites this when it bumps @nylorun/runtime.
3
- export const RUNTIME_VERSION = "0.48.0-beta";
3
+ export const RUNTIME_VERSION = "0.48.1-beta";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/runtime",
3
- "version": "0.48.0-beta",
3
+ "version": "0.48.1-beta",
4
4
  "description": "Nylorun Runtime: the agent execution Host on Postgres, Restate and S2, and model providers.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",