Skip to content

🪡 fix: Persist and Continue Stored Responses - #15683

Closed
dustinhealy wants to merge 15 commits into
devfrom
fix/responses-api-persistence
Closed

dustinhealy wants to merge 15 commits into
devfrom
fix/responses-api-persistence

Conversation

@dustinhealy

@dustinhealy dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Requests to /api/agents/v1/responses with store: true could return success while saving an empty conversation, and the returned resp_* ID could not be used to retrieve or continue it. Stored turns now retain their agent association and linked messages; retrieval returns the original completed response, and continuation restores the selected branch through the authenticated owner's response ID.

Fixes #14466.

Documentation: librechat.ai PR #760. No new package or deployment dependencies are required.

How it works

persistStoredResponse owns turn publication. Shared message reads expose the turn only after its output marker commits, so a partial save cannot appear in history, search, shares, or insights.

persistStoredResponse
  saveConversationFence       establish the conversation and agent association
  saveMessage                 stage linked input and output rows
  commitMessageManifest       append references without replacing concurrent appends
  commitStoredResponseTurn    publish the turn through its output marker
return completed response     emit the same stored envelope for JSON or SSE

Response IDs resolve through the owner's generated output to its conversation. Continuation follows that output's parent chain; legacy UUID continuation selects the latest visible branch, while flat legacy history and earlier snapshots remain readable. Shared visibility uses DocumentDB-compatible joins and does not require MongoDB transactions.

Compatibility: store: true combined with isTemporary: true now returns HTTP 400 before execution, because temporary conversations are excluded from response retrieval. A branched legacy UUID continuation now uses the latest branch instead of combining sibling branches. Persistence failures are reported instead of returning a successful stored response; streaming failures emit response.failed before [DONE].

Change Type

  • Bug fix
  • Breaking change (the request-validation and legacy branch-selection changes described above)
  • This change requires a documentation update

Testing

549 focused tests passed, covering create/GET envelope equality, streamed completion, canonical and legacy continuation, tenant ownership, concurrent appends, failed and ambiguous writes, deletion, staged-row visibility, pagination, search projections, sharing, and limiter regression cases.

Run from the repository root after installing dependencies and building the workspaces:

(cd packages/data-schemas && npx jest --runInBand src/utils/responses.spec.ts src/methods/message.spec.ts src/methods/share.test.ts src/methods/insights.spec.ts src/methods/conversation.spec.ts)
(cd packages/api && npx jest --runInBand src/agents/responses/persistence.spec.ts src/agents/responses/persistence.database.spec.ts src/agents/responses/__tests__/service.test.ts src/middleware/code.spec.ts)
(cd api && npx jest --runInBand server/controllers/agents/__tests__/responses.unit.spec.js)
npm run lighthouse

The full application build, shared-package typecheck, scoped ESLint/Prettier/import checks, and Lighthouse passed locally. CI at 5de9d1c6fc has 30 passing checks and two intentional skips, including TypeScript, API/shared tests, E2E, integration tests, Lighthouse, and container smoke tests. The local API typecheck reports a Langfuse dependency diagnostic in an unchanged file; CI's TypeScript job passes.

Test Configuration:

  • Node.js 24.16.0; dependencies from the repository lockfile.
  • Focused database tests use ephemeral MongoDB instances through mongodb-memory-server and require local socket access; no live model provider is needed.
  • Lighthouse 13.4.1 with Chromium and the seeded application described in the Lighthouse test guide.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • A pull request for updating the documentation has been submitted.

Copilot AI lite review requested due to automatic review settings September 7, 2026 00:09
@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-07T23:17:58.740270Z 5de9d1c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cf32c5e4f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

🔵 Needs a closer look

getResponse currently maps read_only resolutions to a 404, which is misleading and inconsistent with the controller’s 409 handling for the same condition elsewhere.

Pull request overview

Fixes Responses API history persistence and retrieval by ensuring stored responses are linked to the correct UUID conversation, resolving resp_* IDs through the owning assistant message, and filtering/branch-selecting retained history for retrieval and continuation.

Changes:

  • Add retention-aware visibility checks and apply retention filters when loading/storing Responses history.
  • Introduce a persistence helper to resolve response IDs → canonical conversation + select the correct message branch for continuation.
  • Update the legacy /api Responses controller to persist input/output with authenticated context, link parent chains, append message ObjectIds to the conversation, and expand test coverage (including MongoDB-memory integration).
File summaries
File Description
packages/data-schemas/src/utils/retention.ts Adds isRetentionVisible helper to mirror retention visibility rules in code paths that need in-memory checks.
packages/api/src/agents/responses/persistence.ts New resolver/selector utilities for mapping resp_* IDs to UUID conversations and selecting the correct history branch.
packages/api/src/agents/responses/persistence.spec.ts Unit coverage for resolution rules and history branch selection behavior.
packages/api/src/agents/responses/persistence.database.spec.ts MongoDB-memory coverage for tenant scoping and retention visibility constraints in resolution.
packages/api/src/agents/responses/index.ts Re-exports new persistence utilities for use by the legacy controller layer.
api/server/controllers/agents/responses.js Uses persistence utilities; fixes continuation conversation ID selection; links parentMessageId chain; appends message refs; applies retention filters.
api/server/controllers/agents/tests/responses.unit.spec.js Updates mocks + adds regression/integration tests for persistence, retrieval by response ID, and continuation behavior.
Review details

Suppressed comments (1)

api/server/controllers/agents/responses.js:1777

  • getResponse treats resolveStoredResponse results other than found as 404, which also includes the read_only case (child thread). That makes the error misleading and inconsistent with createResponse, which returns a 409 conversation_read_only for the same condition.
    if (resolution.status !== 'found') {
      return sendResponsesErrorResponse(
        res,
        404,
        `Response not found: ${responseId}`,
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 173a8685e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54eb53a5ae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d8521cf7b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: acde433615

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy
dustinhealy marked this pull request as ready for review September 7, 2026 01:52
@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: acde433615

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37f5ac2321

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4cc0c63aef

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila changed the title 💾 fix: Persist and Retrieve Responses API History 🪡 fix: Stitch Responses API History Together Sep 7, 2026
@dustinhealy
dustinhealy force-pushed the fix/responses-api-persistence branch from 4cc0c63 to 7179189 Compare September 7, 2026 03:07
@dustinhealy
dustinhealy force-pushed the fix/responses-api-persistence branch from e7616b4 to 0f35405 Compare September 7, 2026 12:27
@dustinhealy

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f35405ad4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

Review latest head f748aa9 and the complete PR diff, including previously resolved findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f748aa9f1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08eec5b00f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b47172e243

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: a2690410c4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 426d6ba914

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 426d6ba914

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 5de9d1c6fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy

dustinhealy commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 5de9d1c6fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@dustinhealy dustinhealy changed the title 🪡 fix: Stitch Responses API History Together 🪡 fix: Persist and Continue Stored Responses Sep 11, 2026
@dustinhealy

Copy link
Copy Markdown
Collaborator Author

Closing this for now while I evaluate alternative approaches that may address the underlying persistence issues without the substantial refactor this PR requires. The behavior still needs fixing, but I’d like to settle the broader direction before moving this implementation forward.

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