Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(linear): sync archived records instead of dropping them (#100002)

posthog[bot]bdd789fb1c65
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/queries.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/queries.py
index c67d06e592d2..012237e54a70 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/queries.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/queries.py
@@ -1,6 +1,11 @@
+# Every root connection passes `includeArchived: true`. Linear excludes archived entities by
+# default, and it auto-archives closed cycles, issues and projects, so without this a synced row
+# stops being returned once it is archived: full refresh drops it from the table and incremental
+# never sees the archive. `archivedAt` is selected alongside so archived rows stay distinguishable.
+
ISSUES_QUERY = """
query PaginatedIssues($pageSize: Int!, $cursor: String, $filter: IssueFilter) {
- issues(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ issues(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
identifier
@@ -35,7 +40,7 @@ query PaginatedIssues($pageSize: Int!, $cursor: String, $filter: IssueFilter) {
PROJECTS_QUERY = """
query PaginatedProjects($pageSize: Int!, $cursor: String, $filter: ProjectFilter) {
- projects(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ projects(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
name
@@ -44,6 +49,7 @@ query PaginatedProjects($pageSize: Int!, $cursor: String, $filter: ProjectFilter
progress
createdAt
updatedAt
+ archivedAt
completedAt
canceledAt
startedAt
@@ -61,7 +67,7 @@ query PaginatedProjects($pageSize: Int!, $cursor: String, $filter: ProjectFilter
TEAMS_QUERY = """
query PaginatedTeams($pageSize: Int!, $cursor: String) {
- teams(first: $pageSize, after: $cursor) {
+ teams(first: $pageSize, after: $cursor, includeArchived: true) {
nodes {
id
name
@@ -71,6 +77,7 @@ query PaginatedTeams($pageSize: Int!, $cursor: String) {
color
createdAt
updatedAt
+ archivedAt
}
pageInfo { hasNextPage endCursor }
}
@@ -78,7 +85,7 @@ query PaginatedTeams($pageSize: Int!, $cursor: String) {
USERS_QUERY = """
query PaginatedUsers($pageSize: Int!, $cursor: String) {
- users(first: $pageSize, after: $cursor) {
+ users(first: $pageSize, after: $cursor, includeArchived: true) {
nodes {
id
name
@@ -88,6 +95,7 @@ query PaginatedUsers($pageSize: Int!, $cursor: String) {
admin
createdAt
updatedAt
+ archivedAt
isMe
avatarUrl
url
@@ -98,12 +106,13 @@ query PaginatedUsers($pageSize: Int!, $cursor: String) {
COMMENTS_QUERY = """
query PaginatedComments($pageSize: Int!, $cursor: String, $filter: CommentFilter) {
- comments(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ comments(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
body
createdAt
updatedAt
+ archivedAt
url
issue { id identifier }
user { id name email }
@@ -114,7 +123,7 @@ query PaginatedComments($pageSize: Int!, $cursor: String, $filter: CommentFilter
LABELS_QUERY = """
query PaginatedLabels($pageSize: Int!, $cursor: String) {
- issueLabels(first: $pageSize, after: $cursor) {
+ issueLabels(first: $pageSize, after: $cursor, includeArchived: true) {
nodes {
id
name
@@ -122,6 +131,7 @@ query PaginatedLabels($pageSize: Int!, $cursor: String) {
color
createdAt
updatedAt
+ archivedAt
}
pageInfo { hasNextPage endCursor }
}
@@ -129,7 +139,7 @@ query PaginatedLabels($pageSize: Int!, $cursor: String) {
CYCLES_QUERY = """
query PaginatedCycles($pageSize: Int!, $cursor: String, $filter: CycleFilter) {
- cycles(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ cycles(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
name
@@ -140,6 +150,7 @@ query PaginatedCycles($pageSize: Int!, $cursor: String, $filter: CycleFilter) {
completedAt
createdAt
updatedAt
+ archivedAt
progress
scopeHistory
completedScopeHistory
@@ -151,7 +162,7 @@ query PaginatedCycles($pageSize: Int!, $cursor: String, $filter: CycleFilter) {
RESOURCES_QUERY = """
query PaginatedAttachments($pageSize: Int!, $cursor: String, $filter: AttachmentFilter) {
- attachments(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ attachments(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
title
@@ -160,6 +171,7 @@ query PaginatedAttachments($pageSize: Int!, $cursor: String, $filter: Attachment
sourceType
createdAt
updatedAt
+ archivedAt
issue { id identifier }
creator { id name email }
}
@@ -169,7 +181,7 @@ query PaginatedAttachments($pageSize: Int!, $cursor: String, $filter: Attachment
WORKFLOW_STATES_QUERY = """
query PaginatedWorkflowStates($pageSize: Int!, $cursor: String, $filter: WorkflowStateFilter) {
- workflowStates(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ workflowStates(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
name
@@ -189,7 +201,7 @@ query PaginatedWorkflowStates($pageSize: Int!, $cursor: String, $filter: Workflo
PROJECT_MILESTONES_QUERY = """
query PaginatedProjectMilestones($pageSize: Int!, $cursor: String, $filter: ProjectMilestoneFilter) {
- projectMilestones(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ projectMilestones(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
name
@@ -209,7 +221,7 @@ query PaginatedProjectMilestones($pageSize: Int!, $cursor: String, $filter: Proj
INITIATIVES_QUERY = """
query PaginatedInitiatives($pageSize: Int!, $cursor: String, $filter: InitiativeFilter) {
- initiatives(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ initiatives(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
name
@@ -242,7 +254,7 @@ query PaginatedInitiatives($pageSize: Int!, $cursor: String, $filter: Initiative
TEAM_MEMBERSHIPS_QUERY = """
query PaginatedTeamMemberships($pageSize: Int!, $cursor: String) {
- teamMemberships(first: $pageSize, after: $cursor) {
+ teamMemberships(first: $pageSize, after: $cursor, includeArchived: true) {
nodes {
id
owner
@@ -259,7 +271,7 @@ query PaginatedTeamMemberships($pageSize: Int!, $cursor: String) {
ISSUE_RELATIONS_QUERY = """
query PaginatedIssueRelations($pageSize: Int!, $cursor: String) {
- issueRelations(first: $pageSize, after: $cursor) {
+ issueRelations(first: $pageSize, after: $cursor, includeArchived: true) {
nodes {
id
type
@@ -275,7 +287,7 @@ query PaginatedIssueRelations($pageSize: Int!, $cursor: String) {
PROJECT_UPDATES_QUERY = """
query PaginatedProjectUpdates($pageSize: Int!, $cursor: String, $filter: ProjectUpdateFilter) {
- projectUpdates(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ projectUpdates(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
body
@@ -299,7 +311,7 @@ query PaginatedProjectUpdates($pageSize: Int!, $cursor: String, $filter: Project
DOCUMENTS_QUERY = """
query PaginatedDocuments($pageSize: Int!, $cursor: String, $filter: DocumentFilter) {
- documents(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter) {
+ documents(first: $pageSize, after: $cursor, orderBy: updatedAt, filter: $filter, includeArchived: true) {
nodes {
id
title
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
index 6f3a8cfd2dce..0a0a3be24f56 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
@@ -521,6 +521,26 @@ class TestEndpointCatalog:
f"{endpoint_name} query does not select {required}"
)
+ @parameterized.expand([(name,) for name in ENDPOINTS])
+ def test_root_field_includes_archived_records(self, endpoint_name: str) -> None:
+ # Linear hides archived entities unless the connection asks for them, and it auto-archives
+ # closed cycles, issues and projects. Without this argument a row silently leaves the table
+ # once it is archived, so historical rows thin out over time instead of failing loudly.
+ query = QUERIES[endpoint_name]
+ root_args = re.search(r"\)\s*\{\s*\n\s*\w+\(([^)]*)\)", query)
+ assert root_args is not None, f"could not find root field arguments in the {endpoint_name} query"
+ assert "includeArchived: true" in root_args.group(1), (
+ f"{endpoint_name} query does not pass includeArchived on its root connection"
+ )
+
+ @parameterized.expand([(name,) for name in ENDPOINTS])
+ def test_query_selects_archived_at(self, endpoint_name: str) -> None:
+ # Archived rows now land in the same table as live ones, so without this column there is no
+ # way to tell them apart downstream.
+ assert re.search(r"^\s*archivedAt\s*$", QUERIES[endpoint_name], re.MULTILINE), (
+ f"{endpoint_name} query does not select archivedAt"
+ )
+
class TestGetSchemas:
def test_reports_every_endpoint_with_its_sync_capabilities(self) -> None: