Skip to content

Clean up dev branch for production: fix runtime bug, remove debug artifacts, and correct style issues#31

Merged
Blueion76 merged 4 commits intodevfrom
copilot/fix-dev-branch-issues
Mar 6, 2026
Merged

Clean up dev branch for production: fix runtime bug, remove debug artifacts, and correct style issues#31
Blueion76 merged 4 commits intodevfrom
copilot/fix-dev-branch-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 6, 2026

  • Fix engine.py: Remove # === FIX START === / # === FIX END === debug markers
  • Fix engine.py: Add trailing newline at end of file
  • Fix engine.py: Fix buggy entropy calculation using math.log2 (moved import to module level)
  • Fix main.py: Remove redundant import json inside run() method
  • Fix main.py: Remove unused import asyncio
  • Fix main.py: Remove unused load_config_from_env import
  • Fix main.py: Add label variable before if self.audiomuse_client: block to prevent UnboundLocalError
  • Fix main.py: Use label in all logger.debug calls inside _generate_hybrid_daily_mix (replaces Daily Mix {mix_number} which showed Daily Mix None for non-numbered playlists)
  • Fix main.py: Fix inconsistent indentation in run() method's if should_generate_regular and all_playlists: block
  • Fix main.py: Fix except Exception block indentation (3-space → 4-space)
  • Fix main.py: Remove leftover # ✅ Added this! comment
  • Fix main.py: Remove leftover # <-- NEW comment
  • Fix main.py: Reduce extra blank lines between methods and after class body
Original prompt

In-Depth Code Review of the dev branch

Perform a thorough review of the dev branch and fix all code issues, weird syntax, and leftover code to make the repo production-ready. Here is the complete list of issues found during review:

Critical Issues to Fix

1. octogen/ai/engine.py — Leftover debug markers # === FIX START === / # === FIX END ===

Lines ~597 and ~612 have leftover debug/development markers:

        # === FIX START ===
        # Check for empty response
        if not response.text or response.text.strip() == "":
            ...
        return response.text
        # === FIX END ===

Fix: Remove the # === FIX START === and # === FIX END === comment lines. The validation logic between them is correct and should stay.

2. octogen/ai/engine.py — Missing trailing newline

The file ends without a trailing newline (\ No newline at end of file).
Fix: Ensure file ends with a newline character.

3. octogen/main.py — Redundant import json on line 1399

Inside the run() method's time-period playlist section, there's import json but json is already imported at the top of the file (line 9).
Fix: Remove the redundant import json on line 1399.

4. octogen/main.pylabel variable potentially used before assignment

In _generate_hybrid_daily_mix(), the variable label is only assigned inside the if self.audiomuse_client: block (line 786), but is referenced later on lines 819-820 outside that block (after songs.extend(llm_songs)). If self.audiomuse_client is None, label will be an UnboundLocalError.
Fix: Define label at the top of the method, before the if self.audiomuse_client: block:

label = f"Daily Mix {mix_number}" if mix_number in [1,2,3,4,5,6] else playlist_name

5. octogen/main.py — Inconsistent indentation in run() method

The block under if should_generate_regular and all_playlists: (around lines 1078-1141) has an extra level of indentation for the inner if self.audiomuse_client: block and its else. The inner block appears to be double-indented when it should be single-indented relative to the if.
Fix: Fix the indentation to be consistent — the body of if should_generate_regular and all_playlists: should be indented one level, not two.

6. octogen/main.pyasyncio imported but unused (line 14)

import asyncio is present but never used anywhere in the file.
Fix: Remove import asyncio.

7. octogen/main.py — Unused import load_config_from_env from octogen.config (line 38)

The class uses its own _load_config_from_env() instance method; the module-level load_config_from_env import from octogen.config is never called.
Fix: Remove the unused import from octogen.config import load_config_from_env.

8. octogen/main.py — Multiple extra blank lines

  • Lines 700-701: two blank lines between _process_recommendations and create_playlist (should be one inside a class)
  • Lines 1511-1513: three blank lines after the class body
    Fix: Reduce to single blank lines where appropriate (PEP 8: one blank line between methods in a class, two blank lines between top-level definitions).

9. octogen/main.py — Leftover inline comment # ✅ Added this! on line 470

