Python: Improve python sample validation workflow - #7350
Conversation
|
Flagged issue
Source: automated DevFlow PR review |
|
Flagged issue
Source: automated DevFlow PR review |
There was a problem hiding this comment.
Automated Code Review
Reviewers: 5 | Confidence: 93%
✗ Correctness
The PR introduces playbook caching, sample discovery improvements, and several sample fixes. One high-severity bug exists:
delete_hosted_agent_sessionpassessession.session_id(a locally generated UUID) instead ofsession.service_session_id(the actual service-managed ID) to the delete API, which will fail to delete the hosted session server-side. The previous resolved review comment flaged a related issue but the code still uses the wrong ID. The magentic output handling changes are correct. The new playbook caching system and replay executor are well-structured. The main correctness issue is inreplay_playbookwhere the on-disk sample path is reconstructed incorrectly:playbook.samplestores a path relative tosamples_dir(python/samples/) but is joined withpython_root(python/), producing a non-existent path likepython/04-hosting/...instead ofpython/samples/04-hosting/.... This makes the snapshot/restore mechanism silently no-op, so a replay script that edits sample files will leave the repository dirty. This was previously flagged and marked resolved, but the diff still shows the unfixed code.
✗ Security Reliability
The
delete_hosted_agent_sessionfunction inusing_deployed_agent.pypassessession.session_id(a locally-generated UUID) to the server-sidedelete_sessionAPI, instead ofsession.service_session_id(the actual hosted-agent session identifier). This was introduced when refactoring the old code which correctly usedsession.service_session_id. The playbook replay system is well-structured overall with good process isolation and cleanup. However, the path reconstruction bug at playbook.py:238 (previously flaged and resolved but still present in this diff) means the snapshot/restore mechanism operates on incorrect paths, breaking the guarantee that replays never leave the repository dirty. No new security issues beyond the inherent design of executing cached agent-authored scripts.
✓ Test Coverage
This PR introduces substantial new infrastructure code for the sample validation system — playbook caching/replay (~350 lines in playbook.py), a replay executor (replay_executor.py), directory-based sample discovery (discovery.py changes), and snapshot/restore logic (create_dynamic_workflow_executor.py) — with zero unit test coverage. Grep across all test files confirms no file references
discover_samples,DiscoverSamplesExecutor, orsample_validation. While this is CI tooling rather than production code, several modules contain non-trivial logic (subprocess process-group management, file-system snapshot/restore, content-hash-based cache invalidation) that is straightforward to unit test and prone to subtle bugs. Thesample_validationmodule has historically had no tests, but the new code contains pure, easily-testable functions (hash computation, serialization round-trips, store load/save, slug generation) and async logic with meaningful edge cases (timeout handling, process cleanup, snapshot/restore). At minimum the coreplaybook.pyfunctions warrant unit tests to prevent regressions in the caching logic that now gates whether the LM agent is invoked at all.
✗ Failure Modes
The PR is a large workflow infrastructure improvement with playbook caching, job splitting, and sample fixes. Most changes are sound. One concrete failure-mode bug exists: the new
delete_hosted_agent_sessionhelper passessession.session_id(an auto-generated local UUID) to the server-side delete call instead ofsession.service_session_id(the real hosted-agent session identifier). This silently fails to clean up the remote session, leaking server-side resources. This was flagged in a prior review round as resolved, but the code still contains the bug. The path construction inreplay_playbook(playbook.py:238) reconstructs the sample's on-disk path incorrectly:playbook.samplestores a path relative tosamples_dir(i.e.,python/samples/), but line 238 joins it topython_root(python/), omitting thesamples/segment. This causes the snapshot/restore safety mechanism to silently target a non-existent path, so the snapshot is empty and the repo can be left dirty after a replay that edits sample files. This issue was previously raised in an earlier review round and marked resolved, but the code in the current diff remains unchanged.
✗ Design Approach
I found two design-level problems in the current chunk. One is a correctness bug in the hosted-agent cleanup sample: it now deletes sessions by the local
AgentSession.session_idinstead of the service-managed session id returned by Foundry, which can leak hosted sessions. The other is in the new directory-sample discovery rule: treating any folder withmain.py/app.pyas a terminal sample and stopping descent silently drops real child samples such as the multiple DevUI samples documented undersamples/02-agents/devui. The replay cache path reconstruction is still inconsistent with how samples are discovered and stored, so replay can miss the real sample tree when it snapshots/restores edits. Separately, the new hosted-agent validation script skips the native-runtime phase for every invocations sample even though the documented contract and repo sample matrix treat invocations samples as first-class hosted-agent samples that should pass all three validation phases.
Flagged Issues
- playbook.py:238 —
SampleInfo(path=python_root / sample_path, ...)constructs the wrong absolute path becausesample_path(fromplaybook.sample) is relative tosamples_dir(python/samples/), notpython_root(python/). This causes the snapshot/restore mechanism to silently target a non-existent directory, so replays that edit sample files leave the repository dirty. Previously flaged and marked resolved, but the current diff still contains the unfixed code. - using_deployed_agent.py:65 —
session.session_idis a locally generated UUID, not the service-managed session ID stored insession.service_session_id. The server-side hosted-agent session will never be deleted, leaking resources. Previously flagged and marked resolved, but the current diff still uses the wrong identifier.
Automated review by TaoChenOSU's agents
|
Flagged issue playbook.py:238 — Source: automated DevFlow PR review |
|
Flagged issue using_deployed_agent.py:65 — Source: automated DevFlow PR review |
eavanvalkenburg
left a comment
There was a problem hiding this comment.
honestly, I'm not sure how I feel about using agents to do deterministic things, we should be able to validate the vast majority of samples using code, which will be faster and cheaper. Can we scope this to only samples that are more difficult to validate? And I also think we can think about validation more intelligently, for instance by first running static code checks to validate the code, then picking and choosing ones that are in paths that often break, like the most complex OAI Responses sample, run that, if good, no need to run all OAI Responses samples...
I agree. This PR already excludes a bunch of samples from the workflow. The ask was to validate all the FHA samples, which by themselves are hard to validate using code (including running the samples locally and in Foundry). Let's see how well this works and how the requirements evolve. If this doesn't work well, we can scope this to only the FHA samples. |
Motivation & Context
Addresses #7348
Description & Review Guide
Run result:
Related Issue
Fixes #7348
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.