agent-control-plane 0.2.0 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +69 -19
  2. package/assets/workflow-catalog.json +1 -1
  3. package/bin/pr-risk.sh +22 -7
  4. package/bin/sync-pr-labels.sh +1 -1
  5. package/hooks/heartbeat-hooks.sh +125 -12
  6. package/hooks/issue-reconcile-hooks.sh +1 -1
  7. package/hooks/pr-reconcile-hooks.sh +1 -1
  8. package/npm/bin/agent-control-plane.js +296 -61
  9. package/package.json +11 -7
  10. package/tools/bin/agent-github-update-labels +36 -2
  11. package/tools/bin/agent-project-catch-up-merged-prs +4 -2
  12. package/tools/bin/agent-project-cleanup-session +49 -5
  13. package/tools/bin/agent-project-heartbeat-loop +119 -1471
  14. package/tools/bin/agent-project-publish-issue-pr +6 -3
  15. package/tools/bin/agent-project-reconcile-issue-session +78 -106
  16. package/tools/bin/agent-project-reconcile-pr-session +166 -143
  17. package/tools/bin/agent-project-retry-state +18 -7
  18. package/tools/bin/agent-project-run-claude-session +10 -0
  19. package/tools/bin/agent-project-run-codex-resilient +99 -14
  20. package/tools/bin/agent-project-run-codex-session +16 -5
  21. package/tools/bin/agent-project-run-kilo-session +10 -0
  22. package/tools/bin/agent-project-run-openclaw-session +10 -0
  23. package/tools/bin/agent-project-run-opencode-session +10 -0
  24. package/tools/bin/agent-project-sync-source-repo-main +163 -0
  25. package/tools/bin/agent-project-worker-status +10 -7
  26. package/tools/bin/cleanup-worktree.sh +6 -1
  27. package/tools/bin/flow-config-lib.sh +1257 -34
  28. package/tools/bin/flow-resident-worker-lib.sh +119 -1
  29. package/tools/bin/flow-shell-lib.sh +56 -0
  30. package/tools/bin/github-core-rate-limit-state.sh +77 -0
  31. package/tools/bin/github-write-outbox.sh +470 -0
  32. package/tools/bin/heartbeat-loop-cache-lib.sh +164 -0
  33. package/tools/bin/heartbeat-loop-counting-lib.sh +306 -0
  34. package/tools/bin/heartbeat-loop-pr-strategy-lib.sh +199 -0
  35. package/tools/bin/heartbeat-loop-scheduling-lib.sh +506 -0
  36. package/tools/bin/heartbeat-loop-worker-lib.sh +319 -0
  37. package/tools/bin/heartbeat-recovery-preflight.sh +12 -1
  38. package/tools/bin/heartbeat-safe-auto.sh +56 -3
  39. package/tools/bin/install-project-launchd.sh +17 -2
  40. package/tools/bin/project-init.sh +21 -1
  41. package/tools/bin/project-launchd-bootstrap.sh +16 -9
  42. package/tools/bin/project-runtimectl.sh +46 -2
  43. package/tools/bin/reconcile-bootstrap-lib.sh +113 -0
  44. package/tools/bin/resident-issue-controller-lib.sh +448 -0
  45. package/tools/bin/scaffold-profile.sh +61 -3
  46. package/tools/bin/start-pr-fix-worker.sh +47 -10
  47. package/tools/bin/start-resident-issue-loop.sh +28 -439
  48. package/tools/dashboard/app.js +37 -1
  49. package/tools/dashboard/dashboard_snapshot.py +65 -26
  50. package/tools/templates/pr-fix-template.md +3 -1
  51. package/tools/templates/pr-merge-repair-template.md +2 -1
  52. package/SKILL.md +0 -149
  53. package/references/architecture.md +0 -217
  54. package/references/commands.md +0 -128
  55. package/references/control-plane-map.md +0 -124
  56. package/references/docs-map.md +0 -73
  57. package/references/release-checklist.md +0 -65
  58. package/references/repo-map.md +0 -36
  59. package/tools/bin/split-retained-slice.sh +0 -124
@@ -159,16 +159,32 @@ issue_pending_file() {
159
159
  printf '%s/issue-%s.pid\n' "${PENDING_LAUNCH_DIR}" "${issue_id}"
160
160
  }
161
161
 
162
- controller_unregister_pending_issue() {
163
- local issue_id="${1:-${ISSUE_ID:-}}"
164
- [[ -n "${issue_id}" ]] || return 0
165
- rm -f "$(issue_pending_file "${issue_id}")"
166
- }
167
-
168
- controller_register_pending_issue() {
169
- [[ -n "${ISSUE_ID:-}" ]] || return 0
170
- printf '%s\n' "$$" >"$(issue_pending_file "${ISSUE_ID}")"
171
- }
162
+ RESIDENT_CONTROLLER_LIB=""
163
+ for _rcl_candidate in \
164
+ "${SCRIPT_DIR}/resident-issue-controller-lib.sh" \
165
+ "${AGENT_CONTROL_PLANE_ROOT:-}/tools/bin/resident-issue-controller-lib.sh" \
166
+ "${ACP_ROOT:-}/tools/bin/resident-issue-controller-lib.sh" \
167
+ "${SHARED_AGENT_HOME:-}/tools/bin/resident-issue-controller-lib.sh"; do
168
+ if [[ -n "${_rcl_candidate}" && -f "${_rcl_candidate}" ]]; then
169
+ RESIDENT_CONTROLLER_LIB="${_rcl_candidate}"
170
+ break
171
+ fi
172
+ done
173
+ if [[ -n "${SHARED_AGENT_HOME:-}" && -z "${RESIDENT_CONTROLLER_LIB}" ]]; then
174
+ for _rcl_skill in "${AGENT_CONTROL_PLANE_SKILL_NAME:-agent-control-plane}" "${AGENT_CONTROL_PLANE_COMPAT_ALIAS:-}"; do
175
+ [[ -n "${_rcl_skill}" ]] || continue
176
+ _rcl_candidate="${SHARED_AGENT_HOME}/skills/openclaw/${_rcl_skill}/tools/bin/resident-issue-controller-lib.sh"
177
+ if [[ -f "${_rcl_candidate}" ]]; then
178
+ RESIDENT_CONTROLLER_LIB="${_rcl_candidate}"
179
+ break
180
+ fi
181
+ done
182
+ fi
183
+ if [[ -z "${RESIDENT_CONTROLLER_LIB}" ]]; then
184
+ echo "unable to locate resident-issue-controller-lib.sh" >&2
185
+ exit 1
186
+ fi
187
+ source "${RESIDENT_CONTROLLER_LIB}"
172
188
 
