Skip to content

Enhance update-plan-progress to support phase names and progress tracking - #275

Merged
mehdic merged 2 commits into
mainfrom
claude/fix-plan-update-reporting-Qtp4j
Jan 23, 2026
Merged

mehdic merged 2 commits into
mainfrom
claude/fix-plan-update-reporting-Qtp4j

Conversation

@mehdic

@mehdic mehdic commented Jan 23, 2026

Copy link
Copy Markdown
Owner

Summary

Enhanced the update-plan-progress command to accept phase identifiers by name or number, and added support for tracking progress percentages during phase updates.

Key Changes

  • Phase identification: The phase_id parameter now accepts either a phase number (integer) or phase name (string), providing more flexible phase lookup
  • Progress tracking: Added optional progress_percent parameter to track phase completion progress (0-100)
  • Auto-completion: When a phase is marked as completed, progress is automatically set to 100%
  • Better error handling: Added validation to ensure the specified phase exists before updating
  • Documentation: Updated SKILL.md with parameter descriptions and clarified valid status values

Implementation Details

  • Modified update_plan_progress() method signature to accept Union[int, str] for phase_id and optional progress_percent
  • Implemented flexible phase matching logic that checks both phase number and phase name
  • CLI argument parsing now intelligently converts phase_id to int when possible, falling back to string for name-based lookups
  • Updated help text and documentation to reflect the new capabilities
  • Maintains backward compatibility with existing integer-based phase references

The command was failing with exit code 1 when sub-agents passed phase
names (like "LLKB_Adapter_Module") instead of numeric phase IDs. The
implementation now accepts both:
- Phase number (int): matches phase['phase']
- Phase name (str): matches phase['name']

Also added support for optional progress_percent parameter (0-100).

https://claude.ai/code/session_018bfYGzw4pLfiuwDrTcoMqr
Critical review with OpenAI GPT-5 feedback identifying:
- Concurrency/race condition risks (read-modify-write without locking)
- Missing status and progress validation
- Output contract violation (human text vs JSON)
- Timezone-naive timestamps
- Status transition handling gaps

Pending user approval before implementing enhancements.

https://claude.ai/code/session_018bfYGzw4pLfiuwDrTcoMqr
Copilot AI review requested due to automatic review settings January 23, 2026 10:07
@mehdic
mehdic merged commit 7aa4bb0 into main Jan 23, 2026
8 checks passed

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.

Pull request overview

This pull request enhances the update-plan-progress command to accept phase identifiers by name (string) or number (integer), and adds optional progress percentage tracking. The changes address a critical issue where sub-agents were calling the command with phase names instead of numeric IDs, causing crashes. The PR also includes a detailed self-review document identifying several issues with the implementation.

Changes:

  • Modified update_plan_progress() to accept Union[int, str] for phase identification with flexible matching logic
  • Added optional progress_percent parameter (0-100) for tracking phase completion
  • Updated CLI parsing to intelligently convert phase_id to int when possible, falling back to string for name-based lookups
  • Enhanced documentation in SKILL.md with parameter descriptions and valid status values
  • Added comprehensive self-review document analyzing implementation issues

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
.claude/skills/bazinga-db/scripts/bazinga_db.py Enhanced update_plan_progress() method to support both numeric and string phase identifiers, added progress tracking, and updated CLI parsing logic
.claude/skills/bazinga-db-workflow/SKILL.md Updated documentation to reflect new parameter types and added clarification on valid status values
research/update-plan-progress-fix-review.md Added detailed self-review document analyzing implementation issues, including missing validations, concurrency concerns, and recommendations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2232 to +2289
def update_plan_progress(self, session_id: str, phase_id: Union[int, str], status: str,
progress_percent: Optional[int] = None) -> None:
"""Update a specific phase status in the development plan.

Args:
session_id: The session ID
phase_id: Either a phase number (int) or phase name (str)
status: New status (pending, in_progress, completed, blocked)
progress_percent: Optional progress percentage (0-100)
"""
plan = self.get_development_plan(session_id)
if not plan:
print(f"Error: No plan found for session {session_id}", file=sys.stderr)
sys.exit(1)

