Skip to content

Python: Harden FIDES service history continuation - #9877

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 9 commits into
mainfrom
fides-service-history-continuation
Nov 12, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 9 commits into
mainfrom
fides-service-history-continuation

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

FIDES must evaluate the same history and continuation identity that the model uses. Otherwise, resumed service history
can bypass reconstructed labels, partial local archives can understate confidentiality, and approvals can execute
before loaded history is classified.

This is the service-history and continuation layer of the replacement stack for #9652. It builds on #9875 and #9876.
Later layers own AG-UI provenance and MCP/IFC enforcement.

Description & Review Guide

  • What are the major changes? The agent resolves one effective conversation identity for provider preparation and
    model dispatch, normalizes all client-declared continuation carriers, and binds FIDES state to that identity. Local
    reconstruction requires exact history-snapshot coverage. The first prepared snapshot is reused, and persistence
    captures the request after middleware finalizes it.
  • What is the impact of these changes? Opaque, changed, malformed, or partially archived continuations fail closed
    before approval execution or model dispatch. Local history is not loaded or compacted twice on the first call, and
    persisted history matches the request sent to the model. Streaming and non-streaming behavior remain aligned. There
    are no public API or breaking changes.
  • What do you want reviewers to focus on? Review continuation identity binding, complete-history proof, and the
    prepared-history middleware boundary. AG-UI changes and MCP/IFC work are intentionally excluded.

Related Issue

Fixes #9652

#9652 is the original source draft. This PR replaces only its service-history and continuation slice. #9875 and #9876
provide the preceding foundation layers.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: GitHub Copilot assisted with implementation, regression tests, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): 25f03b1d9354
Model: gpt-5.6-sol

Overview

The PR resolves effective history ownership and moves local history loading ahead of FIDES approval preparation, with strong streaming/non-streaming coverage and explicit rejection of several opaque continuation cases. However, the new fail-closed gate does not recognize every client-declared continuation carrier, treats any local message as a complete reconstruction, and does not bind restored FIDES state to the resumed conversation. The middleware reorder also changes which request is persisted, while the approval preload invokes custom history providers twice before the first service call.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
5 verified findings remained after source verification (3 high, 2 medium) across 2 files. Details are attached to the affected lines below.

Affected areas: python/packages/core/agent_framework/_agents.py, python/packages/core/agent_framework/security.py

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

Unresolved critical flaws allow service continuations to bypass authoritative FIDES history reconstruction and cause provider preparation and model dispatch to use different conversation IDs.

4 open issues
What changed in this PR

This PR adds the service-history continuation layer to the FIDES hardening stack, building on #9875 and #9876. It aims to prepare security state before approval execution and reject service continuations whose history cannot be safely reconstructed.

Changes:

  • Resolve effective history ownership and propagate conversation identity into provider preparation.
  • Load local history before approval checks and order per-service-call history middleware before provider middleware.
  • Add streaming and non-streaming regressions for history ordering, write-only archives, and missing continuation security state.
File Description
python/​packages/​core/​tests/​core/​test_agents.py Adds history-ordering, ownership, and continuation regression tests.
python/​packages/​core/​agent_framework/​security.py Adds a guard against service continuation without reconstructable history or authoritative FIDES state.
python/​packages/​core/​agent_framework/​_agents.py Propagates conversation identity and history ownership; adjusts history preparation and middleware ordering.

Review effort: Balanced

@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Nov 5, 2026
Base automatically changed from fides-replay-approval-authority to main November 11, 2026 17:10
@github-code-quality

github-code-quality Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: Python

Python / code-coverage/python

main aad4666 fides-service-histor... bc62f32 +/-
92% 92% 0%
View coverage of the 4 most impacted files.
File main aad4666 fides-service-histor... bc62f32 +/-
packages/core/a...rk/_sessions.py 95% 93% -2%
packages/core/a...ork/security.py 90% 90% 0%
packages/core/a...work/_agents.py 96% 96% 0%
packages/core/a.../_compaction.py 94% 94% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 12, 2026 11:02 UTC

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 2

Result: Findings reported
Scope: full PR (6 commit(s)): 931e8c784a9f, 264bd72ceaf5, c77aaa3a06ec, 8ca5475d520a, ad1351e7a51f, 0291bfa75902
Model: gpt-5.6-sol

Overview

The PR consistently resolves declared continuation identities, fingerprints complete local history, reuses the first prepared snapshot, and captures provider-finalized requests for persistence. The new tests cover the previously reported identity, completeness, retry, ordering, and duplicate-load failures. Residual risk remains because the current continuation is mutated during a tool loop, the stricter message-labeler ordering conflicts with automatic history injection, and OpenAI background-response resumption is absent from the declared carrier set.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
3 verified findings remained after source verification (1 high, 2 medium) across 3 files. Details are attached to the affected lines below.

Affected areas: python/packages/core/agent_framework/_agents.py, python/packages/core/agent_framework/_sessions.py, python/packages/core/agent_framework/security.py

@jpalvarezl Jose Alvarez (jpalvarezl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One behavior issue remains in the per-service-call persistence path.

Merged via the queue into main with commit b89eaeb Nov 12, 2026
58 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the fides-service-history-continuation branch November 12, 2026 11:14

This branch was successfully deployed

1 active deployment
github-app-auth — bc62f32e Deployed Nov 12, 2026 by eavanvalkenburg via add_label #27666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants