pruefwerk-agent-stage logged 'platform token rejected: failed to decode
JWT header' in bursts of five provisions and one targets read, each time
the registry's tests ran (CI and local). The migrations seed the real
provision URLs (0005: pruefwerk-stage), a test config's env 'dev' reads
as 'stage', so every postgres test that provisioned a tenant called the
live endpoint with the Keycloak mock's non-JWT token and got 401.
The postgres harness clears provision_urls after migrating, as the
memory store has none; tests that need one set it themselves. Checked:
a full local run with postgres left no request in Prüfwerk's traces.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
GET /v1/tenants/{id}/{sub} serves eight collections (members, documents,
projects, contracts, managed-services, company-profile, role-dataset,
store), and spans and access-log lines all said '{sub}': SigNoz could
not tell a document-store read from a team list. The route name now
carries the collection when it is one of the eight, and keeps the
wildcard for anything else, so no free path text reaches the name.
The list lives next to the dispatcher; a test keeps the two in step.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
Stage logged ~11,100 failed usage.record items a day ('tenant has no ERP
customer yet') behind 36 customer.upsert failures on the unique
tenants_erp_customer_id_key (backlog t25). The ERP mock keeps its docs
in memory and restarts with every registry deploy on stage: its counter
began at CUST-00001 again and handed new tenants names older tenants are
still linked to, so they never got linked and their usage waited
forever.
- erpmock: Config.NameToken goes into every assigned name; cmd/erpmock
sets one per boot (CUST-<yymmddHHMMSS>-00001). Tests keep plain names.
- outbox: after maxOutboxAttempts (170, about a week at the 1 h cap) an
item is dead-lettered instead of retried forever: done_at set,
last_error 'dead letter: <err>', payload kept for a re-queue, and an
ERROR line (the prod error alert sees it). Store gains
DeadLetterOutbox (memory + postgres).
Tests: dead letter after the last attempt and nothing claimed after,
memory and postgres; mock names carry the token.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
eu_einvoice reads CII only and answers a UBL XRechnung with a 500
("Invalid XML, found tag …ubl…Invoice"). The intake took that for a
transient error and retried three runs (30 min) before the plain
draft. A wrong root element is now treated like the 417 "not an
e-invoice": next file, then the draft with the original attached.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
Every intake run failed with "list Contact: HTTP 500: (1052, Column
'creation' in ORDER BY is ambiguous)": the supplier lookup filters on the
child table Contact Email, Frappe joins it, and the bare order_by column
exists in both tables. Nothing sent to invoice@ became a draft (t53).
order_by is now `tab<Doctype>`.`creation`; the fake ERP in the tests
refuses an unqualified one with a child-table filter, like MariaDB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
The service map draws database nodes from the pre-1.26 db.system key
(dependency_graph_minutes_db_calls_mv_v2); the spans set only
db.system.name, so the registry's Postgres never appeared on the map.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
internal/telemetry: OTLP/HTTP tracer provider from the OTEL_* env
(already set on stage and prod; unset = off), W3C propagation, one server
span per request named after the ServeMux pattern, client spans on the
default transport (Keycloak, ERP, LiteLLM, OIDC) and a pgx QueryTracer.
Client and DB spans only inside a request, so the background loops add
no traces. No raw paths, query strings, bodies, SQL parameters or client
addresses in spans; outbound spans carry the host only.
slog lines logged with a request context get trace_id/span_id; the
access log names the route instead of the raw path (slugs are names).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
- Mehrverbrauch: only on quotes with Prüfwerk, priced from the
CRA-CSA-CLD-SCAN Item Price (falls back to the price list).
- Vertragsgrundlagen default no longer cites a missing Anlage: documents
on request beforehand, in the customer portal after signing.
- USt-IdNr.: NimbusSans sets "Nr." as one № glyph; a ZWNJ keeps it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
With page-break-inside: avoid (#96) the block moves whole to page 2, which
has no letter head, so it sat flush against the top edge. Give the wrapper
28px top padding. Padding rather than margin: wkhtmltopdf drops a margin at
a page break. When the block fits on page 1 it only widens the gap after
the totals a little.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
The Vertragsbedingungen block (#95) only stated the permanent discount for a
document-level discount (total - net_total). The K-00001 Pilotrabatt is a
negative line item, by design, because eu_einvoice cannot carry a
document-level discount, so the sentence never rendered and the Rabattdauer
(one of the reviewer's required terms) was missing from the PDF.
Count negative lines (rate < 0) as well, and say the discount is already
contained in the stated net amount. Keep the block on one page
(page-break-inside: avoid); it split across pages 1-2.
Rendered against mocks: line-item discount, document-level discount and no
discount all produce the expected text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
Angebot review (§3/§5/§6): the Quotation PDF lacked the contractual terms a
B2B-SaaS offer needs. Add a Quotation-GUARDED Vertragsbedingungen block to the
shared documentHTML (Vertragsart, Vertragsbeginn, Laufzeit/Kündigung, Abrechnung,
monatliche Vergütung + Rabattdauer, Mehrverbrauch, Vertragsgrundlagen, Annahme),
the 14-day SEPA Vorabinformation on the non-invoice Zahlungsart line, and a
"Monatlicher Gesamtbetrag" label so the recurring nature is unambiguous (the
"1 Monat" misread). Every new block is doc.doctype == "Quotation" (or the
not-is_inv branch), so the GoBD Sales Invoices are untouched.
Terms per the owner's decisions 2026-10-27: no minimum term (monthly cancellable,
1 month to month-end), permanent discount incl. renewals, SEPA-Lastschrift 21
days, per-Prüfung overage. Vertragsgrundlagen renders a placeholder until the
SaaS-AGB/SLA/AVV/TOMs land in the portal document store. Structured per-field
Custom Fields are a documented follow-up.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KYcAAeTw22GE9QPzDM8yc4
The 22 Expense Claim Types of the Reisekosten app, each with its standard SKR04 Arbeitnehmer account for Breakpilot GmbH (decided 2026-10-20), and breakpilot_report_id (unique) on Expense Claim as the relay's idempotency key. Backlog #39 (a)+(b).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Migration 0021 (company_profiles + company_profile_revisions), GET/PUT /v1/tenants/{id}/company-profile, POST …/submit with optimistic revisions (409 + current revision; unchanged saves are no new revision), staff import via /v1/admin/tenants/{id}/company-profile (named staff member only), outline validation of the form document, audit without answers, OpenAPI.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lieferung an Unternehmen in der EU is an intra-community supply: tax category K with VATEX vatex-eu-ic; Sonstige Leistung an Unternehmen in der EU (services) stays AE. Found in the live dry run of 2026-10-20.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code lists and mappings for eu_einvoice (units, payment means 58/59, AE/G tax categories with VATEX), Mode of Payment Überweisung on the company bank account and terms Überweisung 21 Tage, item RABATT for discount lines (SKR04 4700, Verwaltung), E Invoice Settings (warn on save, block on submit), default profile EN 16931 for new customers, transfer text on offers/orders and a mandate check in the invoice mail. Backlog #16.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Frappe 15.112 lets a user without System Manager create a ToDo only when it is assigned to or by that user, so the service sets assigned_by to its own user (asked once via frappe.auth.get_logged_user). Mails from our own domain or a freemail address no supplier has were forwarded by a person: their ToDo says to enter the invoice by hand instead of suggesting a retry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reads the mails of ERPNext's Email Account Eingangsrechnung via the API: e-invoices become E Invoice Import drafts, other PDFs draft Purchase Invoices (supplier by sender, placeholder line, original attached), the rest ToDos. Never submits; state lives in ERPNext (unique Link intake_communication, ToDo reference). erpsetup adds the marker fields, the placeholder item EINGANGSRECHNUNG and its SKR04 6300 account.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
INVITE_REDIRECT_URI may contain {slug}; the registry replaces it with the
workspace slug at all three invite sites (new workspace, member invite,
resend). Stage and prod currently point at /start?invited=1, which the
portal does not handle, so invitees landed on the trial signup form after
setting their password. With https://app.breakpilot.com/{slug}/dashboard
they arrive signed in in their workspace. A redirect without {slug} stays
as configured, so this is safe to deploy before the env change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On stage, staff picked "Apply" (set status) with `trial` selected on a trial tenant, instead of "Extend". The registry wrote an update, a `tenant.status_changed` audit entry (`trial` → `trial`) and a Keycloak sync. The audit log showed an entry, but nothing had changed.
**Change:** `POST /v1/tenants/{id}/status` with the tenant's current status answers 200 with the unchanged tenant: no write, no audit entry, no Keycloak sync. The call stays idempotent for scripts. Other transitions are unchanged.
**Test:** `TestSetStatus_unchangedIsNoOp` (memory and Postgres) checks 200 and that no audit entry is added. It fails without the fix ("audit entries: 1, want 0"). `go vet` and `go test -short ./...` pass locally; the full Postgres suite runs in CI.
Companion: the portal staff page greys out "Apply" until a different status is chosen (separate portal PR).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #75
`POST /v1/audit` recorded the address of the product that sent the event. So Prüfwerk's API-key writes showed the agent's container address (172.17.0.6 on stage) instead of the caller's.
- `appendAuditReq` gains `source_ip`. It is taken when `net.ParseIP` accepts it and stored in canonical form. The peer that sent the event is kept in `metadata.relayed_by`.
- Anything that doesn't parse is ignored, and the peer is recorded as before.
- Trust: `audit.write` is service-principal only, the same trust as the `actor_id` those callers already set.
- No migration, and existing callers are unchanged.
- Callers: Prüfwerk (pruefwerk #567, from the API host's proxy header); Werkmeister will reuse the field (agreed with werkmeister-18).
Test: `TestAppendAudit_sourceIP` covers a valid IP (recorded, `relayed_by` set) and junk (ignored), in each store.
Not in this PR: `clientIP()` takes the **leftmost** `X-Forwarded-For` entry. orca-proxy appends the peer it saw, so the rightmost entry is authoritative and the leftmost is chosen by the client. Separate issue for werkmeister-18.
Not run locally (RAM); CI runs the tests.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #73
## What
- The letter head step also compares `source` and `footer_source` (want: HTML/HTML).
- `ensureFields` treats `<tbody>`/`</tbody>` as equal (Frappe's HTML editor adds them on a UI save).
## Why
Live ERPNext letter head `BreakPilot` (last saved 2026-10-06 09:19 in the UI): `source = Image`, so documents use an image header instead of our HTML one, plus `<tbody>` in content and footer. The dry run showed `letter head → would update` on every run, and an apply would not have restored `source`.
## Test plan
- [x] New test: tbody-only difference → `exists`; source Image → restored to HTML.
- [x] Existing erpsetup tests.
- [ ] User: dry run shows `letter head → would update` once, apply, then `exists`; check one invoice PDF shows the HTML header.
## Risk
**Blast radius:** Letter Head `BreakPilot` only (source fields). **Rollback:** set source back in the UI.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #68
## What
erpsetup gets two accounting steps (new `internal/erpsetup/accounting.go`), run after the contract-basis fields:
**A1: cost centers**
- Creates Plattform, Prüfwerk, Firmwerk, Werkpilot, Infrastruktur and Verwaltung below the company's root cost center.
- Makes **Verwaltung** the company default. `Main` is kept, not renamed.
- Gives every SKU its product's **selling cost center** in its Item Defaults row for the company:
- PLT → Plattform
- CRA (Prüfwerk + Werkbank) → Prüfwerk
- DEV-FWK → Firmwerk
- DEV-WP → Werkpilot
- INF (Managed Git + build runners) → Infrastruktur
- Other Item Defaults rows and other fields of the company's row (e.g. an income account) are kept.
**A2: deferred revenue**
- The 12 yearly items (`Jahr`: Werkpilot, Firmwerk, Managed Git and build-runner On-Prem) get `enable_deferred_revenue` over **12 months**.
- The company's default deferred revenue account becomes **SKR04 3900** (looked up by account number, never created). If it's missing, the deferral steps are skipped and reported as `missing (not created)`.
- Accounts Settings release the deferral **monthly as Journal Entries that stay drafts** (`submit_journal_entries = 0`): a person checks and submits them.
## Why
These follow the decisions with the tax advisor on 2026-10-12 (Collectives ERP/07):
- Cost centers live in ERPNext only, with no KOST1 in DATEV. They give a P&L per product.
- Yearly licences are deferred, so the monthly ERPNext P&L can be compared with her BWA. She books the RAP at year end in DATEV.
## How
- The cost-center and account names carry the company abbreviation, which is read from the Company.
- Item Defaults are PUT as the full table, because rows left out would be deleted.
- Idempotent and dry-run capable like the other steps; nothing is submitted.
## Test plan
- [x] Unit tests (fake Frappe):
- cost centers and their parent
- company defaults
- Accounts Settings
- cost center per SKU, deferral only on yearly items
- existing Item Defaults rows and fields are kept
- a missing 3900 skips the deferral
- a missing company stops the run
- [x] Second run is a no-op; the dry run writes nothing.
- [ ] `erpsetup -dry-run` against live ERPNext (user): check that `deferred revenue account 3900` resolves, and expect 6 cost centers, 2 company fields, the Accounts Settings and 34 items as `would create`/`would update`.
- [ ] Apply, then spot-check one Werkpilot On-Prem item and one Prüfwerk item in ERPNext.
## Risk
**Blast radius:** live ERPNext master data: cost centers, company defaults, Accounts Settings, Item Defaults and deferral flags on the 34 SKU items. No transactions are touched.
**What could break:**
- New Sales Invoices for yearly items now need a service start and end date (ERPNext fills them from the posting date and the 12 months). Monthly items are unchanged.
- A Journal Entry draft appears each month for open deferrals.
**Rollback plan:** in ERPNext:
- set the company default cost center back to Main
- untick deferred revenue on the 12 yearly items
Cost centers can stay. Nothing is submitted by this change.
## Checklist
- [x] Docs updated (package doc; Collectives ERP/06 gets the cost-center note after the apply)
- [x] Audit events emitted for state changes (n/a: ERP master data)
- [x] Secrets via Infisical, never in repo (no secrets)
- [x] Migration is forward-only + idempotent (no migration; erpsetup is idempotent)
- [x] Tenant scoping enforced on every DB query (no DB access)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #67
portal#74: PATCH/DELETE /v1/tenants/{id}/members/{uid}, POST .../resend and the staff variants; per-workspace block via org_blocked, session logout, last-admin and self guards, audit events.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB