Repository navigation
fix(pull): the system agent claims its own queue with its system-scoped key (abilityai/trinity#3814) - #3832
Conversation
…ed key (#3814) trinity-system's MCP key is scope="system", bound to its own name. The pull seams and the heartbeat accepted only scope="agent", so a system agent put in PULL_MODE_PILOT_AGENTS had every poll and heartbeat refused (403) while the backend routed its turns to the durable queue. Push is being retired, so the system agent needs a claim path rather than an exemption. - authorize_heartbeat accepts a system-scoped key only when the key row's agent_name equals the path and the path is the system agent. It gates next-task, the pull result seam, the heartbeat and the #1083 callback. A system key never acts for another agent (403 / uniform 404). - The result seam's pre-check runs the same predicate against the key's own bound name, so an unbound system key still gets 403. - apply_pull_mode_env gives a piloted system agent TRINITY_BACKEND_URL (its worker cannot start without it) and removes it, clearing the heartbeat seen marker, on de-pilot. _create_system_agent now applies the helper. - check_pull_mode_env_matches treats a piloted system agent without the URL as drift, so a pre-fix container is recreated on its next cold start. - ensure_deployed logs a WARNING while the system agent is piloted and files a system_agent_pull_drift platform alert while its running container has no worker (it is never recreated while running). Mutation check: reverting each production change turned a test red (test_system_key_acts_for_the_system_agent, test_result_system_scoped_key_403, test_piloted_system_agent_gets_pull_flag_and_backend_url, test_creation_arms_a_piloted_system_agents_pull_worker, test_piloted_system_agent_without_backend_url_is_drift, test_boot_reports_the_pull_state_of_a_running_system_agent, test_the_kind_is_registered_under_a_reserved_prefix). Fixes #3814 Co-Authored-By: Claude Opus 5.5 <[email protected]>
) - Boot logs the pull-mode WARNING on a fresh install too (create branch). - POST /api/system-agent/restart re-reads the replacement container, so the system_agent_pull_drift alert ends at the restart it names as the remedy. - Legacy-subject parser for the new base-image-stale-pull- prefix. - apply_pull_mode_env no longer clears the heartbeat itself; every caller recreates the container and clear_agent_breakers already does it. - Stale wording: the 403 detail, pull_mode and reports docstrings, and the internal-system-agent flow. - Learnings fragment for the self-acting-gate class. Mutation check: removing each new wiring line turns its test red (test_boot_reports_the_pull_state_before_a_fresh_create, test_restart_re_reports_the_pull_state_of_the_new_container, test_a_legacy_row_with_the_prefix_parses_to_this_kind). Co-Authored-By: Claude Opus 5.5 <[email protected]>
dolho
left a comment
There was a problem hiding this comment.
Validated (/validate-pr, lane C). authorize_heartbeat admits scope=system only when the key's bound agent_name == path == trinity-system; users cannot mint system-scope keys (mcp_keys router allowlist), and the only system key is minted for trinity-system then flipped, so no cross-agent widening. Result seam pre-check is equivalent for agent keys. Admin gates untouched. Ran test_3814 + 1816 + 3590 + 293 + 186 locally: 189 passed. Mutation: reverting heartbeat_service turns 5 tests red. Test deletions are #1816 pins replaced by piloted/unpiloted counterparts. Known effect (unpiloted pre-#1816 container now heartbeats OK) is documented and acceptable. Tier 1 + journey-smoke/e2e green; dev-ci green. LGTM.
Summary
scope="system"key is accepted by the pull seams and the heartbeat fortrinity-systemonly, with the name taken from the key row. Push is being retired (Decide (on paper) whether human-interactive chat belongs in the pull queue — TARGET_ARCHITECTURE Open Question 7 #1989, Phase 5 refactor: collapse 9-path cleanup pyramid once agent is authoritative #429), so this replaces the exemption option.TRINITY_PULL_MODEandTRINITY_BACKEND_URL; de-pilot removes both and clears its heartbeatseenmarker. The drift check recreates a piloted system container that lacks the URL on its next cold start.system_agent_pull_driftplatform alert while its running container has no worker (a running system agent is never recreated, bug: trinity-system never adopts a rebuilt base image — ensure_deployed short-circuits on 'already running' #1816 AC2).Seams the system key now passes
GET /api/internal/next-taskPOST /api/internal/tasks/{id}/resultPOST /api/agents/trinity-system/heartbeatPOST /api/agents/{name}/executions/{id}/result(#1083, until push is deleted)No lease-renew seam exists; the pull worker calls only the first two. Every other path for system-scoped keys is unchanged. Auto-sync: the armed URL starts the auto-sync loop; any non-200 from the git routes falls back to the env value, so it cannot enable a disabled sync.
Known effect
An unpiloted system container that still carries
TRINITY_BACKEND_URLfrom before #1816 was in a permanent 403 heartbeat loop. Its heartbeats are now accepted, so it appears in fleet health. Fresh and post-#1816 containers carry no URL unless piloted. This is the interim answer to #1816 §10 and can be revisited there.Changes
services/heartbeat_service.py—authorize_heartbeatadmits the system agent's own system-scoped keyrouters/internal.py— result-seam pre-check uses the predicate on the key's own bound nameservices/agent_service/pull_mode.py— system-agentTRINITY_BACKEND_URLset-or-clear inapply_pull_mode_envservices/agent_service/helpers.py— drift check requires the URL for a piloted system agentservices/system_agent_service.py— creation applies the pull env;_report_pull_modeat bootservices/platform_alerts.py—system_agent_pull_driftkind under the reservedbase-image-stale-family, plus its legacy-subject parserrouters/system_agent.py—/restartre-reports pull state on the replacement container, so the alert ends at the remedy it namestest_1816_*(heartbeat stays off unless piloted, plus piloted counterparts),test_3590writer setarchitecture/backend.md,architecture/reliability.md,feature-flows/agent-heartbeat-liveness.md,feature-flows/internal-system-agent.md; learnings fragment; CSO diff report (0 findings)Test Plan
cd tests && pytest unit/test_3814_system_agent_pull.py -v(28 passed)test_293,test_2996,test_1310,test_186,test_agent_auth_header_guard— 137 passedorigin/devin this local env (Python 3.11ipaddressbehaviour, stalepayments_py); this branch adds none.PULL_MODE_PILOT_AGENTS=trinity-systemand the system agent restarted, it claims and completes a task with 0 × 403 and no B-08workers_silentFixes #3814
🤖 Generated with Claude Code