'next_scheduled_run': next_scheduled_run,  # ✅ Added this!

This is a development note that shouldn't be in production code.
Fix: Remove the # ✅ Added this! comment.

10. octogen/main.py — Leftover comment # <-- NEW on line 602

mbid = rec.get("mbid")  # <-- NEW

This is a development marker comment.
Fix: Remove # <-- NEW comment or replace with a meaningful comment.

11. octogen/ai/engine.py — Buggy analyze_listening_profile entropy calculation (lines 148-152)

entropy = sum(-(count/total) * (count/total).bit_length() for count in artist_counts.values() if count > 0)
max_entropy = total.bit_length() if total > 1 else 1

(count/total) is a float, and float does not have a .bit_length() method. This will raise an AttributeError at runtime.
Fix: Use math.log2 for proper Shannon entropy calculation:

import math
entropy = -sum((count/total) * math.log2(count/total) for count in artist_counts.values() if count > 0)
max_entropy = math.log2(len(artist_counts)) if len(artist_counts) > 1 else 1
profile["diversity_score"] = min(entropy / max_entropy, 1.0) if max_entropy > 0 else 0

12. f-string / %-formatting consistency

Several places mix f-strings with %s style logging. While not a bug (logger uses %s by convention), ensure new code added in dev uses logger.info("...", var) style consistently for lazy evaluation, or at minimum don't mix in the same function.
The logger.info(f"...") calls should ideally be logger.info("...", ...) for lazy evaluation but this is a minor style point — don't change existing f-string logging, just ensure consistency in newly added code.
...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…rts, label UnboundLocalError, indentation, and stray comments

Co-authored-by: Blueion76 <128919662+Blueion76@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code issues and cleanup in dev branch Clean up dev branch for production: fix runtime bug, remove debug artifacts, and correct style issues Mar 6, 2026
@Blueion76 Blueion76 marked this pull request as ready for review March 6, 2026 03:11
Copilot AI review requested due to automatic review settings March 6, 2026 03:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prepares the dev branch for production by removing development artifacts and fixing two runtime issues (entropy calculation crash in the AI engine and a potential UnboundLocalError in hybrid playlist generation).

Changes:

  • Fix analyze_listening_profile diversity score calculation by switching to normalized Shannon entropy (math.log2) to prevent runtime crashes.
  • Prevent potential UnboundLocalError in _generate_hybrid_daily_mix by ensuring label is always defined.
  • Remove debug markers, unused imports, redundant inline imports, and indentation/blank-line issues for cleaner production code.

Reviewed changes

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

File Description
octogen/main.py Removes unused/redundant imports and dev comments, fixes indentation in run(), and prevents label from being referenced before assignment.
octogen/ai/engine.py Fixes entropy calculation runtime crash, removes debug markers, and moves math import to module scope.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +739 to 740
label = f"Daily Mix {mix_number}" if mix_number in [1,2,3,4,5,6] else playlist_name

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

Now that label is defined, consider using it for all log messages in this method (e.g., the logger.debug lines that currently print Daily Mix {mix_number}) to avoid confusing output like Daily Mix None for non-number playlists (Chill Vibes, Workout Energy, etc.).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in ee93682. All logger.debug calls inside _generate_hybrid_daily_mix that previously used Daily Mix {mix_number} now use label instead, so non-numbered playlists like "Chill Vibes" and "Workout Energy" log their actual name rather than "Daily Mix None". Also fixed the 3-space except block indentation to the standard 4-space.

octogen/main.py Outdated
Comment on lines 1502 to 1505
@@ -1510,7 +1505,6 @@ def run(self) -> None:
sys.exit(1)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The except Exception as e: block is indented inconsistently (not a 4-space multiple). This is easy to miss and can cause formatter/linter churn; please re-indent the block to the standard 4-space indentation under except.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was already fixed in ee93682 — the except block body is now consistently indented with 4 spaces.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Blueion76 <128919662+Blueion76@users.noreply.github.com>
@Blueion76 Blueion76 merged commit 585eb37 into dev Mar 6, 2026
1 check passed
@Blueion76 Blueion76 deleted the copilot/fix-dev-branch-issues branch March 6, 2026 03:18
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