Repository navigation
Enhance update-plan-progress to support phase names and progress tracking - #275
Conversation
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
There was a problem hiding this comment.
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 acceptUnion[int, str]for phase identification with flexible matching logic - Added optional
progress_percentparameter (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.
| 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}") |
There was a problem hiding this comment.
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.
| if progress_percent is not None: | ||
| phase['progress_percent'] = progress_percent | ||
| if status == 'completed': | ||
| phase['completed_at'] = datetime.now().isoformat() | ||
| phase['progress_percent'] = 100 |
There was a problem hiding this comment.
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.
| 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 |
| 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 |
There was a problem hiding this comment.
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.
| if progress_percent is not None: | ||
| phase['progress_percent'] = progress_percent |
There was a problem hiding this comment.
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.
| 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() |
There was a problem hiding this comment.
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.
| if progress_percent is not None: | ||
| phase['progress_percent'] = progress_percent | ||
| if status == 'completed': | ||
| phase['completed_at'] = datetime.now().isoformat() |
There was a problem hiding this comment.
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.
| # String matching: check name or phase number as string | ||
| matches = (phase_name == phase_id or str(phase_num) == phase_id) |
There was a problem hiding this comment.
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.
| # 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) |
| 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 |
There was a problem hiding this comment.
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.
| 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) |
| if matches: | ||
| found = True | ||
| matched_phase_num = phase_num | ||
| phase['status'] = status |
There was a problem hiding this comment.
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.
Summary
Enhanced the
update-plan-progresscommand to accept phase identifiers by name or number, and added support for tracking progress percentages during phase updates.Key Changes
phase_idparameter now accepts either a phase number (integer) or phase name (string), providing more flexible phase lookupprogress_percentparameter to track phase completion progress (0-100)completed, progress is automatically set to 100%Implementation Details
update_plan_progress()method signature to acceptUnion[int, str]forphase_idand optionalprogress_percent