Skip to main content

Runbook: PVC Connect Integrations Service

Deploy​

  1. Build and push the image (docker build -t <registry>/pvc-connect-integrations:<tag> .).
  2. Create or update the integrations-secrets Secret (see deploy/k8s/secret.template.yaml).
  3. Run the migration Job (deploy/k8s/migrate-job.yaml, image arg migrate) and wait for it to complete.
  4. Apply deploy/k8s (kustomize). The API rolls with zero unavailable pods; the Worker restarts.

The API needs only the database to be ready. AvaTax and RabbitMQ problems degrade the service; they never take pods out of rotation. Check /health/providers for the tax provider and /health/bus for RabbitMQ.

Go-live checklist per entity​

  1. PUT /api/v1/admin/entities/{id} with the AvaTax company code and numeric company id, base currency and GL accounts.
  2. Load tax-code mappings (from Avalara Tax Research) for every work type / sub type / trade in use, per category.
  3. Turn on flags in stages: taxEstimates → salesTaxDocuments/useTaxDocuments (saved, not committed) → compare with the current process → commitDocuments. Turn on partySync and certificates only once the NDA is signed. Turn on canadaTax only for entities with Canadian registration configured in AvaTax.
  4. Switch AvaTax__Environment to Production and set production credentials.

Sandbox smoke test (once credentials exist)​

Run against the AvaTax sandbox with Tax__Provider=AvaTax, AvaTax__Environment=Sandbox:

  • TX job site, labor + material lines → state/county/city breakdown in the response
  • Ohio ZIP that spans jurisdictions → POST /api/v1/addresses/validate returns Rooftop/Interpolated quality
  • AP bill, then commit → visible in the AvaTax portal as a committed PurchaseInvoice
  • ON job site on a CAD entity with a USD invoice → HST line, exchange rate stamped on the AvaTax transaction
  • Credit against the invoice → ReturnInvoice in AvaTax, negative lines in /reports/sales-tax

Common situations​

SymptomWhat it meansAction
Documents in PendingTax, TaxCalculationDeferred eventsAvaTax unreachable, throttling, or failing authCheck /health/providers and provider_call_audit (error codes). The recalculation job catches up on its own. Force a run with POST /api/v1/admin/jobs/tax-pending-recalculation/run.
StalePending reconciliation issuesA document has been pending for more than 24 hUsually credentials or configuration (401/403 count as unavailable). Fix, then run the job.
422 provider_rejected / Failed documentsAvaTax refused the data (address, tax code, company)The details say why. The caller resends corrected content with the same source id.
409 feature_disabledThe entity has not enabled that featureIntended during phased rollout. Enable it on the entity if it is time.
409 party_not_syncedCertificate call for a customer/vendor not yet in AvalaraPUT the party (needs partySync on).
MissingInProvider / TaxMismatch issuesOur committed document and AvaTax disagreeCompare in the AvaTax portal by providerDocumentCode. Recalculating or crediting fixes most. Resolve with POST /api/v1/reports/reconciliation-issues/{id}/resolve.
MissingLocally issuesAvaTax has committed documents this service did not createAnother integration or manual entry is writing to the same AvaTax company. Find out who.
FX provider_unavailableNo publication within the lookback window (source down for over 7 days)Check the Bank of Canada Valet API. Backfill with POST /api/v1/fx/import.
Messages in *_error queuesInvalid payloads, rejections, disabled features, or a message still failing after all redeliveries.Read the MT-Fault-* headers, fix the sender or the configuration, then replay them.
Rows piling up in deferred_messagesMessages waiting for something: the original document, a commit, AvaTaxExpected for minutes during an AvaTax outage. Check reason; a growing original_not_received count means a sender isn't publishing the invoices.
403 entity_forbidden for an admin tokenintegrations:admin no longer implies entity accessGive the client entities:all or entity claims for the entities it manages.
EntityAccessDeniedException faults in *_errorA message from a broker user not in Messaging__Publishers, without user_id, or for an entity that publisher may not touchCheck the message's user_id and entity. Add the publisher or entity to Messaging__Publishers__<user>__Entities, or fix the sender; then replay.
429 responsesA client (or, for anonymous traffic, an IP) went over its per-minute budgetNormal back-pressure; clients retry after Retry-After. Raise RateLimiting__*PermitsPerMinute only for a known batch. Behind a proxy, check Http__ForwardedHeaders is on, or every caller shares the proxy's IP.
A job's last success is oldThe job fails, or no Worker is runningGET /api/v1/admin/jobs shows lastError; run it now with POST /api/v1/admin/jobs/{name}/run (409 if it's already running).

Useful queries​

-- Pending/failed documents
select id, entity_id, source_system, source_document_id, status, status_reason, next_attempt_at
from integrations.tax_documents where status in ('PendingTax','Failed') order by updated_at desc;

-- AvaTax call failures in the last day
select operation, error_code, count(*) from integrations.provider_call_audit
where not succeeded and occurred_at > now() - interval '1 day' group by 1, 2 order by 3 desc;

-- Rates locked today
select from_currency, to_currency, rate, observation_date, created_by from integrations.rate_locks
where rate_date = current_date;
-- Messages parked for redelivery, by reason (see ADR 0008)
select message_type, split_part(reason, ':', 1) as reason, count(*), min(next_attempt_at) as next_due, max(attempt) as max_attempt
from integrations.deferred_messages group by 1, 2 order by 3 desc;

-- Events waiting in the outbox (should drain within seconds while RabbitMQ is up)
select count(*), min(sent_time) as oldest from integrations.outbox_message;

-- Scheduled jobs: last start, success and failure
select name, last_started_at, last_succeeded_at, last_failed_at, last_error from integrations.job_runs order by name;
-- Who committed, voided or credited a document, or changed configuration (append-only; see Security)
select occurred_at, caller_id, action, entity_id, subject_id, details from integrations.admin_audit
where subject_id = '<document, mapping, issue or request id>' or entity_id = 'PVC' order by occurred_at desc limit 50;

-- Who created and last changed a document (token client id, bus:<publisher> or system:<job>)
select id, created_by, modified_by, updated_at from integrations.tax_documents where source_document_id = 'INV-1001';

Broker users for publishers​

To trust each publishing service only for its own entities (Messaging__Publishers, see Security):

  1. One broker user per publishing service, writing only to the exchanges it publishes (rabbitmqctl set_permissions -p pvc-production sage "^$" "^pvc\.integrations\.(vendor-bill-approved|vendor-upserted)$" "^$").
  2. The publisher sets the AMQP user_id property to its user on every message. With MassTransit: cfg.ConfigurePublish(p => p.UseExecute(c => { if (c.TryGetPayload<RabbitMqSendContext>(out var r)) r.BasicProperties.UserId = "sage"; })).
  3. List it here: Messaging__Publishers__sage__Entities__0=PVC (* for every entity). Deploy, then watch the _error queues for EntityAccessDeniedException faults.

Replaying error queues​

Each consumer queue has a <queue>_error companion (e.g. credit-memo-issued_error). Messages land there when they are invalid, rejected, or still failing after the last redelivery; the MT-Fault-Message and MT-Fault-StackTrace headers say why.

  1. Fix the cause (sender data, entity configuration, feature flag).
  2. Move the messages back with the RabbitMQ management UI (Queues → <queue>_error → Move messages to <queue>, needs the shovel plugin) or rabbitmqadmin. They are processed again from the start; consumers are idempotent on the caller's ids, so replaying a message that partly succeeded is safe.
  3. Messages that should never be processed: purge them from the _error queue after noting the source ids.