Skip to content

Fix: gap auto-fill scheduler fails with "Backfill cannot look back more than 90 days"#256507

Merged
nkhristinin merged 2 commits intoelastic:mainfrom
nkhristinin:fix-boundary-limit-gap-scheduler
Mar 7, 2026
Merged

Fix: gap auto-fill scheduler fails with "Backfill cannot look back more than 90 days"#256507
nkhristinin merged 2 commits intoelastic:mainfrom
nkhristinin:fix-boundary-limit-gap-scheduler

Conversation

@nkhristinin
Copy link
Copy Markdown
Contributor

@nkhristinin nkhristinin commented Mar 6, 2026

Fix: gap auto-fill scheduler fails with "Backfill cannot look back more than 90 days"

Problem

Suppose we have gaps that are 100 days old.

Backfill scheduling enforces a 90-day validation limit. The gap auto-fill scheduler fetches all gaps that overlap the now-90d range, so these 100-day-old gaps can still be fetched because their interval overlaps that window. Their interval is then clamped to 90 days.

Later, when scheduleBackfill validates the ranges, it computes its own now, which is slightly later because some processing time has elapsed since the task started. As a result, now - startDate can become greater than 90 days, and the validation rejects the range with:

Backfill cannot look back more than 90 days

Fix

After parsing gapFillRange, clamp startDate so it stays at least 5 minutes inside the 90-day lookback window. This gives enough buffer for processing delays and ensures the clamped ranges remain safely within the validation limit.

How to test

I created this elastic/security-documents-generator#313 for utility which generate rules with gaps. It allows to have long gaps:

1 rules with 1m interval with 1 gap of 100 days durations
npm run start -- rules --rules 100 -d 100 -i"1m" -c

In main enable gap auto fill scheduler, and observe that execution is failed.

In this PR - it should successfully execute the task

@nkhristinin nkhristinin requested review from a team as code owners March 6, 2026 16:48
@nkhristinin nkhristinin requested a review from dhurley14 March 6, 2026 16:48
@nkhristinin nkhristinin self-assigned this Mar 6, 2026
@nkhristinin nkhristinin added backport:version Backport to applied version labels v9.3.0 release_note:skip Skip the PR/issue when compiling release notes labels Mar 6, 2026
@nkhristinin
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 6, 2026

Caution

Review failed

The head commit changed during the review from b6b1c68 to 9f6a480.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Scout: [ observability / uptime ] plugin / local-stateful-classic - MonitorDetails - navigates to monitor details and displays ping data
  • [job] [logs] Jest Tests #11 / When rendering PolicySettingsLayout and user has Edit permissions should allow updates to be made

Metrics [docs]

✅ unchanged

cc @nkhristinin

@nkhristinin nkhristinin merged commit c929b3e into elastic:main Mar 7, 2026
18 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.3

https://github.com/elastic/kibana/actions/runs/22794372835

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 7, 2026
…re than 90 days" (elastic#256507)

## Fix: gap auto-fill scheduler fails with "Backfill cannot look back
more than 90 days"

### Problem

Suppose we have gaps that are 100 days old.

Backfill scheduling enforces a 90-day validation limit. The gap
auto-fill scheduler fetches all gaps that overlap the `now-90d` range,
so these 100-day-old gaps can still be fetched because their interval
overlaps that window. Their interval is then clamped to 90 days.

Later, when `scheduleBackfill` validates the ranges, it computes its own
`now`, which is slightly later because some processing time has elapsed
since the task started. As a result, `now - startDate` can become
greater than 90 days, and the validation rejects the range with:

```text
Backfill cannot look back more than 90 days
```

### Fix

After parsing `gapFillRange`, clamp `startDate` so it stays at least 5
minutes inside the 90-day lookback window. This gives enough buffer for
processing delays and ensures the clamped ranges remain safely within
the validation limit.

### How to test

I created this
elastic/security-documents-generator#313 for
utility which generate rules with gaps. It allows to have long gaps:

1 rules with 1m interval with 1 gap of  100 days durations
 `npm run start -- rules  --rules  100  -d 100  -i"1m" -c`

In main enable gap auto fill scheduler, and observe that execution is
failed.

In this PR - it should successfully execute the task

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit c929b3e)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.3

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 7, 2026
…ack more than 90 days" (#256507) (#256578)

# Backport

