HKUDS/Vibe-Trading · error · StaleGoalError

goal is not current for this session

Error message

goal is not current for this session

What it means

The goal exists and is mutable, but get_current_goal(session_id) returns a different goal (or none). The store only allows mutations on the session's designated current goal.

Source

Thrown at agent/src/goal/store.py:842

    def _require_mutable_goal(
        self,
        session_id: str,
        goal_id: str,
        expected_goal_id: str,
    ) -> GoalRecord:
        if expected_goal_id != goal_id:
            raise StaleGoalError("expected_goal_id does not match target goal")
        session_id = normalize_required_text(session_id, "session_id")
        goal_id = normalize_required_text(goal_id, "goal_id")
        goal = self.get_goal(goal_id)
        if goal is None or goal.session_id != session_id:
            raise StaleGoalError("goal is not available for this session")
        if goal.status not in _CURRENT_STATUSES:
            raise StaleGoalError(f"goal status {goal.status.value!r} is not mutable")
        current = self.get_current_goal(session_id)
        if current is None or current.goal_id != goal_id:
            raise StaleGoalError("goal is not current for this session")
        return goal

    @staticmethod
    def _verification_status(evidence: EvidenceInput) -> str:
        """Return whether evidence has a traceable local artifact/run source."""
        if evidence.artifact_path:
            try:
                artifact = safe_document_path(evidence.artifact_path)
            except ValueError:
                artifact = None
            if artifact and artifact.is_file():
                if GoalStore._artifact_hash_matches(artifact, evidence.artifact_hash):
                    return "verified"
        if evidence.run_id:
            try:
                run_dir = safe_run_id(evidence.run_id)
            except ValueError:
                run_dir = None

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use get_current_goal(session_id).goal_id as the target
  2. If the old goal genuinely needs changes, complete/archive the new one or restructure so only one active goal exists
  3. Treat as a signal to refresh the agent's goal cache

Example fix

// before
store.update_goal(session_id, goal_id=stale_goal_id, ...)
// after
current = store.get_current_goal(session_id)
store.update_goal(session_id, goal_id=current.goal_id, ...)
Defensive patterns

Strategy: validation

Validate before calling

current = store.get_current_goal(session_id)
if current is None or current.goal_id != goal_id:
    goal_id = current.goal_id if current else None  # or bail

Type guard

def is_current_goal(store, session_id: str, goal_id: str) -> bool:
    cur = store.get_current_goal(session_id)
    return cur is not None and cur.goal_id == goal_id

Try / catch

except StaleGoalError as e: if 'not current' in str(e): re-fetch current goal and re-route the operation

Prevention

When it happens

Trigger: A new goal was created for the session, demoting the old one to non-current; then updating the old goal via update_goal/append_evidence/update_status/account_usage.

Common situations: Agent creates a follow-up goal and a delayed writer still targets the previous goal; tests seeding multiple goals per session without setting currency.

Related errors


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