Skip to content

feat(llc): 4-level goal hierarchy — CRUD, ancestry traversal, KB indexing #8212

Closed

Description

@mrveiss

Parent

Phase 1 (#8205) · Umbrella (#8204)

Context

Every work item must trace back to the company root goal. This issue creates the goal hierarchy model and the ancestry traversal API that powers goal-anchored task context.

Goal Levels

company | team | agent | task

Acceptance Criteria

  • llc_goals table created via Alembic:
    • id UUID PK
    • company_id UUID FK NOT NULL (enforces isolation)
    • title TEXT NOT NULL
    • description TEXT nullable
    • level ENUM(company, team, agent, task) NOT NULL
    • parent_id UUID FK → llc_goals.id nullable
    • owner_agent_id UUID FK → agent_org_nodes.id nullable
    • owner_user_id UUID FK → users.id nullable
    • status ENUM(planned, active, achieved, cancelled) NOT NULL DEFAULT planned
    • created_at, updated_at TIMESTAMPTZ
  • Invariant enforced: at least one company-level goal per company (checked on company create)
  • Cycle detection on parent_id
  • GoalService.get_ancestry(goal_id) returns ordered list from leaf to root
  • GoalService.get_tree(company_id) returns nested goal tree
  • /api/llc/companies/{id}/goals route group: GET /, POST /, GET /{goal_id}, PATCH /{goal_id}, DELETE /{goal_id}, GET /{goal_id}/ancestry, GET /tree
  • On goal create/update, goal title + description indexed into company:{company_id} ChromaDB collection via existing KB interface
  • On goal delete/archive, KB entry is removed
  • python -m pytest autobot-backend/llc/ -k goal passes

Files Affected

  • autobot-backend/llc/models/goal.py (new)
  • autobot-backend/llc/services/goal_service.py (new)
  • autobot-backend/llc/api/goals.py (new)
  • autobot-backend/llc/kb/collections.py (new — collection naming helpers)
  • autobot-backend/llc/tests/test_goal.py (new)
  • Alembic migration

Activity

  1. mrveiss commented on May 23, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed — GH#8212 implemented and merged

    Merge commit: `309108ab2` → `Dev_new_gui` (PR #8451, 2026-05-23T09:41:17Z)

    Acceptance Criteria Met:

    • ✅ `LLCGoal` SQLAlchemy model with self-referential `parent_goal_id` FK and `vision → mission → objective → key_result` hierarchy — `llc/models/goal.py`
    • ✅ Alembic migration `20260523_022_llc_goals` creates `llc_goals` table with 5 covering indexes — `migrations/versions/20260523_022_llc_goals.py`
    • ✅ `GoalService.create/get/list_by_company/update/delete` — `llc/services/goal.py`
    • ✅ `get_ancestors()` — cycle-safe parent-chain walk (root-first); `get_subtree()` — BFS over descendants
    • ✅ `_index_goal()` / `_delete_from_chromadb()` — ChromaDB KB indexing, scheduled post-commit to prevent phantom entries on rollback
    • ✅ `_validate_level_order()` — enforces child level = parent level + 1 step; raises HTTP 422 on violation
    • ✅ Cross-tenant guard in `update()` — rejects `parent_goal_id` from a different company (HTTP 400)
    • ✅ API routes: `GET/POST /llc/goals`, `GET/PATCH/DELETE /llc/goals/{id}`, `GET /llc/goals/{id}/ancestors` — `llc/api/goals.py`
    • ✅ 19 unit tests in `llc/tests/test_goals.py` covering all paths including cross-tenant rejection and level validation

    Code review (MVA-821): 4 blocking findings identified and resolved by author in commit `e1de2d4b1` before merge.

  2. mrveiss commented on May 23, 2026

    @mrveiss
    OwnerAuthor

    Implemented and merged via PR #8451 (merged 2026-05-23T09:41Z). Closes GH#8212.

  3. mrveiss commented on May 23, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed — implemented and merged via PR #8451 (commit `309108ab` → Dev_new_gui, 2026-05-23T09:41Z).

    Acceptance Criteria Met:

    • ✅ `LLCGoal` SQLAlchemy model in `autobot-backend/llc/models/goal.py` — id, company_id, parent_goal_id (nullable self-ref FK), title, description, level (GoalLevel enum: vision/mission/objective/key_result), status (GoalStatus enum), owner_agent_id, due_date, created_at/updated_at
    • ✅ Alembic migration `20260523_022_llc_goals` — creates `llc_goals` table, revision chain 021→022, 5 covering indexes
    • ✅ `GoalService` in `autobot-backend/llc/services/goal.py` extending `LLCServiceBase`: create, get, list_by_company, update, delete; `get_ancestors(goal_id)` (cycle-safe parent-chain walker, root-first); `get_subtree(goal_id)` (BFS); `_index_goal()` ChromaDB upsert to `{company_id}_llc_goals` collection on create/update (non-fatal on error)
    • ✅ API routes in `autobot-backend/llc/api/goals.py`: GET/POST /llc/goals, GET/PATCH/DELETE /llc/goals/{id}, GET /llc/goals/{id}/ancestors — wired into LLC router
    • ✅ Tests in `autobot-backend/llc/tests/test_goals.py` — 14 async unit tests covering all paths; all files pass `py_compile`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions