Repository navigation
Conversation
The echo guard could never fire. A push is recorded with the plugin it was pushed to as the target, but shouldSync queried the reverse pair, which no push has ever produced. The target plugin was also part of the payload hash, so the same change hashed differently in each direction and could never have matched either. The check ran at enqueue time while the record was written at execution time, so two rapid changes both passed it. Inbound webhook changes were never applied to the local ticket and the result still reported success. And computeHash passed the top-level key list as the JSON.stringify replacer, which strips nested keys and lets distinct changes collide. The guard now matches the recorded direction and hashes the change's content only. The pending record is written before the enqueue and resolved on completion, so one push leaves one row and two rapid changes cannot both pass. Inbound changes are applied where the local model supports it, and reported as unsupported otherwise. The echo check moved to the fan-out: checked in the TRACKER_SYNC handler it would fire on the very record the job created, so the push would never happen. Refs CopilotKit#139 Co-Authored-By: Claude Code <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Echo detection in the sync engine could never fire, and inbound changes from a tracker were dropped while the engine reported success. This fixes the guard, makes the hash direction-independent, records the echo before the enqueue, and applies or explicitly reports every inbound change.
Closes #139
What was wrong
1. The guard queried the reverse direction. A push is recorded with the plugin it was pushed to as the target (
source='outpost',target=<tracker>), butshouldSynclooked for the reverse pair (source=<tracker>,target='outpost') — a pair no push has ever produced. The guard was structurally unreachable, not merely wrong.2.
targetPluginwas part ofpayloadHash. The same logical change hashed differently depending on where it was going, so even a corrected query could not have matched a change coming back from a tracker.3. The check ran at enqueue time but the record was written at execution time. Two changes arriving inside that window both passed the check, producing duplicate
TRACKER_SYNCjobs.4. Inbound changes were discarded and reported as success.
onWebhookReceivedfanned the change out to the other trackers but never applied it to the local ticket, andSyncResult.successstayedtrue— a sync that did nothing looked like a sync that worked.5.
computeHashstripped nested keys. The top-level key list was passed as theJSON.stringifyreplacer, and an array replacer applies to every nested object too, so any nested key outside the top-level list was dropped and distinct changes could collide.What changed
EchoGuard.shouldSyncnow matches the recorded direction (entityId+targetPlugin+payloadHash+ a status ofpendingorsuccesswithin the echo window). Afailuredeliberately does not block, so a failed push stays retryable.computeHashis direction-independent and covers nested keys. The payload is serialised with its keys sorted at every level, so the hash depends on content only.undefinedis dropped, so an absent field and an unset field hash the same.pendingrow exists before the job does, so two rapid changes cannot both pass the guard. If the enqueue fails, the row is resolved tofailureinstead of being left saying it is in flight. A push therefore leaves one row behind, not two.status_change,close,priority_change,assignee_change(mapped through the plugin'smapUserToMember) andcomment(recorded as aMessage) are applied. A change the local model cannot express —label_change,new_issue, an unknown action, an assignee with no matching team member — is reported asunsupported: …inSyncResult.errors, andsuccessbecomesfalse. Nothing is dropped silently any more.SyncEngine.onTicketChangefor inbound changes, and the check in theTRACKER_SYNChandler was removed. Checking there was wrong twice over: it looked for the reverse direction, and once fixed it would fire on the very record the job itself created, so the push would never happen. A job is a promise to push, and the handler keeps it — the operator-facing force-sync route enqueues jobs directly and expects every one of them to push.Tests
echo-guard.test.ts— asserts the query matches the direction pushes are recorded in, that afailuredoes not block the retry, thatpendingis create-if-absent and resolves the existing row rather than adding a second one, and thatcomputeHashis key-order independent and covers nested keys.sync-engine.test.ts— the pending record is written before the job is enqueued (asserted withinvocationCallOrder), an enqueue failure resolves the row tofailure, both targets get the same hash, inbound status/close/priority/assignee/comment changes are applied locally,label_changeand an unmappable assignee are reported as unsupported, and a change coming back from a tracker is not fanned out again.sync-integration.test.ts— the end-to-end loop case: a push recorded for a tracker is recognised as an echo and the fan-out is blocked.tracker-sync.test.ts— the handler pushes what the job says, without consulting an echo guard.pnpm test(5015 tests),pnpm typecheck,pnpm lintand the prettier format check all pass.Note for reviewers
The inbound application covers what the local model can express.
label_changeis reported as unsupported because Outpost tickets have no labels field; adding one is a separate schema change and out of scope here.🤖 Generated with Claude Code