fix(agent-server): release exclusive slot on stream startup failure by dvd233 · Pull Request #1957 · bytedance/UI-TARS-desktop · GitHub
Skip to content

fix(agent-server): release exclusive slot on stream startup failure - #1957

Open
dvd233 wants to merge 2 commits into
bytedance:mainfrom
dvd233:fix/stream-startup-exclusive-lock
Open

dvd233 wants to merge 2 commits into
bytedance:mainfrom
dvd233:fix/stream-startup-exclusive-lock

Conversation

@dvd233

@dvd233 dvd233 commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Closes #1951

In exclusive mode, both Agent Server implementations mark a session as running before awaiting agent.run(). If that promise rejects before returning an AsyncIterable, the catch path returns a synthetic error stream while leaving the exclusive slot occupied indefinitely.

This change releases the slot immediately in that startup-failure path for both @tarko/agent-server and @tarko/agent-server-next. A successfully created stream still owns the slot until iteration finishes, preserving the existing lifecycle for active streams.

The regression tests exercise both server generations and verify that:

  • a startup rejection releases the slot even when the synthetic error stream is never consumed;
  • consuming that old error stream later cannot clear a newer run for the same session;
  • a successfully started stream continues to hold the slot until it finishes.

Verification

  • pnpm exec vitest run tests/core/agent-session-exclusive-mode.test.ts: 4 tests pass.
  • pnpm exec vitest run --exclude tests/SQLiteStorageProvider.test.ts: 6 suites, 45 tests pass.
  • pnpm --filter @tarko/agent-server build: passes.
  • pnpm --filter @tarko/agent-server-next build: passes.
  • pnpm exec prettier --check tarko/agent-server/tests/core/agent-session-exclusive-mode.test.ts: passes.
  • Full @tarko/agent-server suite: 45 tests pass; the same 19 pre-existing SQLite tests fail before and after this change on Windows because the test setup constructs paths such as D:\tmp\C:\Users\....

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

@netlify

netlify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

@netlify

netlify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tarko ready!

Name Link
🔨 Latest commit ab82586
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/6ab6627bab9d7800091c0212
😎 Deploy Preview https://deploy-preview-1957--tarko.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@CLAassistant

CLAassistant commented Aug 31, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Reviewed commit 5f2e8f8.

The immediate release fixes the original startup-failure leak, but I found a regression when another streaming request targets a session that is already executing: the rejected request clears the slot still owned by the active run. This affects both server implementations; details are in the inline comment.

Validation: an isolated Node source harness reproduced the original leak on the base commit, passed 12 lifecycle checks on this head across both implementations, and reproduced the overlapping-request regression in both (base remains busy; head becomes available while the first stream continues). The harness loads the session implementations and server slot methods, with a fake agent modeling the existing Agent.run() executing guard. The project Vitest suites and builds were not run because workspace dependencies are not installed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Preserve the active run's slot when a duplicate query is rejected

A rejected agent.run() does not necessarily mean this session has no active stream. Start a streaming query for session S, keep it running, then send another /api/v1/sessions/query/stream request for S. These query routes only use session-restore middleware, so the second request reaches Agent.run(), whose isExecuting() guard rejects it. This new unconditional clear then removes S's slot even though the first run is still executing. canAcceptNewRequest() becomes true, allowing session creation (and legacy one-shot execution) through the exclusive-mode gate. The base commit retains S's slot in this scenario; I reproduced the change in both implementations.

Please reject overlapping runs before changing slot ownership, or track ownership per run so this catch only releases its own acquisition. Add a regression test that keeps the first stream active while the second call rejects, and apply the same protection to agent-server-next at its matching catch block.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in ab82586. Both implementations capture whether the agent was already executing and avoid clearing the active run's slot when an overlapping request is rejected. The regression keeps the first stream active while the second request rejects.

Follow-up validation recorded on 2026-10-17: all 6 lifecycle tests passed across both implementations; the non-SQLite run passed 6 files / 47 tests; both agent-server builds passed, including declarations. The fix was already present on this head; no duplicate implementation was added.

SQLite remains excluded from this result; the historical Windows SQLite failures are not marked as resolved. The secretlint run on 2026-09-25 ended with startup_failure and 0 jobs, so it provides no completed scan result:
https://github.com/bytedance/UI-TARS-desktop/actions/runs/36132548639

This branch has not been deployed

No deployments
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.

[Bug Report]: Streaming startup failure leaves exclusive Agent Server busy

3 participants