fix(cron): whitelist cron update_job fields so typos don't silently persist (#67625) - #67660
fix(cron): whitelist cron update_job fields so typos don't silently persist (#67625)#67660Ahmett101 wants to merge 2 commits into
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing the core and dashboard pass-through paths; the current-main premise is valid (cron/jobs.py:1486, hermes_cli/web_server.py:12034).
Problems
- The gateway REST update route remains a silent-partial-update path:
gateway/platforms/api_server.py:5301filters unknown keys, andtests/gateway/test_api_server_jobs.py:358-371currently expects HTTP 200 for a request containingnameplus unknown fields. This PR does not change that route. - The dashboard allow-list is described as mirroring the core allow-list, but the diff accepts
attach_to_sessionin core and omits it in the dashboard. This is the linked #67706 concern; align the contracts or explicitly document the dashboard subset. metadatais described as a dict escape valve, but the proposed guard only allow-lists it; the existing merge atcron/jobs.py:1486will persist a scalar/list too.- The diff also includes the separate ACP fix from
a7a21b2c6f95; this matches the existing request to split or explicitly conduct a combined review.
Suggested changes
- Reject unknown fields before the gateway API sanitization and add a mixed valid-plus-typo regression test.
- Reconcile/document the dashboard and core field sets, validate
metadataas a dict, and add negative coverage.
Automated hermes-sweeper review.
| ) | ||
|
|
||
|
|
||
| _DASHBOARD_ALLOWED_UPDATE_FIELDS = frozenset({ |
There was a problem hiding this comment.
This is documented as mirroring the core allow-list, but the diff omits attach_to_session, which the core list accepts. Linked issue #67706 tracks that drift; please either share one canonical contract or document this as an intentional dashboard-only subset.
| "last_delivery_error", "deliver", "origin", "attach_to_session", | ||
| "provider_snapshot", "model_snapshot", "created_at", | ||
| "created_by_user_id", | ||
| # Fragmentation of arbitrary bookkeeping. Kept opaque downstream |
There was a problem hiding this comment.
metadata is documented here as a dict escape valve, but the subsequent guard only checks its key. Please reject non-dict metadata before the existing {**job, **updates} merge can persist a scalar or list.
| # Collect in-memory sessions first. | ||
| with self._lock: | ||
| seen_ids = set(self._sessions.keys()) | ||
| seen_ids = set() |
There was a problem hiding this comment.
This is the independent #66881 ACP behavior change, not part of the cron validation fix. The existing maintainer comment requested a split or an explicit combined review; please separate it so the cron fix can be evaluated independently.
|
@Ahmett101 — nice fix on #67625; the Mapping to the sweeper's four Problems:
110 cron/gateway/dashboard tests + ruff green, on local branch |
Summary
Reopened as a clean branch — the previous
fix/67625-cron-update-whitelistbranch had grown a stale ACP commit from an unrelated worktree. This branch (fix/67625-clean) carries only the cron whitelist change.Adds an allow-list of valid update fields to
cron/jobs.py::update_joband the dashboard adapter_normalize_dashboard_cron_updates. Unknown keys (promttypo, stale-client custom keys) now raiseValueError(cron layer) orHTTP 422(dashboard) instead of silently being persisted and silently failing the actual intended update. Sanctioned escape valve:metadata: { ... }for legitimate integration bookkeeping.Changes
cron/jobs.py: new_VALID_JOB_FIELDSwhitelist +update_jobrejects any unknown key withValueError. The existing immutable-idguard is preserved as a distinct 400-class error.hermes_cli/web_server.py: new_DASHBOARD_ALLOWED_UPDATE_FIELDSconstant;_normalize_dashboard_cron_updatesreturns 422 listing every offending field, before the IPC round-trip.idis allowed as a payload key so the immutable guard's 400 remains the actionable error.tests/cron/test_jobs.py: 3 new regression tests (typo, multi-unknown, metadata escape valve).tests/hermes_cli/test_web_server_cron_profiles.py: 1 new dashboard test (422 with offending key listed, original field untouched).How to Test
pytest tests/cron/test_jobs.py tests/hermes_cli/test_web_server_cron_profiles.py -q
166/166 passed
Checklist
Risk & Impact: Low. Strict validation: update payloads with typos or stale-client custom keys now raise ValueError / 422. External integrations relying on ad-hoc keys must move to whitelisted fields or use
metadata.Type: Bug fix
Closes: #67625