173
189
  issue_id_is_recurring() {
174
190
  local issue_id="${1:?issue id required}"
@@ -190,161 +206,6 @@ issue_id_is_scheduled() {
190
206
  issue_json_is_scheduled "$(issue_json_for "${issue_id}" 2>/dev/null || printf '{}\n')"
191
207
  }
192
208
 
193
- controller_refresh_execution_context() {
194
- unset \
195
- ACP_CODING_WORKER \
196
- ACP_CODEX_PROFILE_SAFE F_LOSNING_CODEX_PROFILE_SAFE \
197
- ACP_CODEX_PROFILE_BYPASS F_LOSNING_CODEX_PROFILE_BYPASS \
198
- ACP_CLAUDE_MODEL F_LOSNING_CLAUDE_MODEL \
199
- ACP_CLAUDE_PERMISSION_MODE F_LOSNING_CLAUDE_PERMISSION_MODE \
200
- ACP_CLAUDE_EFFORT F_LOSNING_CLAUDE_EFFORT \
201
- ACP_CLAUDE_TIMEOUT_SECONDS F_LOSNING_CLAUDE_TIMEOUT_SECONDS \
202
- ACP_CLAUDE_MAX_ATTEMPTS F_LOSNING_CLAUDE_MAX_ATTEMPTS \
203
- ACP_CLAUDE_RETRY_BACKOFF_SECONDS F_LOSNING_CLAUDE_RETRY_BACKOFF_SECONDS \
204
- ACP_OPENCLAW_MODEL F_LOSNING_OPENCLAW_MODEL \
205
- ACP_OPENCLAW_THINKING F_LOSNING_OPENCLAW_THINKING \
206
- ACP_OPENCLAW_TIMEOUT_SECONDS F_LOSNING_OPENCLAW_TIMEOUT_SECONDS \
207
- ACP_OPENCLAW_STALL_SECONDS F_LOSNING_OPENCLAW_STALL_SECONDS \
208
- ACP_ACTIVE_PROVIDER_POOL_NAME F_LOSNING_ACTIVE_PROVIDER_POOL_NAME \
209
- ACP_ACTIVE_PROVIDER_BACKEND F_LOSNING_ACTIVE_PROVIDER_BACKEND \
210
- ACP_ACTIVE_PROVIDER_MODEL F_LOSNING_ACTIVE_PROVIDER_MODEL \
211
- ACP_ACTIVE_PROVIDER_KEY F_LOSNING_ACTIVE_PROVIDER_KEY \
212
- ACP_PROVIDER_POOLS_EXHAUSTED F_LOSNING_PROVIDER_POOLS_EXHAUSTED \
213
- ACP_PROVIDER_POOL_SELECTION_REASON F_LOSNING_PROVIDER_POOL_SELECTION_REASON \
214
- ACP_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH \
215
- ACP_PROVIDER_POOL_NEXT_ATTEMPT_AT F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_AT \
216
- ACP_PROVIDER_POOL_LAST_REASON F_LOSNING_PROVIDER_POOL_LAST_REASON
217
- flow_export_execution_env "${CONFIG_YAML}"
218
- flow_export_project_env_aliases
219
- CODING_WORKER="${ACP_CODING_WORKER:-codex}"
220
- controller_capture_active_provider_context
221
- }
222
-
223
- controller_refresh_issue_lane_context() {
224
- local is_scheduled="${1:-no}"
225
- local schedule_interval_seconds="${2:-0}"
226
-
227
- if [[ "${is_scheduled}" == "yes" ]]; then
228
- ACTIVE_RESIDENT_LANE_KIND="scheduled"
229
- ACTIVE_RESIDENT_LANE_VALUE="${schedule_interval_seconds}"
230
- else
231
- ACTIVE_RESIDENT_LANE_KIND="recurring"
232
- ACTIVE_RESIDENT_LANE_VALUE="general"
233
- fi
234
-
235
- ACTIVE_RESIDENT_WORKER_KEY="$(flow_resident_issue_lane_key "${CODING_WORKER}" "${MODE}" "${ACTIVE_RESIDENT_LANE_KIND}" "${ACTIVE_RESIDENT_LANE_VALUE}")"
236
- ACTIVE_RESIDENT_META_FILE="$(flow_resident_issue_lane_meta_file "${CONFIG_YAML}" "${ACTIVE_RESIDENT_WORKER_KEY}")"
237
- }
238
-
239
- controller_live_lane_peer() {
240
- [[ -n "${ACTIVE_RESIDENT_WORKER_KEY}" ]] || return 1
241
- flow_resident_live_issue_controller_for_key "${CONFIG_YAML}" "${ACTIVE_RESIDENT_WORKER_KEY}" "$$" || return 1
242
- }
243
-
244
- controller_yield_to_live_lane_peer() {
245
- local live_controller=""
246
- local controller_issue_id=""
247
- local controller_state=""
248
-
249
- live_controller="$(controller_live_lane_peer || true)"
250
- [[ -n "${live_controller}" ]] || return 1
251
-
252
- controller_issue_id="$(awk -F= '/^ISSUE_ID=/{print $2; exit}' <<<"${live_controller}")"
253
- controller_state="$(awk -F= '/^CONTROLLER_STATE=/{print $2; exit}' <<<"${live_controller}")"
254
-
255
- if [[ -n "${controller_issue_id}" && "${controller_issue_id}" != "${ISSUE_ID}" ]]; then
256
- flow_resident_issue_enqueue "${CONFIG_YAML}" "${ISSUE_ID}" "resident-live-lane" >/dev/null || true
257
- CONTROLLER_REASON="live-lane-controller-${controller_issue_id}-${controller_state:-running}"
258
- else
259
- CONTROLLER_REASON="duplicate-live-lane-controller"
260
- fi
261
-
262
- return 0
263
- }
264
-
265
- controller_capture_active_provider_context() {
266
- ACTIVE_PROVIDER_POOL_NAME="${ACP_ACTIVE_PROVIDER_POOL_NAME:-${F_LOSNING_ACTIVE_PROVIDER_POOL_NAME:-}}"
267
- ACTIVE_PROVIDER_BACKEND="${ACP_ACTIVE_PROVIDER_BACKEND:-${F_LOSNING_ACTIVE_PROVIDER_BACKEND:-${CODING_WORKER:-}}}"
268
- ACTIVE_PROVIDER_MODEL="${ACP_ACTIVE_PROVIDER_MODEL:-${F_LOSNING_ACTIVE_PROVIDER_MODEL:-}}"
269
- ACTIVE_PROVIDER_KEY="${ACP_ACTIVE_PROVIDER_KEY:-${F_LOSNING_ACTIVE_PROVIDER_KEY:-}}"
270
- ACTIVE_PROVIDER_SELECTION_REASON="${ACP_PROVIDER_POOL_SELECTION_REASON:-${F_LOSNING_PROVIDER_POOL_SELECTION_REASON:-}}"
271
- ACTIVE_PROVIDER_NEXT_ATTEMPT_EPOCH="${ACP_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH:-${F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH:-}}"
272
- ACTIVE_PROVIDER_NEXT_ATTEMPT_AT="${ACP_PROVIDER_POOL_NEXT_ATTEMPT_AT:-${F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_AT:-}}"
273
- ACTIVE_PROVIDER_LAST_REASON="${ACP_PROVIDER_POOL_LAST_REASON:-${F_LOSNING_PROVIDER_POOL_LAST_REASON:-}}"
274
-
275
- if [[ -z "${ACTIVE_PROVIDER_MODEL}" ]]; then
276
- case "${ACTIVE_PROVIDER_BACKEND}" in
277
- openclaw)
278
- ACTIVE_PROVIDER_MODEL="${ACP_OPENCLAW_MODEL:-${F_LOSNING_OPENCLAW_MODEL:-}}"
279
- ;;
280
- claude)
281
- ACTIVE_PROVIDER_MODEL="${ACP_CLAUDE_MODEL:-${F_LOSNING_CLAUDE_MODEL:-}}"
282
- ;;
283
- codex)
284
- ACTIVE_PROVIDER_MODEL="${ACP_CODEX_PROFILE_SAFE:-${F_LOSNING_CODEX_PROFILE_SAFE:-}}"
285
- ;;
286
- esac
287
- fi
288
-
289
- if [[ -z "${ACTIVE_PROVIDER_KEY}" && -n "${ACTIVE_PROVIDER_BACKEND}" && -n "${ACTIVE_PROVIDER_MODEL}" ]]; then
290
- ACTIVE_PROVIDER_KEY="$(flow_sanitize_provider_key "${ACTIVE_PROVIDER_BACKEND}-${ACTIVE_PROVIDER_MODEL}")"
291
- fi
292
- }
293
-
294
- controller_set_recorded_provider_from_active() {
295
- LAST_RECORDED_PROVIDER_POOL_NAME="${ACTIVE_PROVIDER_POOL_NAME}"
296
- LAST_RECORDED_PROVIDER_BACKEND="${ACTIVE_PROVIDER_BACKEND}"
297
- LAST_RECORDED_PROVIDER_MODEL="${ACTIVE_PROVIDER_MODEL}"
298
- LAST_RECORDED_PROVIDER_KEY="${ACTIVE_PROVIDER_KEY}"
299
- }
300
-
301
- controller_mark_provider_launched() {
302
- LAST_LAUNCHED_PROVIDER_POOL_NAME="${ACTIVE_PROVIDER_POOL_NAME}"
303
- LAST_LAUNCHED_PROVIDER_BACKEND="${ACTIVE_PROVIDER_BACKEND}"
304
- LAST_LAUNCHED_PROVIDER_MODEL="${ACTIVE_PROVIDER_MODEL}"
305
- LAST_LAUNCHED_PROVIDER_KEY="${ACTIVE_PROVIDER_KEY}"
306
-
307
- if [[ -z "${LAST_RECORDED_PROVIDER_KEY}" ]]; then
308
- controller_set_recorded_provider_from_active
309
- fi
310
- }
311
-
312
- controller_track_provider_selection() {
313
- local reason="${1:-provider-selection}"
314
- local now_at=""
315
-
316
- [[ -n "${ACTIVE_PROVIDER_KEY}" ]] || return 0
317
-
318
- if [[ -z "${LAST_RECORDED_PROVIDER_KEY}" ]]; then
319
- controller_set_recorded_provider_from_active
320
- return 0
321
- fi
322
-
323
- if [[ "${ACTIVE_PROVIDER_KEY}" == "${LAST_RECORDED_PROVIDER_KEY}" ]]; then
324
- return 0
325
- fi
326
-
327
- now_at="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
328
- PROVIDER_SWITCH_COUNT=$((PROVIDER_SWITCH_COUNT + 1))
329
- LAST_PROVIDER_SWITCH_AT="${now_at}"
330
- LAST_PROVIDER_SWITCH_REASON="${reason}"
331
- LAST_PROVIDER_FROM_POOL_NAME="${LAST_RECORDED_PROVIDER_POOL_NAME}"
332
- LAST_PROVIDER_FROM_BACKEND="${LAST_RECORDED_PROVIDER_BACKEND}"
333
- LAST_PROVIDER_FROM_MODEL="${LAST_RECORDED_PROVIDER_MODEL}"
334
- LAST_PROVIDER_FROM_KEY="${LAST_RECORDED_PROVIDER_KEY}"
335
- LAST_PROVIDER_TO_POOL_NAME="${ACTIVE_PROVIDER_POOL_NAME}"
336
- LAST_PROVIDER_TO_BACKEND="${ACTIVE_PROVIDER_BACKEND}"
337
- LAST_PROVIDER_TO_MODEL="${ACTIVE_PROVIDER_MODEL}"
338
- LAST_PROVIDER_TO_KEY="${ACTIVE_PROVIDER_KEY}"
339
-
340
- if [[ "${reason}" == "provider-failover" ]]; then
341
- PROVIDER_FAILOVER_COUNT=$((PROVIDER_FAILOVER_COUNT + 1))
342
- LAST_PROVIDER_FAILOVER_AT="${now_at}"
343
- fi
344
-
345
- controller_set_recorded_provider_from_active
346
- }
347
-
348
209
  select_next_recurring_issue_id() {
349
210
  local candidate_id=""
350
211
 
@@ -371,274 +232,6 @@ select_next_recurring_issue_id() {
371
232
  return 1
372
233
  }
373
234
 
374
- controller_adopt_issue() {
375
- local next_issue_id="${1:?issue id required}"
376
- local previous_issue_id="${ISSUE_ID:-}"
377
- local previous_controller_file="${CONTROLLER_FILE:-}"
378
-
379
- if [[ -n "${previous_issue_id}" && "${previous_issue_id}" != "${next_issue_id}" ]]; then
380
- controller_unregister_pending_issue "${previous_issue_id}"
381
- if [[ -n "${previous_controller_file}" && -f "${previous_controller_file}" ]]; then
382
- rm -f "${previous_controller_file}"
383
- fi
384
- fi
385
-
386
- ISSUE_ID="${next_issue_id}"
387
- SESSION="${ISSUE_SESSION_PREFIX}${ISSUE_ID}"
388
- CONTROLLER_FILE="$(flow_resident_issue_controller_file "${CONFIG_YAML}" "${ISSUE_ID}")"
389
- RESIDENT_META_FILE="$(flow_resident_issue_meta_file "${CONFIG_YAML}" "${ISSUE_ID}")"
390
- CONTROLLER_LOOP_COUNT="0"
391
- NEXT_WAKE_EPOCH=""
392
- NEXT_WAKE_AT=""
393
- IDLE_WAIT_STARTED_EPOCH=""
394
- ACTIVE_RESIDENT_WORKER_KEY=""
395
- ACTIVE_RESIDENT_META_FILE=""
396
- ACTIVE_RESIDENT_LANE_KIND=""
397
- ACTIVE_RESIDENT_LANE_VALUE=""
398
- }
399
-
400
- controller_mark_issue_running() {
401
- local is_heavy="no"
402
-
403
- if declare -F heartbeat_issue_is_heavy >/dev/null 2>&1; then
404
- is_heavy="$(heartbeat_issue_is_heavy "${ISSUE_ID}" 2>/dev/null || printf 'no\n')"
405
- fi
406
-
407
- if declare -F heartbeat_mark_issue_running >/dev/null 2>&1; then
408
- heartbeat_mark_issue_running "${ISSUE_ID}" "${is_heavy}" >/dev/null 2>&1 || true
409
- fi
410
- }
411
-
412
- controller_rollback_issue_launch() {
413
- if declare -F heartbeat_issue_launch_failed >/dev/null 2>&1; then
414
- heartbeat_issue_launch_failed "${ISSUE_ID}" >/dev/null 2>&1 || true
415
- fi
416
- }
417
-
418
- controller_adopt_next_recurring_issue() {
419
- local next_issue_id=""
420
- local claim_out=""
421
- local claim_file=""
422
-
423
- claim_out="$(flow_resident_issue_claim_next "${CONFIG_YAML}" "${SESSION}" "${ISSUE_ID}" || true)"
424
- next_issue_id="$(awk -F= '/^ISSUE_ID=/{print $2}' <<<"${claim_out}")"
425
- claim_file="$(awk -F= '/^CLAIM_FILE=/{print $2}' <<<"${claim_out}")"
426
- if [[ -z "${next_issue_id}" ]]; then
427
- next_issue_id="$(select_next_recurring_issue_id || true)"
428
- fi
429
- [[ -n "${next_issue_id}" ]] || return 1
430
-
431
- controller_adopt_issue "${next_issue_id}"
432
- flow_resident_issue_release_claim "${claim_file}"
433
- CONTROLLER_REASON="adopted-next-recurring-issue"
434
- controller_write_state "adopting-issue" ""
435
- return 0
436
- }
437
-
438
- controller_wait_for_leased_issue() {
439
- local idle_timeout="${IDLE_TIMEOUT_SECONDS:-0}"
440
- local now_epoch=""
441
-
442
- case "${idle_timeout}" in
443
- ''|*[!0-9]*) idle_timeout="0" ;;
444
- esac
445
-
446
- if [[ "${idle_timeout}" -le 0 ]]; then
447
- return 1
448
- fi
449
-
450
- if [[ -z "${IDLE_WAIT_STARTED_EPOCH}" ]]; then
451
- IDLE_WAIT_STARTED_EPOCH="$(date +%s)"
452
- fi
453
-
454
- while true; do
455
- if controller_adopt_next_recurring_issue; then
456
- return 0
457
- fi
458
-
459
- now_epoch="$(date +%s)"
460
- if (( now_epoch - IDLE_WAIT_STARTED_EPOCH >= idle_timeout )); then
461
- CONTROLLER_REASON="idle-timeout"
462
- return 1
463
- fi
464
-
465
- controller_write_state "idle" ""
466
- sleep "${POLL_SECONDS}"
467
- done
468
- }
469
-
470
- controller_write_state() {
471
- local state="${1:?state required}"
472
- local reason="${2:-${CONTROLLER_REASON}}"
473
-
474
- CONTROLLER_STATE="${state}"
475
- CONTROLLER_REASON="${reason}"
476
- flow_resident_write_metadata "${CONTROLLER_FILE}" \
477
- "ISSUE_ID=${ISSUE_ID}" \
478
- "SESSION=${SESSION}" \
479
- "CONTROLLER_PID=$$" \
480
- "CONTROLLER_MODE=${MODE}" \
481
- "CONTROLLER_LOOP_COUNT=${CONTROLLER_LOOP_COUNT}" \
482
- "CONTROLLER_STATE=${CONTROLLER_STATE}" \
483
- "CONTROLLER_REASON=${CONTROLLER_REASON}" \
484
- "ACTIVE_RESIDENT_WORKER_KEY=${ACTIVE_RESIDENT_WORKER_KEY}" \
485
- "ACTIVE_RESIDENT_LANE_KIND=${ACTIVE_RESIDENT_LANE_KIND}" \
486
- "ACTIVE_RESIDENT_LANE_VALUE=${ACTIVE_RESIDENT_LANE_VALUE}" \
487
- "ACTIVE_PROVIDER_POOL_NAME=${ACTIVE_PROVIDER_POOL_NAME}" \
488
- "ACTIVE_PROVIDER_BACKEND=${ACTIVE_PROVIDER_BACKEND}" \
489
- "ACTIVE_PROVIDER_MODEL=${ACTIVE_PROVIDER_MODEL}" \
490
- "ACTIVE_PROVIDER_KEY=${ACTIVE_PROVIDER_KEY}" \
491
- "ACTIVE_PROVIDER_SELECTION_REASON=${ACTIVE_PROVIDER_SELECTION_REASON}" \
492
- "ACTIVE_PROVIDER_NEXT_ATTEMPT_EPOCH=${ACTIVE_PROVIDER_NEXT_ATTEMPT_EPOCH}" \
493
- "ACTIVE_PROVIDER_NEXT_ATTEMPT_AT=${ACTIVE_PROVIDER_NEXT_ATTEMPT_AT}" \
494
- "ACTIVE_PROVIDER_LAST_REASON=${ACTIVE_PROVIDER_LAST_REASON}" \
495
- "LAST_LAUNCHED_PROVIDER_POOL_NAME=${LAST_LAUNCHED_PROVIDER_POOL_NAME}" \
496
- "LAST_LAUNCHED_PROVIDER_BACKEND=${LAST_LAUNCHED_PROVIDER_BACKEND}" \
497
- "LAST_LAUNCHED_PROVIDER_MODEL=${LAST_LAUNCHED_PROVIDER_MODEL}" \
498
- "LAST_LAUNCHED_PROVIDER_KEY=${LAST_LAUNCHED_PROVIDER_KEY}" \
499
- "PROVIDER_SWITCH_COUNT=${PROVIDER_SWITCH_COUNT}" \
500
- "PROVIDER_FAILOVER_COUNT=${PROVIDER_FAILOVER_COUNT}" \
501
- "LAST_PROVIDER_SWITCH_AT=${LAST_PROVIDER_SWITCH_AT}" \
502
- "LAST_PROVIDER_SWITCH_REASON=${LAST_PROVIDER_SWITCH_REASON}" \
503
- "LAST_PROVIDER_FROM_POOL_NAME=${LAST_PROVIDER_FROM_POOL_NAME}" \
504
- "LAST_PROVIDER_FROM_BACKEND=${LAST_PROVIDER_FROM_BACKEND}" \
505
- "LAST_PROVIDER_FROM_MODEL=${LAST_PROVIDER_FROM_MODEL}" \
506
- "LAST_PROVIDER_FROM_KEY=${LAST_PROVIDER_FROM_KEY}" \
507
- "LAST_PROVIDER_TO_POOL_NAME=${LAST_PROVIDER_TO_POOL_NAME}" \
508
- "LAST_PROVIDER_TO_BACKEND=${LAST_PROVIDER_TO_BACKEND}" \
509
- "LAST_PROVIDER_TO_MODEL=${LAST_PROVIDER_TO_MODEL}" \
510
- "LAST_PROVIDER_TO_KEY=${LAST_PROVIDER_TO_KEY}" \
511
- "LAST_PROVIDER_FAILOVER_AT=${LAST_PROVIDER_FAILOVER_AT}" \
512
- "PROVIDER_WAIT_COUNT=${PROVIDER_WAIT_COUNT}" \
513
- "PROVIDER_WAIT_TOTAL_SECONDS=${PROVIDER_WAIT_TOTAL_SECONDS}" \
514
- "PROVIDER_LAST_WAIT_SECONDS=${PROVIDER_LAST_WAIT_SECONDS}" \
515
- "PROVIDER_LAST_WAIT_STARTED_AT=${PROVIDER_LAST_WAIT_STARTED_AT}" \
516
- "PROVIDER_LAST_WAIT_COMPLETED_AT=${PROVIDER_LAST_WAIT_COMPLETED_AT}" \
517
- "NEXT_WAKE_EPOCH=${NEXT_WAKE_EPOCH}" \
518
- "NEXT_WAKE_AT=${NEXT_WAKE_AT}" \
519
- "UPDATED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
520
-
521
- if [[ "${CONTROLLER_STATE}" == "stopped" ]]; then
522
- controller_unregister_pending_issue "${ISSUE_ID}"
523
- elif flow_resident_issue_controller_counts_as_pending "${CONTROLLER_STATE}"; then
524
- controller_register_pending_issue
525
- else
526
- controller_unregister_pending_issue "${ISSUE_ID}"
527
- fi
528
- }
529
-
530
- controller_last_failure_reason() {
531
- local metadata_file="${ACTIVE_RESIDENT_META_FILE:-${RESIDENT_META_FILE:-}}"
532
- [[ -n "${metadata_file}" && -f "${metadata_file}" ]] || return 1
533
- awk -F= '/^LAST_FAILURE_REASON=/{print $2; exit}' "${metadata_file}" 2>/dev/null | tr -d '"' || true
534
- }
535
-
536
- controller_provider_state() {
537
- local provider_state_script="${FLOW_TOOLS_DIR}/provider-cooldown-state.sh"
538
- local provider_state=""
539
-
540
- if [[ ! -x "${provider_state_script}" ]]; then
541
- printf 'READY=yes\n'
542
- return 0
543
- fi
544
-
545
- provider_state="$(
546
- env \
547
- -u ACP_CODING_WORKER \
548
- -u ACP_CODEX_PROFILE_SAFE -u F_LOSNING_CODEX_PROFILE_SAFE \
549
- -u ACP_CODEX_PROFILE_BYPASS -u F_LOSNING_CODEX_PROFILE_BYPASS \
550
- -u ACP_CLAUDE_MODEL -u F_LOSNING_CLAUDE_MODEL \
551
- -u ACP_CLAUDE_PERMISSION_MODE -u F_LOSNING_CLAUDE_PERMISSION_MODE \
552
- -u ACP_CLAUDE_EFFORT -u F_LOSNING_CLAUDE_EFFORT \
553
- -u ACP_CLAUDE_TIMEOUT_SECONDS -u F_LOSNING_CLAUDE_TIMEOUT_SECONDS \
554
- -u ACP_CLAUDE_MAX_ATTEMPTS -u F_LOSNING_CLAUDE_MAX_ATTEMPTS \
555
- -u ACP_CLAUDE_RETRY_BACKOFF_SECONDS -u F_LOSNING_CLAUDE_RETRY_BACKOFF_SECONDS \
556
- -u ACP_OPENCLAW_MODEL -u F_LOSNING_OPENCLAW_MODEL \
557
- -u ACP_OPENCLAW_THINKING -u F_LOSNING_OPENCLAW_THINKING \
558
- -u ACP_OPENCLAW_TIMEOUT_SECONDS -u F_LOSNING_OPENCLAW_TIMEOUT_SECONDS \
559
- -u ACP_ACTIVE_PROVIDER_POOL_NAME -u F_LOSNING_ACTIVE_PROVIDER_POOL_NAME \
560
- -u ACP_ACTIVE_PROVIDER_BACKEND -u F_LOSNING_ACTIVE_PROVIDER_BACKEND \
561
- -u ACP_ACTIVE_PROVIDER_MODEL -u F_LOSNING_ACTIVE_PROVIDER_MODEL \
562
- -u ACP_ACTIVE_PROVIDER_KEY -u F_LOSNING_ACTIVE_PROVIDER_KEY \
563
- -u ACP_PROVIDER_POOLS_EXHAUSTED -u F_LOSNING_PROVIDER_POOLS_EXHAUSTED \
564
- -u ACP_PROVIDER_POOL_SELECTION_REASON -u F_LOSNING_PROVIDER_POOL_SELECTION_REASON \
565
- -u ACP_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH -u F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_EPOCH \
566
- -u ACP_PROVIDER_POOL_NEXT_ATTEMPT_AT -u F_LOSNING_PROVIDER_POOL_NEXT_ATTEMPT_AT \
567
- -u ACP_PROVIDER_POOL_LAST_REASON -u F_LOSNING_PROVIDER_POOL_LAST_REASON \
568
- "${provider_state_script}" get 2>/dev/null || true
569
- )"
570
- if [[ -z "${provider_state}" ]]; then
571
- printf 'READY=yes\n'
572
- return 0
573
- fi
574
-
575
- printf '%s\n' "${provider_state}"
576
- }
577
-
578
- controller_wait_for_provider_capacity() {
579
- local provider_state=""
580
- local provider_ready=""
581
- local provider_next_epoch=""
582
- local provider_next_at=""
583
- local now_epoch=""
584
- local remaining=""
585
- local sleep_seconds=""
586
- local wait_started_epoch=""
587
- local wait_completed_epoch=""
588
-
589
- PROVIDER_WAITED="no"
590
-
591
- while true; do
592
- provider_state="$(controller_provider_state)"
593
- provider_ready="$(flow_kv_get "${provider_state}" "READY")"
594
- if [[ "${provider_ready}" == "yes" ]]; then
595
- if [[ -n "${wait_started_epoch}" ]]; then
596
- wait_completed_epoch="$(date +%s)"
597
- if (( wait_completed_epoch >= wait_started_epoch )); then
598
- PROVIDER_LAST_WAIT_SECONDS=$((wait_completed_epoch - wait_started_epoch))
599
- PROVIDER_WAIT_TOTAL_SECONDS=$((PROVIDER_WAIT_TOTAL_SECONDS + PROVIDER_LAST_WAIT_SECONDS))
600
- PROVIDER_LAST_WAIT_COMPLETED_AT="$(date -u -r "${wait_completed_epoch}" +"%Y-%m-%dT%H:%M:%SZ")"
601
- fi
602
- fi
603
- NEXT_WAKE_EPOCH=""
604
- NEXT_WAKE_AT=""
605
- return 0
606
- fi
607
-
608
- provider_next_epoch="$(flow_kv_get "${provider_state}" "NEXT_ATTEMPT_EPOCH")"
609
- provider_next_at="$(flow_kv_get "${provider_state}" "NEXT_ATTEMPT_AT")"
610
- if ! [[ "${provider_next_epoch}" =~ ^[0-9]+$ ]] || [[ "${provider_next_epoch}" == "0" ]]; then
611
- return 1
612
- fi
613
-
614
- if [[ -z "${wait_started_epoch}" ]]; then
615
- wait_started_epoch="$(date +%s)"
616
- PROVIDER_WAIT_COUNT=$((PROVIDER_WAIT_COUNT + 1))
617
- PROVIDER_LAST_WAIT_STARTED_AT="$(date -u -r "${wait_started_epoch}" +"%Y-%m-%dT%H:%M:%SZ")"
618
- fi
619
-
620
- PROVIDER_WAITED="yes"
621
- NEXT_WAKE_EPOCH="${provider_next_epoch}"
622
- NEXT_WAKE_AT="${provider_next_at}"
623
- CONTROLLER_REASON="provider-cooldown"
624
- controller_write_state "waiting-provider" ""
625
-
626
- now_epoch="$(date +%s)"
627
- remaining=$((provider_next_epoch - now_epoch))
628
- sleep_seconds="${POLL_SECONDS}"
629
- if ! [[ "${sleep_seconds}" =~ ^[1-9][0-9]*$ ]]; then
630
- sleep_seconds="60"
631
- fi
632
- if (( remaining > 0 && remaining < sleep_seconds )); then
633
- sleep_seconds="${remaining}"
634
- fi
635
- if (( sleep_seconds <= 0 )); then
636
- sleep_seconds="1"
637
- fi
638
- sleep "${sleep_seconds}"
639
- done
640
- }
641
-
642
235
  record_scheduled_next_due() {
643
236
  local interval_seconds="${1:-0}"
644
237
  local state_file now_epoch next_due_epoch
@@ -650,22 +243,18 @@ record_scheduled_next_due() {
650
243
  now_epoch="$(date +%s)"
651
244
  next_due_epoch=$((now_epoch + interval_seconds))
652
245
  NEXT_WAKE_EPOCH="${next_due_epoch}"
653
- NEXT_WAKE_AT="$(date -u -r "${next_due_epoch}" +"%Y-%m-%dT%H:%M:%SZ")"
246
+ NEXT_WAKE_AT="$(flow_format_epoch_utc "${next_due_epoch}")"
654
247
  state_file="${SCHEDULED_STATE_DIR}/${ISSUE_ID}.env"
655
248
  cat >"${state_file}" <<EOF
656
249
  INTERVAL_SECONDS=${interval_seconds}
657
250
  LAST_STARTED_EPOCH=${now_epoch}
658
- LAST_STARTED_AT=$(date -u -r "${now_epoch}" +"%Y-%m-%dT%H:%M:%SZ")
251
+ LAST_STARTED_AT=$(flow_format_epoch_utc "${now_epoch}")
659
252
  NEXT_DUE_EPOCH=${next_due_epoch}
660
253
  NEXT_DUE_AT=${NEXT_WAKE_AT}
661
254
  UPDATED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
662
255
  EOF
663
256
  }
664
257
 
665
- controller_cleanup() {
666
- controller_write_state "stopped" "${CONTROLLER_REASON:-stopped}"
667
- }
668
-
669
258
  trap 'CONTROLLER_REASON="${CONTROLLER_REASON:-terminated}"; controller_cleanup' EXIT
670
259
  trap 'CONTROLLER_REASON="interrupted"; exit 0' INT TERM
671
260
 
@@ -111,9 +111,10 @@ function renderOverview(snapshot) {
111
111
  acc.cooldowns += profile.counts.provider_cooldowns;
112
112
  acc.queue += profile.counts.queued_issues;
113
113
  acc.alerts += profile.counts.alerts || 0;
114
+ acc.pendingGithubWrites += profile.counts.pending_github_writes || 0;
114
115
  return acc;
115
116
  },
116
- { activeRuns: 0, runningRuns: 0, implementedRuns: 0, reportedRuns: 0, blockedRuns: 0, controllers: 0, cooldowns: 0, queue: 0, alerts: 0 },
117
+ { activeRuns: 0, runningRuns: 0, implementedRuns: 0, reportedRuns: 0, blockedRuns: 0, controllers: 0, cooldowns: 0, queue: 0, alerts: 0, pendingGithubWrites: 0 },
117
118
  );
