Skip to content

feat(computer,agent): add dual-path Antigravity steer and waiting_background state - #748

Open
LeoXing1996 wants to merge 1 commit into
mainfrom
leo/whi-1027-agy-steer-background
Open

LeoXing1996 wants to merge 1 commit into
mainfrom
leo/whi-1027-agy-steer-background

Conversation

@LeoXing1996

Copy link
Copy Markdown
Contributor

What and why

Closes / implements WHI-1027 (【Antigravity】为 agy 实现双路径 Steer(Hook 注入 + 后台等待唤醒)并显式化 waiting_background 调度状态).

  1. Dual-path Antigravity steer (apps/computer/local-daemon):

    • Path A (active turn): AntigravitySharedHookEndpoint runs a daemon-wide loopback HTTP callback server paired with a generated .agents/hooks.json (linger-steer), forwarded by linger-computer-daemon antigravity-hook. During an active Antigravity turn, queued steers are delivered via the PreInvocation hook returning injectSteps (with camelCase hookEventName / conversationId / invocationNum / fullyIdle wire decoding matching Antigravity hooks).
    • Path B (waiting_background): When Antigravity's Stop hook fires with fullyIdle: false and no remaining tool calls, the turn transitions into explicit waiting_background instead of idling ambiguously. Incoming steers while waiting_background skip PreInvocation and wake the session directly via a concurrent/new session/prompt handover.
    • Emits run.background_waiting (with active background tool call descriptors) and run.background_resumed events, gated on operation_background_wait in runner.welcome's service_features.
  2. Explicit waiting_background scheduling & status (apps/node-services, apps/teamhub, apps/web, contracts):

    • Contracts: Adds operation_background_wait, run.background_waiting, run.background_resumed, and model_not_offered to contracts/runner-gateway/envelope.schema.json; adds waiting_background to contracts/openapi/components/agent-runtime-state.yaml and regenerates Go/TypeScript contract artifacts.
    • Node Services: Tracks phase ("running" | "waiting_background") and backgroundTools in RunnerOperationState, surfaces snake_case background_tools in RunnerOperations holders, translates run.background_waiting / run.background_resumed to status.changed in RemoteCodexProvider, and adds ModelLease.suspend() / resume() so the ModelQueue concurrency slot is yielded while waiting on background work.
    • TeamHub: Allows status: "waiting_background" (and optional non-empty title) in agentruntimestate/status.go.
    • Web: Projects waiting_background status in runtime-presentation-events.ts, message-timeline.tsx, runtime-status.messages.ts, and zh-CN.json.

How it was verified

  • Focused tests for the changed behavior
  • make check BASE=origin/<target-branch> or the fast checks of every touched app (individual targeted gates run instead of the top-level meta-target; CI covers the full matrix)
  • Contracts regenerated if contracts/openapi/ changed

Verified after final commit (1627fced8, which only appended docs in apps/node-services/src/agent/AGENTS.md):

  • make check-repository BASE=linger/main (env inventory + Prettier changed-file check)
  • make check-docs (111 Markdown files)
  • make check-contracts (contracts-verify OpenAPI/schema diff, 15 Vitest contract files / 74 tests, Go contract compilation)
  • make -C apps/teamhub fmt-check and go test ./internal/agentruntimestate/... ./tests/integration/layout -count=1
  • cd apps/computer/local-daemon && go test ./cmd/linger-computer-daemon ./internal/provider/native ./internal/provider ./internal/daemon -count=1
  • make -C apps/teamhub lint-go-daemon BASE=linger/main (0 issues on lint & doc-comments)

