HKUDS/Vibe-Trading · warning · HTTPException

No current goal

Error message

No current goal

What it means

GET /sessions/{session_id}/goal returns the current goal snapshot via get_current_snapshot(session_id); when no goal has been created (or the existing goal is no longer 'current', e.g. archived/completed) the route raises 404 'No current goal'. Note the session itself exists — the 404 is about the goal resource, not the session.

Source

Thrown at agent/src/api/sessions_routes.py:492

            raise HTTPException(status_code=400, detail=str(exc)) from exc
        snapshot = goal_store.get_goal_snapshot(goal.goal_id)
        if snapshot is None:
            raise HTTPException(status_code=500, detail="Goal created but could not be reloaded")
        svc.event_bus.emit(session_id, "goal.created", {"goal": snapshot["goal"]})
        return snapshot

    @app.get(
        "/sessions/{session_id}/goal",
        response_model=GoalSnapshotResponse,
        dependencies=[Depends(require_auth)],
    )
    async def get_session_goal(session_id: str):
        """Return the current finance research goal snapshot for a session."""
        _host_validate_path_param(session_id, "session_id")
        _get_existing_session_or_404(session_id)
        snapshot = _get_goal_store().get_current_snapshot(session_id)
        if snapshot is None:
            raise HTTPException(status_code=404, detail="No current goal")
        return snapshot

    @app.patch(
        "/sessions/{session_id}/goal",
        response_model=UpdateGoalResponse,
        dependencies=[Depends(require_auth)],
    )
    async def update_session_goal(session_id: str, req: UpdateGoalRequest):
        """Edit the current finance research goal without replacing the session."""
        _host_validate_path_param(session_id, "session_id")
        svc, _session = _get_existing_session_or_404(session_id)
        from src.goal import StaleGoalError

        if req.objective is None and req.ui_summary is None:
            raise HTTPException(status_code=400, detail="objective or ui_summary is required")

        goal_store = _get_goal_store()
        try:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Create a goal first with POST /sessions/{id}/goal, then read it
  2. Treat 404 on this route as 'no goal yet' and show an empty state rather than an error
  3. Check goal lifecycle state — completed/archived goals may leave no current goal; create a new one
  4. Sequence client flows so goal read happens only after successful goal creation

Example fix

# before
snap = api.get_session_goal(sid)  # 404 for fresh sessions

# after
try:
    snap = api.get_session_goal(sid)
except NotFound:
    snap = api.create_session_goal(sid, objective="...", risk_tier="LOW_RISK")
Defensive patterns

Strategy: try-catch

Validate before calling

# know before you fetch: has a goal been created for this session?
r = client.get(f"/sessions/{sid}/goal")
has_goal = r.status_code == 200  # 404 means none set yet (session itself exists)

Try / catch

try:
    snapshot = api.get_session_goal(sid)
except NotFoundError:
    # 404 here means 'no current goal', not 'no session'
    snapshot = api.create_session_goal(sid, objective=default_objective, risk_tier="LOW_RISK")

Prevention

When it happens

Trigger: Calling GET /sessions/{id}/goal on a session that never had a goal set, or whose goal was replaced/archived so no current snapshot exists. The session id itself is valid (otherwise the session 404 fires first).

Common situations: Client fetches the goal immediately after creating a session but before creating a goal; UI showing a 'current goal' panel for goal-less sessions; flows where goal creation failed earlier and the error was swallowed; goal lifecycle moved it out of current state.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/a7fd483c20773e49. Report an issue: GitHub.