Fix duplicate consciousness bootstrap and import organization#47
Conversation
Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
8c0dcde
into
find-out-the-main-tasks-left-9wLP6LwjQwb7
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical issue where consciousness bootstrap was executing twice during system startup, creating potential race conditions. It also reorganizes imports in the demo file to follow Python conventions by moving them from function scope to module level.
- Adds a guard check using the
bootstrap_completeflag to prevent duplicate consciousness bootstrap calls - Removes the redundant bootstrap logic from unified consciousness engine initialization (lines 481-497)
- Moves 5 backend class imports from function scope to module level in
demo_consciousness.py
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| demo_consciousness.py | Moves 5 backend imports (ConsciousnessEngine, UnifiedConsciousnessEngine, GoalManagementSystem, MetaCognitiveMonitor, KnowledgeGraphEvolution) from function scope to module level for better code organization |
| backend/unified_server.py | Adds bootstrap completion check to prevent duplicate consciousness initialization and removes redundant bootstrap code from unified consciousness engine setup |
| bootstrap_done = False | ||
| if (hasattr(ce, 'current_state') and | ||
| hasattr(ce.current_state, 'phenomenal_experience') and | ||
| ce.current_state.phenomenal_experience): |
There was a problem hiding this comment.
The nested hasattr checks could fail if phenomenal_experience is not a dictionary. Consider adding a type check or restructuring the guard to be more defensive. For example, if (hasattr(ce, 'current_state') and hasattr(ce.current_state, 'phenomenal_experience') and isinstance(ce.current_state.phenomenal_experience, dict)) would prevent potential AttributeError if phenomenal_experience is None or another non-dict type.
| ce.current_state.phenomenal_experience): | |
| isinstance(ce.current_state.phenomenal_experience, dict)): |
| await ce.bootstrap_consciousness() | ||
| logger.info("✅ Consciousness engine bootstrapped successfully") | ||
| else: | ||
| logger.info("🟡 Consciousness engine bootstrap already completed; skipping duplicate call.") |
There was a problem hiding this comment.
[nitpick] The log message uses a semicolon where a comma or dash would be more conventional. Consider changing to "Consciousness engine bootstrap already completed, skipping duplicate call" or "Consciousness engine bootstrap already completed - skipping duplicate call" for better readability.
| logger.info("🟡 Consciousness engine bootstrap already completed; skipping duplicate call.") | |
| logger.info("🟡 Consciousness engine bootstrap already completed, skipping duplicate call.") |
Addresses code review feedback from PR #44: consciousness bootstrap was executing twice on startup, and demo imports violated Python conventions.
Duplicate Bootstrap Prevention
Added guard to check
bootstrap_completeflag before bootstrapping, preventing duplicate execution:Removed duplicate bootstrap call from unified consciousness engine initialization (previously at lines 481-497).
Import Organization
Moved 6 backend imports from function scope to module level in
demo_consciousness.py:ConsciousnessEngineUnifiedConsciousnessEngine(2 occurrences)GoalManagementSystemMetaCognitiveMonitorKnowledgeGraphEvolutionNet: -12 LOC, eliminates race condition risk, follows Python conventions.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.