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(warehouse): drop stale Jira resume tokens minted for a different JQL (#67706)

Luke Belton29ce74d45482
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/jira/jira.py b/products/warehouse_sources/backend/temporal/data_imports/sources/jira/jira.py
index f090e7347e54..1409e97c4b77 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/jira/jira.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/jira/jira.py
@@ -38,6 +38,8 @@ class JiraRetryableError(Exception):
class JiraResumeConfig:
next_page_token: Optional[str] = None
start_at: Optional[int] = None
+ # The JQL the token was minted for — a token replayed against a different JQL is a 400.
+ jql: Optional[str] = None
def is_valid_subdomain(subdomain: str) -> bool:
@@ -152,7 +154,15 @@ def get_rows(
if config.pagination == "token":
last_value = db_incremental_field_last_value if should_use_incremental_field else None
jql = _build_issues_jql(incremental_field, last_value)
- next_page_token = resume.next_page_token if resume else None
+
+ # The JQL moves between runs as the watermark advances. Dropping a stale token is safe:
+ # issues are scanned in incremental-field ASC order, so the watermark query resumes from
+ # where the interrupted run got to (modulo the lookback overlap, which merge dedupes).
+ next_page_token = resume.next_page_token if resume and resume.jql == jql else None
+ if resume and resume.next_page_token and not next_page_token:
+ logger.info(
+ f"Discarding Jira resume token minted for a different JQL: saved={resume.jql!r}, current={jql!r}"
+ )
while True:
params: dict[str, Any] = {"jql": jql, "maxResults": config.page_size, "fields": "*all"}
@@ -168,7 +178,7 @@ def get_rows(
if not next_page_token or data.get("isLast"):
break
- resumable_source_manager.save_state(JiraResumeConfig(next_page_token=next_page_token))
+ resumable_source_manager.save_state(JiraResumeConfig(next_page_token=next_page_token, jql=jql))
return
# offset pagination (startAt / maxResults)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/jira/tests/test_jira.py b/products/warehouse_sources/backend/temporal/data_imports/sources/jira/tests/test_jira.py
index 69fb57e22171..0c23cec6bbd2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/jira/tests/test_jira.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/jira/tests/test_jira.py
@@ -193,13 +193,42 @@ class TestGetRows:
)
assert [row["id"] for batch in batches for row in batch] == ["1", "2"]
# State is saved with the token for the *next* page after the first batch is yielded.
- manager.save_state.assert_called_once_with(JiraResumeConfig(next_page_token="tok2"))
+ full_sync_jql = 'updated >= "1970-01-01 00:00" ORDER BY updated ASC'
+ manager.save_state.assert_called_once_with(JiraResumeConfig(next_page_token="tok2", jql=full_sync_jql))
- def test_token_pagination_resumes_from_saved_token(self) -> None:
- manager = _manager(JiraResumeConfig(next_page_token="tok2"))
- pages = [{"issues": [{"id": "2", "fields": {"created": "c2", "updated": "u2"}}], "isLast": True}]
- batches = self._run("issues", pages, manager, should_use_incremental_field=False)
+ @parameterized.expand(
+ [
+ ("matching_jql_reuses_token", 'updated >= "1970-01-01 00:00" ORDER BY updated ASC', True),
+ ("stale_jql_discards_token", 'updated >= "2026-02-11 09:07" ORDER BY updated ASC', False),
+ ("legacy_state_without_jql_discards_token", None, False),
+ ]
+ )
+ def test_token_pagination_resume_honors_saved_jql(
+ self, _name: str, saved_jql: str | None, expect_token_sent: bool
+ ) -> None:
+ manager = _manager(JiraResumeConfig(next_page_token="tok2", jql=saved_jql))
+ session = mock.MagicMock()
+ session.get.side_effect = [
+ _fake_response({"issues": [{"id": "2", "fields": {"created": "c2", "updated": "u2"}}], "isLast": True})
+ ]
+ with mock.patch(
+ "products.warehouse_sources.backend.temporal.data_imports.sources.jira.jira.make_tracked_session",
+ return_value=session,
+ ):
+ batches = list(
+ get_rows(
+ config=JIRA_ENDPOINTS["issues"],
+ subdomain="acme",
+ api_token="token",
+ logger=mock.MagicMock(),
+ resumable_source_manager=manager,
+ should_use_incremental_field=False,
+ )
+ )
assert [row["id"] for batch in batches for row in batch] == ["2"]
+ params = session.get.call_args.kwargs["params"]
+ assert params.get("nextPageToken") == ("tok2" if expect_token_sent else None)
def test_token_pagination_applies_incremental_jql(self) -> None:
manager = _manager()