Verified on the code commit prior to the doc-only amend (AGENTS.md):

  • Node Services typecheck, lint, and targeted Vitest suites (model-queue.test.ts, remote-codex-provider.test.ts, runner-operations-public.test.ts, runner-gateway-local-models.test.ts, runtime-model-call.test.ts, runner-gateway-websocket.test.ts)
  • TeamHub lint-go BASE=main (0 issues)
  • Web typecheck, lint, react:doctor --base main (0 issues), and targeted Vitest suites (runtime-presentation-events.test.ts, runtime-activity-path.test.tsx, plus 82 related room tests)
  • Live local verification against isolated dev stack + bundled linger-computer-daemon: confirmed antigravity.hook.steer_injected injected steers across invocations during active Antigravity turns (steers/assign -> steers/complete)

Boundary

  • Docs updated: Added operation_background_wait, waiting_background, ModelLease.suspend()/resume(), and dual-path Antigravity steer behavior to apps/node-services/src/agent/AGENTS.md.
  • Critical path (user message -> provider_ready): Adds no network round trip and no file walk while the user waits. Antigravity startup reuses the daemon-wide loopback hook server and writes one small .agents/hooks.json manifest in the Context workspace; PreInvocation / Stop hooks run over local loopback HTTP only after the turn has started.
  • Compatibility: run.background_waiting and run.background_resumed are emitted only when runner.welcome's service_features includes operation_background_wait, preserving compatibility with older Agent Services (whose welcome feature list ignores unknown strings on older Daemons).

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes (1 P1, 1 P2, 2 P3)

Scope: base main, merge base f7f8bec7; 1 commit, 51 files reviewed at 1627fced. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.

Findings

P1

apps/computer/local-daemon/internal/provider/native/antigravity_runtime.go:1003 (also :929-942, :1068-1074): a wake with no steers queued wedges the turn for good

After awaitBackgroundOrWake() returns errAntigravityWake, the previous session/prompt has already returned end_turn, so no prompt is in flight. sendWakePrompt then re-takes the steers under the lock. If none are left it returns (false, nil), and the loop continues into select { case res = <-results: case <-t.wakeCh: }. Nothing ever writes to results, and that select does not watch t.runCtx.Done() or t.proc.conn.closed. The turn never produces an Outcome, and neither the Operation's cancel nor the process exiting can end it. The same thing happens on the end_turn + hasSteers branch (:984): it releases the lock before sendWakePrompt takes the steers again.

The steer queue can be emptied between triggerWake() and sendWakePrompt in three ways, all of them reachable:

  • The caller's context is cancelled. steer() withdraws an unclaimed steer on ctx.Done() (:493-499), and that context is the Runner connection's context (daemon/operation_input.go:137). A steer sent while the turn is waiting_background, followed by a connection drop or reconnect, leaves a wake token with an empty queue.
  • The background continuation's PreInvocation hook claims the steers first. onHook calls takeSteersLocked() at :550 and runs concurrently with the main loop.
  • A wake token is left over from earlier. wakeCh is buffered, and a token can remain after the steers it announced were already delivered through PreInvocation.

Fix: have sendWakePrompt's "nothing sent" result return to awaitBackgroundOrWake() when no prompt is in flight (track an in-flight flag or count instead of discarding sent at :941), and add runCtx.Done() and conn.closed to the main select. Add a test that queues a steer during waiting_background, then withdraws it or drains it through PreInvocation before the wake is handled, and asserts the turn still finishes and can be cancelled.

P2

apps/node-services/src/agent/runner-gateway/remote-codex-provider.ts:1393: the background-wait label is English text generated on the server, so it is never localized

backgroundWaitTitle always returns one of three English strings, and every run.background_waiting becomes status.changed carrying that title. TeamHub persists it. The Web shows title?.trim() || t(m.stateWaitingBackground) (apps/web/src/features/rooms/chat/message-timeline.tsx:726), so the title always wins: a zh-CN user sees "Waiting for background command" and never the stateWaitingBackground translation this PR adds. Fix: omit title for waiting_background, or carry the tool kind as a structured field and translate it in the Web.

