Skip to content

Commit e19c81a

Browse files
nikhilunniclaude
andauthored
orchestrator: slack threads as an agent with one way in (phase 2) (#1695)
* fix(orchestrator): a neutral session end closes the relay in silence A session that ends without a result (the sandbox reclaimed, a kept session swept after its retention) used to post a neutral close into its relay target. With the relay bound to the session, a kept Slack thread session is swept long after the conversation ended, and the thread heard about it. Now only a completed or failed session posts; a neutral end removes the relay row and says nothing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * feat(orchestrator): slack threads on short runs with run_agent The Slack built-in was the one automation that held a run open for the length of a conversation: nested loops over wait_event and wait_session slices, a 48 h deadline, and the join policy to feed replies into the run. Definition 14 makes every mention one short run: - facts, admit, identity and the linked check stay as they were; - `previous` looks up the thread's kept session (the thread is the workstream), `replies` lists the thread, and `turn` folds the replies written since the previous turn into the mention's text; - behind the has-text gate, smart routing runs only for a thread with no session, then `run_agent` continues the kept session or starts one and points the session's relay at the thread, and a new session posts its link; - a failed run closes the relay with the failure; a completed run leaves the relay to the session, which posts on its own with no run live. `idle_timeout` and `max_turns` go: nothing waits, so nothing times out or counts turns. The queue policy keeps a thread's turns in order. `walkBlocks` is exported for the definition tests. The interpreter test drives the new graph end to end: first mention, continued thread, bare mention, unlinked author, smart routing with and without a decision, and the queue of two mentions on one thread. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(orchestrator): a built-in bump drops inputs the shipped schema retired The seed merged an org's stored inputs with the defaults of new keys and kept every stored key. A key the shipped schema no longer declares held a value for a graph that is gone, and the Inputs tab showed it with no field to edit. Now the merge keeps only the keys the shipped schema declares, then fills in defaults for the new ones. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * docs(site): slack threads as one short run per mention The Slack threads pages described a run that stays open until the thread goes quiet, the idle timeout and turn limit inputs, and the join policy. They now describe the short-run model: a mention is a run, the thread's session is kept, the replies since the previous turn go with the next mention, and the session relays on its own. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * feat(orchestrator): slack threads as an agent with one way in The built-in's agent moves out of the block list into the definition's `agent`: scope per thread (the key and label templates that were settings.instance), the profile from smart routing's verdict or the facts, the turn as the prompt, the relay into the thread. The way in's blocks admit the mention, fold the thread, gate a bare mention (now a filter: the run ends filtered, nothing is posted), and route a new session; the engine's agent step ends the run. The started-session block goes: the agent step announces a session it starts through the relay's policy. Smart routing's verdict, when nobody was asked, is posted as a line of its own, so the thread still says which profile answers and why. Definition version 15. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * feat(orchestrator): the relay records its place as the workstream's handle, and the lookup says where it points Two seams the Slack built-in needs now that its "Started a session" post is gone. - That post recorded the thread as the workstream's handle through the action runtime; without it the handle ledger never learned the thread and the UI had no place to name the workstream by. Installing or re-pointing a relay on a run bound to a workstream now records `slack:<channel>:<thread>` for it (idempotent; a conflict is reported on the step, never a rebind, never a failed turn). - `lookup_instance_session` outputs `mention_ts`, the mention the kept session's relay points at: the boundary of what the session has seen, which the fold needs instead of guessing it from the thread page. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(orchestrator): slack threads, the review's findings - The seed's content hash and its stored view left out the agent and the role, so a change to the agent never bumped the built-in, and a stored agent automation hashed as if it had none. Both carry them. - The failed hook closed the thread's live relay (`relay_close`) when a run failed before it reached the agent step, which the queue makes the common failure shape. The hook posts one line that says why; the session keeps its relay and the next mention is a new turn on it. - The fold found the previous turn by scanning the thread page for the newest human mention of the bot, so a mention admission dropped (an unlinked author) moved the boundary and its text was lost. The fold starts at the mention the session's relay points at, with the page scan as the fallback. - The thread page read was unbounded (capped by the API at 500), so a long thread pushed the new messages off the page. A continued session reads from its previous turn on (`oldest`). - The hand-written `queue` concurrency goes: the engine derives it from the kept scope. - A stale comment in the overrides test named a session-link post that no longer exists. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * fix(orchestrator): a built-in bump stops the runs of the version it replaces The Slack threads built-in moves from one long run per thread (a loop parked on a wait, holding the thread's session and a concurrency claim of its own) to one short run per mention. A thread whose old-version run was still parked when the bump landed could not go on: the next mention's run, under the new version's derived concurrency, found the kept session owned by the live old run, and the turn failed. The seed now stops the runs of the version a bump replaces, with a reason that says why. Their kept sessions stay (the old definition keeps them), the binding's owner is over, and the next event's run of the new version continues the session. The store lists an automation's runs that are not over; the seed's production deps send the stop through the run inbox. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017XkqDsk7JzXh98cpgnJJ9w * test(orchestrator): the Slack thread harness answers the open check The agent step asks whether the workstream is still open before it starts a session; the thread harness says yes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017XkqDsk7JzXh98cpgnJJ9w --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 508c2b0 commit e19c81a

17 files changed

Lines changed: 729 additions & 941 deletions

File tree

‎orchestrator/src/__tests__/automations.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ function fakeStore(seed?: {
267267
.sort((x, y) => y.createdAt.getTime() - x.createdAt.getTime())
268268
.slice(0, limit);
269269
},
270+
async listActiveRuns(automationId) {
271+
return [...runs.values()]
272+
.filter((r) => r.automationId === automationId)
273+
.filter((r) => r.status === "pending" || r.status === "running" || r.status === "waiting")
274+
.sort((x, y) => x.createdAt.getTime() - y.createdAt.getTime());
275+
},
270276
async getRun(id) {
271277
return runs.get(id) ?? null;
272278
},

‎orchestrator/src/automations/builtins/__tests__/seed.test.ts‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function harness(
1212
options: {
1313
existing?: { definition: AutomationDefinition; inputs: Record<string, unknown>; overrides: Record<string, Record<string, unknown>> };
1414
raceOnCreate?: boolean;
15+
/** Runs of the automation still going when the seed runs. */
16+
activeRuns?: Array<{ id: string; version: number }>;
1517
} = {},
1618
) {
1719
const rows = new Map<string, AutomationRow>();
@@ -110,12 +112,21 @@ function harness(
110112
},
111113
};
112114

115+
const stopped: Array<{ runId: string; reason: string }> = [];
113116
const deps = {
114117
store,
115118
connections: { async ensureDefault() { return { id: "conn-github" }; } },
116119
log: { info() {}, warn() {} },
120+
runs: {
121+
async listActive() {
122+
return options.activeRuns ?? [];
123+
},
124+
async stop(runId: string, reason: string) {
125+
stopped.push({ runId, reason });
126+
},
127+
},
117128
};
118-
return { store, rows, versions, calls, deps };
129+
return { store, rows, versions, calls, deps, stopped };
119130
}
120131

121132
describe("seedBuiltinAutomations", () => {
@@ -213,12 +224,50 @@ describe("seedBuiltinAutomations", () => {
213224
});
214225
});
215226

227+
test("a bump stops the runs of the version it replaces; a run of the new version goes on", async () => {
228+
const stored = structuredClone(PR_REVIEW_BUILTIN.definition);
229+
if (stored.trigger.kind === "integration") stored.trigger.connectionId = "conn-github";
230+
const h = harness({
231+
existing: { definition: stored, inputs: {}, overrides: {} },
232+
activeRuns: [
233+
{ id: "autorun:old-loop", version: 1 },
234+
{ id: "autorun:already-new", version: 2 },
235+
],
236+
});
237+
const shipped: BuiltinAutomation = {
238+
...PR_REVIEW_BUILTIN,
239+
definition: (() => {
240+
const d = structuredClone(PR_REVIEW_BUILTIN.definition);
241+
d.inputsSchema.push({ key: "new_knob", label: "New knob", type: "string", default: "x" });
242+
return d;
243+
})(),
244+
async defaultInputs() {
245+
return { ...(await PR_REVIEW_BUILTIN.defaultInputs()), new_knob: "x" };
246+
},
247+
};
248+
const result = await seedBuiltinAutomations({ ...h.deps, builtins: [shipped] });
249+
expect(result.bumped).toEqual([{ key: PR_REVIEW_BUILTIN_KEY, from: 1, to: 2 }]);
250+
expect(h.stopped.map((s) => s.runId)).toEqual(["autorun:old-loop"]);
251+
expect(h.stopped[0]!.reason).toContain("upgraded");
252+
// Unchanged: nothing stops.
253+
const again = await seedBuiltinAutomations({ ...h.deps, builtins: [shipped] });
254+
expect(again.bumped).toEqual([]);
255+
expect(h.stopped).toHaveLength(1);
256+
});
257+
216258
test("content hash covers the extra entrypoints", () => {
217259
const withEp = PR_REVIEW_BUILTIN.definition;
218260
const withoutEp = { ...withEp, entrypoints: [] };
219261
expect(definitionContentHash(withEp)).not.toBe(definitionContentHash(withoutEp));
220262
});
221263

264+
test("content hash covers the agent and the main way in's role", () => {
265+
const base = PR_REVIEW_BUILTIN.definition;
266+
const agent = { scope: { kind: "event" as const }, profileId: "p", promptTemplate: "go" };
267+
expect(definitionContentHash({ ...base, agent })).not.toBe(definitionContentHash(base));
268+
expect(definitionContentHash({ ...base, agent, role: "none" })).not.toBe(definitionContentHash({ ...base, agent }));
269+
});
270+
222271
test("content hash ignores key order and is stable", () => {
223272
const a = definitionContentHash(PR_REVIEW_BUILTIN.definition);
224273
const reordered = JSON.parse(JSON.stringify(PR_REVIEW_BUILTIN.definition)) as AutomationDefinition;

0 commit comments

Comments
 (0)