Skip to content

fix(coding-agent): preserve goal continuation after compaction - #1316

Merged
sethkarten merged 17 commits into
mainfrom
feat/async-bash-background-tasks
Aug 18, 2026
Merged

fix(coding-agent): preserve goal continuation after compaction#1316
sethkarten merged 17 commits into
mainfrom
feat/async-bash-background-tasks

Conversation

@samsja

@samsja samsja commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Retarget this PR from the retired async-bash stack to current main.
  • Fix active goals stalling when another threshold compaction starts while the prior goal continuation is still running.
  • Keep deduplication for pending continuation actions, but allow a running continuation to queue its successor.
  • Stabilize the regression fixture with separate threshold and overflow boundaries and replace fixed sleeps with a bounded condition wait.

Root cause

_queuedGoalThresholdContinuation can refer to the continuation that is currently running. If that continuation crosses the compaction threshold, the scheduler treated its running action as an already-pending successor and did not queue another goal continuation. After compaction, the running action completed, leaving no queued work. agent.continue() could not resume the assistant-last stop, so the active goal stalled.

The fix only deduplicates undelivered continuation states: queued, selected, preparing, and committing. A running continuation may now enqueue its successor.

Validation

  • Exact failing regression: 20/20 consecutive passes
  • Full agent-session-compaction-continuation.test.ts: 7/7 passed
  • npm run check
  • git diff --check
  • Full CI workflow: passed

samsja and others added 14 commits August 12, 2026 13:00
Add an async bash() function to the RLM bootstrap code in ipython.ts
that uses asyncio.create_subprocess_exec to run shell commands without
blocking the kernel event loop. Unlike %%bash cells (which block the
kernel until the command finishes), await bash('...') keeps the kernel
responsive to interrupts and other messages while the process runs.

Supports optional timeout (raises TimeoutError) and cwd parameters.
Returns a _PrimeAgentBashResult with stdout, stderr, and returncode.

Update the RLM system prompt to prefer await bash('...') over %%bash
cells.

@jonaowen jonaowen 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.

This prompt tells the agent to end the turn while an unowned asyncio.Task runs only in the kernel. That is not a persistent/durable task contract: kernel restart, session rotation, process teardown, or task GC/cancellation loses the command and its result. asyncio.create_task() also leaves exceptions unobserved until a later turn that may never occur, and there is no cleanup/adoption registry.

Moreover the stacked base #1187’s bash() explicitly terminates background descendants and drains pipes as part of collection. Turning its coroutine into a detached task does not provide receipt paths, durable process identity, restart reconstruction, or cancellation ownership—the properties needed for an actual long job. Do not describe this as “persistent.” Either scope the guidance to short same-kernel work and require an immediate owner plus exception-safe callback/finally cleanup, or land a real managed task registry/detached-job substrate with durable receipts, restart/adoption semantics, bounded output, terminal observation, and cancellation tests. It should also remain stacked until #1187’s contract is accepted.

…tion

# Conflicts:
#	packages/coding-agent/CHANGELOG.md
#	packages/coding-agent/test/system-prompt.test.ts
@sethkarten sethkarten changed the title docs(coding-agent): guide non-blocking long bash tasks fix(coding-agent): preserve goal continuation after compaction Aug 18, 2026
@sethkarten
sethkarten changed the base branch from feat/async-bash-tool to main August 18, 2026 00:45
@sethkarten
sethkarten requested review from jonaowen and sethkarten and removed request for jonaowen August 18, 2026 03:36
@sethkarten
sethkarten merged commit 20b5497 into main Aug 18, 2026
36 of 40 checks passed
@sethkarten
sethkarten deleted the feat/async-bash-background-tasks branch August 18, 2026 03:51
pde-rent pushed a commit to pde-rent/optimus-prime that referenced this pull request Aug 19, 2026
…Intellect-ai#1316)

* feat(coding-agent): add async bash() to IPython kernel

Add an async bash() function to the RLM bootstrap code in ipython.ts
that uses asyncio.create_subprocess_exec to run shell commands without
blocking the kernel event loop. Unlike %%bash cells (which block the
kernel until the command finishes), await bash('...') keeps the kernel
responsive to interrupts and other messages while the process runs.

Supports optional timeout (raises TimeoutError) and cwd parameters.
Returns a _PrimeAgentBashResult with stdout, stderr, and returncode.

Update the RLM system prompt to prefer await bash('...') over %%bash
cells.

* fix(coding-agent): bound async bash subprocesses

* fix(coding-agent): fail closed for bash on Windows

* fix(coding-agent): render async bash output

* fix(coding-agent): clean completed bash sessions

* fix(coding-agent): validate bash output bounds

* fix(coding-agent): bound rendered bash output

* fix(coding-agent): escalate bash group cleanup

* fix(coding-agent): preserve bounded UTF-8 output

* docs(coding-agent): qualify async bash platforms

* fix(coding-agent): clarify bash truncation units

* refactor(coding-agent): keep async bash POSIX-only

* docs(coding-agent): guide background bash tasks

closes PrimeIntellect-ai#1034

* docs(coding-agent): simplify background bash guidance

* fix(coding-agent): preserve goal continuation after compaction

* docs(coding-agent): explain continuation deduplication

---------

Co-authored-by: Seth <seth@primeintellect.ai>
@snimu snimu mentioned this pull request Aug 19, 2026
8 tasks
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.

3 participants