Compare commits
1 Commits
q/378-1776
...
claude/iss
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a9b172a1d |
44
cron/jobs.py
44
cron/jobs.py
@@ -363,45 +363,6 @@ def save_jobs(jobs: List[Dict[str, Any]]):
|
||||
raise
|
||||
|
||||
|
||||
# Patterns that reference local services unreachable on cloud endpoints
|
||||
_LOCAL_SERVICE_CHECK_PATTERNS = [
|
||||
re.compile(r"\b(?:check|verify)\s+(?:that\s+)?ollama\b", re.IGNORECASE),
|
||||
re.compile(r"\bcurl\s+(?:localhost|127\.0\.0\.1)", re.IGNORECASE),
|
||||
re.compile(r"\bpoll\s+localhost\b", re.IGNORECASE),
|
||||
re.compile(r"\bping\s+localhost\b", re.IGNORECASE),
|
||||
re.compile(r"localhost:\d+", re.IGNORECASE),
|
||||
re.compile(r"127\.0\.0\.1:\d+", re.IGNORECASE),
|
||||
]
|
||||
|
||||
|
||||
def _validate_job_prompt_local_refs(prompt: str, base_url: Optional[str] = None) -> List[str]:
|
||||
"""Check if a cron job prompt references local services.
|
||||
|
||||
Returns list of warning messages (empty = no issues).
|
||||
Warnings are advisory — jobs are NOT rejected.
|
||||
"""
|
||||
warnings = []
|
||||
if not prompt:
|
||||
return warnings
|
||||
|
||||
refs = []
|
||||
for pat in _LOCAL_SERVICE_CHECK_PATTERNS:
|
||||
found = pat.findall(prompt)
|
||||
if found:
|
||||
refs.extend(found[:2])
|
||||
|
||||
if refs:
|
||||
refs_str = ", ".join(f"'{r}'" for r in refs[:5])
|
||||
warnings.append(
|
||||
f"Prompt references local services ({refs_str}) which may be "
|
||||
f"unreachable if the job runs on a cloud provider. "
|
||||
f"Consider setting provider='ollama' or base_url='http://localhost:11434/v1'."
|
||||
)
|
||||
|
||||
return warnings
|
||||
|
||||
|
||||
|
||||
def create_job(
|
||||
prompt: str,
|
||||
schedule: str,
|
||||
@@ -496,11 +457,6 @@ def create_job(
|
||||
"origin": origin, # Tracks where job was created for "origin" delivery
|
||||
}
|
||||
|
||||
# Validate prompt for local service references (#378)
|
||||
_warnings = _validate_job_prompt_local_refs(prompt, normalized_base_url)
|
||||
for w in _warnings:
|
||||
logging.getLogger("cron.jobs").warning("Job '%s': %s", job_id, w)
|
||||
|
||||
jobs = load_jobs()
|
||||
jobs.append(job)
|
||||
save_jobs(jobs)
|
||||
|
||||
@@ -18,9 +18,9 @@ from typing import Any, Dict, Optional
|
||||
|
||||
def normalize_job(job: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Normalize a job dict to ensure consistent model field types.
|
||||
Normalize a job dict to ensure consistent model field types and aligned skill fields.
|
||||
|
||||
Before normalization:
|
||||
Model normalization:
|
||||
- If model AND provider: model = raw string, provider = raw string (inconsistent)
|
||||
- If only model: model = raw string
|
||||
- If only provider: provider = raw string at top level
|
||||
@@ -30,37 +30,61 @@ def normalize_job(job: Dict[str, Any]) -> Dict[str, Any]:
|
||||
- If provider exists: model = {"provider": "yyy"}
|
||||
- If both exist: model = {"model": "xxx", "provider": "yyy"}
|
||||
- If neither: model = None
|
||||
|
||||
Skill normalization:
|
||||
- Aligns legacy `skill` (single string) with `skills` (list), setting skill = skills[0]
|
||||
"""
|
||||
job = dict(job) # Create a copy to avoid modifying the original
|
||||
|
||||
|
||||
# --- skill / skills normalization ---
|
||||
raw_skill = job.get("skill")
|
||||
raw_skills = job.get("skills")
|
||||
|
||||
if raw_skills is None:
|
||||
skill_items = [raw_skill] if raw_skill else []
|
||||
elif isinstance(raw_skills, str):
|
||||
skill_items = [raw_skills]
|
||||
else:
|
||||
skill_items = list(raw_skills)
|
||||
|
||||
normalized_skills: list = []
|
||||
for item in skill_items:
|
||||
text = str(item or "").strip()
|
||||
if text and text not in normalized_skills:
|
||||
normalized_skills.append(text)
|
||||
|
||||
job["skills"] = normalized_skills
|
||||
job["skill"] = normalized_skills[0] if normalized_skills else None
|
||||
|
||||
# --- model / provider normalization ---
|
||||
model = job.get("model")
|
||||
provider = job.get("provider")
|
||||
|
||||
|
||||
# Skip if already normalized (model is a dict)
|
||||
if isinstance(model, dict):
|
||||
return job
|
||||
|
||||
|
||||
# Build normalized model dict
|
||||
model_dict = {}
|
||||
|
||||
|
||||
if model is not None and isinstance(model, str):
|
||||
model_dict["model"] = model.strip()
|
||||
|
||||
|
||||
if provider is not None and isinstance(provider, str):
|
||||
model_dict["provider"] = provider.strip()
|
||||
|
||||
|
||||
# Set model field
|
||||
if model_dict:
|
||||
job["model"] = model_dict
|
||||
else:
|
||||
job["model"] = None
|
||||
|
||||
|
||||
# Remove top-level provider field if it was moved into model dict
|
||||
if provider is not None and "provider" in model_dict:
|
||||
# Keep provider field for backward compatibility but mark it as deprecated
|
||||
# This allows existing code that reads job["provider"] to continue working
|
||||
pass
|
||||
|
||||
|
||||
return job
|
||||
|
||||
|
||||
@@ -90,20 +114,26 @@ def normalize_jobs_file(jobs_file: Path, dry_run: bool = False) -> int:
|
||||
for i, job in enumerate(jobs):
|
||||
original_model = job.get("model")
|
||||
original_provider = job.get("provider")
|
||||
|
||||
original_skill = job.get("skill")
|
||||
original_skills = job.get("skills")
|
||||
|
||||
normalized_job = normalize_job(job)
|
||||
|
||||
|
||||
# Check if anything changed
|
||||
if (normalized_job.get("model") != original_model or
|
||||
normalized_job.get("provider") != original_provider):
|
||||
normalized_job.get("provider") != original_provider or
|
||||
normalized_job.get("skill") != original_skill or
|
||||
normalized_job.get("skills") != original_skills):
|
||||
jobs[i] = normalized_job
|
||||
modified_count += 1
|
||||
|
||||
|
||||
job_id = job.get("id", "?")
|
||||
job_name = job.get("name", "(unnamed)")
|
||||
print(f"Normalized job {job_id} ({job_name}):")
|
||||
print(f" model: {original_model!r} -> {normalized_job.get('model')!r}")
|
||||
print(f" provider: {original_provider!r} -> {normalized_job.get('provider')!r}")
|
||||
print(f" skill: {original_skill!r} -> {normalized_job.get('skill')!r}")
|
||||
print(f" skills: {original_skills!r} -> {normalized_job.get('skills')!r}")
|
||||
|
||||
if modified_count == 0:
|
||||
print("All jobs already have consistent model field types.")
|
||||
|
||||
Reference in New Issue
Block a user