Repository navigation
Description
Summary
When an agent's claude subprocess is killed by SIGKILL (exit code -9) before any agentic turn completes — e.g. cgroup OOM, host SIGKILL, watchdog cancel — Trinity reports the failure to the operator and to the DB as "Subscription token may be expired or revoked. Generate a new one with 'claude setup-token'." This is a guess, not an observation. No 401/403/429 was ever seen on the wire. The mis-classification (a) repeatedly misleads operators into the wrong remediation path and (b) leaks into the SUB-003 auto-switch pattern matcher, causing spurious subscription rotations and burning the 2-hour skip-list slot for cases that have nothing to do with auth.
Component
Backend / Agent Runtime — error classification in the headless executor + auto-switch trigger pattern in subscription rate-limit handler
Priority
P2 — feature impaired, workaround exists (operator manually verifies the token isn't actually expired). But the impact is high: operators routinely chase the wrong fix, and the false signal corrupts downstream auto-switch state.
Observed Behavior
Same agent, same time window, same actual root cause (container OOM), three different recorded errors:
exit code -9: Subscription token may be expired or revoked.
Generate a new one with 'claude setup-token'.
Execution terminated by SIGKILL after 0 tool calls / 0 turns (exit code -9).
Likely cause: schedule/agent timeout exceeded, OOM kill, or operator cancel.
Increase the schedule's timeout_seconds, raise agent memory,
or split the skill into smaller steps.
Task execution error: [Errno 32] Broken pipe
Only one of these (#2) is honest about uncertainty. The other two are guesses that look authoritative.
The "Subscription token may be expired or revoked" branch is the worst of the three because:
- It names a specific, actionable cause (regenerate the token).
- Operators see it and act on it — including this ops agent, twice, three days apart.
- It contains a verb ("Generate a new one") that drives wrong behavior.
- It is the string SUB-003's auto-switch pattern matcher uses to decide an auth failure occurred — so a SIGKILL on a perfectly valid token triggers a real subscription switch and burns the cooldown.
In a recent incident, two agents on the same subscription_credentials row had identical token hashes (verified by md5sum of CLAUDE_CODE_OAUTH_TOKEN). One agent was OOM-cycling; the other was working normally. The OOM'd agent logged "token may be expired or revoked" repeatedly; the healthy agent kept making successful API calls with the same token. The token was provably fine. The operator (this ops agent) flagged the wrong remediation for 3 days.
Where (best guesses, please verify)
The "Subscription token may be expired or revoked" string is produced by Trinity, not by the Claude Code SDK. Candidate locations:
agent_server/services/headless_executor.py— the error wrapper around theclaude --print --output-format stream-json ...subprocess. This is what runs inside the agent container.backend/services/task_execution_service.py— the caller side that interprets agent responses and may re-wrap errors.- The auto-switch trigger pattern that consumes this string — likely in subscription rate-limit detection, search the codebase for the literal
may be expiredorrevokedsubstrings.
(Filer doesn't have source access; please confirm exact paths in code review.)
Root Cause
The error classifier infers cause from exit code + a heuristic over recent stderr/stdout, with exit_code == -9 && turns == 0 && tool_calls == 0 mapping to "token expired". That mapping has no causal basis:
- A SIGKILL at 0 turns means the process never got far enough to attempt authentication, so no auth-class HTTP response is possible.
- Real token expiry presents as an HTTP 401 from the API — and the SDK exposes that signal.
- The actual causes of
-9 / 0 turnsare: cgroup OOM (host kernel kills the largest RSS process in the container), platform watchdog cancel, operator cancel, manualdocker kill, or container restart.
In all of those, the platform either (a) has direct local evidence (OOM event, watchdog log, operator action) or (b) has no evidence at all — neither of which is "token expired".
Reproduction
Synthetic repro:
- Create an agent with a small memory limit (e.g. 256 MB).
- In the agent's workspace, drop a skill that allocates >256 MB on startup (e.g.
python -c "x = b'a' * 300_000_000; import time; time.sleep(60)"). - Trigger that skill via
chat_with_agentor a scheduled execution. - Observe: kernel OOM-kills a process in the agent's cgroup; the
claudeCLI exits with-9. - Inspect
schedule_executions.errorfor the resulting row — observe "Subscription token may be expired or revoked". The agent'sCLAUDE_CODE_OAUTH_TOKENenv var was never used in any API call.
Bonus repro for the auto-switch leak: run the above repeatedly. Watch subscription_rate_limit_events accrue rows for an agent whose subscription is provably healthy (other agents on the same subscription continue to succeed). After ~2h, observe the subscription's skip-list slot is consumed.
Suggested Fix
Fix 1 — Don't guess. Be honest.
Replace the "token may be expired" branch with:
Agent subprocess terminated by SIGKILL before any agent activity
(exit code -9, 0 turns, 0 tool calls). The platform did not observe
any API authentication failure. Likely causes (uncorrelated):
• Container OOM (check `docker events`, cgroup memory.events, or `dmesg`)
• Platform watchdog timeout
• Operator or external SIGKILL
For real token failures, the platform records an HTTP 401/403 on the wire.
Three properties matter here:
- States what was observed (process killed before activity) rather than what was guessed.
- Names the actual common causes in rough probability order.
- Tells the reader (and downstream code) that this is not an auth failure.
Fix 2 — Gate the auth classifier on an observed wire signal
Auto-switch (SUB-003) should not trigger on this error string. It should trigger when the SDK or HTTP layer recorded an actual 401, 403, or 429 response from api.anthropic.com. Practically:
- Capture the underlying SDK error type / HTTP status into the execution record (a new column or structured
error_classfield). - The auto-switch matcher reads
error_class, not freeformerrortext. - The freeform
errortext becomes operator-facing prose only; no logic depends on it.
Fix 3 — Optional: read cgroup OOM events to upgrade -9 / 0 turns classification
When exit_code == -9 && turns == 0, the platform can read /sys/fs/cgroup/memory.events (cgroup v2) or memory.oom_control (cgroup v1) for the agent's container scope and check whether oom_kill incremented during the execution window. If so, the error becomes:
Agent container exceeded its memory limit (cgroup OOM kill observed).
Raise the agent's memory limit via PUT /api/agents/{name}/resources,
or reduce memory pressure in the workload.
That is the honest error the operator wanted in the first place.
Why This Matters Beyond Aesthetics
- Operator misdirection: each of these false signals costs an operator a 5–30 minute investigation cycle. In a recent incident the misclassification persisted for 72 hours because the error text named a specific, plausible cause.
- Auto-switch state corruption: SUB-003's 2-hour skip-list slot is a finite resource. Burning it on a phantom auth failure means the next real rate-limit event has no recourse — exactly the case the feature was designed for.
- Observability noise:
subscription_rate_limit_eventsis one of the cleanest signals we have for actual quota pressure. Polluting it with OOM-as-auth events makes the signal less useful for both humans and downstream alerting. - Documentation contagion: ops runbooks and skills (incl.
/monitornarratives) accumulate references to "token expired" as a known operational state when in fact it's a misclassification.
Environment
- Trinity version:
98574f37—fix(cleanup): per-slot TTL prevents false-kill of long-running executions (#869) (#871) - Agent runtime: Claude Code SDK via
claude --print --output-format stream-json --verbose --dangerously-skip-permissions ... - Subprocess wrapper: Trinity's
agent_server.services.headless_executor - Default agent memory limit: 4 GB (host enforces via cgroup)
Related
- bug: agent container OOM cascades into backend worker saturation and freezes admin UI #904 — umbrella P1 covering the full cascade (worker saturation, OOM isolation, this misclassification, auto-switch trigger gating)
- SUB-003 — subscription auto-switch on API auth/rate-limit failures
- TIMEOUT-001 — per-agent execution timeout
- Per-agent resource limits API:
PUT /api/agents/{name}/resources
Activity
oleksandr-korin commentedon May 21, 2026
/claim
github-actions commentedon May 21, 2026
Claimed by @oleksandr-korin. Label
status-in-progressadded.Next steps:
feature/906-<short-slug>Fixes #906fix(chat-path): classify signal exits before auth fallback (#906) (#909)
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).