Skip to content

fix(kap-server): keep foreground tasks out of REST polling - #1644

Closed
wbxl2000 wants to merge 5 commits into
mainfrom
codex/fix-foreground-subagent-task-projection
Closed

fix(kap-server): keep foreground tasks out of REST polling#1644
wbxl2000 wants to merge 5 commits into
mainfrom
codex/fix-foreground-subagent-task-projection

Conversation

@wbxl2000

@wbxl2000 wbxl2000 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Related to #1623. Independent from #1645.

Problem

On the v2 backend, foreground Agent runs are present in the internal task service with detached: false. The /api/v1 task list exposed them as incomplete REST task records, while foreground subagent identity and grouping belong to the snapshot and WebSocket roster. A Web task refresh could therefore add or replace the richer foreground entry with a record that lacked its parent tool call, subagent type, and swarm index.

What changed

  • Keep GET /api/v1/sessions/{sid}/tasks background-only by filtering detached: false records, matching the v1 endpoint.
  • Keep the optional Task.run_in_background projection for precise GET-by-id compatibility; a directly requested foreground task reports false.
  • Add a public Web task-poller regression proving a foreground snapshot task keeps its identity while background task data still refreshes from REST.

Foreground roster recovery remains owned by the existing snapshot + WebSocket path from #1623. No Agent/swarm stop behavior from #1645 is included here.

Verification

  • protocol: 519 tests passed; typecheck.
  • kap-server: test/tasks.test.ts, 12 tests passed; typecheck.
  • Web: test/workspace-state.test.ts, 48 tests passed; typecheck; production build.
  • Web check:style: baseline mode, 29 existing warnings, no failure.
  • root lint passed.
  • git diff --check origin/main.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

wbxl2000 added 3 commits July 13, 2026 21:27
Accumulate the per-session live subagent roster in the broadcaster's
dispatch queue and expose it via getSnapshotState, so the web client
can rebuild swarm cards after a page refresh. Both snapshot assembly
paths (SnapshotReader and the legacy resume path) pass it through as
the optional subagents field.
agent-core-v2 registers foreground Agent runs in the task service too
(detached: false, so the LLM can drive them via TaskList/TaskOutput/
TaskStop). The REST projection dropped that distinction and the web
client defaults subagent tasks to background, so foreground subagents
showed up in the dock as entries that never settle and cannot be
stopped. Add the optional run_in_background field to the protocol Task
schema and project info.detached onto it; older servers keep omitting
the field and the client default stays correct for them.
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6ed6743

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@6ed6743
npx https://pkg.pr.new/@moonshot-ai/kimi-code@6ed6743

commit: 6ed6743

@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 2bd6a8b5cb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/routes/tasks.ts
@wbxl2000 wbxl2000 changed the title fix(kap-server): project run_in_background onto REST tasks fix(kap-server): keep foreground tasks out of REST polling Jul 13, 2026
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: b3ff5bd159

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/kap-server/src/routes/tasks.ts
@wbxl2000
wbxl2000 changed the base branch from main to fix/kap-server-subagent-roster July 13, 2026 22:13
@wbxl2000
wbxl2000 changed the base branch from fix/kap-server-subagent-roster to main July 13, 2026 22:15
@wbxl2000

Copy link
Copy Markdown
Collaborator Author

Superseded by #1648. The replacement is stacked directly on #1623 so the REST foreground filter has an explicit snapshot-roster dependency without duplicating roster code or carrying unrelated main history.

@wbxl2000 wbxl2000 closed this Jul 13, 2026
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