Skip to content

feat(self-modification): backend engine, REST API, and frontend panel#127

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/add-self-modification-engine
Closed

feat(self-modification): backend engine, REST API, and frontend panel#127
Copilot wants to merge 2 commits intomainfrom
copilot/add-self-modification-engine

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 6, 2026

The backend self-modification engine referenced by the existing frontend stores was absent. This PR delivers the engine, wires it to four new REST endpoints, and adds a UI panel that drives the full propose → apply → rollback lifecycle.

Backend: SelfModificationEngine

New backend/core/self_modification_engine.py — standalone, no heavy dependencies:

engine = SelfModificationEngine(cognitive_manager)   # cognitive_manager optional

result = engine.propose_modification(
    target="knowledge_graph",
    modification_type="add_node",
    parameters={"node_id": "foo", "node_data": {"label": "Foo"}},
)
# → ProposalResult(proposal_id=uuid, risk_level="low", predicted_impact={...}, status="pending")

engine.apply_modification(result.proposal_id)     # mutates live NetworkX graph
engine.rollback_modification(result.proposal_id)  # snapshot-based revert
engine.get_modification_history()                 # full audit trail, newest-first

Supported targets: knowledge_graph (add/remove nodes + edges), reasoning_params (parameter tuning), goal_priority (goal reweighting). Operates in simulation mode when no CognitiveManager is provided.

REST API (unified_server.py)

Method Path Returns
POST /api/self-modification/propose proposal_id, predicted_impact, risk_level
POST /api/self-modification/apply/{proposal_id} success, applied_changes
POST /api/self-modification/rollback/{proposal_id} success, reverted_to
GET /api/self-modification/history history[], total

Guarded by SELF_MODIFICATION_AVAILABLE — returns 503 cleanly if the module fails to import.

Frontend

  • SelfModificationPanel.svelte — 3-tab panel: Pending Proposals (risk badges, apply action), History (full audit table with rollback action), New Proposal (target/type dropdowns with JSON parameter editor and auto-populated templates).
  • App.svelte — panel registered as 🔧 Self-Modification in the System Management nav section (featured: true).
  • Syncs pending proposals to the existing evolutionState store (pendingProposals derived store).

Tests

tests/backend/test_self_modification_engine.py — 27 tests covering the four required scenarios:

  • test_propose_modification_returns_proposal_id
  • test_apply_modification_changes_knowledge_graph
  • test_rollback_reverts_applied_modification
  • test_history_records_all_operations

Related Issues

Test Evidence

tests/backend/test_self_modification_engine.py  27 passed in 0.47s

Frontend: npm run build — ✓ built in 6.31s, 0 errors.

Checklist

  • Tests pass locally (pytest tests/)
  • Code is formatted (black . and isort .)
  • Documentation updated (if applicable)
  • No secrets or credentials committed
  • Related issue linked above
Original prompt

Context — Issue #95

PR #41 implements a self-modification UI panel in the Svelte frontend, but the backend engine it is intended to drive is either dormant or absent. This issue delivers the backend self-modification engine and wires it to the existing UI.

Tasks

1. Audit existing self-modification primitives

  • Search godelOS/ for any existing self-modification, meta-learning, or architecture-modification classes/functions
  • Identify what can be reused vs what must be implemented fresh

2. Implement SelfModificationEngine

Create backend/core/self_modification_engine.py (or activate the dormant equivalent) with:

  • propose_modification(target: str, modification_type: str, parameters: dict) -> ProposalResult — creates a sandboxed proposal with predicted impact
  • apply_modification(proposal_id: str) -> ApplyResult — applies the accepted proposal to the live knowledge graph or reasoning module configuration
  • rollback_modification(proposal_id: str) -> RollbackResult — reverts an applied modification
  • get_modification_history() -> list[ModificationRecord] — returns audit trail of all modifications

Modification targets must include at minimum:

  • Knowledge graph assertion (add/remove nodes or edges)
  • Reasoning module parameter tuning (e.g., inference depth, timeout)
  • Active goal priority reweighting

3. REST API endpoints

Add to backend/unified_server.py (or appropriate router file):

  • POST /api/self-modification/propose — body: { target, modification_type, parameters } → returns { proposal_id, predicted_impact, risk_level }
  • POST /api/self-modification/apply/{proposal_id} → returns { success, applied_changes }
  • POST /api/self-modification/rollback/{proposal_id} → returns { success, reverted_to }
  • GET /api/self-modification/history → returns list of ModificationRecord

4. Connect to the frontend (PR #41 UI)

  • Ensure the API response shapes match what the existing Svelte self-modification panel expects (inspect the existing frontend component to determine the contract)

5. Tests

  • test_propose_modification_returns_proposal_id
  • test_apply_modification_changes_knowledge_graph
  • test_rollback_reverts_applied_modification
  • test_history_records_all_operations

Acceptance Criteria

Self-modification operations initiated via the UI produce verifiable changes to the knowledge graph or active reasoning modules, and can be rolled back.

Related Issue

Fixes #95

This pull request was created from Copilot chat.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Copilot AI changed the title [WIP] Add backend self-modification engine and connect to UI feat(self-modification): backend engine, REST API, and frontend panel Mar 6, 2026
@Steake Steake closed this Mar 7, 2026
@Steake Steake added the duplicate This issue or pull request already exists label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Self-modification engine — backend wiring and API

2 participants