Skip to content
Merged

Test #727

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f99277e
feat(measurement-jobs): free-tier card gate (setup mode) + instant ba…
sweetmantech Jun 16, 2026
158a1d4
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 16, 2026
5fa5e3a
fix(songstats-backfill): backoff on 429 + defer instead of churn (cha…
sweetmantech Jun 16, 2026
1e9deac
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 16, 2026
5f45946
refactor(songstats): remove local quota ledger + budget gate (chat#17…
sweetmantech Jun 16, 2026
5472795
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 16, 2026
f24d4c7
feat: POST /api/catalogs (create + materialize from valuation snapsho…
sweetmantech Jun 18, 2026
ace0b01
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 18, 2026
a520a1d
fix: LEFT-join artists in catalog-songs read (materialized tracks wer…
sweetmantech Jun 18, 2026
76b5739
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 18, 2026
709ea0c
feat: add X (Twitter) + LinkedIn to the Composio connector whitelist …
sweetmantech Jun 18, 2026
8a3c3cb
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 18, 2026
66cc2fe
chore: remove unused ALLOWED_ARTIST_CONNECTORS from api (chat#1793) (…
sweetmantech Jun 18, 2026
79c22da
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 18, 2026
6fc10cc
fix: enrich valuation-captured songs (artists + notes) so they render…
sweetmantech Jun 18, 2026
0e42d02
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 18, 2026
2fa7029
fix(tasks): let admins fetch any task by id alone (cross-account read…
sweetmantech Jun 19, 2026
bd2ae10
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 19, 2026
cdb34d0
feat(connectors): POST /api/connectors/files — stage images for Linke…
sweetmantech Jun 20, 2026
acae4d8
Merge main into test (sync #692 Songstats work)
sweetmantech Jun 23, 2026
2a7af68
feat(artists): account_id override for DELETE /api/artists/{id} (#693)
sweetmantech Jun 23, 2026
8c962ef
Merge main into test (sync #696)
sweetmantech Jun 23, 2026
8b6a3bb
feat(chats): admins (RECOUP_ORG) can access any chat — read + write (…
sweetmantech Jun 23, 2026
03e0ef5
Enforce account_api_keys.expires_at in x-api-key auth (chat#1813) (#700)
sweetmantech Jun 24, 2026
bff29ae
Merge branch 'main' into test
sweetmantech Jun 24, 2026
78bd71b
refactor(chat): extract shared buildRunAgentInput (chat#1813) (#701)
sweetmantech Jun 24, 2026
2209b7d
Re-point POST /api/chat/generate onto runAgentWorkflow + ephemeral ke…
sweetmantech Jun 24, 2026
af7eaa5
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 24, 2026
b84e4a1
Merge remote-tracking branch 'origin/main' into HEAD
sweetmantech Jun 24, 2026
4c09cf0
Retire OpenClaw prompt_sandbox → run-sandbox-command bridge (chat#181…
sweetmantech Jun 24, 2026
f1ade64
Merge remote-tracking branch 'origin/main' into HEAD
sweetmantech Jun 24, 2026
4ecca44
feat: POST /api/emails + route ephemeral key to RECOUP_API_KEY (#1815…
sweetmantech Jun 25, 2026
27f0532
Merge origin/main into test (sync after #709 test→main promotion)
sweetmantech Jun 25, 2026
6d9e74e
fix(skills): install the renamed global skills into sandboxes (chat#1…
sweetmantech Jun 25, 2026
a463e59
Merge origin/main into test (sync after #713 test→main promotion)
sweetmantech Jun 25, 2026
18d20f7
feat(emails): make `to` and `subject` optional on POST /api/emails (#…
sweetmantech Jun 25, 2026
d981536
chore: remove POST /api/notifications (superseded by /api/emails) (#711)
sweetmantech Jun 25, 2026
cae9f35
Merge origin/main into test (sync for #715 promotion)
sweetmantech Jun 25, 2026
be2abcc
fix: repoint dead .com hosts to live .dev (recoupable/chat#1819 §A+§B…
sweetmantech Jun 29, 2026
0e0bac0
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 29, 2026
e6610b4
fix: repoint remaining .com refs missed by api#719 (domain cutover) (…
sweetmantech Jun 30, 2026
bdcd796
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 30, 2026
c5e3e1f
Merge remote-tracking branch 'origin/main' into test
sweetmantech Jun 30, 2026
8a3d084
fix(chat/runs): install global skills in the headless run path (#722)
sweetmantech Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions lib/chat/runs/__tests__/provisionRunSession.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { describe, it, expect, vi, beforeEach } from "vitest";

import { provisionRunSession } from "../provisionRunSession";
import { createSessionWithInitialChat } from "@/lib/sessions/createSessionWithInitialChat";
import { connectSandbox } from "@/lib/sandbox/factory";
import { markSessionSandboxActive } from "@/lib/sandbox/markSessionSandboxActive";
import { discoverSkills } from "@/lib/skills/discoverSkills";
import { installSessionGlobalSkills } from "@/lib/sandbox/installSessionGlobalSkills";

vi.mock("@/lib/sessions/createSessionWithInitialChat", () => ({
createSessionWithInitialChat: vi.fn(),
}));
vi.mock("@/lib/sandbox/factory", () => ({ connectSandbox: vi.fn() }));
vi.mock("@/lib/sandbox/getSessionSandboxName", () => ({
getSessionSandboxName: vi.fn(() => "sandbox-name"),
}));
vi.mock("@/lib/sandbox/resolveGitUser", () => ({
resolveGitUser: vi.fn(async () => ({ name: "x", email: "y" })),
}));
vi.mock("@/lib/github/getServiceGithubToken", () => ({
getServiceGithubToken: vi.fn(() => "gh-token"),
}));
vi.mock("@/lib/sandbox/markSessionSandboxActive", () => ({
markSessionSandboxActive: vi.fn(),
}));
vi.mock("@/lib/skills/discoverSkills", () => ({ discoverSkills: vi.fn(async () => []) }));
vi.mock("@/lib/skills/getSandboxSkillDirectories", () => ({
getSandboxSkillDirectories: vi.fn(async () => ["/skills"]),
}));
vi.mock("@/lib/sandbox/installSessionGlobalSkills", () => ({
installSessionGlobalSkills: vi.fn(async () => undefined),
}));

const session = {
id: "session-1",
clone_url: "https://github.com/org/repo",
sandbox_state: { type: "vercel" },
};
const updated = { ...session };
const chat = { id: "chat-1" };
const sandbox = {
getState: () => ({ type: "vercel" }),
workingDirectory: "/work",
};

describe("provisionRunSession", () => {
beforeEach(() => {
vi.clearAllMocks();
vi.mocked(createSessionWithInitialChat).mockResolvedValue({
ok: true,
session,
chat,
} as never);
vi.mocked(connectSandbox).mockResolvedValue(sandbox as never);
vi.mocked(markSessionSandboxActive).mockResolvedValue(updated as never);
});

it("installs global skills into the sandbox before discovering them", async () => {
await provisionRunSession({ accountId: "account-1", title: "t" });

// Headless runs must PROVISION skills, not just discover them (chat#1822).
expect(installSessionGlobalSkills).toHaveBeenCalledWith({
sessionRow: updated,
sandbox,
});

const installOrder = vi.mocked(installSessionGlobalSkills).mock.invocationCallOrder[0];
const discoverOrder = vi.mocked(discoverSkills).mock.invocationCallOrder[0];
expect(installOrder).toBeLessThan(discoverOrder);
});

it("still completes the run when skill install fails (best-effort)", async () => {
vi.mocked(installSessionGlobalSkills).mockRejectedValueOnce(new Error("install boom"));

const result = await provisionRunSession({ accountId: "account-1", title: "t" });

expect(result.session).toEqual(updated);
expect(discoverSkills).toHaveBeenCalled();
});
});
13 changes: 13 additions & 0 deletions lib/chat/runs/provisionRunSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getSessionSandboxName } from "@/lib/sandbox/getSessionSandboxName";
import { resolveGitUser } from "@/lib/sandbox/resolveGitUser";
import { getServiceGithubToken } from "@/lib/github/getServiceGithubToken";
import { markSessionSandboxActive } from "@/lib/sandbox/markSessionSandboxActive";
import { installSessionGlobalSkills } from "@/lib/sandbox/installSessionGlobalSkills";
import { discoverSkills } from "@/lib/skills/discoverSkills";
import { getSandboxSkillDirectories } from "@/lib/skills/getSandboxSkillDirectories";
import { DEFAULT_WORKING_DIRECTORY } from "@/lib/sandbox/vercel/sandbox/constants";
Expand Down Expand Up @@ -76,6 +77,18 @@ export async function provisionRunSession({
const updated = await markSessionSandboxActive(session, sandbox.getState() as Json);
if (!updated) throw new Error("Failed to activate session sandbox");

// Install global skills BEFORE discovery — the headless run path must
// provision skills, not just discover them. Without this the sandbox skills
// dir is empty, `discoverSkills` returns [], the agent gets no `skill` tool,
// and it falls back to guessing API endpoints + fabricating (chat#1822).
// Best-effort: a failed install must not block the run (mirrors
// `createSandboxHandler`).
try {
await installSessionGlobalSkills({ sessionRow: updated, sandbox });
} catch (error) {
console.error("[provisionRunSession] installSessionGlobalSkills failed:", error);
}

// Best-effort skill + working-directory discovery from the live handle —
// a failure falls back to defaults so the run can still start (tools surface
// the underlying issue when they reconnect). Mirrors handleChatWorkflowStream.
Expand Down
Loading