Skip to content

feat(session-collaboration): immediate delivery for reports and follow-ups - #2355

Merged
Tioit-Wang merged 3 commits into
mainfrom
feat/session-report-priority
Nov 14, 2026
Merged

Tioit-Wang merged 3 commits into
mainfrom
feat/session-report-priority

Conversation

@Tioit-Wang

@Tioit-Wang Tioit-Wang commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Why

A worker's report is invisible until the receiving session gets to it. The
dispatch started it with admission: "queue" and never promoted it, so a busy
parent ran the receipt after everything the user had already queued. With
maxConcurrentSessions now defaulting to 8, a fan-out of eight review sessions
looks stalled even though every report has already arrived — which is what
prompted the plugin-side request "reports should be sent immediately, not
queued".

What changed

apps/desktop/electron/main/services/session-collaboration.ts promotes a queued
completion receipt:

if (current.kind === "completion" && started.turn.status === "queued") {
  await bridge.queue.prioritize(started.turn.id).catch(...);
}

This is the same queue move the row action performs (ADR 0265), so a busy target
delivers the report as its next turn instead of behind the plain queue. Ordering
between competing reports stays arrival order, because promotion appends to the
priority block.

The steering rules are unchanged. deliverPromotedBlock still accepts immediate
injection only from a paired caller's own input, so a Desktop-owned turn is never
injected with another session's text: here "immediate" means the next turn
boundary, not preemption. A turn that already started, or a queue move that lost
a race, is not an error — only a non-CONFLICT failure is logged.

Scope: kind === "completion" only. task and message deliveries keep today's
ordering, so plugin-sent work is still a normal queue entry.

Docs

  • docs/adr/0265-...: records automatic promotion of completion receipts and the
    boundary it inherits.
  • docs/spec/07-plugins/03-plugin-api.md + zh-CN: the gateway contract now says a
    receipt is promoted in the target's queue and never injected into a running
    turn.

Verification

  • tsc -p apps/desktop/tsconfig.json --noEmit with this change: clean.
  • No schema change, no Rust change, no new operation or permission.
  • The Electron main service has no unit-test harness today, so this path is
    covered by typecheck and by the queue rules it reuses; a harness for
    createSessionCollaborationService would be the natural follow-up.

Follow-up not in this PR

RacpTurnAdmission has no interrupt value, so a report cannot preempt a running
turn. If "immediate" should mean injection mid-turn for Desktop-owned turns, that
is a security-relevant change to the paired-caller steering guard and needs its
own decision record. A per-delivery choice exposed to the plugin as a setting also
needs a durable hint on the message row (schema v30), which is why it is not part
of this fix.

Also in this PR: a send can ask for the same treatment

send always appended behind whatever the target had already queued. It now
accepts delivery: "queue" | "immediate" (default queue = today):

  • immediate promotes the follow-up in the same block a completion receipt
    uses, so a busy target runs it at its next turn boundary instead of behind
    already-queued input.
  • It never preempts a running turn: the paired-caller steering guard is
    unchanged.
  • An unknown value fails with INVALID_ARGUMENT before anything is created;
    spawn rejects the field because a worker's first task has nothing to jump.

The operation catalog's argumentShape for send advertises the field, and
the plugin-side counterpart (SessionTask delivery) ships in
vastsa/pi-plugin-session-orchestrator#3.

The report is text a model can read, not JSON

The receipt used to carry {"sessionId":…,"status":…,"result":…}. The receiving
Agent had to parse its own inbox, and a human reading the transcript saw the same
blob. It is now a structured block:

Sub-session report
Session: <worker title> (<session id>)
Status: completed | failed | cancelled | interrupted
Delivery: <message id> (turn <turn id>)

Report:
<the worker's final text, or why there is none>

Error: <the fence or turn error, when it failed>

Nothing parses the body for state — session.collaboration.result still returns
the machine-readable projection — and two tests now lock the format: the completed
receipt must contain Status: completed and Report:\nAuthoritative final result while containing no "result" key, and the interrupted receipt must
carry Status: interrupted plus the fence error.

…oundary

A completion receipt is invisible until the target session gets to it. With
`admission: queue` and no promotion, a busy parent ran the report after
everything the user had already queued, so a fan-out of eight workers looked
like it stalled even though every report had arrived.

Completion receipts are now promoted in the target's turn queue (ADR 0265): the
same move the queue row action performs, so a busy session delivers the report
as its next turn instead of behind the plain queue. Ordering between competing
reports stays arrival order, because promotion appends to the priority block.

The promotion keeps the existing steering rules. A Desktop-owned turn never has
another session's text injected into it, so "immediate" means the next turn
boundary, not preemption. A turn that already started, or a queue move that lost
a race, is logged only when the error is not CONFLICT.

Verified: `tsc -p apps/desktop/tsconfig.json --noEmit` with this change clean.
No schema change, and task/message deliveries keep today's ordering.
…livery

`send` always appended behind whatever the target had already queued, so a
caller that needed to correct a busy worker had no way to say "this matters now".

`session/collaboration/send` accepts `delivery: "queue" | "immediate"` (default
`queue`, which is today's order). `immediate` uses the same promotion block as a
completion receipt (ADR 0265): a busy target runs the follow-up at its next turn
boundary instead of behind already-queued input. It never preempts a running turn
— steering stays restricted to a paired caller — and an unknown value is
rejected before anything is created. `spawn` rejects the field, because a
worker's first task has nothing to jump.

Verified: `tsc -p apps/desktop/tsconfig.json --noEmit` with this change clean.
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
pi-desktop Error Error Nov 14, 2026 7:50pm UTC

@Tioit-Wang Tioit-Wang changed the title feat(session-collaboration): run a worker's report at the next turn boundary feat(session-collaboration): immediate delivery for reports and follow-ups Nov 14, 2026
The completion receipt carried a serialized envelope
(`{"sessionId":…,"status":…,"result":…}`), so the receiving Agent had to parse a
JSON string out of its own inbox before it could use the report, and a human
reading the transcript saw the same blob.

The receipt is now a structured report a model can act on directly:

    Sub-session report
    Session: <worker title> (<session id>)
    Status: completed | failed | cancelled | interrupted
    Delivery: <message id> (turn <turn id>)

    Report:
    <the worker's final text, or why there is none>

    Error: <the fence or turn error, when it failed>

The machine-readable fields stay available where they belong: the
`session.collaboration.result` projection is unchanged, so nothing parses the
message body for state. Tests now lock the format and assert the envelope is
gone.

@aiuo-codepilot aiuo-codepilot 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.

AIUO CodePilot · Preliminary review

Diff-only preliminary review of session-collaboration delivery promotion, receipt text format, and docs. The change promotes queued completion/immediate deliveries via queue.prioritize and replaces the JSON receipt envelope with readable text. One concrete issue: the shared dispatch logging message says "Session completion delivery" for any promote, including a caller-requested immediate follow-up. Other limits: no execution or full-repo context available (added-line evidence only), so race behavior, queue semantics, and Rust message fields were not verified at runtime.

  • low apps/desktop/electron/main/services/session\-collaboration\.ts:170: The error log message is hardcoded as a completion-delivery failure even when the promoted turn came from `delivery: "immediate"` on a non-completion send. Operators will misattribute an immediate follow-up prioritization failure as a completion receipt problem. Use a message that reflects the actual promotion source.
    Evidence: deps\.log\("Session completion delivery could not be prioritized", \{

Head: 77d5b7a
Base: f3cb2a3
CI: success; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@Tioit-Wang
Tioit-Wang merged commit c39e301 into main Nov 14, 2026
7 of 8 checks passed
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