Repository navigation
fix(mercury): authoritative global source-ownership preflight in Finance - #203
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ReviewOverall: a small, well-scoped, read-only change. Fail-closed handling is sensible, and the 404 test for the public host and wrong caller is good. A few things to look at before merge. Performance
Correctness
Style
Security
Tests
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d271ad017
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .where(eq(schema.transactions.externalId, externalId)) | ||
| .limit(2); |
There was a problem hiding this comment.
Add an index for the global external-ID lookup
This new query filters only on transactions.external_id, but the transaction schema has indexes for tenant, account, date, property, and COA fields—not external_id. Consequently, each ownership preflight can require a full scan across every tenant, and the common owner: null case must scan the entire transaction table despite limit(2). Add an index on external_id (ideally scoped appropriately to Mercury IDs) before putting this lookup on the reconciliation path.
Useful? React with 👍 / 👎.
| .select({ | ||
| tenantId: schema.transactions.tenantId, | ||
| financeAccountId: schema.transactions.accountId, |
There was a problem hiding this comment.
Validate the account belongs to the reported tenant
When an inconsistent transaction row exists, this projection combines transactions.tenant_id and transactions.account_id into a supposedly authoritative owner without verifying that the referenced account has the same tenant. Such rows are possible because account_id has only a standalone foreign key and createTransaction does not enforce the tenant/account pairing; the endpoint would therefore return a cross-tenant owner instead of failing closed, allowing reconciliation to attribute the Mercury source to a contradictory financial identity. Join the account on both ID and tenant, or otherwise reject mismatches.
Useful? React with 👍 / 👎.
Production defect
The merged chittyconnect-finance source-owner preflight requires ChittyFinance SOT lookups across every tenant before FC/CHIT reconciliation. The deployed Finance read projection only exposed tenant-scoped transaction listings. Per-tenant
getTransactionByExternalIdcannot establish absence of an external Mercury ID in another tenant.Changes
mercury:<id>external source identity across all tenant partitions, returning at most two owners./internal/chittyconnect/mercury/source-owner/:sourceIdentitythrough the existing ChittyConnect→Finance service-binding security boundary; no public access.{tenantId, financeAccountId}orowner:nullon a complete empty result, 409 on duplicates, 503 on database failures/incomplete identity, 400 on malformed source identifiers.Guardrails
No new schema, database, queue, KV keys, credential bindings, financial writes, or public route. This patch does not implement the separate missing
acceptMercuryReconciliationIntentRPC or claim production webhook repair. Connect must consume this read projection only after a valid Mercury activity gate. Existing seven webhooks remain untouched.Validation
CI typecheck and focused
server/__tests__/internal-chittyconnect.test.tsrequired. Confirm deployment and private broker visibility separately after merge. Do not assert end-to-end reconciliation until durable consumer is integrated and receipt verified.Summary by CodeRabbit