phases = plan['phases']
found = False
matched_phase_num = None

for phase in phases:
if phase['phase'] == phase_number:
# Match by phase number (int) or by name (string)
phase_num = phase.get('phase')
phase_name = phase.get('name', '')

matches = False
if isinstance(phase_id, int):
matches = (phase_num == phase_id)
else:
# String matching: check name or phase number as string
matches = (phase_name == phase_id or str(phase_num) == phase_id)

if matches:
found = True
matched_phase_num = phase_num
phase['status'] = status
if progress_percent is not None:
phase['progress_percent'] = progress_percent
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()
phase['progress_percent'] = 100
break

if not found:
print(f"Error: Phase '{phase_id}' not found in development plan", file=sys.stderr)
sys.exit(1)

# Use matched phase number for current_phase, or keep existing if string lookup
current_phase = matched_phase_num if matched_phase_num is not None else plan.get('current_phase')

conn = self._get_connection()
conn.execute("""
UPDATE development_plans
SET phases = ?, current_phase = ?, updated_at = CURRENT_TIMESTAMP
WHERE session_id = ?
""", (json.dumps(phases), phase_number, session_id))
""", (json.dumps(phases), current_phase, session_id))
conn.commit()
conn.close()
self._print_success(f"✓ Updated phase {phase_number} status to: {status}")
self._print_success(f"✓ Updated phase '{phase_id}' status to: {status}")

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

No test coverage for the updated functionality. There are no tests for update_plan_progress despite significant changes to its behavior. The repository has comprehensive testing for other functions (tests/test_concurrent_access.py, tests/test_performance_comparison.py), but this critical function lacks test coverage for: numeric phase ID lookup, string phase name lookup, progress_percent handling, invalid status rejection, phase not found errors, and case sensitivity behavior. This creates a risk of regressions and makes the expected behavior unclear.

Copilot uses AI. Check for mistakes.
Comment on lines +2267 to +2271
if progress_percent is not None:
phase['progress_percent'] = progress_percent
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()
phase['progress_percent'] = 100

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Status transition handling issue: reverting from 'completed' to 'in_progress' leaves stale completed_at timestamp. When a phase status is changed from 'completed' back to 'in_progress' or another status, the completed_at timestamp remains set, creating misleading data. The function should clear the completed_at field when transitioning away from completed status to maintain data integrity.

Suggested change
if progress_percent is not None:
phase['progress_percent'] = progress_percent
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()
phase['progress_percent'] = 100
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()
phase['progress_percent'] = 100
else:
# Clear stale completion timestamp when moving away from 'completed'
phase['completed_at'] = None
if progress_percent is not None:
phase['progress_percent'] = progress_percent

Copilot uses AI. Check for mistakes.
Comment on lines 2251 to 2272
for phase in phases:
if phase['phase'] == phase_number:
# Match by phase number (int) or by name (string)
phase_num = phase.get('phase')
phase_name = phase.get('name', '')

matches = False
if isinstance(phase_id, int):
matches = (phase_num == phase_id)
else:
# String matching: check name or phase number as string
matches = (phase_name == phase_id or str(phase_num) == phase_id)

if matches:
found = True
matched_phase_num = phase_num
phase['status'] = status
if progress_percent is not None:
phase['progress_percent'] = progress_percent
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()
phase['progress_percent'] = 100
break

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Potential for ambiguous phase matching without detection. The loop stops at the first matching phase and doesn't check if multiple phases could match the given phase_id. For example, if one phase has name="2" and another has phase number 2, passing "2" could match either depending on the order in the phases list. Consider checking for multiple matches and failing with a clear error message if ambiguity is detected, ensuring deterministic behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +2267 to +2268
if progress_percent is not None:
phase['progress_percent'] = progress_percent

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Missing range validation for progress_percent parameter. The function accepts any integer value without validating that it's in the valid range of 0-100. This could result in nonsensical values like -50 or 150 being saved to the database. Add validation to ensure progress_percent is between 0 and 100 when provided.

Copilot uses AI. Check for mistakes.
Comment on lines 2281 to 2288
conn = self._get_connection()
conn.execute("""
UPDATE development_plans
SET phases = ?, current_phase = ?, updated_at = CURRENT_TIMESTAMP
WHERE session_id = ?
""", (json.dumps(phases), phase_number, session_id))
""", (json.dumps(phases), current_phase, session_id))
conn.commit()
conn.close()

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Potential race condition in concurrent updates. This function uses a read-modify-write pattern without any locking mechanism or optimistic concurrency control. When multiple agents update different phases simultaneously, the last write will overwrite all previous changes to the phases JSON. In a multi-agent orchestration system, this is not an edge case but a core usage pattern. Consider implementing optimistic locking using a WHERE clause that checks the updated_at timestamp, or add a version field to prevent lost updates.

