Skip to content

fix: 3 bugs in incoherence detector script#21

Open
axatbhardwaj wants to merge 2 commits intosolatis:mainfrom
axatbhardwaj:fix/incoherence-script-bugs
Open

fix: 3 bugs in incoherence detector script#21
axatbhardwaj wants to merge 2 commits intosolatis:mainfrom
axatbhardwaj:fix/incoherence-script-bugs

Conversation

@axatbhardwaj
Copy link
Copy Markdown

Summary

  • Missing --thoughts CLI arg: The skill docs and step guidance reference --thoughts for passing context between steps, but the argparse only defined --step-number. Added it as an optional string argument.
  • Undefined total variable: format_incoherence_output() referenced bare total which was never defined, causing a NameError. Changed to WORKFLOW.total_steps.
  • False "WORKFLOW COMPLETE" trigger: The check "COMPLETE" in next_text.upper() matched any step whose "next" text contained the word "complete" (e.g., step 3: "After all agents complete"). Changed to exact sentinel match next_text.strip().upper() == "WORKFLOW COMPLETE.".

Test plan

  • Verified step 3 no longer false-triggers WORKFLOW COMPLETE (outputs <invoke_after> for step 4)
  • Verified step 21 correctly triggers WORKFLOW COMPLETE
  • Verified --thoughts "test context" is accepted without error
  • Ran full 21-step workflow end-to-end on a real repo

- Add missing --thoughts CLI arg (documented but not in argparse)
- Fix undefined `total` variable, use WORKFLOW.total_steps
- Fix false WORKFLOW COMPLETE trigger via exact match
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Fix three bugs in incoherence detector script

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Fix undefined total variable by using WORKFLOW.total_steps
• Fix false "WORKFLOW COMPLETE" trigger with exact sentinel match
• Add missing --thoughts CLI argument for context passing
Diagram
flowchart LR
  A["Incoherence Script Issues"] --> B["Variable Reference Bug"]
  A --> C["Workflow Completion Logic Bug"]
  A --> D["Missing CLI Argument"]
  B --> B1["Use WORKFLOW.total_steps"]
  C --> C1["Exact match WORKFLOW COMPLETE."]
  D --> D1["Add --thoughts argument"]
Loading

Grey Divider

File Changes

1. skills/scripts/skills/incoherence/incoherence.py 🐞 Bug fix +3/-1

Fix variable reference and workflow completion bugs

• Fixed undefined total variable reference by replacing with WORKFLOW.total_steps
• Fixed false positive workflow completion detection by changing substring match to exact sentinel
 match "WORKFLOW COMPLETE."
• Added missing --thoughts CLI argument with string type and empty default value

skills/scripts/skills/incoherence/incoherence.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Feb 15, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

✅ 1. Sub-agent steps chain forward 🐞 Bug ✓ Correctness
Description
With the new exact-sentinel completion check, steps whose next says “Sub-agent task complete.” no
longer terminate and will emit an ` to the next numeric step. Because step 1 mandates invoking `,
sub-agent runs will incorrectly continue into parent steps (e.g., 7→8, 11→12, 19→20) with
wrong/partial context.
Code

skills/scripts/skills/incoherence/incoherence.py[R185-189]

   next_text = guidance.get("next", "")
-    if step >= total or "COMPLETE" in next_text.upper():
+    if step >= WORKFLOW.total_steps or next_text.strip().upper() == "WORKFLOW COMPLETE.":
       parts.append("WORKFLOW COMPLETE - Present report to user.")
   else:
       next_cmd = f'python3 -m skills.incoherence.incoherence --step-number {step + 1}'
Evidence
format_incoherence_output() now only stops when step >= WORKFLOW.total_steps or when next is
exactly WORKFLOW COMPLETE.; otherwise it always emits an ` for step + 1`. Several sub-agent
steps explicitly mark themselves complete via “Sub-agent task complete.”, which no longer matches
the sentinel, so they will incorrectly fall into the else-branch and emit the next command. This is
compounded by the step-1 XML mandate instructing the agent to invoke the exact `` command.

