Skip to content

Hardening/additional r bug fixes#51

Merged
rkboyce merged 5 commits into
mainfrom
hardening/additional-R-bug-fixes
May 14, 2026
Merged

Hardening/additional r bug fixes#51
rkboyce merged 5 commits into
mainfrom
hardening/additional-R-bug-fixes

Conversation

@rkboyce
Copy link
Copy Markdown
Collaborator

@rkboyce rkboyce commented May 14, 2026

No description provided.

rkboyce added 5 commits May 14, 2026 04:27
The shared dialogue reader in [workflow_dialogue.R](/ai-agent/HadesProject/OHDSI-Study-Agent/R/slashOhdsiStrategusAssistant/R/workflow_dialogue.R) now recognizes `/back` and returns a navigation signal only when a caller explicitly enables it. Normal `/ohdsi` handling is unchanged.

In [strategus_incidence_shell.R](/ai-agent/HadesProject/OHDSI-Study-Agent/R/slashOhdsiStrategusAssistant/R/strategus_incidence_shell.R), I wired that signal into major boundaries only:
- study intent / intent-split editing
- target selection entry
- outcome selection entry
- time-at-risk confirmation
- Keeper-review entry

This is intentionally not a universal rewind. It is a bounded step-back mechanism at stage boundaries, which keeps the implementation small and avoids trying to undo arbitrary downstream side effects mid-stage. The shell banner now also tells the user that `/back` is available at supported boundaries.

I added focused static coverage in [test_r_workflow_context_dialogue_wrapper.py](/ai-agent/HadesProject/OHDSI-Study-Agent/tests/test_r_workflow_context_dialogue_wrapper.py).

Verified with:
- `Rscript -e "parse(file='R/strategus_incidence_shell.R'); parse(file='R/workflow_dialogue.R')"`
- `pytest -q ../../tests/test_r_workflow_context_dialogue_wrapper.py ../../tests/test_keeper_dialogue_integration_static.py`
It now uses the shared dialogue navigation pattern and supports stepping back at major boundaries only:

- study intent -> target selection
- target -> comparator selection
- comparator -> outcome selection
- outcome -> study configuration
- study configuration -> Keeper review options

The shell banner now advertises `/back`, and the same `readline_with_navigation()` / `is_back_signal()` pattern from incidence is wired in. I left the lower Keeper defaults unchanged.

I also extended the static coverage in [test_r_workflow_context_dialogue_wrapper.py](/ai-agent/HadesProject/OHDSI-Study-Agent/tests/test_r_workflow_context_dialogue_wrapper.py) for the cohort-methods shell boundaries.

Verified with:
- `Rscript -e "parse(file='R/strategus_cohort_methods_shell.R')"`
- `pytest -q ../../tests/test_r_workflow_context_dialogue_wrapper.py ../../tests/test_keeper_dialogue_integration_static.py`

One limitation remains intentional: this is still stage-boundary navigation, not universal rewind inside every prompt.
Findings**
1. Fixed a real Keeper workflow regression in [keeper_review_workflow.R](/ai-agent/HadesProject/OHDSI-Study-Agent/R/slashOhdsiStrategusAssistant/R/keeper_review_workflow.R:223). When a per-domain ACP call failed and the user chose `rerun`, the old error stayed in `keeper_review_state.json` even if the rerun succeeded, so the workflow could finish with a false `status="error"`. I added `clear_workflow_errors()` and keyed domain-generation errors by `domain_key` before re-appending them.

2. Fixed stale shell documentation in [R_STRATEGUS_COHORT_METHODS_SHELL.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/R_STRATEGUS_COHORT_METHODS_SHELL.md:18). It still documented a 50-character cohort/comparison analysis-label cap, but the code now allows 100. That doc now matches the implementation.

3. Fixed stale workflow/docs references in [R_STRATEGUS_COHORT_METHODS_SHELL.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/R_STRATEGUS_COHORT_METHODS_SHELL.md:15) and [WORKFLOW_COHORT_METHODS.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/WORKFLOW_COHORT_METHODS.md:1). The shell doc pointed to the wrong workflow filename and still used incidence-style work/results folder examples in the execution-settings template.

No additional behavioral issues stood out in the recent R-shell changes after this pass.

**Updates**
I aligned the package/docs with the implemented behavior in:
- [README.md](/ai-agent/HadesProject/OHDSI-Study-Agent/R/slashOhdsiStrategusAssistant/README.md:1)
- [R_STRATEGUS_INCIDENCE_SHELL.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/R_STRATEGUS_INCIDENCE_SHELL.md:1)
- [R_STRATEGUS_COHORT_METHODS_SHELL.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/R_STRASHOhdsiStrategusAssistant/../../docs/R_STRATEGUS_COHORT_METHODS_SHELL.md:1)
- [WORKFLOW_COHORT_METHODS.md](/ai-agent/HadesProject/OHDSI-Study-Agent/docs/WORKFLOW_COHORT_METHODS.md:1)

Those updates now document:
- `/back` support at major shell boundaries
- bounded inline Keeper stage gates
- suppressed Keeper reuse/resume prompts when no artifacts exist
- the 100-character cohort-method analysis-label limit

I also extended the focused static coverage in [test_keeper_dialogue_integration_static.py](/ai-agent/HadesProject/OHDSI-Study-Agent/tests/test_keeper_dialogue_integration_static.py:1).

**Verification**
Ran:
- `Rscript -e "parse(file='R/keeper_review_workflow.R'); parse(file='R/strategus_incidence_shell.R'); parse(file='R/strategus_cohort_methods_shell.R')"`
- `pytest -q ../../tests/test_keeper_dialogue_integration_static.py ../../tests/test_r_workflow_context_dialogue_wrapper.py`

Result: `10 passed`.
Two issues were involved:

- `cached_inputs` / `cached_manual_intent` were initialized to `NULL` but never reloaded from `manual_inputs.json` / `manual_intent.json` when `resume=TRUE`. That was a real bug.
- Empty target/comparator recommendation selections could fall through to a generic `Missing Target.` / `Missing Comparator.` stop. I replaced that with a safer resolver that:
  - uses recommendation-selected IDs when present
  - falls back to explicit or cached IDs when available
  - prompts interactively if needed
  - gives a more informative non-interactive error with the statement and recommendation artifact path

I also added a small static guard so this resume-cache load path does not disappear again.

Verified with:
- `Rscript -e "parse(file='R/strategus_cohort_methods_shell.R')"`
- `pytest -q ../../tests/test_r_workflow_context_dialogue_wrapper.py ../../tests/test_keeper_dialogue_integration_static.py`

This looks like a genuine bug in the cohort-method shell, and the recent control-flow changes likely made it easier to hit.
@rkboyce
Copy link
Copy Markdown
Collaborator Author

rkboyce commented May 14, 2026

bug fixes to R scripts and /back is an option at the main stages of each workflow within R strategus demo flows

@rkboyce rkboyce merged commit fbfb012 into main May 14, 2026
2 checks passed
@rkboyce rkboyce deleted the hardening/additional-R-bug-fixes branch May 14, 2026 11:40
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.

1 participant