You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(company-os): a heartbeat run key is revoked seconds after start, while the agent is still working #20466
Host evidence, 2026-11-01, on 45f10d1773, from a scheduled CEO run (#20247).
The heartbeat's run key was revoked while the run was still working. Times are from the run's own output:
Time (Riga)
Call
Result
10:15:12
GET /llc/agent/work-items/next
OK
10:15:16
GET /llc/agent/context/<id>
OK
10:15:24
GET /llc/agent/work-items/<id>
401
10:21:51
POST /llc/agent/comments
401
10:21:57
GET /llc/agent/context/<id>
401, the same call that worked at 10:15:16
The run itself ended at 10:22:11 with is_error=false. So the agent worked for 7 minutes and could not report its result: its findings reached only its own output.
The key is revoked in one place on the dispatch path: the finally in _dispatch_registry_adapter, after _await_adapter_completion returns. So the likely reading is that the scheduler saw the run as terminal within seconds, while the process was alive. That would also mean billing and run status are read before the run ends. The cause is not established. One thing to test: the base status check and its process identity check (spawn_create_time records psutil's create_time), which may mismatch on this host.
Note the third call's path isn't a route in agent_api.py, but the auth middleware answers first, and the later 401 on a working route shows the key itself was dead.
Acceptance criteria
The cause is established, on the host's real behaviour.
A run key stays valid until the process has exited (test with a process that outlives several polls).
Run status and usage are read after the process has exited (test).
Host evidence: a scheduled run posts its comment through the API.
Read-only investigation on current main and the install, 2026-11-07. Cause: still not established, so AC1 stays unticked.
Chain (main)
Spawn: claude_code_adapter._build_state records create_time from spawn_create_time (subprocess_support.py).
Poll: _await_adapter_completion (heartbeat_scheduler.py) checks every 5 s.
Status: subprocess_base checks liveness with probe_pid_identity(pid, create_time). On a mismatch or NoSuchProcess it returns COMPLETED silently.
Revoke: the finally in _dispatch_registry_adapter revokes the run key. Usage is ingested after that.
So a false COMPLETED revokes the key while the process is still alive, and also reads usage too early.
Hypotheses
H1, process identity drift: most probable, not confirmed. Before the fix, the stamp was the absolute create_time, which is derived from /proc/statbtime.
The timing fits: spawn at 08:15:00 UTC, first 401 at 08:15:24.
I sampled btime on the install read-only, 13 times over 65 s today: it was constant. The drift the code comment describes did not reproduce now. It may only occur around host sleep or clock-sync events.
H2, a wrapper PID instead of the CLI's: unlikely.spawn_detached uses start_new_session=True, and proc.pid is the spawned process. I did not check the command for an sh/npx wrapper.
H3, a sweep revoking the key: ruled out by code. The only revoke_key callers are run_key.py, the manual API-key route and org deactivation. The key TTL is at least 7800 s.
Logs: the 2026-11-01 backend log shows the run's creation and spawn, but nothing from 08:15 to 08:25. The pre-fix code logged neither an identity mismatch nor a revoke, so the logs cannot confirm or refute H1. There has been no scheduled spawn since 11-02, so there is no post-fix host run yet.
Next (one PR):
probe_pid_identity logs a WARNING (pid, expected, actual) when it judges a mismatch COMPLETED, so this class becomes visible.
AC2 test: a scheduler-level fake adapter stays RUNNING for N polls, and the key is not revoked before the terminal poll.
AC3 test: status and usage are read only after the process exits, using a real subprocess that writes its result late.
AC4 (host evidence) needs a scheduled run on the install that posts its comment.
Part landed: PR #21068 merged to main via merge train #21184 (merge commit 209d547): run-identity mismatch is logged and the run-key and usage ordering are pinned. This PR referenced the issue (Refs), it did not close it; the issue is open and its remaining acceptance criteria are not claimed as delivered.
Progress check on main and on the local install, which was updated to main 85d5d2e at 21:13 Riga.
AC
Evidence
Met
A run key stays valid until the process has exited
llc/tests/test_run_key_outlives_process_20466.py::test_run_key_is_revoked_once_and_only_after_the_terminal_poll: 4 RUNNING polls, then the terminal poll, then exactly one revoke. Also test_run_identity_survives_clock_drift_20466.py::test_exited_process_is_completed_after_several_running_polls.
yes (ticked)
Run status and usage are read after the process has exited
llc/adapters/tests/test_usage_read_after_exit_20466.py::test_status_is_running_while_alive_and_usage_arrives_only_after_exit: a real child blocks until released, then the exact [RUNNING]*3 + [COMPLETED] sequence; usage arrives only on the terminal poll.
yes (ticked)
The cause is established on the host's real behaviour
Since the update, 5 scheduled wakes (21:15 to 22:30) were all "no eligible work (idle wake recorded)", with no run created. Nothing to observe yet. Backend log: 0 run-key revocation lines.
not yet
Host evidence: a scheduled run posts its comment through the API
No scheduled run has had work since the update, so there is no comment to show.
not yet
The two host ACs stay open until a scheduled run actually picks up work on the updated install.
Open: AC1 (cause established on the host's real behaviour) and AC4 (host: a scheduled run posts its comment through the API) need host evidence, which a merge does not give. Left unticked.
Read-only host check, 2026-11-21 02:43 Riga. The deployed commit is bcd41c623d, which includes the #20466 AC2/AC3 code and the probe_pid_identity mismatch logging.
probe_pid_identity mismatch warnings over 7 days of logs: 0. Mentions of "revok": 0. Instrument check: the same log carries 148 WARNING lines, so warnings are being captured.
Scheduled heartbeat runs that picked up work in 7 days: 0 (634 wakes, all skipped with "no eligible work").
AC1 (cause): cannot tell. The revocation hasn't reproduced since the update, but no run has had the chance. AC4 (a scheduled run posts its comment): not met. No scheduled run picked up work, so no comment could be posted. Run and comment rows were not queried (no read-only database credential).
Activity
mrveiss commentedon Nov 7, 2026
Read-only investigation on current main and the install, 2026-11-07. Cause: still not established, so AC1 stays unticked.
Chain (main)
claude_code_adapter._build_staterecordscreate_timefromspawn_create_time(subprocess_support.py)._await_adapter_completion(heartbeat_scheduler.py) checks every 5 s.subprocess_basechecks liveness withprobe_pid_identity(pid, create_time). On a mismatch orNoSuchProcessit returns COMPLETED silently.finallyin_dispatch_registry_adapterrevokes the run key. Usage is ingested after that.So a false COMPLETED revokes the key while the process is still alive, and also reads usage too early.
Hypotheses
create_time, which is derived from/proc/statbtime.btimeon the install read-only, 13 times over 65 s today: it was constant. The drift the code comment describes did not reproduce now. It may only occur around host sleep or clock-sync events.spawn_detachedusesstart_new_session=True, andproc.pidis the spawned process. I did not check the command for ansh/npxwrapper.revoke_keycallers arerun_key.py, the manual API-key route and org deactivation. The key TTL is at least 7800 s.Logs: the 2026-11-01 backend log shows the run's creation and spawn, but nothing from 08:15 to 08:25. The pre-fix code logged neither an identity mismatch nor a revoke, so the logs cannot confirm or refute H1. There has been no scheduled spawn since 11-02, so there is no post-fix host run yet.
Next (one PR):
probe_pid_identitylogs a WARNING (pid, expected, actual) when it judges a mismatch COMPLETED, so this class becomes visible.AC4 (host evidence) needs a scheduled run on the install that posts its comment.
test(llc): count a poll as live only when the child is alive on both …
test(llc): drive the usage-after-exit polls explicitly and assert the…
mrveiss commentedon Nov 8, 2026
Part landed: PR #21068 merged to main via merge train #21184 (merge commit 209d547): run-identity mismatch is logged and the run-key and usage ordering are pinned. This PR referenced the issue (Refs), it did not close it; the issue is open and its remaining acceptance criteria are not claimed as delivered.
Merge pull request #21201 from mrveiss/issue-20466-poll-test
github-actions commentedon Nov 8, 2026
Landed in #21201, merge
085943d594fix(llc): log a run-identity mismatch and pin the run-key and usage o…
test(llc): drive the usage-after-exit polls explicitly and assert the…
mrveiss commentedon Nov 9, 2026
Progress check on main and on the local install, which was updated to main 85d5d2e at 21:13 Riga.
llc/tests/test_run_key_outlives_process_20466.py::test_run_key_is_revoked_once_and_only_after_the_terminal_poll: 4 RUNNING polls, then the terminal poll, then exactly one revoke. Alsotest_run_identity_survives_clock_drift_20466.py::test_exited_process_is_completed_after_several_running_polls.llc/adapters/tests/test_usage_read_after_exit_20466.py::test_status_is_running_while_alive_and_usage_arrives_only_after_exit: a real child blocks until released, then the exact[RUNNING]*3 + [COMPLETED]sequence; usage arrives only on the terminal poll.The two host ACs stay open until a scheduled run actually picks up work on the updated install.
Merge main into issue-20466 (usage-after-exit test reap already on ma…
mrveiss commentedon Nov 20, 2026
AC audit against main 13685f3 (2026-11-20). A branch deleted as ZERO means its content is on main; it does not by itself meet the ACs.
PR #21068 closed (ZERO); #21201 merged (poll test); #20475 closed.
mrveiss commentedon Nov 21, 2026
Read-only host check, 2026-11-21 02:43 Riga. The deployed commit is
bcd41c623d, which includes the #20466 AC2/AC3 code and theprobe_pid_identitymismatch logging.probe_pid_identitymismatch warnings over 7 days of logs: 0. Mentions of "revok": 0. Instrument check: the same log carries 148 WARNING lines, so warnings are being captured.AC1 (cause): cannot tell. The revocation hasn't reproduced since the update, but no run has had the chance. AC4 (a scheduled run posts its comment): not met. No scheduled run picked up work, so no comment could be posted. Run and comment rows were not queried (no read-only database credential).