Skip to content

feat(lastcode): wait for wrapped commands in the background - #831

Merged
lastobelus merged 7 commits into
lastcode/mainfrom
lastcode/background-wait-script-wrapper
Nov 23, 2026
Merged

lastobelus merged 7 commits into
lastcode/mainfrom
lastcode/background-wait-script-wrapper

Conversation

@lastobelus

@lastobelus lastobelus commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Problem

Agents can keep a turn open by polling a long LastCode command. In the stand-in runs below, the same command used nine model requests unwrapped and three wrapped. Marking the result as awaited lets the agent end its turn and wake when the command finishes.

What changes

  • ./scripts/lc-run wraps dependency preparation, checkpoint dependency preparation, Quick or Full CI, the checkpoint waiter, and local package builds from the agent's checkout.
  • Codex and Claude recognize the actual wrapped command and mark it awaited. The main agent can end its turn and receive the result when the command finishes.
  • Fast commands return in the original call. The wrapper prints a short final result that fits in the wake's output tail.
  • Default off. lastcodeBackgroundWaitEnabled gates automatic marking, the wrapper's wait instruction, and Claude's two-hour fallback timeout.
  • Cursor and OpenCode keep manual marking. Saved Project Actions and agent guidance stay in place.
  • Checkpoint preparation takes an explicit upstream commit. Package builds take an exact installable tag, so the same invocation can be retried.

Known limits

  • A rerun of wait-checkpoint observes whichever supervisor run is active at the time.
  • Claude uses the same default for foreground Bash, so raising the background default to two hours also raises the foreground default. Configured Claude timeout defaults and explicit tool timeouts keep their values.
  • Across roughly 12,700 Claude shell commands over two weeks, 13 foreground commands moved to the background at their timeout. Eight used an explicit timeout. The five that used the default were four slow searches and one stalled Git fetch. The flag-on soak should watch for a Claude turn held by a hung command.

Validation

Local, on the rebased head 6d58c41747c3

  • vp run check:changed origin/lastcode/main passed. It covered 825 tests and 43 package typechecks.
  • Quick CI passed.
  • Rebased onto fix(codex): port explicit background waits #791 and exercised wrapped Codex and Claude commands through recorded provider frames, including holding an owned result and clearing it.

Live evidence from 461b471f9a2, before the rebase

  • A stand-in using the same launcher name and output shape marked and woke 3 of 3 four-minute Codex runs. Each ended its turn within 40 seconds and used three model requests, compared with nine for the unwrapped command.
  • A fast Codex run returned inline. A 36-minute run held and woke once. A delegated child delivered one result. A command that merely mentioned the wrapper stayed unmarked. A restarted command reran, was marked again, and finished.
  • Claude completed four- and 36-minute foreground runs with the stand-in. With an explicit 20-second foreground timeout, the command moved to the background, the opening line reached the tool result, and the thread was marked and woken once.
  • The real ./scripts/lc-run prepare ran live. Full stand-in and live results

Live verification still needs to cover the other four real operations and the rebased head, including the revised opening line for supported launches in the main LastCode conversation.

Provenance

Part of #824. Builds on #791 and the upstream Codex background-wait port at 5e048c23d68396b46e7a2e387755da157dd04bee.

Local review: 3 rounds with GPT-6.1 Terra (xhigh) at 6d58c41, not clean.

Terra's last finding was addressed by narrowing the advertised directory prefix and testing the excluded forms. The subsequent Claude Fable convergence review confirmed that the fix closes the finding.

Implemented with GPT-6.2 Sol in Codex.

@lastobelus
lastobelus marked this pull request as ready for review November 23, 2026 02:49
@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T03:18:17.437903Z 5887528 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d58c41747

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lastobelus

Copy link
Copy Markdown
Owner Author

Hold for merge: a live pass on this head found that the Codex hold is not engaging. The cause is not in this PR. It is a regression already on lastcode/main from the last pre-review fix in #791 (bisected to the commit titled "fix(codex): clear background waits during result handoff"): the tool reports the task matched, but the thread completes with the task not awaited. A fix-forward is in progress. This PR should be rebased onto that fix and pass a live check on its exact head before it merges. Details in #824.

