Skip to content

[openai] Page audit logs with after and move the cursor after the last page - #22733

Open
vatsaldesai93 wants to merge 6 commits into
elastic:mainfrom
vatsaldesai93:openai-audit-cursor-after-paging
Open

vatsaldesai93 wants to merge 6 commits into
elastic:mainfrom
vatsaldesai93:openai-audit-cursor-after-paging

Conversation

@vatsaldesai93

@vatsaldesai93 vatsaldesai93 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Proposed commit message

openai: page audit logs with after and move the cursor after the last page

Paging sent before=<last_id>, which the API reference and the openai
SDK use for the previous page. The next page is after=<last_id>.

Records come newest first, but last_timestamp was set from the first
page. If a later page failed or the agent restarted, the next window
started after the unread pages and skipped them. Keep the newest
timestamp in state until the last page, and drop the page cursor when
a new window starts. Until the last page the cursor holds the window
start, so an interrupted first window restarts from the same point.
Re-read events keep the same _id.

How to test

elastic-package test script -C packages/openai -d audit

The second page fails once. The test expects 4 events and 1 error. Without the fix it stops at 3 documents.

Notes

  • API reference: list audit logs. The SDK pages with after=last_id (openai/pagination.py, ConversationCursorPage).
  • Not run against a live org.

The audit program set last_timestamp from the first page of a window,
before the older pages were read. If a later page failed, or the agent
restarted, the next window started at that timestamp and the remaining
pages were never collected. The failed run also left next.before_cursor
in state, so the next window was requested with a stale page cursor.

Keep the newest timestamp in state until the last page and only then
move the cursor, and drop the page cursor when a new window starts.
Events read again after an interruption have the same _id.
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

Reviewers

Buildkite doesn't run automatically for external contributions. To start one, a
user who is a member of the elastic GitHub organization or who has write access
to this repository needs to add a comment:

  • /test : will kick off a build in Buildkite.

Commenting /test as an external contributor without write access will not start a
build. In that case, please ask a maintainer to review the pull request and start
the build.

NOTE: https://github.com/elastic/integrations/blob/main/.buildkite/pull-requests.json contains all those details.

@vatsaldesai93 vatsaldesai93 changed the title [openai] Audit: move the cursor only after paging completes [openai] Move the audit cursor only after the last page Nov 25, 2026
@vatsaldesai93 vatsaldesai93 changed the title [openai] Move the audit cursor only after the last page [openai] Page audit logs with after and move the cursor after the last page Nov 25, 2026
@vatsaldesai93
vatsaldesai93 marked this pull request as ready for review November 26, 2026 16:59
@vatsaldesai93
vatsaldesai93 requested review from a team as code owners November 26, 2026 16:59
Copilot AI balanced review requested due to automatic review settings November 26, 2026 16:59
@mergify

mergify Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical cursor-persistence issue can permanently skip unread events if pagination fails or the agent restarts during the first collection.

1 open issue
What changed in this PR

This PR updates the OpenAI integration’s audit-log pagination to use after and defer timestamp advancement until the final page, aiming to prevent skipped events after interrupted collection.

Changes:

  • Switch pagination to after and clear stale paging state when starting a new window.
  • Add a regression script for a second-page failure and update the existing mock.
  • Bump the package to 2.4.1 and document the fix.
File Description
packages/​openai/​manifest.yml Bumps the package version to 2.4.1.
packages/​openai/​data_stream/​audit/​agent/​stream/​cel.yml.hbs Updates pagination and defers timestamp cursor advancement.
packages/​openai/​data_stream/​audit/​_dev/​test/​scripts/​interrupted_paging.txt Adds interrupted-pagination regression coverage.
packages/​openai/​changelog.yml Documents the pagination bug fix.
packages/​openai/​_dev/​deploy/​docker/​files/​config.yml Updates the mock to match the after parameter.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 26, 2026 18:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the audit-log pagination change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants