Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(antigravity): allow subturn waits for managed background tasks (#10950)

AstralSolipsism3724ccd8ce3a
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.go
index 50afd272e6..7a0bed2708 100644
--- a/server/internal/daemon/execenv/execenv_test.go
+++ b/server/internal/daemon/execenv/execenv_test.go
@@ -1329,6 +1329,8 @@ func TestInjectRuntimeConfigBackgroundTaskSafetyProviderAgnostic(t *testing.T) {
}{
{"claude", "CLAUDE.md"},
{"codex", "AGENTS.md"},
+ {"codebuddy", "CODEBUDDY.md"},
+ {"antigravity", "AGENTS.md"},
{"opencode", "AGENTS.md"},
{"codearts", "AGENTS.md"},
{"hermes", "AGENTS.md"},
@@ -1347,6 +1349,26 @@ func TestInjectRuntimeConfigBackgroundTaskSafetyProviderAgnostic(t *testing.T) {
t.Fatalf("read %s: %v", tc.file, err)
}
s := string(data)
+ providerPins := []string{
+ "no background-completion wakeup",
+ "whatever a tool response promises",
+ "Never background-and-yield",
+ }
+ if tc.name == "antigravity" {
+ // Its model subturn can end while the same agy process waits.
+ // Detached processes and the shared CI contract stay restricted.
+ providerPins = []string{
+ "completion notifications in the same process",
+ "yield the model subturn while waiting",
+ "without polling `manage_task` or task logs",
+ "have no such wakeup",
+ }
+ }
+ for _, want := range providerPins {
+ if !strings.Contains(s, want) {
+ t.Errorf("%s missing provider boundary %q", tc.name, want)
+ }
+ }
for _, want := range []string{
"## Background Task Safety",
// MUL-5442 judgment rewrite (owner-authorized pin renegotiation): the
@@ -1360,12 +1382,9 @@ func TestInjectRuntimeConfigBackgroundTaskSafetyProviderAgnostic(t *testing.T) {
// What stays pinned: the fact, each boundary, each exception, and
// the handoff triple — the things an agent cannot infer.
"any run-owned work still active is orphaned",
- "no background-completion wakeup",
- "whatever a tool response promises",
- "Never background-and-yield",
+ "standing by",
"foreground tool calls that block",
"run unobservable work synchronously",
- "standing by",
"are not run-owned: do not wait",
// The full compound ban, not its first item — MUL-5223 made this a
// non-derivable boundary, so no member may be silently dropped.
diff --git a/server/internal/daemon/execenv/runtime_config_kind_test.go b/server/internal/daemon/execenv/runtime_config_kind_test.go
index 78e88575e2..c6bdf9b10a 100644
--- a/server/internal/daemon/execenv/runtime_config_kind_test.go
+++ b/server/internal/daemon/execenv/runtime_config_kind_test.go
@@ -323,6 +323,31 @@ func TestSlimQuickCreateAvailableCommands(t *testing.T) {
}
}
+func TestAntigravityBackgroundTaskSafetyAllKinds(t *testing.T) {
+ t.Parallel()
+ for name, ctx := range map[string]TaskContextForEnv{
+ "comment": {IssueID: "i", TriggerCommentID: "c"},
+ "assignment": {IssueID: "i"},
+ "autopilot": {AutopilotRunID: "r"},
+ "quick-create": {QuickCreatePrompt: "p"},
+ "chat": {ChatSessionID: "c"},
+ } {
+ t.Run(name, func(t *testing.T) {
+ agy := buildMetaSkillContent("antigravity", ctx)
+ if !strings.Contains(agy, "yield the model subturn while waiting") ||
+ strings.Contains(agy, "whatever a tool response promises") || strings.Contains(agy, "Never background-and-yield") {
+ t.Fatal("Antigravity model-subturn contract missing or contradicted")
+ }
+ for _, provider := range []string{"claude", "codex", "codebuddy", "hermes"} {
+ other := buildMetaSkillContent(provider, ctx)
+ if !strings.Contains(other, "Never background-and-yield") || strings.Contains(other, "yield the model subturn") {
+ t.Fatalf("%s inherited Antigravity's exception", provider)
+ }
+ }
+ })
+ }
+}
+
// TestBackgroundTaskSafetySlimHardPins asserts the slim brief carries the
// same hardened Background Task Safety pins as the legacy brief (MUL-4140).
// The verbose path is covered by
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index 6538c2c0ec..c88f0a561a 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -65,9 +65,13 @@ func multicaCLICommand() string {
// Keep the explicit watch/poll restriction and its foreground-watch exception
// together. User-requested persistent services require a separate lifecycle,
// readiness verification, durable logs, and a cleanup handle.
-func writeBackgroundTaskSafetySlim(b *strings.Builder) {
+func writeBackgroundTaskSafetySlim(b *strings.Builder, provider string) {
b.WriteString("## Background Task Safety\n\n")
- b.WriteString("Multica marks the task terminal the moment your top-level turn exits — any run-owned work still active is orphaned, its result lost, and the final comment you meant to post never sends. There is no background-completion wakeup, whatever a tool response promises; an issue or chat wakeup (`multica issue wakeup create` / `multica chat wakeup create`) is different — the platform stores it and starts a new run later. Never background-and-yield: collect required results inside foreground tool calls that block to completion, run unobservable work synchronously, and never end a turn \"standing by\" for something to finish — that message becomes your final output.\n\n")
+ if provider == "antigravity" {
+ b.WriteString("Multica marks the task terminal when the `agy -p` process exits — any run-owned work still active is orphaned, its result lost, and the final comment you meant to post never sends. Non-daemon `task-XXX` commands and subagents managed by agy keep `agy -p` alive and deliver completion notifications in the same process. Stop calling tools and yield the model subturn while waiting, without polling `manage_task` or task logs. Processes detached from agy (such as `&` or `nohup`) have no such wakeup; an issue or chat wakeup (`multica issue wakeup create` / `multica chat wakeup create`) is different — the platform stores it and starts a new run later. For detached work, never background-and-yield: collect required results inside foreground tool calls that block to completion, run unobservable work synchronously, and never end a turn \"standing by\" for something to finish — that message becomes your final output.\n\n")
+ } else {
+ b.WriteString("Multica marks the task terminal the moment your top-level turn exits — any run-owned work still active is orphaned, its result lost, and the final comment you meant to post never sends. There is no background-completion wakeup, whatever a tool response promises; an issue or chat wakeup (`multica issue wakeup create` / `multica chat wakeup create`) is different — the platform stores it and starts a new run later. Never background-and-yield: collect required results inside foreground tool calls that block to completion, run unobservable work synchronously, and never end a turn \"standing by\" for something to finish — that message becomes your final output.\n\n")
+ }
b.WriteString("External systems triggered by your completed actions — CI, GitHub Actions after a successful push — are not run-owned: do not wait for them, and do not run `gh pr checks --watch`, `gh run watch`, or sleep/retry polls. A repo's merge gate (\"CI must be green before merge\") is NOT your delivery acceptance criteria. Deliver what you have — \"Local tests pass; CI running: <PR link>\" is a complete hand-off. The one exception: when the trigger comment or the issue's acceptance criteria explicitly ask for the CI result, collect it as ONE foreground blocking call (`gh pr checks <pr> --watch`) inside this same turn.\n\n")
b.WriteString("A user explicitly asking for a local service to stay available after the turn is a persistent service handoff, not background-and-yield — allowed only when the running service itself is the requested deliverable. Detach its lifecycle from this run first (durable logs, a recorded cleanup handle such as PID/profile), verify readiness, and reply with the URL, logs, and stop instructions. Without a supervisor, describe survival as best-effort, not guaranteed. When the repository declares the service in `.multica/environments.toml`, start it with `multica env start <name>` instead: the daemon supervises it, keeps its log, stops it at its TTL, and shows it in the issue sidebar.\n\n")
b.WriteString("Never terminate `multica` or `multica.exe` by executable name: a long-lived matching process may be the workspace daemon. Cancel only the exact child PID you started, and before terminating it compare that PID with `multica daemon status --output json`; never kill it if it is the reported daemon PID.\n\n")
@@ -1011,7 +1015,7 @@ func buildMetaSkillContentSlim(provider string, ctx TaskContextForEnv) string {
// every resume; they now travel in the per-turn user message
// (daemon.BuildPrompt) instead. See MUL-5377.
writeHeader(&b)
- writeBackgroundTaskSafetySlim(&b)
+ writeBackgroundTaskSafetySlim(&b, provider)
writeAgentIdentity(&b, ctx)
writeRequestingUser(&b, ctx)
writeWorkspaceContext(&b, ctx)
diff --git a/server/pkg/agent/antigravity_test.go b/server/pkg/agent/antigravity_test.go
index 6ea6294548..ddf4257564 100644
--- a/server/pkg/agent/antigravity_test.go
+++ b/server/pkg/agent/antigravity_test.go
@@ -894,6 +894,52 @@ sleep 60
`
}
+func TestAntigravityBackendManagedWakeup(t *testing.T) {
+ t.Parallel()
+
+ // Trimmed agy 1.5.12 capture with one repeated final usage snapshot.
+ fakePath := filepath.Join(t.TempDir(), "agy")
+ writeTestExecutable(t, fakePath, []byte(`#!/bin/sh
+cat <<'JSONL'
+{"event":"step_update","step_update":{"step_index":0,"state":"DONE","step_type":"user_input"}}
+{"event":"step_update","step_update":{"step_index":1,"state":"DONE","step_type":"agent_response","usage":{"input_tokens":8975,"output_tokens":84,"thinking_tokens":0,"cache_read_tokens":0,"total_tokens":9059}}}
+{"event":"step_update","step_update":{"step_index":2,"state":"ACTIVE","step_type":"tool","tool_name":"run_command","tool_info":{"name":"run_command","parameters":{"CommandLine":"sleep 25"}}}}
+{"event":"step_update","step_update":{"step_index":2,"state":"DONE","step_type":"tool","tool_name":"run_command","tool_info":{"name":"run_command","parameters":{"CommandLine":"sleep 25"},"output":"Command exited with code 0."}}}
+{"event":"step_update","step_update":{"step_index":3,"state":"DONE","step_type":"agent_response","text_delta":"Waiting for completion.\n","usage":{"input_tokens":2325,"output_tokens":8,"thinking_tokens":0,"cache_read_tokens":6935,"total_tokens":2333}}}
+{"event":"step_update","step_update":{"step_index":4,"state":"DONE","step_type":"system_message"}}
+{"event":"step_update","step_update":{"step_index":5,"state":"ACTIVE","step_type":"agent_response","text_delta":"Command finished."}}
+{"event":"step_update","step_update":{"step_index":5,"state":"DONE","step_type":"agent_response","text_delta":"\n","usage":{"input_tokens":2297,"output_tokens":7,"thinking_tokens":0,"cache_read_tokens":7227,"total_tokens":2304}}}
+{"event":"step_update","step_update":{"step_index":5,"state":"DONE","step_type":"agent_response","usage":{"input_tokens":2297,"output_tokens":7,"thinking_tokens":0,"cache_read_tokens":7227,"total_tokens":2304}}}
+{"event":"result","result":{"status":"SUCCESS","response":"Waiting for completion.\nCommand finished.\n","usage":{"input_tokens":13597,"output_tokens":99,"thinking_tokens":0,"cache_read_tokens":14162,"total_tokens":13696}}}
+JSONL
+`))
+ backend := &antigravityBackend{cfg: Config{ExecutablePath: fakePath, Logger: quietAntigravityLogger()}}
+ ctx, cancel := context.WithTimeout(context.Background(), testFallbackTimeout)
+ defer cancel()
+ session, err := backend.Execute(ctx, "fixture prompt", ExecOptions{ResumeSessionID: "conversation"})
+ if err != nil {
+ t.Fatal(err)
+ }
+ var tools []Message
+ for msg := range session.Messages {
+ if msg.Type == MessageToolUse || msg.Type == MessageToolResult {
+ tools = append(tools, msg)
+ }
+ }
+ result := <-session.Result
+ if result.Status != "completed" || result.Output != "Waiting for completion.\nCommand finished.\n" {
+ t.Fatalf("unexpected result: %+v", result)
+ }
+ if len(tools) != 2 || tools[0].Type != MessageToolUse || tools[1].Type != MessageToolResult ||
+ tools[0].Tool != "run_command" || tools[0].CallID == "" || tools[0].CallID != tools[1].CallID {
+ t.Fatalf("expected one closed run_command call, got %+v", tools)
+ }
+ want := TokenUsage{InputTokens: 13597, OutputTokens: 99, CacheReadTokens: 14162}
+ if len(result.Usage) != 1 || result.Usage["unknown"] != want {
+ t.Fatalf("usage = %+v, want %+v", result.Usage, want)
+ }
+}
+
func TestAntigravityBackendStreamJSONCapturesUsage(t *testing.T) {
t.Parallel()