skills/scripts/skills/incoherence/incoherence.py[162-191]
skills/scripts/skills/incoherence/incoherence.py[173-179]
skills/scripts/skills/incoherence/incoherence.py[279-292]
skills/scripts/skills/incoherence/incoherence.py[339-351]
skills/scripts/skills/incoherence/incoherence.py[478-488]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Terminal SUB-AGENT steps (7/11/19) currently emit an `&amp;lt;invoke_after&amp;gt;` command due to the new exact-match completion check, causing sub-agents to incorrectly chain into parent steps.
### Issue Context
Several step definitions use `next: &amp;quot;... Sub-agent task complete.&amp;quot;` to indicate the sub-agent should stop and return results; step 1 mandates invoking `&amp;lt;invoke_after&amp;gt;` when present.
### Fix Focus Areas
- skills/scripts/skills/incoherence/incoherence.py[162-191]
- skills/scripts/skills/incoherence/incoherence.py[279-292]
- skills/scripts/skills/incoherence/incoherence.py[339-351]
- skills/scripts/skills/incoherence/incoherence.py[478-488]
### Notes
Implement a separate check, e.g.:
- `is_workflow_complete = step &amp;gt;= WORKFLOW.total_steps or next_text.strip().upper() == &amp;quot;WORKFLOW COMPLETE.&amp;quot;`
- `is_subagent_complete = &amp;quot;SUB-AGENT TASK COMPLETE&amp;quot; in next_text.upper()` (or a `TERMINAL_SUBAGENT_STEPS={7,11,19}`)
Then:
- if `is_workflow_complete`: print workflow complete message
- elif `is_subagent_complete`: print a sub-agent completion message and DO NOT render `InvokeAfterNode`
- else: render `InvokeAfterNode`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. --thoughts not propagated 🐞 Bug ✓ Correctness
Description
The PR adds --thoughts to argparse but the script never uses it and the generated next-step
command omits it. Many steps and the skill docs rely on --thoughts to carry state (dimension,
findings, resolutions), so following `` will drop required context between steps.
Code

skills/scripts/skills/incoherence/incoherence.py[R648-654]

   parser = argparse.ArgumentParser(description="Incoherence Detector")
   parser.add_argument("--step-number", type=int, required=True)
+    parser.add_argument("--thoughts", type=str, default="",
+                        help="Accumulated context from previous steps")
   args = parser.parse_args()

   guidance = get_step_guidance(args.step_number, WORKFLOW.total_steps)
Evidence
Although --thoughts is now accepted by argparse, it is not passed into formatting/output and is
not included in the autogenerated `` command. Meanwhile, step definitions explicitly state that key
information is “in --thoughts” and instruct invoking subsequent steps with results in --thoughts;
SKILL.md also marks --thoughts as required. As a result, the workflow’s own emitted commands will
fail to preserve state across steps.

skills/scripts/skills/incoherence/incoherence.py[648-680]
skills/scripts/skills/incoherence/incoherence.py[185-191]
skills/scripts/skills/incoherence/incoherence.py[241-253]
skills/scripts/skills/incoherence/incoherence.py[207-222]
skills/incoherence/SKILL.md[13-19]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`--thoughts` is parsed but never used or forwarded in the auto-generated next-step command, so workflow state is lost when following `&amp;lt;invoke_after&amp;gt;`.
### Issue Context
Many step action strings explicitly rely on `--thoughts` (“Your dimension is in --thoughts”, “invoke step N with … in --thoughts”), and SKILL.md documents it as required.
### Fix Focus Areas
- skills/scripts/skills/incoherence/incoherence.py[162-191]
- skills/scripts/skills/incoherence/incoherence.py[641-681]
- skills/incoherence/SKILL.md[13-19]
### Notes
Recommended approach:
1. Update `next_cmd` to include a thoughts placeholder, e.g.
 `python3 -m skills.incoherence.incoherence --step-number {step+1} --thoughts &amp;quot;&amp;lt;accumulated&amp;gt;&amp;quot;`
2. Optionally print the received `args.thoughts` (e.g., in a `&amp;lt;context&amp;gt;` block) so the agent can see what state it has.
3. Consider whether `--thoughts` should be `required=True` (or update SKILL.md to reflect optional usage), to avoid silently losing state.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

Comment on lines 185 to 189
next_text = guidance.get("next", "")
if step >= total or "COMPLETE" in next_text.upper():
if step >= WORKFLOW.total_steps or next_text.strip().upper() == "WORKFLOW COMPLETE.":
parts.append("WORKFLOW COMPLETE - Present report to user.")
else:
next_cmd = f'python3 -m skills.incoherence.incoherence --step-number {step + 1}'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Sub-agent steps chain forward 🐞 Bug ✓ Correctness

