Skip to content

fix(automations): unblock non-sessionActivity agents, surface blocked delivery, and refactor automations - #3353

Open
zxch3n wants to merge 4 commits into
mainfrom
fix/auto-delivery-native-activity
Open

zxch3n wants to merge 4 commits into
mainfrom
fix/auto-delivery-native-activity

Conversation

@zxch3n

@zxch3n zxch3n commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix native_activity_unobserved deadlock for Auto delivery & Merge archive
    • AgentClient.getNativeActivityObservation() now distinguishes 'unsupported' (agents that do not advertise Core sessionActivity v1, such as Antigravity, Codex, Kimi, Pi) from authoritative 'idle' | 'running' | 'background' (defaulting to 'idle' before the first update under Core sessionActivity v1 replace semantics).
    • MessageHandler falls back to SessionActivePresence.native.hasLateActivity(sessionId) for 'unsupported' agents (matching GC and turn-completion semantics), and wakes session-blocked automation receipts immediately when onNativeWorkChanged transitions to null via AutomationLedger.wakeSessionBlocked.
  • Surface unexpected blocked Auto delivery receipts in UI
    • Adds request_blocked to SessionAutoDeliveryStallReason and optional blockReason to SessionAutoDelivery.
    • policies/delivery.ts keeps normal busy waits (session_work_active, queue_pending, native_work_active, etc.) in the active step state while surfacing other blocked receipts as reversible stalled (request_blocked + blockReason) instead of silently staying on Merging.
    • Updates SessionAutoDeliveryNote and en / zh_CN locales to render human-readable block reasons and a popover diagnostic row.
  • Modular refactor of apps/cli/src/automations/
    • Extracts DeliveryCoordinator, conditions/evaluator.ts, runtime/wait-evaluator.ts, control/command-handler.ts, and control/remote-control.ts out of workspace-legacy.ts (989 -> 360 lines).
    • Splits session-actions-legacy.ts (760 -> 160 lines) into archive-action.ts, compact-action.ts, invoke-action.ts, and unified sync/async receipt authorization in actions/authorization.ts.
    • Extracts SQLite DDL, v1-v4 migrations, and column projections into storage/schema.ts without changing indexes, query plans, or cross-table transactions, and removes policy-name hardcoding from engine.ts wokeDuringCheck.

Verification

  • pnpm format, pnpm check:quick (oxlint, boundary guards, i18n check, comment ratchet), pnpm check:typecheck (all 24 workspace packages), and pnpm run docs check all passed.
  • apps/cli automation & agent suites: 6 files / 128 tests passed (including EXPLAIN QUERY PLAN ratchet, v2->v4 migration, 200-run Auto delivery property test, blocked-delivery surfacing, and immediate idle wake).
  • packages/components Auto delivery UI suites: 2 files / 19 tests passed.

… delivery, and refactor automations

- Distinguish unsupported Core sessionActivity from authoritative idle/running/background
  observations in AgentClient (honoring replace semantics where no update yet = idle).
- Fall back to SessionActivePresence lateActivity for agents without sessionActivity
  in MessageHandler, aligning automations with GC and turn completion, and wake
  session-blocked receipts immediately when native work becomes idle.
- Surface non-busy blocked Auto delivery receipts as stalled (request_blocked +
  blockReason) in shared schema, delivery policy, and SessionAutoDeliveryNote UI.
- Decompose workspace-legacy, session-actions-legacy, and ledger schema/migrations
  into focused collaborators while preserving SQL query plans and transaction boundaries.

Model: gemini-4-neon-high
…ighten types and tests

- Collapse 8 shallow wrapper modules back into cohesive deep owners
  (authorization.ts, session-actions-legacy.ts, policies/delivery.ts,
  runtime/managed-runs.ts, control/commands.ts) and unify native work
  observation in AgentClient/MessageHandler.
- Harden Effect v4 lifecycle: promote ManagedRunsService to a scoped
  Layer with LIFO teardown before ledger.close(), share the wake queue
  via Layer.unwrap to remove startup races, migrate command routing and
  DeliveryCoordinator to Effect.fn/Effect.gen with explicit lock order,
  and gate all workspace boundary calls during close().
- Harden ledger.wakeSessionBlocked to wake all waiting states, preserve
  the MAX_SAFE_INTEGER capacity-push sentinel, and bump
  capacityWakeRevision to prevent stale backoff overwrites.
- Enforce invariants via discriminated unions on SessionAutoDelivery,
  ConditionObservation, ActionAuthorization, and DeliveryStepDecision,
  and document remaining runtime invariants in automations AGENTS.md/README.
- Tighten tests to pure unit and real-boundary integration coverage.

Model: gemini-4-neon-high
…ope, and dead code

- Add target_input_pending to SESSION_BUSY_BLOCK_REASONS (moved to
  storage/schema.ts to decouple policies/delivery.ts from
  session-automation-authority.ts) and add a 60s grace window
  (DELIVERY_TRANSIENT_BLOCK_GRACE_MS) for transient/unconfirmed blocks
  so normal retries do not flash stalled status or sidebar alerts.
- Narrow ledger.wakeSessionBlocked to state = 'blocked' receipts with
  session-busy reasons so quota estimatedReset/sentinel and waiting
  not_before timers are never spuriously woken or timestamp-bumped.
- Re-read fresh SessionMeta after await deps.capacity() in
  authorizeAutomationReceipt instead of reusing pre-refresh meta.
- Remove unreachable SessionNativeActivity 'unknown' / native_activity_unobserved
  code path and dead locale entries; format popover blockReason with
  localized labels.
- Add implemented EN/ZH Agent Note documenting the shared native-work
  contract, 30s non-reporting trade-off, idle wake scope, and 3-tier
  blocked delivery surfacing.

Model: gemini-4-neon-high

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant