fix(copilot): make createRunSegment idempotent on stream_id, surface swallowed PG errors#5379
Open
Sg312 wants to merge 1 commit into
Open
fix(copilot): make createRunSegment idempotent on stream_id, surface swallowed PG errors#5379Sg312 wants to merge 1 commit into
Sg312 wants to merge 1 commit into
Conversation
…swallowed PG errors The headless lifecycle derives copilot_runs.stream_id (UNIQUE) from the message id but generates a fresh run id per attempt, so any client retry of the same message was guaranteed to fail the insert with a duplicate-key error (~26 failing traces/day in prod, logged as an opaque Drizzle "Failed query" with the real Postgres error swallowed). - createRunSegment: onConflictDoNothing on stream_id + fetch the existing row, so a replay resolves to the original segment instead of erroring. - ensureHeadlessRunIdentity continues under the existing segment's execution/run ids on replay rather than fabricating fresh ones. - Both catch sites now log the Postgres error cause (constraint/detail) that Drizzle buries, so any remaining failure mode (e.g. FK violation) is diagnosable from logs. - Regenerated contract mirrors (metrics-v1, trace-attributes-v1, trace-attribute-values-v1) from the companion mothership change: copilot.auth.rejections metric + auth.reject_reason attribute/enum (additive only). Companion: mothership stops marking auth rejections as span errors and adds the rejection counter + Loki log export. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
|
Too many files changed for review. ( Bypass the limit by tagging |
|
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
Fixes the recurring
copilot_runsinsert failure on the headless copilot path. The headless lifecycle derivescopilot_runs.stream_id(UNIQUE) from the message id but generates a fresh run id per attempt, so any client retry of the same message was guaranteed to fail with a duplicate-key error (~26 failing traces/day in prod, surfaced only as an opaque Drizzle "Failed query" span with the real Postgres error swallowed).createRunSegmentis now idempotent onstream_id, replays continue under the original run identity, and both call sites log the buried Postgres errorcauseso any remaining failure mode (e.g. an FK violation) is diagnosable from logs. Also syncs the generated contract mirrors from the companion mothership change (additive only:copilot.auth.rejectionsmetric,auth.reject_reasonattribute + enum).Type of Change
Testing
lib/copilot/async-runs/{repository,lifecycle}.test.ts,lib/copilot/request/lifecycle/{run,start,headless}.test.ts.tsc --noEmitclean; biome clean on changed files.onConflictDoNothing+ fetch-existing semantics increateRunSegment(a replayed message now resolves to the pre-existing segment instead of erroring), andensureHeadlessRunIdentityreturning the existing row'sexecutionId/idon replay.Checklist
Companion PR
Companion: https://github.com/simstudioai/mothership/pull/341