118
119
 
119
120
  overviewNode.innerHTML = [
@@ -125,6 +126,7 @@ function renderOverview(snapshot) {
125
126
  ["Blocked", totals.blockedRuns],
126
127
  ["Live Controllers", totals.controllers],
127
128
  ["Provider Cooldowns", totals.cooldowns],
129
+ ["Pending GitHub Writes", totals.pendingGithubWrites],
128
130
  ["Alerts", totals.alerts],
129
131
  ["Queued Issues", totals.queue],
130
132
  ]
@@ -219,6 +221,9 @@ function renderProfile(profile) {
219
221
  ? `<span class="badge">${profile.provider_pool.backend}: ${profile.provider_pool.model || "n/a"}</span>`
220
222
  : "",
221
223
  profile.provider_pool.name ? `<span class="badge">${profile.provider_pool.name}</span>` : "",
224
+ profile.provider_pool.pools_exhausted
225
+ ? `<span class="badge warn">pools exhausted</span>`
226
+ : "",
222
227
  profile.provider_pool.last_reason ? `<span class="badge warn">${profile.provider_pool.last_reason}</span>` : "",
223
228
  ]
224
229
  .filter(Boolean)
@@ -234,6 +239,8 @@ function renderProfile(profile) {
234
239
  ["Live controllers", profile.counts.live_resident_controllers],
235
240
  ["Stale controllers", profile.counts.stale_resident_controllers],
236
241
  ["Provider cooldowns", profile.counts.provider_cooldowns],
242
+ ["Pending GitHub writes", profile.counts.pending_github_writes || 0],
243
+ ["Failed GitHub writes", profile.counts.failed_github_writes || 0],
237
244
  ["Alerts", profile.counts.alerts || 0],
238
245
  ["Issue retries", profile.counts.active_retries],
239
246
  ["Queued issues", profile.counts.queued_issues],
@@ -280,6 +287,7 @@ function renderProfile(profile) {
280
287
  [
281
288
  { label: "Issue", key: "issue_id" },
282
289
  { label: "State", render: renderControllerState },
290
+ { label: "Lane", render: (row) => `${row.lane_kind || "n/a"} / ${row.lane_value || "n/a"}` },
283
291
  { label: "Reason", render: (row) => row.reason || "n/a" },
284
292
  { label: "Provider", render: (row) => `${row.provider_backend || "n/a"} ${row.provider_model || ""}`.trim() },
285
293
  { label: "Failover", render: (row) => `${row.provider_failover_count} failovers / ${row.provider_switch_count} switches` },
@@ -320,6 +328,7 @@ function renderProfile(profile) {
320
328
  { label: "Scope", key: "scope" },
321
329
  { label: "Worker", key: "coding_worker" },
322
330
  { label: "Issue", render: (row) => row.issue_id || "n/a" },
331
+ { label: "Lane", render: (row) => `${row.resident_lane_kind || "n/a"} / ${row.resident_lane_value || "n/a"}` },
323
332
  { label: "Tasks", key: "task_count" },
324
333
  { label: "Last status", render: (row) => row.last_status || "n/a" },
325
334
  { label: "Last started", render: (row) => row.last_started_at ? `${relativeTime(row.last_started_at)}<div class="muted">${row.last_started_at}</div>` : "n/a" },
@@ -355,6 +364,7 @@ function renderProfile(profile) {
355
364
  [
356
365
  { label: "Issue", key: "issue_id" },
357
366
  { label: "Session", render: (row) => row.session ? `<div class="mono">${row.session}</div>` : "n/a" },
367
+ { label: "Queued by", key: "queued_by" },
358
368
  { label: "Updated", render: (row) => row.updated_at ? `${relativeTime(row.updated_at)}<div class="muted">${row.updated_at}</div>` : "n/a" },
359
369
  ],
360
370
  profile.issue_queue.pending,
@@ -365,12 +375,33 @@ function renderProfile(profile) {
365
375
  [
366
376
  { label: "Issue", key: "issue_id" },
367
377
  { label: "Session", render: (row) => row.session ? `<div class="mono">${row.session}</div>` : "n/a" },
378
+ { label: "Claimed by", key: "claimer" },
368
379
  { label: "Updated", render: (row) => row.updated_at ? `${relativeTime(row.updated_at)}<div class="muted">${row.updated_at}</div>` : "n/a" },
369
380
  ],
370
381
  profile.issue_queue.claims || [],
371
382
  "No claimed issues.",
372
383
  );
373
384
 
385
+ const githubOutbox = profile.github_outbox || { counts: {}, pending: [] };
386
+ const githubOutboxTable = renderTable(
387
+ [
388
+ { label: "Type", render: (row) => row.type || "n/a" },
389
+ { label: "Target", render: (row) => `${row.kind || row.type || "write"} #${row.number || "?"}` },
390
+ {
391
+ label: "Payload",
392
+ render: (row) => {
393
+ if (row.type === "labels") {
394
+ return `+${row.add_count || 0} / -${row.remove_count || 0}`;
395
+ }
396
+ return row.body_preview || "n/a";
397
+ },
398
+ },
399
+ { label: "Created", render: (row) => row.created_at ? `${relativeTime(row.created_at)}<div class="muted">${row.created_at}</div>` : "n/a" },
400
+ ],
401
+ githubOutbox.pending || [],
402
+ "No pending GitHub write intents.",
403
+ );
404
+
374
405
  const codexRotationPanel =
375
406
  profile.coding_worker === "codex"
376
407
  ? `
@@ -445,6 +476,11 @@ function renderProfile(profile) {
445
476
  <h3>Claimed Issues</h3>
446
477
  ${claimsTable}
447
478
  </section>
479
+ <section class="panel">
480
+ <h3>GitHub Outbox</h3>
481
+ <p class="panel-subtitle">Local write intents queued while ACP defers or retries GitHub sync. Pending ${githubOutbox.counts?.pending || 0}, sent ${githubOutbox.counts?.sent || 0}, failed ${githubOutbox.counts?.failed || 0}.</p>
482
+ ${githubOutboxTable}
483
+ </section>
448
484
  </section>
449
485
  </article>
450
486
  `;