-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(mesh): derive thread status from every run's close obligation #11230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
yiliang114
wants to merge
1
commit into
codex/multi-agent-mesh-foundation
Choose a base branch
from
codex/mesh-step-5-status
base: codex/multi-agent-mesh-foundation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+569
−7
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,287 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { | ||
| acknowledgeCloseObligations, | ||
| outstandingCloseObligations, | ||
| resolveThreadStatus, | ||
| } from './thread-status.js'; | ||
| import { | ||
| HUMAN_AUTHOR_ID, | ||
| MESH_SCHEMA_VERSION, | ||
| type MessageOutcome, | ||
| type Thread, | ||
| type ThreadMessage, | ||
| type ThreadRun, | ||
| } from './types.js'; | ||
|
|
||
| function run(overrides: Partial<ThreadRun> = {}): ThreadRun { | ||
| return { | ||
| id: 'rn_1', | ||
| agentId: 'ag_alice', | ||
| status: 'completed', | ||
| triggerMessageIds: ['ms_1'], | ||
| acceptedMessageIds: [], | ||
| consumedMessageIds: [], | ||
| usageByRound: [], | ||
| queueSequence: 1, | ||
| queuedAt: 1_000, | ||
| attempts: 1, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function message(overrides: Partial<ThreadMessage> = {}): ThreadMessage { | ||
| return { | ||
| id: 'ms_1', | ||
| sequence: 1, | ||
| authorKind: 'human', | ||
| from: HUMAN_AUTHOR_ID, | ||
| authorNameSnapshot: 'user', | ||
| text: 'have a look', | ||
| mentions: [], | ||
| outcomes: [], | ||
| at: 2_000, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| const booked: MessageOutcome[] = [ | ||
| { kind: 'dispatch', targetAgentId: 'ag_alice', runId: 'rn_1' }, | ||
| ]; | ||
|
|
||
| function thread(overrides: Partial<Thread> = {}): Thread { | ||
| return { | ||
| schemaVersion: MESH_SCHEMA_VERSION, | ||
| id: 'th_1', | ||
| title: 'Investigate', | ||
| body: '', | ||
| status: 'in_progress', | ||
| createdAt: 1_000, | ||
| createdBy: HUMAN_AUTHOR_ID, | ||
| rootThreadId: 'th_1', | ||
| messages: [message({ outcomes: booked })], | ||
| runs: [], | ||
| nextMessageSequence: 2, | ||
| deliveryByAgent: {}, | ||
| outbox: [], | ||
| autoTurnsUsed: 0, | ||
| tokensUsed: 0, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function resolve(thread: Thread, hasLiveChildDependency = false) { | ||
| return resolveThreadStatus({ thread, hasLiveChildDependency }); | ||
| } | ||
|
|
||
| describe('resolveThreadStatus', () => { | ||
| it('stays in_progress while any run is live, whatever another run recorded', () => { | ||
| // The case status-as-last-writer got wrong: alice reviews, bob is still | ||
| // working. A person must not be told this is ready. | ||
| const result = resolve( | ||
| thread({ | ||
| runs: [ | ||
| run({ id: 'rn_alice', closeKind: 'review' }), | ||
| run({ id: 'rn_bob', agentId: 'ag_bob', status: 'running' }), | ||
| ], | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('in_progress'); | ||
| expect(result.reason).toContain('1 run(s) still queued'); | ||
| }); | ||
|
|
||
| it('reports in_review once the last run is quiescent', () => { | ||
| const result = resolve( | ||
| thread({ | ||
| runs: [ | ||
| run({ id: 'rn_alice', closeKind: 'review' }), | ||
| run({ | ||
| id: 'rn_bob', | ||
| agentId: 'ag_bob', | ||
| closeKind: 'unclosed', | ||
| closeAcknowledgedAtSequence: 1, | ||
| }), | ||
| ], | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('in_review'); | ||
| expect(result.reason).toContain('rn_alice'); | ||
| }); | ||
|
|
||
| it('lets a blocker outrank a review from another agent', () => { | ||
| const result = resolve( | ||
| thread({ | ||
| runs: [ | ||
| run({ id: 'rn_alice', closeKind: 'review' }), | ||
| run({ id: 'rn_bob', agentId: 'ag_bob', closeKind: 'blocked' }), | ||
| ], | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('blocked'); | ||
| expect(result.reason).toContain('rn_bob'); | ||
| }); | ||
|
|
||
| it('does not pin the thread to a failure that later work superseded', () => { | ||
| // Round-2 finding I2: acknowledgement was human-only, so one launch | ||
| // failure blocked the thread forever even after another agent finished. | ||
| const failed = thread({ | ||
| runs: [run({ id: 'rn_alice', status: 'failed', error: 'launch failed' })], | ||
| }); | ||
| expect(resolve(failed).status).toBe('blocked'); | ||
|
|
||
| const afterBooking = acknowledgeCloseObligations(failed, 2); | ||
| const withReview = { | ||
| ...afterBooking, | ||
| runs: [ | ||
| ...afterBooking.runs, | ||
| run({ id: 'rn_bob', agentId: 'ag_bob', closeKind: 'review' }), | ||
| ], | ||
| }; | ||
|
|
||
| expect(resolve(withReview).status).toBe('in_review'); | ||
| }); | ||
|
|
||
| it('treats a same-thread wait as satisfied by a later close', () => { | ||
| // Round-2 finding I1: A waits for B, B reviews without @-ing A. Blocked | ||
| // outranks review, so the thread used to report blocked when it was ready. | ||
| const waiting = thread({ | ||
| runs: [run({ id: 'rn_alice', closeKind: 'waiting' })], | ||
| }); | ||
| expect(resolve(waiting).status).toBe('blocked'); | ||
|
|
||
| const released = acknowledgeCloseObligations( | ||
| waiting, | ||
| 2, | ||
| (obligation) => obligation.kind === 'waiting', | ||
| ); | ||
| const withReview = { | ||
| ...released, | ||
| runs: [ | ||
| ...released.runs, | ||
| run({ id: 'rn_bob', agentId: 'ag_bob', closeKind: 'review' }), | ||
| ], | ||
| }; | ||
|
|
||
| expect(resolve(withReview).status).toBe('in_review'); | ||
| }); | ||
|
|
||
| it('keeps a wait in_progress only while a child can still wake it', () => { | ||
| const waiting = thread({ | ||
| runs: [run({ id: 'rn_alice', closeKind: 'waiting' })], | ||
| }); | ||
|
|
||
| expect(resolve(waiting, true).status).toBe('in_progress'); | ||
| expect(resolve(waiting, false).status).toBe('blocked'); | ||
| expect(resolve(waiting, false).reason).toContain('no longer exists'); | ||
| }); | ||
|
|
||
| it('blocks a quiescent thread whose last admission booked nothing', () => { | ||
| // Round-2 finding I6: the silent path. A post whose assignee is gone left | ||
| // the thread in in_progress with no live run and no explanation. | ||
| const result = resolve( | ||
| thread({ | ||
| messages: [ | ||
| message({ | ||
| sequence: 1, | ||
| outcomes: [{ kind: 'skip', reason: 'agent_unknown' }], | ||
| }), | ||
| ], | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('blocked'); | ||
| expect(result.reason).toContain('agent_unknown'); | ||
| }); | ||
|
|
||
| it('ignores a post that was never an admission', () => { | ||
| const result = resolve( | ||
| thread({ messages: [message({ sequence: 1, outcomes: [] })] }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('in_progress'); | ||
| }); | ||
|
|
||
| it('keeps done sticky against a late post', () => { | ||
| const result = resolve( | ||
| thread({ | ||
| status: 'done', | ||
| messages: [ | ||
| message({ | ||
| sequence: 1, | ||
| outcomes: [{ kind: 'skip', reason: 'thread_done' }], | ||
| }), | ||
| ], | ||
| runs: [run({ id: 'rn_alice', status: 'failed' })], | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.status).toBe('done'); | ||
| }); | ||
|
|
||
| it('leaves an untouched thread open', () => { | ||
| expect(resolve(thread({ status: 'open', messages: [] })).status).toBe( | ||
| 'open', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('close obligations', () => { | ||
| it('reports a failed run as a failure even when it recorded a close kind', () => { | ||
| const obligations = outstandingCloseObligations( | ||
| thread({ | ||
| runs: [run({ status: 'failed', closeKind: 'review' })], | ||
| }), | ||
| ); | ||
|
|
||
| expect(obligations).toEqual([ | ||
| { runId: 'rn_1', agentId: 'ag_alice', kind: 'failure' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('ignores live runs and already-acknowledged closes', () => { | ||
| const obligations = outstandingCloseObligations( | ||
| thread({ | ||
| runs: [ | ||
| run({ id: 'rn_live', status: 'running' }), | ||
| run({ | ||
| id: 'rn_done', | ||
| closeKind: 'review', | ||
| closeAcknowledgedAtSequence: 4, | ||
| }), | ||
| ], | ||
| }), | ||
| ); | ||
|
|
||
| expect(obligations).toEqual([]); | ||
| }); | ||
|
|
||
| it('acknowledges only what the selector matches and is a no-op otherwise', () => { | ||
| const source = thread({ | ||
| runs: [ | ||
| run({ id: 'rn_wait', closeKind: 'waiting' }), | ||
| run({ id: 'rn_block', agentId: 'ag_bob', closeKind: 'blocked' }), | ||
| ], | ||
| }); | ||
|
|
||
| const partial = acknowledgeCloseObligations( | ||
| source, | ||
| 7, | ||
| (obligation) => obligation.kind === 'waiting', | ||
| ); | ||
| expect( | ||
| partial.runs.map((entry) => entry.closeAcknowledgedAtSequence), | ||
| ).toEqual([7, undefined]); | ||
|
|
||
| const none = acknowledgeCloseObligations(partial, 8, () => false); | ||
| expect(none).toBe(partial); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] R1-22: This added line records round-2 finding I2 as pinned by a test for both halves, but no test in this commit exercises an outstanding
unclosedobligation at all — so the artifact that tracks which round-2 findings are closed closes one that is not.The claim is "any later successful booking discharges an earlier failure or unclosed return (I2)".
'unclosed'occurs exactly once inthread-status.test.ts(at :108) withcloseAcknowledgedAtSequence: 1on the next line, sooutstandingCloseObligationsfilters that run out before any branch reads it;hand-offoccurs zero times; and none of the threeacknowledgeCloseObligationscalls (:141, :161, :275/:284) touches anunclosedobligation. Two mutations that falsify exactly that sentence both leave the cited suite green. The consequence is not just an imprecise sentence: a later reviewer reads this file to decide whether I2 is settled, and it records the unclosed half as closed when nothing pins it.Witness:
Either narrow the claim to the half that is pinned — "any later successful booking discharges an earlier failure (I2)" — or add the missing case and name it here:
If the test is the route taken, assert the discharge rather than unconditional blocking: design
docs/plans/2026-09-06-multi-agent-board-collaboration.md:476makes this row conditional ("recordcloseKind=unclosed; block only if no successor is runnable"), and a separate finding disputes whether the unconditional block is correct — so a test that pins unconditional blocking here would have to be edited when that is settled.The underlying coverage gap is reported separately at the four untested resolver dimensions; what is distinct here, in a different file, is the false evidence claim in the acceptance record.
— qwen3.8-max via Qwen Code /review (v0.23.0)