Repository navigation
feat(apply): add package for applying mapping results to a store - #17
Merged
Merged
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Desired-state handling and conflict detection can produce incorrect store updates, and duplicate deletes can cause rejected writes.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Adds an SDK-independent apply package that reconciles mapper results with a tuple store through a caller-provided adapter.
Changes:
- Implements validation, reads, diffing, conflict checks, and writes.
- Distinguishes write-phase failures with
WriteError. - Adds pipeline documentation and unit tests.
| File | Description |
|---|---|
| apply/README.md | Documents pipeline behavior and adapter responsibilities. |
| apply/diff.go | Computes condition-aware tuple deltas. |
| apply/diff_test.go | Tests diff behavior and condition changes. |
| apply/apply.go | Implements reconciliation and error handling. |
| apply/apply_test.go | Tests pipeline execution and conflicts. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ewanharris
force-pushed
the
feat/add-apply-package
branch
from
October 7, 2026 09:09
b5411d0 to
7c8c5d0
Compare
…rage gaps Two validation gaps in the reconciliation pipeline allowed silent data loss: 1. Overlapping patch operations on the same filter scope could each delete the other's already-satisfied desired tuples. Because satisfied desires produce no write, they were invisible to the write-vs-delete conflict check in combineTuples. Phase 3 now tracks these as satisfiedClaims and combineTuples checks them against the full delete set before writing. 2. The per-tuple coverage check in validate accepted a delete filter's scope as evidence that a desired tuple was reachable. Delete filters never write tuples; coverage now only counts patch filters. Adds two regression tests, one per fix. Co-Authored-By: Claude <noreply@anthropic.com>
4 tasks done
sergiught
approved these changes
Oct 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
What problem is being solved?
mapper.Compile+mapper.Evaluateproduce amapper.Resultdescribing the tuple writes and deletes implied by a JSON event, but the library provides no mechanism to apply that result to a store. Callers had to implement the read/diff/write pipeline themselves.How is it being solved?
A new
applypackage implements the pipeline behind a narrowTupleClientinterface (ReadTuples,WriteTuples). The package has no dependency on the OpenFGA Go SDK; callers supply an adapter.What changes are made to solve it?
The pipeline runs five phases: validate (structural check before any I/O), read (deduplicated reads per filter), diff (desired vs. existing state per filter), combine (merges direct tuples with filter deltas, deduplicates, and detects conflicts), and write. Two conflict kinds are detected: competing writes on the same URO with different conditions, and a write+delete on the identical tuple. Write-phase errors are wrapped in
*WriteErrorto let callers distinguish retryable failures from hard errors.References
Review Checklist
apply/README.md)main