This will backport the following commits from `main` to `9.3`:
- [Fix: gap auto-fill scheduler fails with "Backfill cannot look back
more than 90 days"
(#256507)](#256507)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Khristinin
Nikita","email":"nikita.khristinin@elastic.co"},"sourceCommit":{"committedDate":"2026-03-07T07:04:24Z","message":"Fix:
gap auto-fill scheduler fails with \"Backfill cannot look back more than
90 days\" (#256507)\n\n## Fix: gap auto-fill scheduler fails with
\"Backfill cannot look back\nmore than 90 days\"\n\n###
Problem\n\nSuppose we have gaps that are 100 days old.\n\nBackfill
scheduling enforces a 90-day validation limit. The gap\nauto-fill
scheduler fetches all gaps that overlap the `now-90d` range,\nso these
100-day-old gaps can still be fetched because their interval\noverlaps
that window. Their interval is then clamped to 90 days.\n\nLater, when
`scheduleBackfill` validates the ranges, it computes its own\n`now`,
which is slightly later because some processing time has elapsed\nsince
the task started. As a result, `now - startDate` can become\ngreater
than 90 days, and the validation rejects the range
with:\n\n```text\nBackfill cannot look back more than 90
days\n```\n\n### Fix\n\nAfter parsing `gapFillRange`, clamp `startDate`
so it stays at least 5\nminutes inside the 90-day lookback window. This
gives enough buffer for\nprocessing delays and ensures the clamped
ranges remain safely within\nthe validation limit.\n\n### How to
test\n\n\nI created
this\nhttps://github.com/elastic/security-documents-generator/pull/313
for\nutility which generate rules with gaps. It allows to have long
gaps:\n\n1 rules with 1m interval with 1 gap of 100 days durations\n
`npm run start -- rules --rules 100 -d 100 -i\"1m\" -c`\n\nIn main
enable gap auto fill scheduler, and observe that execution
is\nfailed.\n\nIn this PR - it should successfully execute the
task\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c929b3e7620e1d71c6de2ac444f979b48f41aad1","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:version","v9.3.0","v9.4.0"],"title":"Fix:
gap auto-fill scheduler fails with \"Backfill cannot look back more than
90
days\"","number":256507,"url":"https://github.com/elastic/kibana/pull/256507","mergeCommit":{"message":"Fix:
gap auto-fill scheduler fails with \"Backfill cannot look back more than
90 days\" (#256507)\n\n## Fix: gap auto-fill scheduler fails with
\"Backfill cannot look back\nmore than 90 days\"\n\n###
Problem\n\nSuppose we have gaps that are 100 days old.\n\nBackfill
scheduling enforces a 90-day validation limit. The gap\nauto-fill
scheduler fetches all gaps that overlap the `now-90d` range,\nso these
100-day-old gaps can still be fetched because their interval\noverlaps
that window. Their interval is then clamped to 90 days.\n\nLater, when
`scheduleBackfill` validates the ranges, it computes its own\n`now`,
which is slightly later because some processing time has elapsed\nsince
the task started. As a result, `now - startDate` can become\ngreater
than 90 days, and the validation rejects the range
with:\n\n```text\nBackfill cannot look back more than 90
days\n```\n\n### Fix\n\nAfter parsing `gapFillRange`, clamp `startDate`
so it stays at least 5\nminutes inside the 90-day lookback window. This
gives enough buffer for\nprocessing delays and ensures the clamped
ranges remain safely within\nthe validation limit.\n\n### How to
test\n\n\nI created
this\nhttps://github.com/elastic/security-documents-generator/pull/313
for\nutility which generate rules with gaps. It allows to have long
gaps:\n\n1 rules with 1m interval with 1 gap of 100 days durations\n
`npm run start -- rules --rules 100 -d 100 -i\"1m\" -c`\n\nIn main
enable gap auto fill scheduler, and observe that execution
is\nfailed.\n\nIn this PR - it should successfully execute the
task\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c929b3e7620e1d71c6de2ac444f979b48f41aad1"}},"sourceBranch":"main","suggestedTargetBranches":["9.3"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/256507","number":256507,"mergeCommit":{"message":"Fix:
gap auto-fill scheduler fails with \"Backfill cannot look back more than
90 days\" (#256507)\n\n## Fix: gap auto-fill scheduler fails with
\"Backfill cannot look back\nmore than 90 days\"\n\n###
Problem\n\nSuppose we have gaps that are 100 days old.\n\nBackfill
scheduling enforces a 90-day validation limit. The gap\nauto-fill
scheduler fetches all gaps that overlap the `now-90d` range,\nso these
100-day-old gaps can still be fetched because their interval\noverlaps
that window. Their interval is then clamped to 90 days.\n\nLater, when
`scheduleBackfill` validates the ranges, it computes its own\n`now`,
which is slightly later because some processing time has elapsed\nsince
the task started. As a result, `now - startDate` can become\ngreater
than 90 days, and the validation rejects the range
with:\n\n```text\nBackfill cannot look back more than 90
days\n```\n\n### Fix\n\nAfter parsing `gapFillRange`, clamp `startDate`
so it stays at least 5\nminutes inside the 90-day lookback window. This
gives enough buffer for\nprocessing delays and ensures the clamped
ranges remain safely within\nthe validation limit.\n\n### How to
test\n\n\nI created
this\nhttps://github.com/elastic/security-documents-generator/pull/313
for\nutility which generate rules with gaps. It allows to have long
gaps:\n\n1 rules with 1m interval with 1 gap of 100 days durations\n
`npm run start -- rules --rules 100 -d 100 -i\"1m\" -c`\n\nIn main
enable gap auto fill scheduler, and observe that execution
is\nfailed.\n\nIn this PR - it should successfully execute the
task\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"c929b3e7620e1d71c6de2ac444f979b48f41aad1"}}]}]
BACKPORT-->

