This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch release/v1.3
in repository https://gitbox.apache.org/repos/asf/texera.git
The following commit(s) were added to refs/heads/release/v1.3 by this push:
new 29e6db3de4 fix(agent-service, v1.3): send the delegate user's token on
compile requests (#9268)
29e6db3de4 is described below
commit 29e6db3de4ec88d71a53511c39232af012de5b3a
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Nov 2 23:18:57 2026 +0000
fix(agent-service, v1.3): send the delegate user's token on compile
requests (#9268)
### What changes were proposed in this PR?
Automated backport of #9079 to `release/v1.3`.
Source: 07fffb3d5cc1a114052484019b068d2e73a4c587 · [automation
run](https://github.com/apache/texera/actions/runs/41543820426)
### Any related issues, documentation, discussions?
Backport of #9079. Originally linked #9078.
### How was this PR tested?
The backported tree built green before #9079 merged. Release-branch CI
runs on this PR once it is reopened — see the comment below.
### Was this PR authored or co-authored using generative AI tooling?
No.
Co-authored-by: Suryaa Charan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
agent-service/src/agent/texera-agent.spec.ts | 16 ++++++++++++
agent-service/src/agent/texera-agent.ts | 2 +-
agent-service/src/api/compile-api.spec.ts | 39 ++++++++++++++++++++++++++++
agent-service/src/api/compile-api.ts | 8 ++++--
4 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/agent-service/src/agent/texera-agent.spec.ts
b/agent-service/src/agent/texera-agent.spec.ts
index 52d9103866..8519060e86 100644
--- a/agent-service/src/agent/texera-agent.spec.ts
+++ b/agent-service/src/agent/texera-agent.spec.ts
@@ -859,6 +859,22 @@ describe("delegate mode", () => {
},
};
+ test("compiles with the delegating user's token (compile service is
JWT-protected)", async () => {
+ dispatch(okExec);
+ const compileHeaders: unknown[] = [];
+ const routed = fetchSpy.getMockImplementation()!;
+ fetchSpy.mockImplementation((async (u: any, init?: RequestInit) => {
+ if (String(u).includes("/api/compile"))
compileHeaders.push(init?.headers);
+ return routed(u, init);
+ }) as any);
+ const agent = makeAgentWith(textModel("ok", 1, 1));
+ agent.setDelegateConfig({ userToken: "tok", workflowId: 7 });
+ await agent.sendMessage("go");
+ expect(compileHeaders.length).toBeGreaterThan(0);
+ for (const h of compileHeaders)
+ expect(h).toEqual({ Authorization: "Bearer tok", "Content-Type":
"application/json" });
+ });
+
test("refreshes the workflow once, on the first turn only", async () => {
dispatch(okExec);
const model = textModel("ok", 1, 1);
diff --git a/agent-service/src/agent/texera-agent.ts
b/agent-service/src/agent/texera-agent.ts
index 9a640aaab6..d29e281f02 100644
--- a/agent-service/src/agent/texera-agent.ts
+++ b/agent-service/src/agent/texera-agent.ts
@@ -532,7 +532,7 @@ export class TexeraAgent {
if (this.workflowState.getAllOperators().length > 0) {
try {
const logicalPlan = this.workflowState.toLogicalPlan();
- compilationResult = await compileWorkflowAsync(logicalPlan);
+ compilationResult = await compileWorkflowAsync(logicalPlan,
this.delegateConfig?.userToken);
} catch (e: any) {
this.log.warn({ err: e?.message || e }, "compilation failed;
proceeding without schemas");
}
diff --git a/agent-service/src/api/compile-api.spec.ts
b/agent-service/src/api/compile-api.spec.ts
index 16b19e0611..498f22b54b 100644
--- a/agent-service/src/api/compile-api.spec.ts
+++ b/agent-service/src/api/compile-api.spec.ts
@@ -53,6 +53,45 @@ describe("compileWorkflowAsync", () => {
});
});
+ test("sends the user's token as a Bearer Authorization header when given",
async () => {
+ const fetchSpy = spyOn(globalThis, "fetch").mockResolvedValue(
+ new Response(JSON.stringify({ operatorOutputSchemas: {}, operatorErrors:
{} }), { status: 200 })
+ );
+
+ await compileWorkflowAsync(plan, "user-jwt");
+
+ const [, init] = fetchSpy.mock.calls[0] as [string, RequestInit];
+ expect(init.headers).toEqual({ Authorization: "Bearer user-jwt",
"Content-Type": "application/json" });
+ });
+
+ test("omits the Authorization header when the token is empty", async () => {
+ const fetchSpy = spyOn(globalThis, "fetch").mockResolvedValue(
+ new Response(JSON.stringify({ operatorOutputSchemas: {}, operatorErrors:
{} }), { status: 200 })
+ );
+
+ await compileWorkflowAsync(plan, "");
+
+ const [, init] = fetchSpy.mock.calls[0] as [string, RequestInit];
+ expect(init.headers).toEqual({ "Content-Type": "application/json" });
+ });
+
+ test("against a JWT-protected endpoint, returns schemas only when the token
is passed", async () => {
+ const compilation: WorkflowCompilationResponse = {
+ operatorOutputSchemas: { opX: { "output-0": [{ attributeName: "a",
attributeType: "string" }] } },
+ operatorErrors: {},
+ };
+ // Mirrors JwtAuthFilter: 401 unless a Bearer token is present.
+ spyOn(globalThis, "fetch").mockImplementation((async (_url: string, init?:
RequestInit) => {
+ const auth = (init?.headers as Record<string, string> |
undefined)?.Authorization ?? "";
+ return /^Bearer \S+$/.test(auth)
+ ? new Response(JSON.stringify(compilation), { status: 200 })
+ : new Response("", { status: 401, headers: { "WWW-Authenticate":
'Bearer realm="texera"' } });
+ }) as unknown as typeof fetch);
+
+ expect(await compileWorkflowAsync(plan)).toBeNull();
+ expect(await compileWorkflowAsync(plan, "user-jwt")).toEqual(compilation);
+ });
+
test("returns null on a non-ok response", async () => {
spyOn(globalThis, "fetch").mockResolvedValue(new Response("boom", {
status: 500 }));
expect(await compileWorkflowAsync(plan)).toBeNull();
diff --git a/agent-service/src/api/compile-api.ts
b/agent-service/src/api/compile-api.ts
index 8ffd27fd52..98cc4cdf24 100644
--- a/agent-service/src/api/compile-api.ts
+++ b/agent-service/src/api/compile-api.ts
@@ -18,6 +18,7 @@
*/
import { getBackendConfig } from "./backend-api";
+import { createAuthHeaders } from "./auth-api";
import type { LogicalPlan, OperatorPortSchemaMap } from "../types/workflow";
import { createLogger } from "../logger";
@@ -42,7 +43,10 @@ export interface WorkflowCompilationResponse {
operatorErrors: Record<string, WorkflowFatalError>;
}
-export async function compileWorkflowAsync(logicalPlan: LogicalPlan):
Promise<WorkflowCompilationResponse | null> {
+export async function compileWorkflowAsync(
+ logicalPlan: LogicalPlan,
+ token?: string
+): Promise<WorkflowCompilationResponse | null> {
const config = getBackendConfig();
const url = `${config.compileEndpoint}/api/compile`;
@@ -56,7 +60,7 @@ export async function compileWorkflowAsync(logicalPlan:
LogicalPlan): Promise<Wo
try {
const response = await fetch(url, {
method: "POST",
- headers: { "Content-Type": "application/json" },
+ headers: token ? createAuthHeaders(token) : { "Content-Type":
"application/json" },
body: JSON.stringify(body),
});