Run finite LastCode scripts through one shell entry point and keep the owning Codex or Claude thread waiting when a command outlives the turn. Give opted-in Claude sessions the two-hour background default.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: Wrapped LastCode commands reuse the providers' native background result holds.
Register the shell-launched script with Knip, include its shared parser in the scripts typecheck, and follow the Node import conventions. Type the Claude launch settings with the SDK contract.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: The standalone wrapper is loaded by its shell launcher before workspace dependencies exist.
Exercise Codex auto-marking through roster updates and retained result admission or release. Verify Claude keeps an explicit release across a later roster snapshot.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: Wrapped commands must preserve the merged provider hold lifecycle.
Clarify that the main LastCode conversation owns the automatic wake and native subagents must collect their results. Recognize direct shell launches of the wrapper and preserve configured Claude defaults.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: An eligible wrapper must agree with the adapter's ownership rules and respect Claude configuration.
Only promise an automatic wake for standalone wrapper launches in the main LastCode thread. Tell agents to collect results from compound commands and native subagent launches.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: The instruction must match the shell shapes eligible for an automatic hold.
State that automatic wake advice covers a literal cd path without options or expansions. Exercise the excluded forms raised in review.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: Agent advice describes a subset of literal shell syntax accepted by the wrapper matcher.
Move the wrapped-command cases out of the upstream adapter suites. Reuse a recorded Codex turn and assert its terminal event arrives while the command remains awaited, then check result admission and release. Preserve Claude roster, release, and timeout coverage in the same fork-owned suite.

Implemented with GPT-6.2 Sol in Codex.

Carry-Group: incubator
Carry-Fix: #824
Carry-Observation: Wrapper coverage belongs to the fork and verifies the provider boundary after the launching turn settles.
@lastobelus
lastobelus force-pushed the lastcode/background-wait-script-wrapper branch from 6d58c41 to 5887528 Compare November 23, 2026 03:15
@lastobelus

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 5887528d5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lastobelus

Copy link
Copy Markdown
Owner Author

Hold lifted. The regression on lastcode/main is fixed by #832, and this PR's head 5887528 merged locally with the fixed main passes live in a dev instance with the flag on (Codex gpt-6-luna, stand-in wrapper with the real command line and output): two wrapped commands were marked by the server, held the thread, and woke it once; a fast command returned in the same call; a delegated child that was only told to run the wrapper returned exactly one result to its parent. No automated Claude sessions were run in this pass.

The failed Test job on this head is one desktop test, DesktopCliShim.test.ts ("keeps the AppImage mounted until the server exits after SIGHUP to the process group", expected exit 7, got 130). This PR changes no desktop code, so the failed job has been rerun once.

@lastobelus
lastobelus merged commit 4e02407 into lastcode/main Nov 23, 2026
44 of 47 checks passed
@lastobelus
lastobelus deleted the lastcode/background-wait-script-wrapper branch November 23, 2026 03:45
lastobelus added a commit that referenced this pull request Nov 23, 2026
Codex could drop the result of a command a thread was waiting on. If the command exited just before the marking turn ended, the result landed in the command item, and the thread and its delegated parent could finish before Codex saw it.

## What changed

- **Owed results** stay pending until the turn's completion is saved, then go out through the existing continuation path.
- **Automatic wraps** use Codex's token-usage notification to tell when the launch tool has returned and the shell is still running. Codex sends that notification after the batch's tools finish.
- **Explicit marks** confirm on their own when `t3_background_wait` matches the command.
- **Foreground commands** still get their result in the launch response.
- **Unsuccessful turns**, including interruptions, clear the owed result.
- **Instructions** now ask Codex for manual registration unless `lc-run` reports a registered wake. The `lc-run` launch line says LastCode already registered the wake and to end the turn without calling a tool. The standing instruction is 23 bytes shorter, and the wrapper prints the 316-byte launch line from the eval. The setting remains opt-in.

## Proof

- **Adapter replay** failed before the fix on mark → command exit → turn completion. It now covers that order, automatic marking, duplicate completion events, a foreground exit, interrupted turns, and withdrawing the wait.
- **Luna tool-use eval** passed 15 of 15 samples. The new wrapped case went from 0 of 3 passing to 3 of 3.
- **Changed-file checks** passed across 6 files, including 273 tests.
- **Recorded sessions** showed no token-usage update between launch and exit in all three foreground prepares. All three early exits from the eval had at least one update in that interval.
- **Real-session acceptance** against the pushed head is pending.

An automatically marked wrapper can still miss its wake if it yields and exits before the other tools in the same batch finish. Track that case in the #824 soak.

Follow-up to #791, #831 and #832. Tracks #824 and convergence under #823. The same settled-turn condition is present in [upstream pingdotgg#37572](https://redirect.github.com/pingdotgg/t3code/pull/37572) at `5e048c23d68396b46e7a2e387755da157dd04bee`.

Local review: 3 rounds with GPT-6.1 Terra (xhigh) at 02b382a, approved.

Implemented with GPT-6.2 Sol in Codex. PR copy reviewed with Claude Sonnet 5.5 in Claude Code.

Carry-Source-Ref: refs/lastcode/carry-sources/pr-833/02b382ae1173d8cc78425b824595e1d931f9592f
Carry-Source-Base: 4e02407
Carry-Source-Head: 02b382a
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