HKUDS/Vibe-Trading · error · HTTPException
Goal created but could not be reloaded
Error message
Goal created but could not be reloaded
What it means
After replace_goal returns a goal, the route re-reads it with goal_store.get_goal_snapshot(goal.goal_id); if that returns None (store inconsistency, eviction, or a persistence failure between write and read) the route fails with 500 'Goal created but could not be reloaded'. The write happened, but the read-back did not — so state may be inconsistent.
Source
Thrown at agent/src/api/sessions_routes.py:477
goal_store = _get_goal_store()
try:
goal = goal_store.replace_goal(
session_id=session_id,
objective=req.objective,
criteria=criteria,
ui_summary=req.ui_summary,
source="api",
protocol=req.protocol,
risk_tier=risk_tier,
token_budget=req.token_budget,
turn_budget=req.turn_budget,
time_budget_seconds=req.time_budget_seconds,
)
except ValueError as exc:
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(View on GitHub (pinned to 80ffdda44c)
Solutions
- Retry the operation: GET /sessions/{id}/goal to see if the goal actually exists despite the 500
- If it persists, inspect the goal store implementation/persistence config (get_goal_snapshot vs replace_goal asymmetry)
- Isolate concurrent store resets in tests (one store per test) to rule out interference
- Report upstream with the goal_id if the store is the library's own — the write/read mismatch indicates a bug
Example fix
# before
snapshot = api.create_session_goal(sid, ...) # 500, goal may exist
# after
try:
snapshot = api.create_session_goal(sid, ...)
except HTTPError as e:
if e.response.status_code == 500:
snapshot = api.get_session_goal(sid) # confirm whether it was actually created
else:
raise Defensive patterns
Strategy: fallback
Validate before calling
# nothing client-side can prevent an internal read-back failure; pre-flight store health if available
r = requests.get(f"{BASE}/sessions", params={"limit": 1})
if r.status_code >= 500:
raise RuntimeError("Server unhealthy; goal create may fail with 500") Try / catch
try:
snap = api.create_session_goal(sid, payload)
except HTTPError as e:
if e.response.status_code == 500:
snap = None
try:
snap = api.get_session_goal(sid) # goal may exist despite the 500
except NotFoundError:
pass
if snap is None:
raise
else:
raise Prevention
- After a 500 on create, verify with GET before assuming failure
- Use isolated goal stores per test to avoid concurrent resets
- Monitor 500 rates on goal routes to catch store regressions early
When it happens
Trigger: A race where the just-created goal is evicted/deleted/never persisted before the immediate re-read; snapshot construction failing; storage backend (DB/file) losing the row; concurrent tests resetting the store mid-request.
Common situations: Flaky test suites sharing a goal store that gets cleared between operations; in-memory store swapped concurrently; DB transaction visibility issues (uncommitted write); a bug in a custom goal-store backend.
Related errors
- Session runtime not enabled
- Session {session_id} not found
- invalid risk_tier: {req.risk_tier}
- live trading or execution goals are not supported
- str(exc)
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/e609d0c4ebcb7803.
Report an issue: GitHub.