Observe native Claude automations and preserve pending timers

This commit is contained in:
2026-11-08 15:52:22 +00:00
parent 9d3358be47
commit 3fbfb85ace
17 changed files with 757 additions and 34 deletions
+7 -3
View File
@@ -545,14 +545,18 @@ sessions pipeline runs create. The protocol types are:
rather than a stale count.
- `chat_automations` reads provider-owned scheduled work for one operator chat.
Its body is `chat_query: {session_id}` and the reply is
`chat_automations: {session_id, provider, status, active_count?, reason?}`.
`chat_automations: {session_id, provider, status, active_count?, observed_at_ms?, reason?}`.
`status` is `supported` or `unavailable`; a supported empty result has
`active_count: 0`, while an unavailable result omits the count (unknown is
never represented as zero). OpenCode uses its documented
`GET /api/experimental/schedule?sessionID=...` read and counts only records
whose native `sessionID` matches and whose status is `active`. The older
OpenCode serve surface, Claude Code (which currently exposes schedule data
only through events/hooks), and Codex report their exact readback limitation.
OpenCode serve surface and Codex report their exact readback limitation.
Claude Code is supported only after its native Stop-hook reports a bounded
`session_crons` snapshot; `observed_at_ms` is when that last snapshot arrived,
not a live query, and both one-shot and recurring entries count. Before that,
or when the host is stale/legacy or metadata is malformed, Claude reports
`unavailable` rather than guessing from transcript history or CronCreate.
The request is ownership-checked against the operator session registry,
bounded and read-only; it never starts or resumes a model turn and does not
inspect transcripts or count project/global work.
+6 -5
View File
@@ -6,11 +6,12 @@ supported empty result (`active_count: 0`) from an unavailable provider
(`active_count` omitted), so a composer must not render unknown as zero.
OpenCode endpoints that expose scheduling use the documented experimental read endpoint and filters
the validated response to the requested session and `active` status. Claude
Code's installed control protocol has no authoritative read-only schedule
operation; its event/hook metadata is therefore not promoted to a current
count. Codex has no documented native scheduled-management read API. No
schedule is created, changed, resumed, or inferred from a transcript or cwd.
the validated response to the requested session and `active` status. Fresh
Claude CLI processes now register a private native Stop-hook observer; only a
validated bounded `session_crons` snapshot is promoted, with `observed_at_ms`
identifying when it was reported. Old hosts and sessions without that snapshot
remain unavailable. Codex has no documented native scheduled-management read
API. No schedule is created, changed, resumed, or inferred from a transcript or cwd.
Pipeline291 passed implementation and code review (UI review skipped: backend-only),
then blocked at its read-only delivery-stage commit step. The manager retained the
@@ -0,0 +1,31 @@
# Claude automation manager review and recovery
Run292 implemented the observer and completed two review/fix cycles, then failed
its third review with remaining timer-retention and exited-host issues. The
manager took over directly without creating a recovery workflow.
Resolved findings:
- Own observer callbacks acknowledge absent/invalid metadata and clear unknown
snapshots; unrelated callbacks keep their prior unsupported response.
- Direct snapshots belong only to the same live process. Hosted reads use the
actual non-attaching status and reject exited/unreachable hosts, with no
historical cache fallback. Observation time stays separate from query time.
- Status reads honor cancellation after connecting and bound responses to4MiB.
- Observed future native automations prevent adapter idle/excess reaping and
detached host idle cleanup. An empty native snapshot allows ordinary cleanup.
Existing explicit operator shutdown/max-detached policy remains unchanged.
Manager verification uses real owned scratch subprocesses and private Unix
sockets, not model inference or production sessions. It covers native callback
ACK without a server, retention/empty cleanup, missing metadata clearing, operator
permissions left pending, old/exited/replaced process refusal, active attachment
preservation, bounded-spool survival, cancellation and response-size refusal.
Checks passed: focused native automation tests; focused race tests for Claude and
claudehost; go build ./..., go vet ./..., go test ./...; git diff --check.
Logs: /tmp/claude-automation-manager-focused.log,
/tmp/claude-automation-manager-race.log, /tmp/claude-automation-go-final.log.
Native Claude model-auth probes failed before Stop; real native schedule delivery
remains unverified. No login/config changes or real chat prompts were performed.
Old retained hosts are not restarted or retrofitted. The composer feature and
combined deployment follow separately.
@@ -0,0 +1,21 @@
# Claude native automation snapshots
`chat_automations` does not start a Claude turn or inspect a transcript. Fresh
Claude CLI initialization registers one private Stop hook callback. When the
native callback contains the expected main-thread session and a bounded
`session_crons` list, Pipelines retains only its IDs, count, and the report
timestamp. One-shot and recurring entries are both counted.
Detachable hosts acknowledge that exact observer callback themselves, including
while the Pipelines server is disconnected. The snapshot is independent of the
bounded output spool, so reattachment or spool trimming cannot erase it. Missing/malformed metadata clears the snapshot to unknown while the observer
still receives its nonblocking acknowledgement. Wrong-session data cannot update
a count. Permission callbacks remain operator-owned; other SDK callbacks retain
their existing response behavior. Missing data is never an empty schedule.
The API's `observed_at_ms` describes the last native Stop snapshot; it is not a
live schedule query and does not infer work from historical `CronCreate` calls.
Reported native timers prevent idle cleanup while pending. Empty snapshots permit
normal cleanup. The manager completed lifecycle fixes and integration checks after
run292; see claude-automation-manager-review.md for exact evidence and limits.