Repository navigation
feat(computer,agent): add dual-path Antigravity steer and waiting_background state - #748
LeoXing1996 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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 onctx.Done()(:493-499), and that context is the Runner connection's context (daemon/operation_input.go:137). A steer sent while the turn iswaiting_background, followed by a connection drop or reconnect, leaves a wake token with an empty queue. - The background continuation's
PreInvocationhook claims the steers first.onHookcallstakeSteersLocked()at:550and runs concurrently with the main loop. - A wake token is left over from earlier.
wakeChis buffered, and a token can remain after the steers it announced were already delivered throughPreInvocation.
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 enterswaiting_backgroundafter aStophook withfullyIdle: 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 sayresume()"re-acquires" the slot, butmodel-queue.ts:436just incrementsactivewithout checking capacity, so a resumed Run can push an endpoint over its concurrency limit. Separately, the PR body sayshooks.jsonis written "in the Context workspace"; it is actually one Daemon-wide temp dir passed to everyagythrough--add-dir.apps/computer/local-daemon/internal/provider/native/antigravity_hook.go:143: the hooks temp dir is never cleaned up.AntigravityHookEndpoint.Closehas no caller, so every Daemon start leaves alinger-agy-hooks-*directory in the temp dir. Close the shared endpoint on Daemon shutdown, or dropCloseif it isn't needed.
Verified as fine
- Feature gating: the Daemon emits
run.background_waiting/run.background_resumedonly when the welcome declaresoperation_background_wait(daemon/connection.go:350, captured per Operation atoperation_start.go:150, enforced inprovider/event_projection.go:38-80), and the flag is cleared when the stream drops (connection.go:508). - The projected
call_idmatches the envelopeIdpattern:antigravity-call-<sha256 hex>(antigravity_runtime.go:1503);tool_nameis 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 bothexchangeandfinish. - The hook subcommand fails open with
{}and exit 0, and only posts tohttp://127.0.0.1:URLs (antigravity_hook.goAntigravityRunHook). The endpoint listens on loopback under a random 24-byte path, andhooks.jsonis 0600 inside a 0700MkdirTempdir. - Cancellation behaviour matches the base:
cancelPromptalways returnsrunCtx.Err(), so the old code also returnedfailed(...)after cancelling. - Lease accounting:
finish()decrementssuspendedinstead ofactivewhen a lease ends while suspended, and#prunekeeps 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_backgroundwith an optional non-empty title (agentruntimestate/status.go:381-383), consistent with the OpenAPI enum and the regenerated artifacts (CIcheck (contracts)passed). - Adding
model_not_offeredto 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.jsonwith this top-levellinger-steerschema. The behaviour is external, and the PR reports a live check. - How Antigravity handles a second
session/promptsent while one is still in flight (the wake path at:933). - Whether adding the shared, writable hooks dir to every
agyworkspace 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.
1627fce to
dae991e
Compare
What and why
Closes / implements WHI-1027 (
【Antigravity】为 agy 实现双路径 Steer(Hook 注入 + 后台等待唤醒)并显式化 waiting_background 调度状态).Dual-path Antigravity steer (
apps/computer/local-daemon):AntigravitySharedHookEndpointruns a daemon-wide loopback HTTP callback server paired with a generated.agents/hooks.json(linger-steer), forwarded bylinger-computer-daemon antigravity-hook. During an active Antigravity turn, queued steers are delivered via thePreInvocationhook returninginjectSteps(with camelCasehookEventName/conversationId/invocationNum/fullyIdlewire decoding matching Antigravity hooks).waiting_background): When Antigravity'sStophook fires withfullyIdle: falseand no remaining tool calls, the turn transitions into explicitwaiting_backgroundinstead of idling ambiguously. Incoming steers whilewaiting_backgroundskipPreInvocationand wake the session directly via a concurrent/newsession/prompthandover.run.background_waiting(with active background tool call descriptors) andrun.background_resumedevents, gated onoperation_background_waitinrunner.welcome'sservice_features.Explicit
waiting_backgroundscheduling & status (apps/node-services,apps/teamhub,apps/web,contracts):operation_background_wait,run.background_waiting,run.background_resumed, andmodel_not_offeredtocontracts/runner-gateway/envelope.schema.json; addswaiting_backgroundtocontracts/openapi/components/agent-runtime-state.yamland regenerates Go/TypeScript contract artifacts.phase("running" | "waiting_background") andbackgroundToolsinRunnerOperationState, surfaces snake_casebackground_toolsinRunnerOperationsholders, translatesrun.background_waiting/run.background_resumedtostatus.changedinRemoteCodexProvider, and addsModelLease.suspend()/resume()so theModelQueueconcurrency slot is yielded while waiting on background work.status: "waiting_background"(and optional non-emptytitle) inagentruntimestate/status.go.waiting_backgroundstatus inruntime-presentation-events.ts,message-timeline.tsx,runtime-status.messages.ts, andzh-CN.json.How it was verified
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/openapi/changedVerified after final commit (
1627fced8, which only appended docs inapps/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-verifyOpenAPI/schema diff, 15 Vitest contract files / 74 tests, Go contract compilation)make -C apps/teamhub fmt-checkandgo test ./internal/agentruntimestate/... ./tests/integration/layout -count=1cd apps/computer/local-daemon && go test ./cmd/linger-computer-daemon ./internal/provider/native ./internal/provider ./internal/daemon -count=1make -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):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)lint-go BASE=main(0 issues)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)linger-computer-daemon: confirmedantigravity.hook.steer_injectedinjected steers across invocations during active Antigravity turns (steers/assign->steers/complete)Boundary
operation_background_wait,waiting_background,ModelLease.suspend()/resume(), and dual-path Antigravity steer behavior toapps/node-services/src/agent/AGENTS.md.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.jsonmanifest in the Context workspace;PreInvocation/Stophooks run over local loopback HTTP only after the turn has started.run.background_waitingandrun.background_resumedare emitted only whenrunner.welcome'sservice_featuresincludesoperation_background_wait, preserving compatibility with older Agent Services (whose welcome feature list ignores unknown strings on older Daemons).