Copilot uses AI. Check for mistakes.
if progress_percent is not None:
phase['progress_percent'] = progress_percent
if status == 'completed':
phase['completed_at'] = datetime.now().isoformat()

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Using timezone-naive timestamps. The code uses datetime.now().isoformat() which creates a timezone-naive timestamp. This can cause ambiguity in multi-timezone deployments or when comparing timestamps. Consider using datetime.now(timezone.utc).isoformat() to create timezone-aware UTC timestamps, which is a best practice for stored timestamps.

Copilot uses AI. Check for mistakes.
Comment on lines +2260 to +2261
# String matching: check name or phase number as string
matches = (phase_name == phase_id or str(phase_num) == phase_id)

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Case-sensitive phase name matching may cause lookup failures. The phase name matching is case-sensitive, so if a plan has "LLKB_Adapter_Module" but an agent passes "llkb_adapter_module", it won't match and will result in a "Phase not found" error. In a multi-agent system where different agents might use inconsistent casing, this could be problematic. Consider implementing case-insensitive matching as the default behavior to improve robustness.

Suggested change
# String matching: check name or phase number as string
matches = (phase_name == phase_id or str(phase_num) == phase_id)
# String matching: case-insensitive on name and phase number as string
phase_id_str = str(phase_id).lower()
phase_name_str = str(phase_name).lower() if phase_name is not None else ""
phase_num_str = str(phase_num).lower() if phase_num is not None else ""
matches = (phase_name_str == phase_id_str or phase_num_str == phase_id_str)

Copilot uses AI. Check for mistakes.
phase_id_str = cmd_args[1]
status = cmd_args[2]
db.update_plan_progress(session_id, phase_number, status)
progress_percent = int(cmd_args[3]) if len(cmd_args) > 3 else None

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Missing error handling for invalid progress_percent values in CLI parsing. If a user passes a floating-point value like "50.5" for progress_percent, the int() conversion at line 4478 will raise a ValueError that's not caught, causing a cryptic error message. Consider adding a try-except block with a user-friendly error message, or documenting that only integer values are accepted.

Suggested change
progress_percent = int(cmd_args[3]) if len(cmd_args) > 3 else None
progress_percent = None
if len(cmd_args) > 3:
try:
progress_percent = int(cmd_args[3])
except ValueError:
print("ERROR: progress_percent must be an integer (e.g., 0-100).", file=sys.stderr)
sys.exit(1)

Copilot uses AI. Check for mistakes.
if matches:
found = True
matched_phase_num = phase_num
phase['status'] = status

Copilot AI Jan 23, 2026

Copy link

Choose a reason for hiding this comment

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

Missing validation for the status parameter. The function accepts any string value for status without validating it against the valid values (pending, in_progress, completed, blocked). This can lead to invalid status values being saved to the database. The codebase has a pattern of validating status values - see _validate_criterion_status at line 2293 which validates criterion statuses, and VALID_SESSION_STATUSES at line 116 which is used to validate session statuses. Consider adding a similar validation here to prevent database corruption.

Copilot uses AI. Check for mistakes.
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.

3 participants