feat(feedback): POST /v1/feedback files crash and bug reports as Gitea issues #147

Open
sharang wants to merge 3 commits from feat/feedback-endpoint into main
pull from: feat/feedback-endpoint
Owner

What

  • New endpoint POST /v1/feedback. A CLI user sends a crash report or /bug report with their own Keycloak token. The registry files it as an issue in the private repo platform/werkpilot-feedback and answers 201 {"id": <issue number>}, with no URL.
  • Gitea client. internal/gitea gains CreateIssue, with the same error hygiene as ListUsers: errors carry no response body, URL or token.
  • Config. Three new settings, FEEDBACK_GITEA_URL, FEEDBACK_GITEA_REPO and FEEDBACK_GITEA_TOKEN, plus their README rows and the OpenAPI entry.

Why

Refs platform/werkpilot#86 (crash reports and /bug feedback). The Werkpilot CLI side is being built in parallel against this contract.

Linked milestone: n/a (werkpilot#86)

How

Request: {"product","kind","title","body","version","device"}

  • kind is crash or bug.
  • title is 1–200 characters (runes) after trimming.
  • product is required, at most 100 characters.
  • version and device are optional, at most 100 characters each.
  • body must be non-empty and at most 200000 bytes, otherwise 413 too_large. The request itself is capped at 2 MiB, also 413.
  • In title, product, version and device, line breaks and other control characters (and U+2028/U+2029) become spaces before trimming and counting. A multi-line panic message still files as a title, and a caller can't forge provenance lines or an early ---. Values that are too long are refused, not cut.

Issue:

  • Title: [<tenant slug>] <kind>: <title>.
  • Body: a provenance list first (tenant slug and id, user subject plus e-mail when the token has one, product, version, device, kind, received time in UTC RFC 3339), then ---, then the submitted body verbatim.
  • The tenant is the token's. The slug is read from the store, and a tenant_id in the JSON is ignored.

Errors (all use the existing writeError envelope):

Status Code When
503 feedback_disabled No token is configured
403 user_token_required Service token, or no principal
400 invalid_input Validation fails
413 too_large Body or request too big
429 rate_limited More than 10 per user subject per sliding hour (in memory, the keyRateLimiter CI licences use). Refused requests don't count.
502 feedback_failed Gitea fails. Logged with Gitea's status only; no title, body, token or Gitea body in the log or the response.

Authz:

  • New route group feedback. There is no org-role check, so any member may send; requireMember still stops blocked members.
  • A user token from a client that holds licences passes too. That covers werkpilot-cli and firmwerk-cli with the AUTHZ_RULES deployed today (licences,usage), so no orca rule change is needed.
  • Other clients need feedback itself, or get 403 FORBIDDEN_CLIENT. That includes the portal's sign-in client, and service tokens that hold licences.

Audit: feedback.submitted (actor, product, kind, version, device, issue number; not the title or body).

On-prem: with a token set, FEEDBACK_GITEA_URL and FEEDBACK_GITEA_REPO must be given explicitly. This mirrors the LiteLLM rule.

Going live (orca, not in this PR)

After this is merged and deployed, the endpoint stays inert (503) until a Gitea bot account's token is put into the deployment secret (orca, platform-stage / platform-prod) as FEEDBACK_GITEA_TOKEN. The bot needs write access to issues in platform/werkpilot-feedback. No AUTHZ_RULES change is needed.

No bot account or token was created for this PR. Read-only check: platform/werkpilot-feedback exists, is private and has issues enabled.

Test plan

  • Unit tests in internal/server/feedback_test.go, run against an httptest fake Gitea:
    • 201: the exact title and body sent to Gitea, including the provenance block. The fake returns different id and number, and the response must be {"id": number}. Also checks the token is in the header only, never in the URL, and the audit event.
    • 503 without a token.
    • Validation: bad or missing kind, empty or long title, missing or long product, long version, empty or missing body, bad JSON, body over 200000 bytes (413), request over 2 MiB (413). The exact limits pass.
    • One-line fields: line breaks in the title, version and device become spaces, and the exact body shows the provenance block still has its seven lines.
    • Tenant: taken from the principal even when the JSON names another tenant.
    • Rate limit: 10 per person, the 11th gets 429. Refused requests don't count, a colleague is unaffected, and the window slides.
    • Gitea failure (500 with the token and a marker in its body, 403, 201 without an issue, 200): 502. Neither the marker nor the token appears in the response or the log, and neither do the title or body in the log.
    • Gitea unreachable: 502, and neither the token nor the URL leaks.
    • Malformed FEEDBACK_GITEA_REPO: 502.
    • Access: user tokens from werkpilot-cli and firmwerk-cli, with only licences,usage as deployed, reach the handler (201). So does a client granted feedback. These are refused:
      • a user token from a client without licences (FORBIDDEN_CLIENT);
      • a service token holding licences (FORBIDDEN_CLIENT);
      • a service token holding everything (user_token_required);
      • a request with no principal (user_token_required).
  • internal/gitea: CreateIssue path escaping, the 201 check, errors without body or token, and repo validation.
  • authz_test (route group), openapi_test (route in the spec), config defaults and the on-prem rule.
  • gofmt -l . clean, go vet ./... clean, golangci-lint run (v2.12.2, as in CI): 0 issues, go test -race -count=1 ./... all green.
  • Integration tests (testcontainers): the Postgres variants skipped locally, because the harness skips when Docker is unreachable and it is here. The endpoint uses only existing store methods (GetTenant, AppendAudit) and adds no migration. audit_log.target_id/target_type are plain TEXT with no CHECK, so the issue number as target_id is fine.
  • Not verified against the real git.breakpilot.com: no bot token exists yet. The request shape follows Gitea's POST /api/v1/repos/{owner}/{repo}/issues (201, number).
  • Manual smoke on stage after deploy, once the token and the AUTHZ rule are in.

Risk

Blast radius: one new route; nothing existing changes behaviour (internal/gitea's request code was factored into a shared do, and the ListUsers tests still pass).

What could break:

  • Nothing until it is configured; it answers 503.
  • Once live, Gitea outages surface as 502 to the CLI only.
  • The rate limit is per process, which matches the single replica.

Rollback plan: unset FEEDBACK_GITEA_TOKEN (endpoint goes back to 503), or revert the PR and redeploy.

Checklist

  • Docs updated (README env table, OpenAPI)
  • Audit events emitted for state changes (feedback.submitted)
  • Secrets via Infisical, never in repo (FEEDBACK_GITEA_TOKEN is a deployment secret)
  • Migration is forward-only + idempotent (or no migration): no migration
  • Tenant scoping enforced on every DB query (or no DB access): tenant from the principal only
  • OpenAPI spec updated
  • featureFlags.evaluate() used for any toggleable behavior: n/a, the token's presence is the switch, as with other integrations here
  • CHANGELOG entry under "Unreleased": n/a, the file is generated by git-cliff on release and hasn't been hand-edited since the first milestones

Screenshots / recordings

n/a (no UI)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR

## What - **New endpoint `POST /v1/feedback`.** A CLI user sends a crash report or `/bug` report with their own Keycloak token. The registry files it as an issue in the private repo `platform/werkpilot-feedback` and answers `201 {"id": <issue number>}`, with no URL. - **Gitea client.** `internal/gitea` gains `CreateIssue`, with the same error hygiene as `ListUsers`: errors carry no response body, URL or token. - **Config.** Three new settings, `FEEDBACK_GITEA_URL`, `FEEDBACK_GITEA_REPO` and `FEEDBACK_GITEA_TOKEN`, plus their README rows and the OpenAPI entry. ## Why Refs platform/werkpilot#86 (crash reports and `/bug` feedback). The Werkpilot CLI side is being built in parallel against this contract. Linked milestone: **n/a** (werkpilot#86) ## How **Request:** `{"product","kind","title","body","version","device"}` - `kind` is `crash` or `bug`. - `title` is 1–200 characters (runes) after trimming. - `product` is required, at most 100 characters. - `version` and `device` are optional, at most 100 characters each. - `body` must be non-empty and at most 200000 bytes, otherwise 413 `too_large`. The request itself is capped at 2 MiB, also 413. - In title, product, version and device, line breaks and other control characters (and U+2028/U+2029) become spaces before trimming and counting. A multi-line panic message still files as a title, and a caller can't forge provenance lines or an early `---`. Values that are too long are refused, not cut. **Issue:** - Title: `[<tenant slug>] <kind>: <title>`. - Body: a provenance list first (tenant slug and id, user subject plus e-mail when the token has one, product, version, device, kind, received time in UTC RFC 3339), then `---`, then the submitted body verbatim. - The tenant is the token's. The slug is read from the store, and a `tenant_id` in the JSON is ignored. **Errors** (all use the existing `writeError` envelope): | Status | Code | When | |---|---|---| | 503 | `feedback_disabled` | No token is configured | | 403 | `user_token_required` | Service token, or no principal | | 400 | `invalid_input` | Validation fails | | 413 | `too_large` | Body or request too big | | 429 | `rate_limited` | More than 10 per user subject per sliding hour (in memory, the `keyRateLimiter` CI licences use). Refused requests don't count. | | 502 | `feedback_failed` | Gitea fails. Logged with Gitea's status only; no title, body, token or Gitea body in the log or the response. | **Authz:** - New route group `feedback`. There is no org-role check, so any member may send; `requireMember` still stops blocked members. - A **user token from a client that holds `licences`** passes too. That covers `werkpilot-cli` and `firmwerk-cli` with the AUTHZ_RULES deployed today (`licences,usage`), so no orca rule change is needed. - Other clients need `feedback` itself, or get 403 `FORBIDDEN_CLIENT`. That includes the portal's sign-in client, and service tokens that hold `licences`. **Audit:** `feedback.submitted` (actor, product, kind, version, device, issue number; not the title or body). **On-prem:** with a token set, `FEEDBACK_GITEA_URL` and `FEEDBACK_GITEA_REPO` must be given explicitly. This mirrors the LiteLLM rule. ## Going live (orca, not in this PR) After this is merged and deployed, the endpoint stays inert (503) until a Gitea bot account's token is put into the deployment secret (orca, `platform-stage` / `platform-prod`) as `FEEDBACK_GITEA_TOKEN`. The bot needs write access to issues in `platform/werkpilot-feedback`. No AUTHZ_RULES change is needed. No bot account or token was created for this PR. Read-only check: `platform/werkpilot-feedback` exists, is private and has issues enabled. ## Test plan - [x] Unit tests in `internal/server/feedback_test.go`, run against an httptest fake Gitea: - **201:** the exact title and body sent to Gitea, including the provenance block. The fake returns different `id` and `number`, and the response must be `{"id": number}`. Also checks the token is in the header only, never in the URL, and the audit event. - **503** without a token. - **Validation:** bad or missing kind, empty or long title, missing or long product, long version, empty or missing body, bad JSON, body over 200000 bytes (413), request over 2 MiB (413). The exact limits pass. - **One-line fields:** line breaks in the title, version and device become spaces, and the exact body shows the provenance block still has its seven lines. - **Tenant:** taken from the principal even when the JSON names another tenant. - **Rate limit:** 10 per person, the 11th gets 429. Refused requests don't count, a colleague is unaffected, and the window slides. - **Gitea failure** (500 with the token and a marker in its body, 403, 201 without an issue, 200): 502. Neither the marker nor the token appears in the response or the log, and neither do the title or body in the log. - **Gitea unreachable:** 502, and neither the token nor the URL leaks. - **Malformed `FEEDBACK_GITEA_REPO`:** 502. - **Access:** user tokens from `werkpilot-cli` and `firmwerk-cli`, with only `licences,usage` as deployed, reach the handler (201). So does a client granted `feedback`. These are refused: - a user token from a client without `licences` (`FORBIDDEN_CLIENT`); - a service token holding `licences` (`FORBIDDEN_CLIENT`); - a service token holding everything (`user_token_required`); - a request with no principal (`user_token_required`). - [x] `internal/gitea`: `CreateIssue` path escaping, the 201 check, errors without body or token, and repo validation. - [x] `authz_test` (route group), `openapi_test` (route in the spec), config defaults and the on-prem rule. - [x] `gofmt -l .` clean, `go vet ./...` clean, `golangci-lint run` (v2.12.2, as in CI): 0 issues, `go test -race -count=1 ./...` all green. - [ ] Integration tests (testcontainers): the Postgres variants skipped locally, because the harness skips when Docker is unreachable and it is here. The endpoint uses only existing store methods (`GetTenant`, `AppendAudit`) and adds no migration. `audit_log.target_id`/`target_type` are plain `TEXT` with no CHECK, so the issue number as `target_id` is fine. - [ ] Not verified against the real git.breakpilot.com: no bot token exists yet. The request shape follows Gitea's `POST /api/v1/repos/{owner}/{repo}/issues` (201, `number`). - [ ] Manual smoke on stage after deploy, once the token and the AUTHZ rule are in. ## Risk **Blast radius:** one new route; nothing existing changes behaviour (`internal/gitea`'s request code was factored into a shared `do`, and the `ListUsers` tests still pass). **What could break:** - Nothing until it is configured; it answers 503. - Once live, Gitea outages surface as 502 to the CLI only. - The rate limit is per process, which matches the single replica. **Rollback plan:** unset `FEEDBACK_GITEA_TOKEN` (endpoint goes back to 503), or revert the PR and redeploy. ## Checklist - [x] Docs updated (README env table, OpenAPI) - [x] Audit events emitted for state changes (`feedback.submitted`) - [x] Secrets via Infisical, never in repo (`FEEDBACK_GITEA_TOKEN` is a deployment secret) - [x] Migration is forward-only + idempotent (or no migration): no migration - [x] Tenant scoping enforced on every DB query (or no DB access): tenant from the principal only - [x] OpenAPI spec updated - [ ] `featureFlags.evaluate()` used for any toggleable behavior: n/a, the token's presence is the switch, as with other integrations here - [ ] CHANGELOG entry under "Unreleased": n/a, the file is generated by git-cliff on release and hasn't been hand-edited since the first milestones ## Screenshots / recordings n/a (no UI) 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
sharang added 1 commit 2026-11-23 12:49:33 +00:00
feat(feedback): POST /v1/feedback files crash and bug reports as Gitea issues
ci / shared (pull_request) Successful in 15s
ci / test (pull_request) Successful in 6m48s
ci / image (pull_request) Skipped
553f4c52fe
A CLI user sends a crash report or /bug report with their own token; the
registry files it as an issue in the private feedback repo, titled
"[<tenant slug>] <kind>: <title>", with a provenance block (tenant, user,
product, version, device, kind, time received) above the body. The caller
gets the issue number only.

- route group "feedback"; user tokens only; tenant from the principal
- 10 reports per person and hour (in memory)
- FEEDBACK_GITEA_URL / _REPO / _TOKEN; no token answers 503
- Gitea errors become 502 feedback_failed without body, URL or token
- audit event feedback.submitted

Refs platform/werkpilot#86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
CODEOWNERS rules requested review from Benjamin_Boenisch 2026-11-23 12:49:33 +00:00
sharang added 1 commit 2026-11-23 12:53:04 +00:00
fix(feedback): turn line breaks in one-line fields into spaces
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m49s
ci / image (pull_request) Skipped
dfc9f72a24
A crash title built from a multi-line panic message was refused with 400.
Control characters (and U+2028/U+2029) in title, product, version and
device now become spaces, so the report files and the provenance block
still cannot be forged.

Refs platform/werkpilot#86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
sharang added 1 commit 2026-11-23 12:57:22 +00:00
fix(feedback): let the CLIs' user tokens reach /v1/feedback
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 6m39s
ci / image (pull_request) Skipped
c5a6c0d20e
The deployed AUTHZ_RULES give werkpilot-cli and firmwerk-cli only
licences and usage, so the new feedback group answered FORBIDDEN_CLIENT.
A user token from a client holding licences now passes for feedback too;
other clients still need the feedback group, and service tokens are
refused by the handler.

Refs platform/werkpilot#86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
All checks were successful
ci / shared (pull_request) Successful in 12s
Required
Details
ci / test (pull_request) Successful in 6m39s
ci / image (pull_request) Skipped
Checking for merge conflicts…
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feat/feedback-endpoint:feat/feedback-endpoint
git checkout feat/feedback-endpoint
Sign in to join this conversation.