Co-authored-by: Khristinin Nikita <nikita.khristinin@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
kapral18 pushed a commit to kapral18/kibana that referenced this pull request Mar 9, 2026
…re than 90 days" (elastic#256507)

## Fix: gap auto-fill scheduler fails with "Backfill cannot look back
more than 90 days"

### Problem

Suppose we have gaps that are 100 days old.

Backfill scheduling enforces a 90-day validation limit. The gap
auto-fill scheduler fetches all gaps that overlap the `now-90d` range,
so these 100-day-old gaps can still be fetched because their interval
overlaps that window. Their interval is then clamped to 90 days.

Later, when `scheduleBackfill` validates the ranges, it computes its own
`now`, which is slightly later because some processing time has elapsed
since the task started. As a result, `now - startDate` can become
greater than 90 days, and the validation rejects the range with:

```text
Backfill cannot look back more than 90 days
```

### Fix

After parsing `gapFillRange`, clamp `startDate` so it stays at least 5
minutes inside the 90-day lookback window. This gives enough buffer for
processing delays and ensures the clamped ranges remain safely within
the validation limit.

### How to test


I created this
elastic/security-documents-generator#313 for
utility which generate rules with gaps. It allows to have long gaps:

1 rules with 1m interval with 1 gap of  100 days durations
 `npm run start -- rules  --rules  100  -d 100  -i"1m" -c`

In main enable gap auto fill scheduler, and observe that execution is
failed.

In this PR - it should successfully execute the task

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
…re than 90 days" (elastic#256507)

## Fix: gap auto-fill scheduler fails with "Backfill cannot look back
more than 90 days"

### Problem

Suppose we have gaps that are 100 days old.

Backfill scheduling enforces a 90-day validation limit. The gap
auto-fill scheduler fetches all gaps that overlap the `now-90d` range,
so these 100-day-old gaps can still be fetched because their interval
overlaps that window. Their interval is then clamped to 90 days.

Later, when `scheduleBackfill` validates the ranges, it computes its own
`now`, which is slightly later because some processing time has elapsed
since the task started. As a result, `now - startDate` can become
greater than 90 days, and the validation rejects the range with:

```text
Backfill cannot look back more than 90 days
```

### Fix

After parsing `gapFillRange`, clamp `startDate` so it stays at least 5
minutes inside the 90-day lookback window. This gives enough buffer for
processing delays and ensures the clamped ranges remain safely within
the validation limit.

### How to test


I created this
elastic/security-documents-generator#313 for
utility which generate rules with gaps. It allows to have long gaps:

1 rules with 1m interval with 1 gap of  100 days durations
 `npm run start -- rules  --rules  100  -d 100  -i"1m" -c`

In main enable gap auto fill scheduler, and observe that execution is
failed.

In this PR - it should successfully execute the task

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes v9.3.0 v9.3.2 v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants