Skip to content

Gitea Integration

Taskbase can optionally mirror tasks as Gitea issues — one issue per task in the linked repository. The sync is bidirectional for issue lifecycle events: outbound (Taskbase → Gitea) for task create/update/close/reopen and agent progress comments, inbound (Gitea → Taskbase) via webhooks for issue edits, state changes, comments, and PR references. See the Gitea → Taskbase (Webhooks) section for the inbound flow.

Activation

Sync is opt-in at the project level. Both the organization's gitea_org field and the project's gitea_repo field must be set for sync to be active on that project. Once both are set, the API auto-registers a webhook on the target repo — no manual per-repo setup.

The sections below walk through each step. If you are enabling sync for an existing Taskbase project, jump straight to Enabling a project.

Prerequisites (platform-level, one-time)

These are done once per Taskbase deployment and already in place for the prod environment. You only need to revisit them when standing up a new deployment or rotating credentials.

Item Where Notes
taskbase-bot user in Gitea gitea.prod.skatzi.com site admin Service account that owns the PAT and is named in GITEA_BOT_LOGIN (webhook events from this user are dropped as loop echoes).
Bot PAT User Settings → Applications → Tokens (logged in as the bot) Scopes: read:user, write:issue, write:repository. write:repository is required to manage webhooks; write:issue alone will 403 on hook creation.
hetzner-mgmt/taskbase/gitea / token OpenBao The bot PAT. Consumed as GITEA_TOKEN.
hetzner-mgmt/taskbase/gitea-webhook / secret OpenBao Random HMAC (openssl rand -hex 32). Consumed as GITEA_WEBHOOK_SECRET and passed to Gitea when registering each webhook.
hetzner-mgmt/taskbase/gitea-webhook / bot-login OpenBao Bot username (e.g. taskbase-bot). Consumed as GITEA_BOT_LOGIN.
PUBLIC_BASE_URL env deploy/prod/api-deployment.yaml External URL of the Taskbase API (e.g. https://taskbase.skatzi.com). Gitea uses this to reach our webhook endpoint. Unset in dev — registration becomes a no-op.

After changing any OpenBao value, trigger an ExternalSecret refresh and restart the deployment so the new secret reaches the pod:

kubectl --context admin@mgmt-cluster -n tasks-prod annotate externalsecret tasks-gitea force-sync="$(date +%s)" --overwrite
kubectl --context admin@mgmt-cluster -n tasks-prod rollout restart deploy platform-tasks-api

Enabling a Gitea org on a Taskbase organization

Per org, done once. The bot must be a member of the Gitea org with Admin on the repos that will be linked — webhook management requires Admin, not Write. Easiest path: add taskbase-bot to the Owners team of the Gitea org. If you prefer a narrower team, grant it Code: Admin on the repos you plan to link.

Then set gitea_org on the Taskbase organization:

curl -sH "X-API-Key: $TASKBASE_PROD_API_KEY" -XPUT \
  https://taskbase.skatzi.com/api/organizations/{orgId} \
  -H 'Content-Type: application/json' \
  -d '{"name":"Skatzi","description":"...","gitea_org":"Skatzi"}'

gitea_org is the owner name as it appears in Gitea URLs (gitea.prod.skatzi.com/<gitea_org>/<repo>). It's case-sensitive.

Enabling a project

Per project, done once. Set gitea_repo to the repository name (not a URL):

curl -sH "X-API-Key: $TASKBASE_PROD_API_KEY" -XPUT \
  https://taskbase.skatzi.com/api/projects/{id} \
  -H 'Content-Type: application/json' \
  -d '{"name":"Platform","description":"...","gitea_repo":"platform"}'

The API validates that the repo exists before persisting the link. If Gitea responds with 404, the PUT is rejected with HTTP 400 and {"error":"gitea repo not found"} — catches typos and wrong capitalisation before they produce a broken project. Other errors (network, 5xx) are treated as soft-fails: the link is saved and the webhook registration step is attempted anyway, so a Gitea outage can't block project edits.

As soon as this PUT succeeds, the API:

  1. Calls POST /api/v1/repos/{gitea_org}/{gitea_repo}/hooks to register the webhook.
  2. Stores the returned hook ID in projects.gitea_webhook_id.

Verify:

curl -sH "X-API-Key: $TASKBASE_PROD_API_KEY" \
  https://taskbase.skatzi.com/api/projects/{id} | jq '{gitea_repo, gitea_webhook_id}'

gitea_webhook_id should be non-null. You should also see a new webhook at gitea.prod.skatzi.com/{gitea_org}/{gitea_repo}/settings/hooks. Smoke-test by editing an issue title in Gitea and confirming the linked task updates in Taskbase.

Pre-existing gitea_repo values

Auto-registration fires only on a change to gitea_repo. If a project already had gitea_repo set before auto-registration shipped, a plain save won't re-trigger it. Toggle the field: PUT with gitea_repo: null, then PUT again with the original value.

Disabling sync

Clearing gitea_repo (PUT with null) deletes the webhook and stops sync for that project. Deleting the project itself also deletes the webhook. Existing issues in Gitea stay untouched.

Troubleshooting

Symptom Likely cause
PUT /api/projects/{id} returns 400 gitea repo not found The gitea_repo value doesn't match any repo under the org's gitea_org. Check capitalisation (Gitea is case-sensitive) and confirm the repo exists at gitea.prod.skatzi.com/{gitea_org}/{gitea_repo}.
gitea_webhook_id stays null after setting gitea_repo Registration failed and was logged non-fatally. Check the pod logs: kubectl --context admin@mgmt-cluster -n tasks-prod logs -l app=platform-tasks-api --tail=200 \| grep -i gitea.
Logs show HTTP 403 ... required=[write:repository] The PAT in hetzner-mgmt/taskbase/gitea is missing write:repository scope. Regenerate as the bot, update OpenBao, force-sync, restart the pod.
Logs show HTTP 403 without a scope complaint Bot lacks Admin on the target repo. Add it to the Owners team of the Gitea org (or give its team Code: Admin).
Webhook created but events never arrive PUBLIC_BASE_URL points at an address Gitea can't reach (dev/staging). Registration succeeded; delivery fails. Check the Recent Deliveries tab on the Gitea webhook.
Inbound webhook returns 401 HMAC mismatch — usually means the OpenBao secret was rotated but the pod wasn't restarted, or existing webhooks still hold the old config.secret. Toggle the project's gitea_repo to re-register with the new value.
Inbound webhook returns 503 GITEA_WEBHOOK_SECRET is empty in the pod env. Secret missing or not mounted.

What gets synced

Taskbase event Gitea action
Task created Issue created with title and description (Markdown)
Task title or description updated Issue updated
Task marked done = true Issue closed
Task reopened (done = false) Issue reopened
Task deleted Issue hard-deleted (destructive — see note below)
Task moved to a project with another repository Issue created in the new repository; the old issue is closed with a pointer to it (task moves)
Agent posts a progress note Comment added to issue

Task delete is destructive

Deleting a task in Taskbase permanently removes the linked Gitea issue and all of its comments. This is intentional: a task delete signals "this should never have existed" (e.g. duplicate, spam, mis-clicked create), so the mirror issue is retracted with it. Use task close (set done=true or move to the Done column) when you simply want to mark work as finished — that maps to PATCH state=closed on the Gitea side and preserves history.

Tasks created before sync was enabled are not back-filled, except that the issue reconciler gives an issue to a task created in the last 7 days. Otherwise only changes after activation trigger Gitea calls.

Issue reconciler

The calls above are fire-and-forget: when one fails (Gitea down), the error is logged and the task write still succeeds. The issue reconciler repairs what they missed, in the Taskbase → Gitea direction only; changes made in Gitea come in through the webhooks. Source: api/internal/task/reconcile.go and reconcile_pg.go in the Taskbase repository (task #1383, taskbase PR #560, read 2026-10-21).

It runs at API start and then every 2 minutes, and repairs up to 25 tasks of Gitea-linked projects per sweep, oldest first:

Task Repair
kind: task, created in the last 7 days, no issue Gets an issue. It first adopts an existing issue updated since the task was created whose body has the task's footer <!-- taskbase:task:<id> -->, so a create whose answer was lost is not made twice; only if there is none does it create one
Has an issue in another state than the task The issue is closed or reopened to match. The task counts as closed when it is done or in a column named Done

Details:

  • Requests, Renovate dependency tasks, deploy-failure tasks, attention triage tasks (task #1457), legacy review tasks and the tasks of a routine without create_gitea_issue (or since deleted, task #1737) never get an issue. A task is left to the create handler for its first 2 minutes.
  • The adopt search reads at most 200 issues updated since the task was created. Beyond that the repair fails instead of risking a duplicate issue.
  • tasks.gitea_issue_closed (database schema, migration 077) holds the state the reconciler last saw the issue in, so it reads Gitea only for tasks whose state differs from it or whose issue is unchecked. An issue closed in Gitea in the last 2 minutes is left to its webhook. An issue deleted in Gitea is logged as gitea sync: issue is gone and no longer checked.
  • Each task is repaired under a Postgres advisory lock and read again first, so two API replicas do not repair the same task twice.
  • A repair Gitea refuses for that task (a 4xx, or the 200-issue search limit) logs gitea sync: repair failed and the sweep goes on. When Gitea is unavailable (no connection, timeout, 5xx or 429) the sweep stops, and the following sweeps back off: 0, 1, 3 and then 7 sweeps are skipped while failures continue.
  • Without GITEA_TOKEN the reconciler does not run.

Log lines to look for:

Log line Meaning
gitea sync: created issue, adopted issue, closed issue, reopened issue One repair, with task_id and issue
gitea sync: pending The number of tasks known to need a repair changed; pending is the new count
gitea sync: repair failed Gitea refused one task's repair; retried next sweep
gitea sync: sweep failed Gitea was unavailable or the backlog query failed; skipped_sweeps is the backoff
gitea sync: issue is gone The task's issue no longer exists in Gitea

Pending metric

The count in gitea sync: pending is also the Prometheus gauge taskbase_gitea_sync_pending: the tasks whose issue is missing or whose issue state differs from the task (task #1395, taskbase PR #564, read 2026-10-21). Where it is served and how Prometheus scrapes it is in API metrics.

  • Each sweep counts it before it repairs, so it shows the backlog the last sweep started from. A sweep that fails before counting, or is skipped by the backoff, leaves the last value.
  • Before the first sweep the gauge has no sample, only its # HELP and # TYPE lines.
  • It is briefly above zero in normal operation. Only a value that stays above zero, for 30 minutes or more, means Gitea or the sync is down.
  • The alert TaskbaseGiteaSyncPending fires on exactly that: max(taskbase_gitea_sync_pending{namespace="tasks-prod"}) > 0 for 30m, severity: warning. Its description gives the count and points at the API log lines gitea sync: sweep failed and gitea sync: repair failed. It has no incident: "true" label, so it goes to Mattermost only and never opens a Taskbase incident (Receivers and routes). It is prod only; tasks-dev has no rule. Where the rule lives: API metrics (task #1422, taskbase PR #587, read 2026-10-25).
  • Without GITEA_TOKEN there is no reconciler, so no metric either.

Agent personas (agents repository)

Separately from issue sync, Taskbase pulls the agent personas (ADR-0005, amended) from one agents repository into the agent_types table of every organization (api/internal/agenttype/sync.go).

Which organizations All of them — each gets every persona, whether or not it has a gitea_org
Repository AGENTS_REPO on the API (owner/name), default Skatzi/skatzi-agents. GET /api/agent-types/source reports it; the UI shows it under Settings → Agents
Files personas/<slug>.md — the slug is the file name (lowercase a-z, 0-9, -)
Format A --- frontmatter block with name and description, the optional kind (task, the default, or session for a persona that only chats in agent sessions) and the optional default_model (a tier or model id), then the markdown body used as the agent's system prompt
When At API startup and every 5 minutes, in every replica (idempotent)
Credential The same bot PAT as issue sync (GITEA_TOKEN); the bot must be able to read the agents repository

It is deliberately conservative about removing personas:

  • A missing repository or personas/ directory — or one the token cannot see — deactivates nothing, so a typo or a lost permission cannot wipe the personas. It is logged every sync as agent types: agents repository or its personas directory not found.
  • An organization whose update fails keeps its personas; the others are still updated.
  • A file that cannot be read or parsed (e.g. an unknown frontmatter key) is skipped and keeps its previous state; the reason is logged as agent types: invalid persona skipped.
  • Only a persona absent from a successful listing is marked is_active = false. Restoring the file reactivates it.
  • A file's default_model is stored only while the organization's persona has no default model (agent_types.default_model NULL). The sync never overwrites a default set with PUT /api/organizations/{orgId}/agent-types/{slug}/default-model, and removing the key from the file keeps the stored value. An owner who clears the default gets the file's value back on the next sync; to run a persona on the runner's default, drop the key from the file as well. An invalid kind or model skips the file like an unknown key.

Assign a task to a persona with assignee_type = 2 and assignee = its slug; a runner claiming the task receives the persona's body. A push webhook for faster pickup is planned; until then a change lands within five minutes.

Gitea API — Investigation Notes

Gitea exposes a REST API at https://gitea.prod.skatzi.com/api/v1/.

Auth

Personal Access Token (PAT) via Authorization: token <pat> header. A service account PAT with read:user, write:issue, and write:repository scopes is required. No OAuth app is needed for server-side sync.

The PAT is stored in OpenBao at hetzner-mgmt/taskbase/gitea under key token and injected as GITEA_TOKEN env var in the Taskbase API deployment via External Secrets Operator. See Prerequisites above for the full secret layout.

Endpoints used

Operation Endpoint
Create issue POST /repos/{owner}/{repo}/issues
Update issue title/body PATCH /repos/{owner}/{repo}/issues/{index}
Close issue PATCH /repos/{owner}/{repo}/issues/{index} with {"state": "closed"}
Reopen issue PATCH /repos/{owner}/{repo}/issues/{index} with {"state": "open"}
Delete issue DELETE /repos/{owner}/{repo}/issues/{index}
Add comment POST /repos/{owner}/{repo}/issues/{index}/comments
Read a file or list a directory (persona sync, model policy) GET /repos/{owner}/{repo}/contents/{path}
Read a pull request (below) GET /repos/{owner}/{repo}/pulls/{index}
Read the combined CI status at a commit (task PRs, project pipelines) GET /repos/{owner}/{repo}/commits/{ref}/status
Read a repository's default branch (below) GET /repos/{owner}/{repo}
List a branch's recent commits (below) GET /repos/{owner}/{repo}/commits?sha={ref}&limit=10
List a repository's open pull requests (stalled trivial upgrades) GET /repos/{owner}/{repo}/pulls?state=open&sort=newest&page={n}&limit=10

The POST /issues response includes a stable number field (the issue number within the repo) that Taskbase stores in tasks.gitea_issue_number for subsequent updates.

Reading a task's pull request

GET /api/tasks/{id}/pull-request[?pr=<url or owner/repo#n>] (api/internal/pullrequest/) gives people and agents a neutral, read-only summary of a task's pull request and its CI, read with Taskbase's own bot token. Agents and session turns hold no Gitea token, and get none (ADR-0015).

  • Which PR. By default the task's own, found as its Needs attention item finds it (Attention — Which pull request an item shows): the newest event's payload, then its runs' pr_url, then a linked task's (only for a person's task), then a PR URL named in text. ?pr= names another PR.
  • Answer. {"pull_request": {repository, number, title, state, merged, mergeable, base, head_sha, url, ci: {state, checks: [{name, state, target_url}]}}}. ci.state is the combined commit status at the head (none when no check has reported). No logs: they can be large and can hold secrets that a turn's transcript must not carry. A task without a PR answers {"pull_request": null}.
  • Only the organization's repositories. A PR outside the organization's gitea_org, on another host, or anything that is not a Gitea PR answers 400 without calling Gitea. A PR Gitea does not know answers 404; a Gitea failure 502.
  • Cache. Each summary is cached in the API process for 60 seconds; a 200 from Gitea with an empty pull request is not cached. A session turn's frame reads through the same service and cache. The Needs attention list uses the cache only and never waits on Gitea: it shows states up to 1 hour old and refreshes older or missing ones in the background (Context header).
  • Who. People of the task's organization, and agents of it, run-scoped and session-turn-scoped. MCP exposes it as get_task_pull_request.

Reading a project's pipeline

GET /api/projects/{id}/pipeline[?ref=<branch>] (api/internal/pipeline/; ADR-0016 §5) answers "is main green, deployed, promoted?" for a project's repository, read from Gitea's commit statuses with Taskbase's own bot token. Gitea Actions posts each workflow job as a status on the commit it ran for, so deploy and promotion jobs show up there too. The Actions API is not used: it refused the bot token (/actions/runs) or ignored limit (/actions/tasks).

  • It walks back past [skip ci] heads. Commits marked [skip ci] (such as the release bot's chore: promote prod … [skip ci]) carry no statuses, so the head of main often has none. Taskbase reads the branch's last 10 commits and their combined statuses, and reports the newest one that has any.
  • Answer. {repository, ref, head: {sha, title, time, url}, older, run}. run is that newest checked commit: {commit, state, checks: [{context, state, description, target_url}], workflows: [{name, state, jobs}]}, where workflows groups the checks by the context's prefix before / (release-and-deploy-dev / promote-prod (push) → workflow release-and-deploy-dev, job promote-prod) with each job's state, so "was it promoted?" is one field. older is true when the head itself has no statuses; run is null when none of the 10 has any. No logs.
  • Which branch. ref (at most 200 characters, no whitespace; else 400), by default the repository's default branch.
  • Only the organization's repositories. A project without a repository, or whose repository lies outside the organization's gitea_org, answers 400 without calling Gitea. An unknown repository or ref answers 404; a Gitea failure 502.
  • Cache. Each answer is cached in the API process for 60 seconds per repository and ref.
  • Who. People of the project's organization, and agents of it, run-scoped and session-turn-scoped (a general chat turn reads the projects of its organizations). MCP exposes it as get_project_pipeline.

Rate limits

Our self-hosted Gitea has no enforced rate limits. If limits are added in future, the client should handle 429 Too Many Requests with exponential backoff.

Error handling

Gitea sync failures are non-fatal — a task update succeeds even if the Gitea API call fails. Errors are logged by the Taskbase API server. There is no retry queue: the issue reconciler creates missing issues and fixes issue state on its next sweeps. Title and description edits that failed are not repaired.

Configuration

Env var Description Example
GITEA_BASE_URL Base URL of the Gitea instance https://gitea.prod.skatzi.com
GITEA_TOKEN Personal Access Token for the service account (from OpenBao)
GITEA_WEBHOOK_SECRET HMAC secret shared with Gitea for signing inbound webhooks (from OpenBao)
GITEA_BOT_LOGIN Username that owns GITEA_TOKEN; webhook events from this user are ignored to prevent loops taskbase-bot
RENOVATE_BOT_LOGIN The Renovate bot's username. Its labelled PRs on renovate/ branches become dependency tasks, and stalled trivial ones are escalated; unset, they are ordinary PRs. Must not be GITEA_BOT_LOGIN renovate-bot
LEFTOVER_PR_SWEEP close lets the hourly leftover PR sweep close PRs; any other value, or unset, makes it only log would close (dry run). A task becoming done closes its leftover PRs either way close
FLUX_WEBHOOK_SECRET HMAC secret shared with Flux's generic-hmac Provider and promote-prod for post-merge failures; unset, that endpoint answers 503 (from OpenBao hetzner-mgmt/taskbase/flux-webhook)
PUBLIC_BASE_URL External URL of the Taskbase API; used when auto-registering webhooks. If unset, auto-registration is skipped (dev). https://taskbase.skatzi.com

GITEA_TOKEN, GITEA_BASE_URL are all optional. If GITEA_TOKEN is empty, Gitea sync (both directions) is globally disabled regardless of per-project configuration.

Gitea → Taskbase (Webhooks)

Inbound webhooks keep Taskbase state in sync with changes made on the Gitea side: issue edits, state changes, comments, and pull requests that reference an issue.

Endpoint

POST /api/webhooks/gitea — single endpoint, dispatches on the X-Gitea-Event header.

Event scope (v1)

Gitea event Header value Taskbase effect
Issue opened issues / action=opened Ignored — issues created outside Taskbase are not imported. Responds 200.
Issue edited (title or body) issues / action=edited Update tasks.title and tasks.description.
Issue closed issues / action=closed Move task to the project's Done column and set done=true.
Issue reopened issues / action=reopened Clear done=false; keep group unless it is Done, in which case move back to Backlog. The webhook names no column; the store applies the Done-column rule.
Issue comment created/edited/deleted issue_comment Upsert / soft-delete a row in task_comments keyed on gitea_comment_id. Orphan comments (issue not linked to a task) are logged and dropped.
Pull request opened/closed/reopened referencing an issue pull_request For each #<N> ref in the PR title or body that matches a linked task, insert a synthetic row in task_comments (with gitea_comment_id=null) summarising the PR action. Skipped when the sender is the bot account.
Pull request merged pull_request / action=closed, merged=true Every task not yet done in the linked repository's Taskbase organization (across its projects) with an implementation run whose task_runs.pr_url is this PR, or a dependency_update task whose dependency.pull_request is, is completed exactly like an issue close: done=true, moved to its own project's Done column, done_at set, dispatch state cleared, attention events resolved. See Merged pull requests. A PR closed without merging changes nothing.

| Renovate pull request | pull_request, any action | Creates, refreshes, reopens or closes its dependency_update task; see Renovate pull requests. |

Label, assignee, and milestone events are out of scope for v1 except on Renovate pull requests; otherwise they 200 and log.

Merged pull requests

For a PR in the task's own repository, Closes #<Gitea issue> in the PR description lets Gitea close the issue; the issues / closed event then completes the task. The merge webhook also matches the PR against implementation runs across all projects of the linked repository's Taskbase organization, including tasks in a different project. A task in another Taskbase organization is never completed by that merge. This also covers a PR whose description lacks or misnames the closing line (Taskbase #425). Whichever event arrives first wins; a task that is already done is left alone. Either way, the task's other open PRs are then closed as leftover pull requests.

  • The PR is matched against the pr_url an implementation run recorded: the URL's path must end in /owner/repo/pulls/<number>, case-insensitively, ignoring a trailing slash, query or fragment. The host is not compared.
  • A merge counts even when the sender is the bot account (GITEA_BOT_LOGIN), since Taskbase never merges pull requests itself. PR-activity comments are still skipped for the bot.
  • An incident task whose alert still fires and that waits for a person is not completed by the merge: it is parked in Needs attention as incident_waits_for_person (task #1555).

Renovate pull requests

The Renovate ADR (§4–§7) has no Renovate-side integration: Taskbase reads Renovate's pull requests from this webhook (task #102). A PR is Renovate's when its author is RENOVATE_BOT_LOGIN and its head branch starts with renovate/. Gitea sends every PR sub-event (label_updated, synchronized, edited, …) as X-Gitea-Event: pull_request to a hook registered for pull_request, so no new hook events are needed.

  • Class. The highest of the PR's upgrade/<class> labels, in the order trivial, standard, breaking, stateful, core. Only standard and up make a task; trivial PRs automerge, unless they stall and the sweep escalates them.
  • Task. Kind dependency_update, in the repository's linked project's Backlog, titled with the PR title. Its description links the PR and the upgrade playbook and tells the agent to work on the PR's branch. Its dependency object holds the repository, branch, PR (owner/repo#n), class, the PR as release_notes_url, and packages from the body's <!-- taskbase:dep {"name","datasource","from","to","type"} --> lines (malformed lines are skipped). A note may also carry released_at, the new version's release time (RFC 3339, Renovate's releaseTimestamp; task #1177), which the upgrade metrics read. The shared preset does not write it yet: that is Taskbase task #1239. It has no Gitea issue: the PR is the task's Gitea artefact.
  • Routing (ADR §5; task #1333, Taskbase PR #571, RouteDependency and RouteDependencyTask in api/internal/task/dependency.go, read 2026-10-24), assigned to the agent with the model tier, effort and required runner labels:
Class Persona Model Effort Required labels
standard junior-developer small low none
breaking operator large high role=ops
stateful operator large high role=ops
core operator large high role=ops

Only a runner labelled role=ops, the ops-agent runner, takes the operator tasks. A task whose packages are owner-only goes to the owner instead, whatever its class. First in Taskbase v1.229.0; on 2026-10-24 deploy/prod/ still ran v1.228.0, where breaking went to developer/medium and stateful and core to senior-developer, with no labels.

  • Deduplication (§6): one open task per (repository, branch), enforced by a unique index. Any event on the PR while its task is open refreshes the title, the packages (kept when the body has no notes, e.g. after an agent's push) and the class, which is never lowered. A raise can change the route: see Re-routing on a raise below. Once the task is done, a new PR on the same branch gets a new task.
  • Lifecycle (§7): a merge completes the task through Merged pull requests, which also matches dependency.pull_request, and first sets dependency.merged_at to the time the webhook handled the merge (task #1177), so the upgrade metrics count merges apart from closes. Closed without merging with a title ending in - autoclosed (Renovate's mark) → done, with a comment that Renovate autoclosed it. Closed by anyone else → done as won't do, with a comment naming who closed it. Renovate reopening the PR (reopened) opens the same task again; other events on a closed PR change nothing.
  • One at a time per repository (§10, Blast radius; task #1172, Taskbase PR #515): stateful and core tasks of one repository run in order. When such a task is created, or its class is raised from below stateful to stateful or core (a relabelled PR, or the API below), it gets depends_on the newest unfinished stateful/core dependency task of the same repository (compared case-insensitively) that does not already wait for it, so the chain never closes a cycle. A raised task joins the end of the line. The claim holds it until that task is done — merged, autoclosed or closed as won't do — and then the next one can run. Other repositories, and standard and breaking tasks, are not held. A per-repository advisory lock serialises concurrent creates, and a new task's link is written in the same transaction, so it is never claimable unchained. A task Renovate reopens keeps the links it had and is not chained again.
  • Class through the API. dependency is read-only on PUT /api/tasks/{id} except class, which may be raised and never lowered (400); omitted, null or without class keeps it. MCP's update_task takes it as dependency_class. Raising it re-routes the task as below; raising it to stateful or core also chains it as above.
  • Re-routing on a raise (task #1515, Taskbase PR #575, RaisedRoute in api/internal/task/dependency.go and RerouteDependency in api/internal/task/dependency_pg.go, read 2026-10-24): when a raised class has a different route from the old class, for example standard → breaking, the task takes the new class's route from the table above: assignee, model, effort and required labels. Its model escalation goes back to 0. Both a relabelled PR (the webhook) and the API above do this. The task is re-routed only while all of these hold, checked in one UPDATE, so it cannot race a claim:
    • it is open;
    • it has no unfinished run;
    • it still has the old class's route: assignee, assignee type, model and labels.

Otherwise it keeps its route. A task a person reassigned therefore keeps that assignment, and so does a PUT that sets a new assignee together with the raise. An agent that raises the class during its own run (playbook step 8) has an unfinished run, its own, so that raise does not re-route the task. Both routes pass the owner guard, so an owner-only task stays with the owner. A raise between breaking, stateful and core has the same route and changes nothing. A task Renovate reopens is refreshed while it is still done, so a raise in the same event does not re-route it. First in Taskbase v1.233.0; on 2026-10-24 deploy/prod/ still ran v1.228.0, where a raise kept the route. - Renovate PRs get no PR-activity comments: their release notes mention upstream #numbers.

Owner-only upgrades

Talos, Kubernetes itself, Terraform and Hetzner tools that need credentials outside the cluster stay manual: the owner upgrades them, and the operator has no access to them (task #1333, narrowed by task #1531, Taskbase PR #577, in prod from v1.233.1; ownerOnly in api/internal/task/dependency.go, read 2026-10-24). Renovate disables most of these packages, so this guards tasks that arrive another way. A dependency task or a post-merge failure task is assigned to the person dunk (task.Owner), with no model, effort or labels, when any of these holds, with names compared in lower case:

  • a package's datasource starts with terraform;
  • a package's name, or a failure's object name, starts with ghcr.io/siderolabs/, siderolabs/ (Talos) or registry.k8s.io/kube- (Kubernetes control-plane images);
  • the last path segment of such a name is talos or starts with talos-, is terraform or starts with terraform-, or is hcloud (the Hetzner CLI);
  • the last path segment is kubernetes, kubelet, kube-apiserver, kube-controller-manager, kube-scheduler or kube-proxy.

For example the packages ghcr.io/siderolabs/installer, registry.k8s.io/kube-apiserver, kubernetes/kubernetes, hetznercloud/hcloud and a terraform-provider package, and the HelmRelease names talos-cloud-controller-manager, kube-apiserver and terraform-controller, go to the owner (Taskbase tests api/internal/webhook/dependency_test.go and flux_test.go).

hcloud CSI is not owner-only (owner, 2026-10-24, on task #1526). The chart hcloud-csi, the image hetznercloud/hcloud-csi-driver and failures of the HelmRelease hcloud-csi go to operator, model large, role=ops, like other core upgrades: the driver uses its own in-cluster hcloud-token Secret (components/hetzner-csi/helmrelease.yaml), so the operator needs no Hetzner credentials (Taskbase tests TestRenovateHcloudCSIGoesToOperator and TestFluxFailureOfHcloudCSIGoesToOperator). The reasons are in the Renovate ADR §5.

Stalled trivial upgrades

Gitea automerges Renovate PRs labelled upgrade/trivial, and no task is made for them. An hourly sweep (Renovate ADR §4 item 2; task #1171, Taskbase PR #514; api/internal/webhook/sweep.go, read on 2026-10-18) finds the ones that stalled and gives each a standard dependency task, so an agent unblocks it.

  • When. Once at API startup, since every deploy restarts the clock, then every hour. Each API process runs its own sweep.
  • Where. Every repository linked to a project: the organization's gitea_org and the project's gitea_repo, each pair once. Repositories are read one at a time, with 200 ms between Gitea reads. Per repository the sweep reads at most 200 open PRs, newest first, in pages of 10.
  • Which PRs. Renovate's, as for the webhook: author RENOVATE_BOT_LOGIN, head branch renovate/…, and trivial as the highest upgrade/<class> label.
  • Stalled means either:
    • open over 24 hours, counted from the PR's creation; or
    • younger than that, with a combined commit status of failure or error at its head. The status comes from the same read and 60-second cache as GET /api/tasks/{id}/pull-request. pending, success and no checks are left alone, and so is a PR Gitea no longer knows.
  • Conflicts. A conflict or a missing check does not change the combined status, so such a PR is escalated only once it is over 24 hours old.
  • Escalation. The sweep passes the PR to the webhook's Renovate path as if it were labelled upgrade/standard. That creates the PR's dependency_update task with class standard (junior-developer, model small), or, when the branch already has an open task for a different PR, refreshes that task. The task then gets a comment from taskbase that says why, followed by the PR's URL on the next line. The hours are whole hours, rounded down. For example:

    Trivial upgrade Skatzi/taskbase#42 has been open for 25 hours without automerging, so it is now a standard upgrade for an agent.
    Trivial upgrade Skatzi/taskbase#43 has failing checks (failure), so it cannot automerge, so it is now a standard upgrade for an agent.
    
  • Never twice. A PR whose branch's task — the open one, else the newest done one — already names this PR is skipped, whether that task is open or done. So a PR gets one task and one comment, even when it stays open after its task is done. A later webhook event on the PR keeps the class standard, because the class is never lowered.

  • Off when RENOVATE_BOT_LOGIN is unset. There is no setting of its own. Also off without GITEA_TOKEN: the no-token Gitea client cannot list pull requests, so the sweep does not start and logs nothing.
  • Logs. An escalation logs renovate sweep: stalled trivial upgrade escalated with the task, the PR and the reason.

Leftover pull requests

When a task becomes done, Taskbase comments on and closes the open PRs in the task's project repository that belong to the task, so a second PR whose work landed another way does not stay open forever. An hourly sweep catches missed events and older leftovers, but by default it only logs. Source: task #1300, Taskbase PR #547, api/internal/webhook/leftover.go and api/cmd/server/main.go, read on 2026-10-20.

  • When. A task becomes done through:
    • the issues / closed webhook;
    • the merged-PR webhook, also for a task that Closes # had already completed, so the comment can name the merge;
    • PUT /api/tasks/{id} or task.Service (the MCP tools), when the update makes the task done.

The close runs in the background; the event or request does not wait for it. - Where. Only the repository linked to the task's own project (gitea_org + gitea_repo). A project without a repository closes nothing. Per repository Taskbase reads at most 200 open PRs, newest first. - Which PRs belong to a task. Any of: - the PR is recorded on one of the task's implementation runs (task_runs.pr_url, matched as for merged pull requests); - the PR's head branch starts with feat/<id>- or fix/<id>-, and task <id> is in the same Taskbase organization as the repository; a task of another organization is ignored; - the PR body has Closes, Fixes or Resolves (any tense, any case) followed by #<issue>, and <issue> is the task's Gitea issue in that repository.

A bare #n mention does not make a task own a PR. A PR can belong to several tasks. - Never closed. - Merged PRs, and PRs that are not open. - Renovate's PRs: head branch renovate/…, or author RENOVATE_BOT_LOGIN. They have their own lifecycle. - PRs that any task that is still open also owns. A PR is closed only when every task it belongs to is done. - PRs that belong to no task. - A PR whose tasks cannot be read; it is skipped and logged (leftover prs: find tasks). - Comment. The bot (GITEA_TOKEN) comments first, then closes the PR through Gitea's issue route (PATCH /repos/{owner}/{repo}/issues/{n} with state: closed). If the comment fails, the PR is left open. The comment lists every task the PR belongs to (format from closingNote in leftover.go):

```text
Closing: task #732 is done; its work merged via PR #269.
Closing: tasks #732, #733 are done, so this pull request is left over. Reopen it if it still has work to land.
```

The first form is used when a merge completed the task; the second otherwise, including in the sweep. - Hourly sweep. Once at API startup, then every hour, over every linked repository, one at a time. It looks at all open PRs of each repository, not only those of one task, with the same rules as above. Unless the API has LEFTOVER_PR_SWEEP=close, it closes nothing and logs leftover prs: would close (dry run) with the PR and its tasks. A task becoming done always closes, whatever the setting. Neither deploy/prod nor deploy/dev in the Taskbase repository sets LEFTOVER_PR_SWEEP (read on 2026-10-20), so both sweeps run dry. - One pass at a time. Passes are serialised, so the merge and issue-closed events of one PR do not comment twice on the same leftover. - Off without GITEA_TOKEN: the no-token client cannot list pull requests, so nothing is closed and there is no sweep. - Logs. leftover prs: closed with the PR and its tasks; errors as leftover prs: comment, leftover prs: close or leftover prs: list pull requests.

Open questions

  • Closing a PR through the issue PATCH route is covered by unit tests with a fake Gitea client only; it has not been run against the real Gitea (run #2389 for task #1300).
  • When several projects of one organization link the same repository, Closes #<issue> is matched only against the Gitea issues of the lowest-id of those projects (LinkedRepos keeps one project per repository). A task in another of those projects is not found through its issue number.

Post-merge failures

A second endpoint, POST /api/webhooks/flux, turns a failure after a merge into a task that follows up the dependency upgrade that caused it (Renovate ADR §7; task #1174, Taskbase PR #526; source api/internal/webhook/flux.go, read 2026-10-19). Two senders use it:

  • Flux's notification-controller on hetzner-mgmt, through a generic-hmac Provider and one Alert per source repository (Failure alerts to Taskbase).
  • The promote-prod job, when a release is not promoted (Failure notice).

Like the Gitea webhook it sits outside the authenticated API; the sender proves itself with its signature.

  • Signature. X-Signature: sha256=<hex HMAC-SHA256 of the raw body>, keyed with FLUX_WEBHOOK_SECRET (OpenBao hetzner-mgmt/taskbase/flux-webhook, property secret), compared in constant time. Without the secret every request gets 503.
  • Replay window. The event's timestamp must be at most 15 minutes old and at most 5 minutes ahead of Taskbase's clock; otherwise 401.
  • Events that count. Only severity: error events whose involvedObject.kind is HelmRelease, Kustomization or Promotion (promote-prod's own kind). Anything else answers 200 {"result":"ignored"}.
  • Required metadata. metadata.cluster, metadata.repository (owner/repo) and metadata.revision, plus involvedObject.name. Flux's Alert adds cluster and repository through spec.eventMetadata. The repository must be linked to a Taskbase project (organizations.gitea_org + projects.gitea_repo); otherwise 422.
  • Deduplication. One task per (cluster, kind, namespace, name, revision), kept in the deploy_failures table. A repeat answers 200 {"result":"duplicate","task_id":N}; concurrent repeats are settled in one transaction.
  • Cause. Taskbase looks at the repository's dependency_update tasks that are done, with done_at in the last 24 hours, newest first (the repository is compared case-insensitively):
    • when metadata.renovate_branches (comma-separated) is set, as promote-prod sends it, the newest task whose dependency.branch is one of them;
    • otherwise the newest task with a package whose last path segment equals the object's name, case-insensitively (package gitea/gitea matches HelmRelease gitea).
  • Task. Kind task, in the project's Backlog, assigned to the agent, titled Post-merge failure: <kind> <namespace>/<name> on <cluster> at <revision>. The description quotes the event message (cut at 4000 characters), names the cause and its packages, and points to the upgrade playbook. With a cause, the task is follow_up_of it when there is a cause. It always goes to operator, model large, effort high, with required_labels: ["role=ops"], whatever the cause's class or without one, because a failure needs cluster access (RouteDeployFailure in api/internal/task/dependency.go, task #1333, read 2026-10-24). It goes to the owner instead when the object's name or a cause's package is owner-only. Before Taskbase v1.229.0 it was routed by the cause's class, else as breaking. It has no Gitea issue.
  • Hold while source-controller is unreachable. A Kustomization error whose message contains both failed to download archive and connection refused, as while the single source-controller replica restarts, makes its task as above but with start_after set 10 minutes after Taskbase received the event (SourceUnreachableHold in api/internal/webhook/flux.go; task #2659, Taskbase PR #696, read 2026-11-07). Flux retries the failed Kustomization within 2 minutes (spec.retryInterval: 2m on hetzner-mgmt, task #2658), so the operator run usually starts after the object is Ready again and closes the task. The task is held, never dropped: if source-controller stays down, the run still happens after the hold. Its description says why it waits. HelmRelease, Promotion and other Kustomization failures are not held.
Answer When
201 {"result":"created","task_id":N} A new failure task was made
200 {"result":"duplicate","task_id":N} The key already has a task
200 {"result":"ignored"} Not an error, or not one of the three kinds
400 The body cannot be read or is not JSON
401 Signature missing or wrong, or the timestamp outside the window
422 Missing cluster, repository, revision or object name, or no project linked to the repository
500 Database error
503 FLUX_WEBHOOK_SECRET is not set

The event as promote-prod sends it (copied from .gitea/scripts/promote-prod.sh; not posted from this page):

{
  "involvedObject": {"kind": "Promotion", "namespace": "tasks-prod", "name": "taskbase"},
  "severity": "error",
  "timestamp": "2026-10-19T12:00:00Z",
  "message": "Taskbase v1.222.0 was not promoted to prod: <reason> — <run link>",
  "reason": "PromotionFailed",
  "metadata": {"cluster": "hetzner-mgmt", "repository": "Skatzi/taskbase", "revision": "v1.222.0",
               "renovate_branches": "renovate/a,renovate/b"},
  "reportingController": "promote-prod"
}

Alertmanager alerts take a third endpoint, POST /api/webhooks/alertmanager, which keeps one incident task per alert group: see Incidents from Alertmanager.

Signature verification

Gitea signs webhook bodies with HMAC-SHA256 using the configured secret. The hex digest is sent in X-Gitea-Signature. The handler:

  1. Reads the raw request body.
  2. Computes hmac.SHA256(GITEA_WEBHOOK_SECRET, body) and compares (constant-time) to the header value.
  3. On mismatch, returns 401 and does not process.

Task lookup

  1. repository.full_name (e.g. Skatzi/platform) is split and matched to a project via organizations.gitea_org + projects.gitea_repo.
  2. issue.number is matched to a task via tasks.gitea_issue_number + that project id.
  3. If either lookup fails, respond 200 with a log line. This prevents Gitea from retrying forever on unlinked repos or orphan issues.

Idempotency and redelivery

Handlers are idempotent by construction — every operation is "set state to X" or "upsert by Gitea ID". Redelivery is safe. The X-Gitea-Delivery UUID is recorded in the structured log for debugging but is not stored.

Loop prevention

When Taskbase writes to Gitea, Gitea immediately fires the webhook back. The handler drops events whose sender.login == GITEA_BOT_LOGIN. This string-match is sufficient as long as the bot PAT is not used by any other automation.

Auto-registration

Webhooks are registered automatically by the Taskbase API when a project's gitea_repo is set (or changes) — no manual setup per repo. All three of the following must be true:

  • the project has a non-empty gitea_repo
  • its organization has a non-empty gitea_org
  • the deployment has PUBLIC_BASE_URL and GITEA_WEBHOOK_SECRET set

When these conditions are met, the API calls:

POST /api/v1/repos/{owner}/{repo}/hooks
{
  "type": "gitea",
  "active": true,
  "events": ["issues", "issue_comment", "pull_request"],
  "config": {
    "url": "{PUBLIC_BASE_URL}/api/webhooks/gitea",
    "content_type": "json",
    "secret": "{GITEA_WEBHOOK_SECRET}"
  }
}

The returned hook ID is stored on the project in the gitea_webhook_id column so it can be removed later. When gitea_repo changes, the old hook is deleted (DELETE /repos/{owner}/{repo}/hooks/{id}) and a new one is registered against the new repo. Clearing gitea_repo or deleting the project also deletes the hook. Registration failures are non-fatal — they log and leave gitea_webhook_id null; the project CRUD call itself still succeeds. An operator can rerun registration by toggling the gitea_repo field.

In local development PUBLIC_BASE_URL is typically unset, in which case registration is a no-op (dev is not reachable from the prod Gitea anyway).

Schema additions

ALTER TABLE projects
    ADD COLUMN gitea_webhook_id BIGINT DEFAULT NULL;

CREATE TABLE task_comments (
    id               BIGSERIAL PRIMARY KEY,
    task_id          BIGINT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
    gitea_comment_id BIGINT UNIQUE,
    author_login     TEXT NOT NULL,
    body             TEXT NOT NULL,
    created_at       TIMESTAMPTZ NOT NULL,
    updated_at       TIMESTAMPTZ NOT NULL,
    deleted_at       TIMESTAMPTZ DEFAULT NULL
);

CREATE INDEX ON task_comments (task_id, created_at);

gitea_comment_id is unique to deduplicate redelivery; nullable so the table can later hold Taskbase-originated comments. Deletion is soft so a user who accidentally deletes in Gitea can see the ghost row in history.

Surfacing activity in the UI

Mirrored comments and PR activity are exposed at GET /api/tasks/{id}/comments and rendered as an Activity section in the task detail modal. Comments with a non-null gitea_comment_id deep-link back to the issue page on Gitea; synthetic PR-activity rows render with a dashed border to distinguish them from real comments.

Out of scope (deferred to v2)

  • Bi-directional comment authoring (v1 is read-only; users comment in Gitea).
  • Assignee / label / milestone sync.
  • Bulk import of pre-existing Gitea issues as tasks.
  • Automatic issue close on PR merge (kept as human action so the kanban stays the source of truth for workflow state).