-
Notifications
You must be signed in to change notification settings - Fork 1
fix(runtime): surface writeback no-receipt failures #244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { mkdir, mkdtemp, readFile, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import path from 'node:path'; | ||
| import test from 'node:test'; | ||
| import { | ||
| WorkforceIntegrationError, | ||
| WritebackError, | ||
| normalizeWritebackStatus, | ||
| writeJsonFile | ||
| } from './index.js'; | ||
|
|
||
| test('writeJsonFile returns successful writes with receipts', async () => { | ||
| const root = await mkdtemp(path.join(tmpdir(), 'workforce-writeback-ok-')); | ||
| const relayPath = '/slack/channels/C123/messages/msg.json'; | ||
| const absolutePath = path.join(root, relayPath.slice(1)); | ||
|
|
||
| const pending = writeJsonFile( | ||
| { relayfileMountRoot: root, writebackTimeoutMs: 1_000, writebackPollMs: 10 }, | ||
| 'slack', | ||
| 'postMessage', | ||
| relayPath, | ||
| { text: 'hello' } | ||
| ); | ||
|
|
||
| await waitForDraft(absolutePath); | ||
| await writeFile( | ||
| absolutePath, | ||
| `${JSON.stringify({ created: '2026-06-18T18:00:00.000Z', id: 'msg-1', path: relayPath })}\n`, | ||
| 'utf8' | ||
| ); | ||
|
|
||
| const result = await pending; | ||
| assert.equal(result.path, relayPath); | ||
| assert.equal(result.receipt?.id, 'msg-1'); | ||
| assert.equal(normalizeWritebackStatus(result).state, 'succeeded'); | ||
| }); | ||
|
|
||
| test('writeJsonFile treats missing receipts as first-class writeback errors', async () => { | ||
| const root = await mkdtemp(path.join(tmpdir(), 'workforce-writeback-no-receipt-')); | ||
|
|
||
| await assert.rejects( | ||
| () => | ||
| writeJsonFile( | ||
| { relayfileMountRoot: root, writebackTimeoutMs: 1, writebackPollMs: 1 }, | ||
| 'slack', | ||
| 'postMessage', | ||
| '/slack/channels/C123/messages/msg.json', | ||
| { text: 'hello' } | ||
| ), | ||
| (error: unknown) => { | ||
| assert(error instanceof WritebackError); | ||
| assert(error instanceof WorkforceIntegrationError); | ||
| assert.equal((error as { state?: unknown }).state, 'no_receipt'); | ||
| assert.equal((error as { path?: unknown }).path, '/slack/channels/C123/messages/msg.json'); | ||
| return true; | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('writeJsonFile preserves explicit fire-and-forget writebacks', async () => { | ||
| const root = await mkdtemp(path.join(tmpdir(), 'workforce-writeback-fire-and-forget-')); | ||
| const relayPath = '/slack/channels/C123/messages/msg.json'; | ||
|
|
||
| const result = await writeJsonFile( | ||
| { relayfileMountRoot: root, writebackTimeoutMs: 0 }, | ||
| 'slack', | ||
| 'postMessage', | ||
| relayPath, | ||
| { text: 'hello' } | ||
| ); | ||
|
|
||
| assert.equal(result.path, relayPath); | ||
| assert.equal(result.receipt, undefined); | ||
| assert.deepEqual(JSON.parse(await readFile(path.join(root, relayPath.slice(1)), 'utf8')), { | ||
| text: 'hello' | ||
| }); | ||
| }); | ||
|
|
||
| async function waitForDraft(filePath: string): Promise<void> { | ||
| await mkdir(path.dirname(filePath), { recursive: true }); | ||
| const deadline = Date.now() + 1_000; | ||
| do { | ||
| try { | ||
| await readFile(filePath, 'utf8'); | ||
| return; | ||
| } catch { | ||
| await new Promise((resolve) => setTimeout(resolve, 10)); | ||
| } | ||
| } while (Date.now() < deadline); | ||
| throw new Error(`draft was not written: ${filePath}`); | ||
| } |
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
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.
When a client intentionally sets
writebackTimeoutMs: 0, adapter-core returns immediately with no receipt;mcp-workforcestill relies on that mode in its GitHub tool test (packages/mcp-workforce/src/tools/integrations.test.ts:65-67) and calls this runtime helper fromintegrations.ts:84. This new branch normalizes that expected fire-and-forget result tono_receiptand throws, sointegration.github.comment/createIssue/etc. can no longer write drafts in offline/fire-and-forget mode and the existingmcp-workforcetest would fail. Preserve timeout-0 as a successful draft write or update the callers/config to stop using it.Useful? React with 👍 / 👎.
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.
Addressed in 672f3e0. The wrapper now preserves explicit
writebackTimeoutMs: 0fire-and-forget writes by returning the draft result when normalization reportsno_receipt; timed waiters still throwWritebackError. Added regression coverage for both paths and verified@agentworkforce/runtime(95/95) plus@agentworkforce/mcp-workforce(25/25). The aggregate check got through lint/typecheck and later hit an unrelated timing flake in a deploy OAuth polling test; rerunning that deploy test passed.