P3

  • apps/node-services/src/agent/AGENTS.md:225: the docs don't match the code. The docs say a turn enters waiting_background after a Stop hook with fullyIdle: false "and no remaining tool calls". The code does the opposite: it enters the wait only when open tools remain (antigravity_runtime.go:575-596, len(tools) > 0). The docs also say resume() "re-acquires" the slot, but model-queue.ts:436 just increments active without checking capacity, so a resumed Run can push an endpoint over its concurrency limit. Separately, the PR body says hooks.json is written "in the Context workspace"; it is actually one Daemon-wide temp dir passed to every agy through --add-dir.
  • apps/computer/local-daemon/internal/provider/native/antigravity_hook.go:143: the hooks temp dir is never cleaned up. AntigravityHookEndpoint.Close has no caller, so every Daemon start leaves a linger-agy-hooks-* directory in the temp dir. Close the shared endpoint on Daemon shutdown, or drop Close if it isn't needed.

Verified as fine

  • Feature gating: the Daemon emits run.background_waiting / run.background_resumed only when the welcome declares operation_background_wait (daemon/connection.go:350, captured per Operation at operation_start.go:150, enforced in provider/event_projection.go:38-80), and the flag is cleared when the stream drops (connection.go:508).
  • The projected call_id matches the envelope Id pattern: antigravity-call-<sha256 hex> (antigravity_runtime.go:1503); tool_name is clipped to 200 characters (event_projection.go).
  • Hook registration is keyed by session ID, and unregistering checks entry identity, so a later turn's registration on a reused resident process is not removed by an earlier turn's cleanup (antigravity_hook.go:156-171). The turn unregisters in both exchange and finish.
  • The hook subcommand fails open with {} and exit 0, and only posts to http://127.0.0.1: URLs (antigravity_hook.go AntigravityRunHook). The endpoint listens on loopback under a random 24-byte path, and hooks.json is 0600 inside a 0700 MkdirTemp dir.
  • Cancellation behaviour matches the base: cancelPrompt always returns runCtx.Err(), so the old code also returned failed(...) after cancelling.
  • Lease accounting: finish() decrements suspended instead of active when a lease ends while suspended, and #prune keeps endpoints that have suspended leases (model-queue.ts:390-400, 505-510). Phase changes call suspend/resume only for non-terminal Operations (runner-operations.ts:785-794).
  • TeamHub accepts waiting_background with an optional non-empty title (agentruntimestate/status.go:381-383), consistent with the OpenAPI enum and the regenerated artifacts (CI check (contracts) passed).
  • Adding model_not_offered to the envelope schema fixes existing drift: the Daemon already emits it (antigravity_runtime.go:1200).
  • No CJK in added lines outside apps/web/src/i18n/locales/, and none in the commit message.

Unverified:

  • That agy acp --add-dir <dir> loads <dir>/.agents/hooks.json with this top-level linger-steer schema. The behaviour is external, and the PR reports a live check.
  • How Antigravity handles a second session/prompt sent while one is still in flight (the wake path at :933).
  • Whether adding the shared, writable hooks dir to every agy workspace lets one Context's model edit the hook command other Contexts run.
  • Rollout order: an Agent Service running ahead of TeamHub would send waiting_background, which an older TeamHub rejects.

Process notes

  • The branch is 10 commits behind main; rebase before merging.
  • Single commit, no merge or fixup commits. The author is linked (LeoXing1996).

CI

All checks pass. CI's check (computer-go) runs without -race, so I ran go test -race -count=1 ./internal/provider/native/ -run Antigravity myself: everything passed except TestAntigravityTimeoutStopsTheProcess ("a timed-out prompt must be cancelled"). It then passed in a -race -count=3 rerun on its own, so it looks flaky under host load and is not reported as a finding. I did not run the @linger/computer TS tests or the Node and Web suites; CI covers the latter two.

Automated review by Claude Code


Automated review of 1627fce by Claude Code.

@LeoXing1996
LeoXing1996 force-pushed the leo/whi-1027-agy-steer-background branch from 1627fce to dae991e Compare November 25, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant