Skip to content

Defer instruction-only thread reconfigure while background tasks are open - #1219

Open
sholub-dev wants to merge 1 commit into
get-bb:mainfrom
sholub-dev:defer-instruction-reconfigure-with-open-background-tasks
Open

Defer instruction-only thread reconfigure while background tasks are open#1219
sholub-dev wants to merge 1 commit into
get-bb:mainfrom
sholub-dev:defer-instruction-reconfigure-with-open-background-tasks

Conversation

@sholub-dev

Copy link
Copy Markdown
Contributor

Fixes #1217.

Summary

When a turn arrives with instructions that differ from what the session was started with, reconfigureThreadIfNeeded issues thread/resume. For claude-code that replaces the live CLI session: every running background task is killed with it, and the adapter settles them as interrupted — in the same second as the user's message.

Instructions drift between turns without any user action: the Memory plugin renders the memory catalog into thread instructions, so any memory write armed the next message to silently kill all running background tasks; AGENTS.md edits and plugin dynamic instructions do the same.

An instruction-only change is now deferred while the thread has open background tasks: the stored runtime config stays stale, so the reconfigure retries on the first turn after the tasks settle. Explicit execution-setting changes (e.g. a model switch) still apply immediately.

The change is daemon-local (no wire shape change), so HOST_DAEMON_PROTOCOL_VERSION is untouched. The new regression test reproduces the kill without the fix: a turn with changed instructions and an open background task previously emitted thread/resume, now it does not, and the deferred instructions apply once the task completes.

@SawyerHood

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request for security, code quality, performance, tests, and architectural duplication.

// live work over: defer the instruction-only reconfigure — the stored
// config stays stale, so it retries once the tasks settle. Explicit
// settings changes (e.g. a model switch) still apply immediately.
if (sameSettings && backgroundWorkState.hasOpenWorkForThread(args.threadId)) {

@SawyerHood SawyerHood Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 slopcop/review — Prettier rejects this changed line.

The format check also rejects runtime.lifecycle.test.ts at line 514. Please run Prettier on both changed files before merge. This note is non-blocking.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5: A thread can start a long job. New instructions now wait until that job ends. The job stays alive.

Result: I found no blocking defect.

  • Format: One low-severity issue remains. Prettier rejects two changed lines. See the inline note.

  • Security: I found no security defect. A task can delay instruction updates indefinitely. The pull request defines this behavior. Permission changes still apply immediately.

  • Quality and architecture: The change uses the existing RuntimeBackgroundWorkState. I found no duplicate mechanism. More tests for repeated defer and thread isolation would improve coverage.

  • Performance: The new lookup uses the existing per-thread map. It adds no scan, queue, or timer.

  • Validation: The agent-runtime type check passed. The focused lifecycle tests passed 27 of 27. The background-state tests passed 5 of 5.

The full package run passed 838 tests. One unchanged stderr-tail test failed. The same test failed alone at runtime.process-lifecycle.test.ts:461.

A browser test does not apply because this daemon runtime change has no UI route.

Three GPT-5.6 workers reviewed the change in parallel. The internal GPT-5.6 gate returned APPROVE. I used only a comment review on GitHub.

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.

Sending a message kills a thread's running background tasks when instructions drifted between turns

2 participants