With the new exact-sentinel completion check, steps whose next says “Sub-agent task complete.” no
longer terminate and will emit an <invoke_after> to the next numeric step. Because step 1 mandates
invoking <invoke_after>, sub-agent runs will incorrectly continue into parent steps (e.g., 7→8,
11→12, 19→20) with wrong/partial context.
Agent Prompt
### Issue description
Terminal SUB-AGENT steps (7/11/19) currently emit an `<invoke_after>` command due to the new exact-match completion check, causing sub-agents to incorrectly chain into parent steps.

### Issue Context
Several step definitions use `next: "... Sub-agent task complete."` to indicate the sub-agent should stop and return results; step 1 mandates invoking `<invoke_after>` when present.

### Fix Focus Areas
- skills/scripts/skills/incoherence/incoherence.py[162-191]
- skills/scripts/skills/incoherence/incoherence.py[279-292]
- skills/scripts/skills/incoherence/incoherence.py[339-351]
- skills/scripts/skills/incoherence/incoherence.py[478-488]

### Notes
Implement a separate check, e.g.:
- `is_workflow_complete = step >= WORKFLOW.total_steps or next_text.strip().upper() == "WORKFLOW COMPLETE."`
- `is_subagent_complete = "SUB-AGENT TASK COMPLETE" in next_text.upper()` (or a `TERMINAL_SUBAGENT_STEPS={7,11,19}`)
Then:
- if `is_workflow_complete`: print workflow complete message
- elif `is_subagent_complete`: print a sub-agent completion message and DO NOT render `InvokeAfterNode`
- else: render `InvokeAfterNode`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 648 to 654
parser = argparse.ArgumentParser(description="Incoherence Detector")
parser.add_argument("--step-number", type=int, required=True)
parser.add_argument("--thoughts", type=str, default="",
help="Accumulated context from previous steps")
args = parser.parse_args()

guidance = get_step_guidance(args.step_number, WORKFLOW.total_steps)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. --thoughts not propagated 🐞 Bug ✓ Correctness

The PR adds --thoughts to argparse but the script never uses it and the generated next-step
command omits it. Many steps and the skill docs rely on --thoughts to carry state (dimension,
findings, resolutions), so following <invoke_after> will drop required context between steps.
Agent Prompt
### Issue description
`--thoughts` is parsed but never used or forwarded in the auto-generated next-step command, so workflow state is lost when following `<invoke_after>`.

### Issue Context
Many step action strings explicitly rely on `--thoughts` (“Your dimension is in --thoughts”, “invoke step N with … in --thoughts”), and SKILL.md documents it as required.

### Fix Focus Areas
- skills/scripts/skills/incoherence/incoherence.py[162-191]
- skills/scripts/skills/incoherence/incoherence.py[641-681]
- skills/incoherence/SKILL.md[13-19]

### Notes
Recommended approach:
1. Update `next_cmd` to include a thoughts placeholder, e.g.
   `python3 -m skills.incoherence.incoherence --step-number {step+1} --thoughts "<accumulated>"`
2. Optionally print the received `args.thoughts` (e.g., in a `<context>` block) so the agent can see what state it has.
3. Consider whether `--thoughts` should be `required=True` (or update SKILL.md to reflect optional usage), to avoid silently losing state.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

- Sub-agent terminal steps (7/11/19) no longer emit <invoke_after>,
  preventing incorrect chaining into parent steps
- --thoughts is displayed as <context> and included in next-step
  command so workflow state is preserved between steps
gcharang added a commit to playactai/claude-config that referenced this pull request Apr 16, 2026
PR solatis#21 (incoherence.py): add --thoughts CLI arg with context
propagation via <context> block and next-cmd placeholder, replace
substring "COMPLETE" check with exact WORKFLOW COMPLETE. sentinel,
and add SUB-AGENT TASK COMPLETE branch so terminal sub-agent steps
(7/11/19) return to parent instead of chaining forward.

PR solatis#18 (arxiv_to_md): replace hardcoded /Users/lmergen path in
sub_agent.py with SCRIPTS_DIR computed from __file__, injected via
repr() to survive backslashes and embedded quotes (Qodo review).
Add package-level CLAUDE.md and README.md documenting the path
resolution approach and the f-string vs {result} brace-collision
trap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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