From aac78d374a42ed3076e1980a62daefeefb5af559 Mon Sep 17 00:00:00 2001 From: shuv1337 Date: Wed, 18 Nov 2026 11:48:03 -0800 Subject: [PATCH 1/2] feat(self-host): file feedback as GitHub issues EXECUTOR_FEEDBACK_GITHUB_REPOSITORY and EXECUTOR_FEEDBACK_GITHUB_TOKEN file each feedback.submit submission as an issue. With the operator webhook also set, the issue is filed first, the webhook payload links it, and feedback is accepted when either receiver took it. --- .github/workflows/fork-ci.yml | 2 +- apps/docs/content/run/usage-analytics.md | 2 +- apps/hosted/self-host/README.md | 28 ++- apps/hosted/self-host/compose.yaml | 5 + .../src/implementation/feedback-github.ts | 115 ++++++++++++ .../src/implementation/feedback-webhook.ts | 146 ++++++++++----- e2e/support/managed-server.ts | 4 + e2e/test-plan.ts | 10 + e2e/tests/feedback-github.spec.ts | 174 ++++++++++++++++++ 9 files changed, 433 insertions(+), 53 deletions(-) create mode 100644 apps/hosted/self-host/src/implementation/feedback-github.ts create mode 100644 e2e/tests/feedback-github.spec.ts diff --git a/.github/workflows/fork-ci.yml b/.github/workflows/fork-ci.yml index 9e4045e3ba..7ba640c447 100644 --- a/.github/workflows/fork-ci.yml +++ b/.github/workflows/fork-ci.yml @@ -94,7 +94,7 @@ jobs: - name: Reused app account scenario run: bun run e2e:self-host --test-name '^a reused hosted app account (stops serving|refuses a call)' --workers 1 - name: Operator feedback scenarios - run: bun run e2e:self-host --test-name 'self-host feedback webhook|self-host with DO_NOT_TRACK|self-host analytics pseudonymize|Hosted feedback enforces' + run: bun run e2e:self-host --test-name 'self-host feedback webhook|self-host feedback files|self-host with DO_NOT_TRACK|self-host analytics pseudonymize|Hosted feedback enforces' # Run the large cold catalog alone, not beside the functional scenarios' servers. - name: Cold MCP discovery run: bun run e2e:self-host --test-name 'Cold MCP discovery serves 8549' diff --git a/apps/docs/content/run/usage-analytics.md b/apps/docs/content/run/usage-analytics.md index d286c82867..3c3c14936e 100644 --- a/apps/docs/content/run/usage-analytics.md +++ b/apps/docs/content/run/usage-analytics.md @@ -20,7 +20,7 @@ EXECUTOR_DISABLE_ANALYTICS=1 Any value other than empty, `0`, `false`, `no` or `off` turns analytics off. Nothing is recorded or sent to analytics, including feedback: the `feedback.submit` tool then returns `FeedbackDisabled` unless the self-host operator configured -`EXECUTOR_FEEDBACK_WEBHOOK_URL`. That independent receiver takes precedence for +`EXECUTOR_FEEDBACK_WEBHOOK_URL` or `EXECUTOR_FEEDBACK_GITHUB_REPOSITORY`. That independent receiver takes precedence for feedback and receives the submitted message, sender identity and instance origin; the anonymous analytics guarantees below do not apply to that explicit delivery. diff --git a/apps/hosted/self-host/README.md b/apps/hosted/self-host/README.md index 4cad8463d6..ff098d888f 100644 --- a/apps/hosted/self-host/README.md +++ b/apps/hosted/self-host/README.md @@ -318,13 +318,37 @@ the receiver URL or response. Delivery is not retried automatically; after an ambiguous timeout a caller retry may duplicate feedback. `Idempotency-Key` is a unique per-delivery ID, not a deduplication key across separate caller submissions. -The webhook takes precedence over feedback analytics and works even with +An operator receiver takes precedence over feedback analytics and works even with `DO_NOT_TRACK=1`, `EXECUTOR_DISABLE_ANALYTICS=1`, or no analytics destination. -Other usage analytics are unchanged. With the URL unset or empty, existing +Other usage analytics are unchanged. With the URL and the GitHub repository +below unset or empty, existing analytics feedback behavior is unchanged, including `FeedbackDisabled` when analytics are unavailable. Submissions are not stored in the product database: there is no feedback table, so durable retention belongs to the receiver for now. +#### GitHub issues + +Set `EXECUTOR_FEEDBACK_GITHUB_REPOSITORY` to `owner/repository` and +`EXECUTOR_FEEDBACK_GITHUB_TOKEN` to a token that may create issues there (a +fine-grained token with read and write access to Issues on that repository alone) +to file each submission as an issue. Its title is the message's first line, up to +120 characters. Its body is the whole message, which GitHub renders as Markdown, +then the sender's email and client, the source, organization ID, instance origin +and time. Issues identify the sender, so use a private repository. +`EXECUTOR_FEEDBACK_GITHUB_LABELS` is an optional comma-separated list of labels. +`EXECUTOR_FEEDBACK_GITHUB_API_URL` is the API root for GitHub Enterprise Server +(`https://github.example.com/api/v3`); the default is `https://api.github.com`. +A repository with a missing token, or a malformed repository or API URL, is +logged at start and every submission returns `FeedbackUnavailable`. + +Issue filing has the same 10-second limit, redirect refusal and precedence over +analytics as the webhook, and does not need one. With both set, the issue is +filed first and the webhook payload gains `issue: { url, number }` and a final +`Issue: ` line in `body` (`Issue: not created` when GitHub refused it). +Feedback is then `accepted` when either receiver took it, so a failed +notification does not make a caller file the issue twice; the failed receiver is +logged. `FeedbackUnavailable` means neither did. + ### Trace sampling Recording every span made the telemetry collector the busiest process under load, diff --git a/apps/hosted/self-host/compose.yaml b/apps/hosted/self-host/compose.yaml index 971d32b51a..b7bd87a62e 100644 --- a/apps/hosted/self-host/compose.yaml +++ b/apps/hosted/self-host/compose.yaml @@ -20,6 +20,11 @@ services: # Optional operator-owned feedback receiver, independent of anonymous analytics. EXECUTOR_FEEDBACK_WEBHOOK_URL: EXECUTOR_FEEDBACK_WEBHOOK_SECRET: + # Optional: file each feedback submission as an issue in owner/repository. + EXECUTOR_FEEDBACK_GITHUB_REPOSITORY: + EXECUTOR_FEEDBACK_GITHUB_TOKEN: + EXECUTOR_FEEDBACK_GITHUB_LABELS: + EXECUTOR_FEEDBACK_GITHUB_API_URL: # Optional override of X-Forwarded-For for client-IP assertions from trusted peers. # Requires EXECUTOR_TRUSTED_PROXIES; see README "Rate limits behind a proxy". EXECUTOR_TRUSTED_PROXY_HEADER: diff --git a/apps/hosted/self-host/src/implementation/feedback-github.ts b/apps/hosted/self-host/src/implementation/feedback-github.ts new file mode 100644 index 0000000000..ceac22c0e0 --- /dev/null +++ b/apps/hosted/self-host/src/implementation/feedback-github.ts @@ -0,0 +1,115 @@ +/** Explicit feedback filed as issues in an operator-owned GitHub repository. */ +import { FeedbackUnavailable } from "@executor-js/telemetry/product-analytics"; +import { Config, Effect, Option, Redacted, Schema } from "effect"; +import { HttpClient, HttpClientRequest } from "effect/http"; + +/** What an issue says about one submission; the operator's repository sees the sender. */ +export interface FeedbackReport { + readonly message: string; + readonly submittedAt: string; + readonly who: string; + readonly source: string | undefined; + readonly organizationId: string; + readonly instanceOrigin: string; +} + +const Created = Schema.Struct({ html_url: Schema.String, number: Schema.Int }); +/** The issue GitHub created for a submission. */ +export interface FeedbackIssue { + readonly url: string; + readonly number: number; +} + +const Repository = /^[A-Za-z0-9][A-Za-z0-9-]*\/(?!\.{1,2}$)[\w.-]+$/u; +const titleLimit = 120; + +/** The first line that says something, without Markdown heading or list markers. */ +const issueTitle = (message: string) => { + const line = + message + .split("\n") + .map((text) => text.replace(/^[\s#>*-]+/u, "").trim()) + .find((text) => text !== "") ?? "Executor feedback"; + return line.length > titleLimit ? `${line.slice(0, titleLimit - 1)}…` : line; +}; + +const issueBody = (report: FeedbackReport) => + [ + report.message, + "", + "---", + "", + "Submitted through Executor feedback.", + "", + `- From: ${report.who}`, + ...(report.source === undefined ? [] : [`- Source: ${report.source}`]), + `- Organization: ${report.organizationId}`, + `- Instance: ${report.instanceOrigin}`, + `- Submitted: ${report.submittedAt}`, + ].join("\n"); + +const optionalText = (name: string) => + Config.String(name).pipe( + Config.option, + Effect.map(Option.map((text) => text.trim())), + Effect.map(Option.filter((text) => text !== "")), + ); + +/** + * A repository leaves issue filing off when unset. The returned effect needs an HTTP client and + * fails for any refusal; the caller bounds, reports and hides it. + */ +export const selfHostFeedbackIssues = Effect.gen(function* () { + const repository = yield* optionalText("EXECUTOR_FEEDBACK_GITHUB_REPOSITORY"); + if (Option.isNone(repository)) return undefined; + const token = yield* Config.Redacted("EXECUTOR_FEEDBACK_GITHUB_TOKEN").pipe(Config.option); + const api = URL.parse( + Option.getOrElse( + yield* optionalText("EXECUTOR_FEEDBACK_GITHUB_API_URL"), + () => "https://api.github.com", + ), + ); + const labels = Option.getOrElse(yield* optionalText("EXECUTOR_FEEDBACK_GITHUB_LABELS"), () => "") + .split(",") + .map((label) => label.trim()) + .filter((label) => label !== ""); + if ( + !Repository.test(repository.value) || + Option.isNone(token) || + Redacted.value(token.value).trim() === "" || + api === null || + !["https:", "http:"].includes(api.protocol) || + api.username !== "" || + api.password !== "" || + api.search !== "" || + api.hash !== "" + ) { + yield* Effect.logWarning( + "EXECUTOR_FEEDBACK_GITHUB_REPOSITORY must be owner/repository with EXECUTOR_FEEDBACK_GITHUB_TOKEN set; EXECUTOR_FEEDBACK_GITHUB_API_URL must be an HTTP(S) URL without credentials or a query", + ); + return () => Effect.fail(new FeedbackUnavailable()); + } + const destination = `${api.href.replace(/\/+$/u, "")}/repos/${repository.value}/issues`; + + return (report: FeedbackReport) => + Effect.gen(function* () { + const response = yield* HttpClient.execute( + HttpClientRequest.post(destination).pipe( + HttpClientRequest.bodyJsonUnsafe({ + title: issueTitle(report.message), + body: issueBody(report), + ...(labels.length === 0 ? {} : { labels }), + }), + HttpClientRequest.setHeaders({ + accept: "application/vnd.github+json", + "x-github-api-version": "2022-11-28", + "user-agent": "executor-feedback", + }), + HttpClientRequest.bearerToken(token.value), + ), + ); + if (response.status < 200 || response.status >= 300) return yield* new FeedbackUnavailable(); + const created = yield* Schema.decodeUnknownEffect(Created)(yield* response.json); + return { url: created.html_url, number: created.number } satisfies FeedbackIssue; + }); +}); diff --git a/apps/hosted/self-host/src/implementation/feedback-webhook.ts b/apps/hosted/self-host/src/implementation/feedback-webhook.ts index dcd3cdb9ea..48e96cb8c3 100644 --- a/apps/hosted/self-host/src/implementation/feedback-webhook.ts +++ b/apps/hosted/self-host/src/implementation/feedback-webhook.ts @@ -1,31 +1,68 @@ -/** Explicit feedback delivery to an operator-owned receiver, independent of usage analytics. */ +/** Explicit feedback delivery to operator-owned receivers, independent of usage analytics. */ import { CurrentUsage, ProductAnalytics } from "@executor-js/hosted-server"; import { FeedbackUnavailable } from "@executor-js/telemetry/product-analytics"; import { Config, DateTime, Effect, Option, Redacted, Schema } from "effect"; import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http"; import { SqlClient } from "effect/sql"; +import { type FeedbackIssue, selfHostFeedbackIssues } from "./feedback-github.ts"; const Person = Schema.Struct({ email: Schema.String }); -/** An unset URL leaves the existing analytics sink (including its opt-out) untouched. */ +/** One receiver's request: bounded, never traced, and reported without its URL or response. */ +const delivered = (receiver: string, request: Effect.Effect) => + request.pipe( + Effect.timeout("10 seconds"), + Effect.tapError(() => Effect.logWarning(`Feedback ${receiver} delivery failed`)), + // Do not trace the URL, authorization or response: all may contain receiver secrets. + Effect.provideService(HttpClient.TracerDisabledWhen, () => true), + Effect.provideService(HttpClient.TracerPropagationEnabled, false), + Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }), + Effect.provide(FetchHttpClient.layer), + Effect.option, + ); + +/** The operator's HTTP receiver; an unset URL leaves it off. */ +const webhookReceiver = Effect.gen(function* () { + const configured = yield* Config.Redacted("EXECUTOR_FEEDBACK_WEBHOOK_URL").pipe(Config.option); + if (Option.isNone(configured) || Redacted.value(configured.value).trim() === "") return undefined; + const destination = URL.parse(Redacted.value(configured.value)); + if ( + destination === null || + !["https:", "http:"].includes(destination.protocol) || + destination.username !== "" || + destination.password !== "" + ) { + yield* Effect.logWarning( + "EXECUTOR_FEEDBACK_WEBHOOK_URL must be an HTTP(S) URL without embedded credentials", + ); + return () => Effect.fail(new FeedbackUnavailable()); + } + const secret = yield* Config.Redacted("EXECUTOR_FEEDBACK_WEBHOOK_SECRET").pipe(Config.option); + return (payload: unknown) => + Effect.gen(function* () { + const request = HttpClientRequest.post(destination.href).pipe( + HttpClientRequest.bodyJsonUnsafe(payload), + HttpClientRequest.setHeader("Idempotency-Key", crypto.randomUUID()), + ); + const response = yield* HttpClient.execute( + Option.isSome(secret) && Redacted.value(secret.value) !== "" + ? HttpClientRequest.bearerToken(request, secret.value) + : request, + ); + if (response.status < 200 || response.status >= 300) return yield* new FeedbackUnavailable(); + }); +}); + +/** + * With neither a GitHub repository nor a webhook URL set, the existing analytics sink (including + * its opt-out) is untouched. With both, the issue is filed first so the webhook can link it, and + * feedback is accepted when either receiver took it. + */ export const selfHostFeedbackWebhook = (origin: string) => Effect.gen(function* () { - const configured = yield* Config.Redacted("EXECUTOR_FEEDBACK_WEBHOOK_URL").pipe(Config.option); - if (Option.isNone(configured) || Redacted.value(configured.value).trim() === "") - return undefined; - const destination = URL.parse(Redacted.value(configured.value)); - if ( - destination === null || - !["https:", "http:"].includes(destination.protocol) || - destination.username !== "" || - destination.password !== "" - ) { - yield* Effect.logWarning( - "EXECUTOR_FEEDBACK_WEBHOOK_URL must be an HTTP(S) URL without embedded credentials", - ); - return () => Effect.fail(new FeedbackUnavailable()); - } - const secret = yield* Config.Redacted("EXECUTOR_FEEDBACK_WEBHOOK_SECRET").pipe(Config.option); + const issues = yield* selfHostFeedbackIssues; + const webhook = yield* webhookReceiver; + if (issues === undefined && webhook === undefined) return undefined; const sql = yield* SqlClient.SqlClient; const submit: typeof ProductAnalytics.Service.submitFeedback = (feedback) => @@ -38,38 +75,49 @@ export const selfHostFeedbackWebhook = (origin: string) => ...(Option.isSome(person) ? { email: person.value.email } : {}), }; const submittedAt = DateTime.formatIso(yield* DateTime.now); - const who = [user.email ?? user.id, caller.client_name].filter(Boolean).join(" / "); - const payload = { - message: feedback.message, - submittedAt, - organization: { id: feedback.organizationId }, - user, - caller, - instanceOrigin: origin, - // Common notification receivers can consume these without a translation service. - title: "Executor feedback", - body: `${feedback.message.slice(0, 1500)}\nFrom: ${who.slice(0, 300)}`, - }; - const request = HttpClientRequest.post(destination.href).pipe( - HttpClientRequest.bodyJsonUnsafe(payload), - HttpClientRequest.setHeader("Idempotency-Key", crypto.randomUUID()), + const who = [user.email ?? user.id, caller.client_name] + .filter(Boolean) + .join(" / ") + .slice(0, 300); + const issue = + issues === undefined + ? Option.none() + : yield* delivered( + "GitHub issue", + issues({ + message: feedback.message, + submittedAt, + who, + source: caller.source, + organizationId: feedback.organizationId, + instanceOrigin: origin, + }), + ); + if (webhook === undefined) { + if (Option.isNone(issue)) return yield* new FeedbackUnavailable(); + return; + } + const filed = + issues === undefined + ? "" + : `\nIssue: ${Option.match(issue, { onNone: () => "not created", onSome: (created) => created.url })}`; + const notified = yield* delivered( + "webhook", + webhook({ + message: feedback.message, + submittedAt, + organization: { id: feedback.organizationId }, + user, + caller, + instanceOrigin: origin, + ...(Option.isSome(issue) ? { issue: issue.value } : {}), + // Common notification receivers can consume these without a translation service. + title: "Executor feedback", + body: `${feedback.message.slice(0, 1500)}\nFrom: ${who}${filed}`, + }), ); - const response = yield* HttpClient.execute( - Option.isSome(secret) && Redacted.value(secret.value) !== "" - ? HttpClientRequest.bearerToken(request, secret.value) - : request, - ); - if (response.status < 200 || response.status >= 300) + if (Option.isNone(issue) && Option.isNone(notified)) return yield* new FeedbackUnavailable(); - }).pipe( - Effect.timeout("10 seconds"), - Effect.tapError(() => Effect.logWarning("Feedback webhook delivery failed")), - Effect.mapError(() => new FeedbackUnavailable()), - // Do not trace the URL, authorization or response: all may contain receiver secrets. - Effect.provideService(HttpClient.TracerDisabledWhen, () => true), - Effect.provideService(HttpClient.TracerPropagationEnabled, false), - Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }), - Effect.provide(FetchHttpClient.layer), - ); + }).pipe(Effect.mapError(() => new FeedbackUnavailable())); return submit; }); diff --git a/e2e/support/managed-server.ts b/e2e/support/managed-server.ts index 4f799196db..5e65e2bce9 100644 --- a/e2e/support/managed-server.ts +++ b/e2e/support/managed-server.ts @@ -56,6 +56,10 @@ const maxClockOffset = 40 * 86_400_000; export const OperatorSettings = Schema.Struct({ EXECUTOR_FEEDBACK_WEBHOOK_URL: Schema.optionalKey(Schema.String), EXECUTOR_FEEDBACK_WEBHOOK_SECRET: Schema.optionalKey(Schema.String), + EXECUTOR_FEEDBACK_GITHUB_REPOSITORY: Schema.optionalKey(Schema.String), + EXECUTOR_FEEDBACK_GITHUB_TOKEN: Schema.optionalKey(Schema.String), + EXECUTOR_FEEDBACK_GITHUB_API_URL: Schema.optionalKey(Schema.String), + EXECUTOR_FEEDBACK_GITHUB_LABELS: Schema.optionalKey(Schema.String), EXECUTOR_URL_ALLOW_LOOPBACK_HTTP: Schema.optionalKey(Schema.String), EXECUTOR_URL_ALLOW_HTTP_ORIGINS: Schema.optionalKey(Schema.String), NODE_EXTRA_CA_CERTS: Schema.optionalKey(Schema.NonEmptyString), diff --git a/e2e/test-plan.ts b/e2e/test-plan.ts index 6ea17f0c6f..81cb0d2203 100644 --- a/e2e/test-plan.ts +++ b/e2e/test-plan.ts @@ -3676,6 +3676,16 @@ export const scenarios = plan({ local: na("Operator feedback webhooks are self-host only."), }, }, + feedbackGithubIssues: { + fixtures: "actors", + file: "feedback-github.spec.ts", + title: "self-host feedback files a GitHub issue and links it in the operator webhook", + targets: { + "self-host": scheduled, + cloud: na("Operator feedback receivers are self-host only."), + local: na("Operator feedback receivers are self-host only."), + }, + }, selfHostAnalytics: { fixtures: "actors", file: "instance-analytics.spec.ts", diff --git a/e2e/tests/feedback-github.spec.ts b/e2e/tests/feedback-github.spec.ts new file mode 100644 index 0000000000..39e1c837a7 --- /dev/null +++ b/e2e/tests/feedback-github.spec.ts @@ -0,0 +1,174 @@ +/** Real self-host feedback requests file issues through the operator's GitHub API. */ +import { expect, layer } from "@effect/vitest"; +import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"; +import { Effect, FileSystem, Layer, Schema } from "effect"; +import { HttpRouter, HttpServer, HttpServerRequest, HttpServerResponse } from "effect/http"; +import { createServer } from "node:http"; +import { scenarios } from "../test-plan.ts"; +import { Actors } from "../support/actors.ts"; +import { Api } from "../support/api.ts"; +import { HostedLive, withHostedCase } from "../support/case.ts"; +import type { OperatorSettings } from "../support/managed-server.ts"; +import { Target } from "../support/platform.ts"; +import { serverControl } from "../support/server-control.ts"; + +const Issue = Schema.Struct({ + title: Schema.String, + body: Schema.String, + labels: Schema.optionalKey(Schema.Array(Schema.String)), +}); +const Notification = Schema.Struct({ + message: Schema.String, + body: Schema.String, + issue: Schema.optionalKey(Schema.Struct({ url: Schema.String, number: Schema.Number })), +}); +const token = "synthetic-github-token"; +const issueUrl = "https://github.test/acme/feedback/issues/7"; + +const exercise = Effect.gen(function* () { + const api = yield* Api; + const actors = yield* Actors; + const target = yield* Target; + const post = (message: string) => + api.request(actors.owner, "POST", `/api/organizations/${actors.organization.id}/feedback`, { + message, + }); + const issues: { + headers: Readonly>; + issue: typeof Issue.Type; + }[] = []; + const notifications: (typeof Notification.Type)[] = []; + let github = 201; + let webhook = 204; + const routes = Layer.mergeAll( + // A base URL with a path, as GitHub Enterprise Server has. + HttpRouter.add( + "POST", + "/api/v3/repos/acme/feedback/issues", + Effect.gen(function* () { + const request = yield* HttpServerRequest.HttpServerRequest; + issues.push({ + headers: request.headers, + issue: yield* request.json.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Issue))), + }); + return github === 201 + ? yield* HttpServerResponse.json({ html_url: issueUrl, number: 7 }, { status: 201 }) + : HttpServerResponse.empty({ status: github }); + }).pipe(Effect.orDie), + ), + HttpRouter.add( + "POST", + "/hook", + Effect.gen(function* () { + const request = yield* HttpServerRequest.HttpServerRequest; + notifications.push( + yield* request.json.pipe(Effect.flatMap(Schema.decodeUnknownEffect(Notification))), + ); + return HttpServerResponse.empty({ status: webhook }); + }).pipe(Effect.orDie), + ), + ); + const services = yield* Layer.build( + Layer.fresh( + HttpRouter.serve(routes, { disableLogger: true, disableListenLog: true }).pipe( + Layer.provideMerge(NodeHttpServer.layer(createServer, { host: "127.0.0.1", port: 0 })), + ), + ), + ); + const server = yield* HttpServer.HttpServer.pipe(Effect.provideContext(services)); + if (!("port" in server.address)) return yield* Effect.die("The GitHub API needs TCP"); + const receiver = `http://127.0.0.1:${server.address.port}`; + const configure = (environment: typeof OperatorSettings.Type) => + Effect.gen(function* () { + yield* serverControl("stop"); + yield* serverControl("environment", 200, environment); + yield* serverControl("start"); + }); + + // GitHub alone: the issue is the receipt. + yield* configure({ + EXECUTOR_FEEDBACK_GITHUB_REPOSITORY: "acme/feedback", + EXECUTOR_FEEDBACK_GITHUB_TOKEN: token, + EXECUTOR_FEEDBACK_GITHUB_API_URL: `${receiver}/api/v3/`, + EXECUTOR_FEEDBACK_GITHUB_LABELS: "feedback, from agents", + }); + const message = `\n## Tool search hides ${"long ".repeat(40)}names\n\nExpected \`tools.search\` to list it.`; + const filed = yield* post(message); + expect(filed.status, JSON.stringify(filed.body)).toBe(200); + expect(filed.body).toEqual({ status: "accepted" }); + expect(issues).toHaveLength(1); + expect(issues[0]!.headers).toMatchObject({ + authorization: `Bearer ${token}`, + accept: "application/vnd.github+json", + "user-agent": "executor-feedback", + }); + const { title, body, labels } = issues[0]!.issue; + expect(title.startsWith("Tool search hides long long")).toBe(true); + expect(title).toHaveLength(120); + expect(title.endsWith("…")).toBe(true); + expect(labels).toEqual(["feedback", "from agents"]); + expect(body.startsWith(message)).toBe(true); + expect(body).toMatch(/\n- From: \S+@\S+/u); + expect(body).toContain("\n- Source: dashboard"); + expect(body).toContain(`\n- Organization: ${actors.organization.id}`); + expect(body).toContain(`\n- Instance: ${target.metadata.origin}`); + expect(Number.isNaN(Date.parse(/\n- Submitted: (\S+)/u.exec(body)?.[1] ?? ""))).toBe(false); + + github = 422; + const refused = yield* post("GitHub refuses this issue"); + expect(refused.status).toBe(503); + expect(refused.body).toMatchObject({ _tag: "FeedbackUnavailable" }); + expect(JSON.stringify(refused.body)).not.toContain(receiver); + expect(issues).toHaveLength(2); + + // With a webhook too, the notification links the issue and either receiver is a receipt. + yield* configure({ EXECUTOR_FEEDBACK_WEBHOOK_URL: `${receiver}/hook` }); + github = 201; + expect((yield* post("Both receivers")).status).toBe(200); + expect(issues.at(-1)?.issue.title).toBe("Both receivers"); + expect(notifications).toHaveLength(1); + expect(notifications[0]).toMatchObject({ + message: "Both receivers", + issue: { url: issueUrl, number: 7 }, + body: expect.stringContaining(`\nIssue: ${issueUrl}`), + }); + + github = 500; + expect((yield* post("Only the webhook")).status).toBe(200); + expect(issues).toHaveLength(4); + expect(notifications).toHaveLength(2); + expect(notifications[1]!.issue).toBeUndefined(); + expect(notifications[1]!.body).toContain("\nIssue: not created"); + + github = 201; + webhook = 503; + expect((yield* post("Only the issue")).status).toBe(200); + expect(issues).toHaveLength(5); + expect(notifications).toHaveLength(3); + + github = 500; + const lost = yield* post("Neither receiver"); + expect(lost.status).toBe(503); + expect(lost.body).toMatchObject({ _tag: "FeedbackUnavailable" }); + expect(issues).toHaveLength(6); + expect(notifications).toHaveLength(4); + + // A repository without a usable token refuses feedback without calling GitHub. + yield* configure({ EXECUTOR_FEEDBACK_WEBHOOK_URL: "", EXECUTOR_FEEDBACK_GITHUB_TOKEN: "" }); + github = 201; + expect((yield* post("No token")).status).toBe(503); + expect(issues).toHaveLength(6); + + yield* serverControl("stop"); + const fs = yield* FileSystem.FileSystem; + const logs = yield* fs.readFileString(`${target.directory}/server.log`); + expect(logs).not.toContain(receiver); + expect(logs).not.toContain(token); + expect(logs).toContain("Feedback GitHub issue delivery failed"); + expect(logs).toContain("Feedback webhook delivery failed"); + expect(logs).toContain("EXECUTOR_FEEDBACK_GITHUB_REPOSITORY must be owner/repository"); +}); + +layer(HostedLive, { excludeTestServices: true })("Self-host feedback issues", (it) => { + it.effect(scenarios.feedbackGithubIssues.title, (context) => withHostedCase(context, exercise)); +}); From c34e5f399771110f8db2e90ede90a2169e52c64e Mon Sep 17 00:00:00 2001 From: shuv1337 Date: Wed, 18 Nov 2026 11:51:26 -0800 Subject: [PATCH 2/2] Keep issue titles and sender lines well-formed, and cover redirect refusal --- apps/hosted/self-host/README.md | 9 +++++---- .../src/implementation/feedback-github.ts | 4 +++- .../src/implementation/feedback-webhook.ts | 2 ++ e2e/tests/feedback-github.spec.ts | 15 ++++++++++----- e2e/tests/feedback-webhook.spec.ts | 2 ++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/apps/hosted/self-host/README.md b/apps/hosted/self-host/README.md index ff098d888f..c325aa3858 100644 --- a/apps/hosted/self-host/README.md +++ b/apps/hosted/self-host/README.md @@ -331,10 +331,11 @@ there is no feedback table, so durable retention belongs to the receiver for now Set `EXECUTOR_FEEDBACK_GITHUB_REPOSITORY` to `owner/repository` and `EXECUTOR_FEEDBACK_GITHUB_TOKEN` to a token that may create issues there (a fine-grained token with read and write access to Issues on that repository alone) -to file each submission as an issue. Its title is the message's first line, up to -120 characters. Its body is the whole message, which GitHub renders as Markdown, -then the sender's email and client, the source, organization ID, instance origin -and time. Issues identify the sender, so use a private repository. +to file each submission as an issue. Its title is the message's first non-blank +line without leading Markdown heading, quote or list markers, up to 120 +characters. Its body is the whole message, which GitHub renders as Markdown, +then the sender's email (their user ID when they have none) and client, the +source, organization ID, instance origin and time. Issues identify the sender, so use a private repository. `EXECUTOR_FEEDBACK_GITHUB_LABELS` is an optional comma-separated list of labels. `EXECUTOR_FEEDBACK_GITHUB_API_URL` is the API root for GitHub Enterprise Server (`https://github.example.com/api/v3`); the default is `https://api.github.com`. diff --git a/apps/hosted/self-host/src/implementation/feedback-github.ts b/apps/hosted/self-host/src/implementation/feedback-github.ts index ceac22c0e0..9bce6264f9 100644 --- a/apps/hosted/self-host/src/implementation/feedback-github.ts +++ b/apps/hosted/self-host/src/implementation/feedback-github.ts @@ -30,7 +30,9 @@ const issueTitle = (message: string) => { .split("\n") .map((text) => text.replace(/^[\s#>*-]+/u, "").trim()) .find((text) => text !== "") ?? "Executor feedback"; - return line.length > titleLimit ? `${line.slice(0, titleLimit - 1)}…` : line; + // By code point: a cut surrogate pair is not valid text for GitHub. + const characters = Array.from(line); + return characters.length > titleLimit ? `${characters.slice(0, titleLimit - 1).join("")}…` : line; }; const issueBody = (report: FeedbackReport) => diff --git a/apps/hosted/self-host/src/implementation/feedback-webhook.ts b/apps/hosted/self-host/src/implementation/feedback-webhook.ts index 48e96cb8c3..eec0fe8ea8 100644 --- a/apps/hosted/self-host/src/implementation/feedback-webhook.ts +++ b/apps/hosted/self-host/src/implementation/feedback-webhook.ts @@ -78,6 +78,8 @@ export const selfHostFeedbackWebhook = (origin: string) => const who = [user.email ?? user.id, caller.client_name] .filter(Boolean) .join(" / ") + // One line: a client names itself, and must not add lines to an issue's sender list. + .replace(/\s+/gu, " ") .slice(0, 300); const issue = issues === undefined diff --git a/e2e/tests/feedback-github.spec.ts b/e2e/tests/feedback-github.spec.ts index 39e1c837a7..66fd36fb9d 100644 --- a/e2e/tests/feedback-github.spec.ts +++ b/e2e/tests/feedback-github.spec.ts @@ -53,7 +53,7 @@ const exercise = Effect.gen(function* () { }); return github === 201 ? yield* HttpServerResponse.json({ html_url: issueUrl, number: 7 }, { status: 201 }) - : HttpServerResponse.empty({ status: github }); + : HttpServerResponse.empty({ status: github, headers: { location: "/hook" } }); }).pipe(Effect.orDie), ), HttpRouter.add( @@ -120,6 +120,11 @@ const exercise = Effect.gen(function* () { expect(refused.body).toMatchObject({ _tag: "FeedbackUnavailable" }); expect(JSON.stringify(refused.body)).not.toContain(receiver); expect(issues).toHaveLength(2); + // A redirect is refused, not followed with the token. + github = 307; + expect((yield* post("GitHub redirects this issue")).status).toBe(503); + expect(issues).toHaveLength(3); + expect(notifications).toHaveLength(0); // With a webhook too, the notification links the issue and either receiver is a receipt. yield* configure({ EXECUTOR_FEEDBACK_WEBHOOK_URL: `${receiver}/hook` }); @@ -135,7 +140,7 @@ const exercise = Effect.gen(function* () { github = 500; expect((yield* post("Only the webhook")).status).toBe(200); - expect(issues).toHaveLength(4); + expect(issues).toHaveLength(5); expect(notifications).toHaveLength(2); expect(notifications[1]!.issue).toBeUndefined(); expect(notifications[1]!.body).toContain("\nIssue: not created"); @@ -143,21 +148,21 @@ const exercise = Effect.gen(function* () { github = 201; webhook = 503; expect((yield* post("Only the issue")).status).toBe(200); - expect(issues).toHaveLength(5); + expect(issues).toHaveLength(6); expect(notifications).toHaveLength(3); github = 500; const lost = yield* post("Neither receiver"); expect(lost.status).toBe(503); expect(lost.body).toMatchObject({ _tag: "FeedbackUnavailable" }); - expect(issues).toHaveLength(6); + expect(issues).toHaveLength(7); expect(notifications).toHaveLength(4); // A repository without a usable token refuses feedback without calling GitHub. yield* configure({ EXECUTOR_FEEDBACK_WEBHOOK_URL: "", EXECUTOR_FEEDBACK_GITHUB_TOKEN: "" }); github = 201; expect((yield* post("No token")).status).toBe(503); - expect(issues).toHaveLength(6); + expect(issues).toHaveLength(7); yield* serverControl("stop"); const fs = yield* FileSystem.FileSystem; diff --git a/e2e/tests/feedback-webhook.spec.ts b/e2e/tests/feedback-webhook.spec.ts index 12afce5d3c..8bf35c7982 100644 --- a/e2e/tests/feedback-webhook.spec.ts +++ b/e2e/tests/feedback-webhook.spec.ts @@ -102,6 +102,8 @@ const exercise = (analyticsOff: boolean) => }, }); expect(Number.isNaN(Date.parse(requests[0]!.payload.submittedAt))).toBe(false); + // Without a GitHub repository the notification says nothing about an issue. + expect(requests[0]!.payload.body).not.toContain("Issue:"); hold = false; yield* Deferred.succeed(release, undefined); const accepted = yield* Fiber.join(pending);