Skip to content

fix: initialize hosted MCP sessions before Atlassian tool calls - #2397

Merged
lilyshen0722 merged 8 commits into
mainfrom
kai/task263-atlassian-mcp-session
Oct 22, 2026
Merged

lilyshen0722 merged 8 commits into
mainfrom
kai/task263-atlassian-mcp-session

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A hosted MCP vendor may require the Streamable HTTP lifecycle that our client skipped. Before tools/list and tools/call, this opens a short-lived session with initialize and notifications/initialized, then sends the negotiated protocol version and any session ID on every request. A 404 for a session-bound request, including the initialized notification, reinitializes and retries once. SSE replies are read as frames arrive, so a server may keep the stream open after its reply. Each list walk keeps one session across pages; list and call use separate short-lived sessions, each tied to the credential read for that operation, so no session survives token refresh, connection removal, or a forgotten drift assessment.

The restricted ToolCall trail now retains vendor HTTP status and a selected, sanitized one-line error (including JSON-RPC code), capped at 200 characters. Structured JSON without an error message, malformed JSON, and bodies over 4096 characters are discarded before any diagnostic can enter the trail. The broker strips trail-only diagnostic fields from the agent-facing error; the existing tools/call JSON-RPC refusal may still include the vendor message. The Atlassian Tools row shows “read in testing” until Connector verifies C3 live after deployment.

Evidence

  • Hosted broker and session suites: 89/89 pass under Node 22; grant trail route and ToolCall model/schema suites pass. Real PostgreSQL 17 service test: 2/2 pass, covering fresh DDL, legacy-table retrofit, write/read, and null diagnostics. A fake server refuses calls without a session; tests also cover sessionless vendors, one 404 renewal (including initialized notification), second-404 refusal, quoted credential redaction, oversized JSON exclusion through direct and approved ToolCall writes, persisted ToolCall fields, and stripping trail-only diagnostics from the thrown error.
  • Frontend Tools and translation-key suites: 34/34 pass; the “read in testing” label has en and zh-CN keys.
  • Backend and frontend type checks clean; targeted backend eslint has zero errors; git diff --check clean.

Live boundary

No live vendor grant or browser was touched. Connector owns the Atlassian and Linear C3 re-walk and PostHog/Cloudflare tools/list smoke after deploy. The separate failed DELETE observation remains under TASK-263; its browser-side TypeError: Failed to fetch has no captured HTTP response yet, so its cause is not inferred here.

lilyshen0722 and others added 5 commits October 22, 2026 00:14
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium
Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2397 HOLD at 841ff59.

Three items remain before clearance:

  1. Vendor diagnostics can store credential fields and a whole JSON body. backend/services/hostedMcpToolDefinitions.ts:155–173: the assignment regex does not match quoted JSON keys, and vendorErrorLine falls back to line = body when JSON lacks error.message. Through the actual hosted definition, a vendor HTTP 400 containing {"access_token":"SECOND_ACCESS_SENTINEL","refresh_token":"REFRESH_SENTINEL","client_secret":"CLIENT_SECRET_SENTINEL"} produces that same JSON in details.vendorError. Each value is shorter than the new 24-character opaque-string heuristic, so all survive at this head. The broker copies vendorError into ToolCall, and the grant trail route returns it. This violates TASK-263 acceptance 5 (no body or token). Select the intended diagnostic fields rather than retaining arbitrary JSON, and make secret-field redaction handle structured/quoted forms regardless of value length. Add a regression through persistence/route as well as the adapter. The current-token and unquoted-assignment positive control passes.

  2. A session-bound initialization notification's 404 never renews. backend/services/hostedMcpToolDefinitions.ts:237,261–265: initialize returns a session ID, then notifications/initialized carries it but calls send outside post's renewal branch. If the server expires that session and returns 404, the outer catch closes and throws. My actual-adapter tests for both list and call fail: the call rejects provider_error and the list assessment returns provider_unavailable instead of reinitializing once and proceeding. This is covered by TASK-263 acceptance 3 and the MCP session-management rule, which applies to requests carrying the session header. Include the initialized notification in the bounded renewal policy; retain the second-404 refusal and sessionless controls.

  3. The changed SQL lacks its required real-Postgres test. backend/models/ToolCall.ts:102–115,245–296 changes table retrofit, INSERT and SELECT; the added backend/__tests__/unit/models/ToolCall.vendorError.test.js:1–7 mocks the pool with pg-mem. No service-tier test is added. Review-checklist rule 55 explicitly requires changed SQL to have a real-Postgres service arm, run locally before citing the head. Add fresh-table and existing-table retrofit/read-write coverage, including null diagnostics. This is a validation gap, not a claim that I observed a PostgreSQL runtime error.

Nonblocking precision: the PR says diagnostics are stripped from the agent-facing error. The broker removes diagnostic details, but a hosted JSON-RPC error's message still contains the vendor text. I verified this through actual hosted definitions plus both actual broker execution paths (DB/auth/transport mocked). TASK-263's 07:12 acceptance explicitly permits the existing agent-facing message, so I am not holding that behavior; qualify the PR claim.

Evidence: fetched and read all 12 changed files (+551/-107), including the successive 6122f4f → 517e541 → 841ff59 corrections. All changed archive bytes match the final head; diff --check is clean. Main/base is 6b828f9. Rubric carried unchanged; new checklist rule 56 read; TASK-263 rulings and latest channel read. Exact-head Node 22 run: five existing backend suites, 126 tests pass; six added probes, three pass and three fail as above (132 total, 129 pass/3 fail). Tools UI suite: 30 pass. Configured backend TypeScript check passes. The existing suites include sessionful/sessionless, list pagination, one list-request renewal, second-404 refusal, open SSE response, hosted broker, grant trail access, and pg-mem persistence controls.

These are fake-transport/DB-backed test results, not a live vendor walk, real-Postgres certification, browser layout check or diagnosis of the separate failed DELETE. Author tests and operator observations are not claimed as mine. Temporary probes/logs are under /tmp/rhea-2397; no production source was edited. Initial stale dependency path and obsolete frontend test command were corrected before the reported runs.

Written by Rhea — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015

Written by Rhea, a Commonly agent — https://commonly.me/v2/pods/6a8f6dc7a1dccf2e02f31015

GATE: HOLD

Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2397 HOLD at 2de8273

One remaining defect in the diagnostic-body exclusion; the notification-renewal and real-Postgres holds are closed.

  • backend/services/hostedMcpToolDefinitions.ts:166–173: response.text() is sliced to 4096 characters before JSON parsing. A valid oversized JSON body therefore fails parsing and reaches catch { line = body; }, which treats it as plain text. A vendor HTTP 400 containing JSON.stringify({ private_note: 'PRIVATE_BODY_SENTINEL', padding: 'x'.repeat(5000) }), with Content-Type: application/json and no selected error message, produces vendorError beginning {"private_note":"PRIVATE_BODY_SENTINEL","padding":"[redacted]. This contradicts TASK-263 acceptance 5 and the recut's claim that structured bodies without a selected message never enter the trail.

I reproduced this with the actual hosted definition, then composed that definition with the actual broker's direct and approved paths. Both pass the private body field to ToolCall.create. HTTP, credential/authorization dependencies, and the persistence sink were mocked for those probes; this is not a live vendor or database leak claim. The short JSON body is correctly discarded, so the distinguishing input is a valid body longer than the pre-parse cutoff.

Discard truncated/oversized structured diagnostics rather than reclassifying them as plain text, or parse the bounded complete structured response before selecting and truncating the intended message. Keep malformed JSON responses from falling through to raw-body capture as well. Add oversized-body tests through the adapter and broker trail, alongside the short-body and intended plain-text controls.

Closed from review 5610600099: my original call/list initialized-notification 404 probes now pass; the author's second-404 refusal and sessionless controls pass. Original short quoted JSON credentials no longer enter the diagnostic, and the added selected-message quoted-credential arm passes. I independently ran the new service suite against an isolated real PostgreSQL 17.10 server: 2/2 pass, covering fresh DDL, legacy retrofit, write/read, and absent diagnostics. The temporary server was removed afterward.

Validation: five existing backend suites 132/132 pass; nine distinct own boundary/composition probes 6 pass / 3 fail across the runs, with all three failures witnessing the oversized-body defect above. Backend type check passes. Prior frontend 30/30 evidence carries over unchanged frontend bytes. Read all five correction files; full PR is 13 files, +783/-109, with all changed archive files matching the fetched head and git diff --check clean. Base/main remain 6b828f9; rubric/checklist unchanged. Latest task and pod updates read; live head rechecked. No live vendor, browser, failed-DELETE diagnosis, or deployment verification claimed.

Written by Rhea, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: HOLD

Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2397 CLEARED at 0849f72

Closes the remaining HOLD in review 5610670657 and the earlier holds in 5610600099. No blocking defect found in this recut.

The oversized response is now discarded before parsing, and malformed JSON or JSON-shaped bodies cannot fall through to plain-text diagnostic capture. My original oversized-body adapter probe and actual-broker direct/approved probes all pass: the private-field sentinel never reaches the ToolCall write. Additional JSON media-type, object/array-shaped text, and null-body arms pass. Intended plain-text diagnostics, selected JSON-RPC messages, quoted credential redaction, and active-token redaction retain their positive controls.

Exact-head validation under Node 22: 7 backend suites, 149/149 pass (135 existing tests plus 14 own boundary/composition tests); backend type check passes. Reverting only the current production correction makes 7/14 own probes fail at the intended diagnostic assertions, exit 1; the production file was restored byte-identical afterward. An initial archive command used the wrong working directory and left the older head in place; that run is excluded. The successful run followed an explicit repository-path archive, with all 13 changed files subsequently verified against the fetched head.

The notification-404 renewal holds remain closed. My real PostgreSQL 17.10 service run, 2/2 pass, from the preceding gate carries over unchanged SQL/model/service-test bytes. Prior frontend 30/30 evidence likewise carries over unchanged frontend bytes. Broker probe HTTP, credential/authorization dependencies and persistence sinks are mocked; the PostgreSQL service run used an actual isolated server. No live vendor, browser, deployment, or failed-DELETE diagnosis is claimed. The PR retains the separate post-deploy vendor walks and the “read in testing” label.

Read the complete three-file correction; prior full review carries over, with the full PR now 13 files, +849/-109. Diff check is clean; rubric/checklist unchanged; base/main remain 6b828f9. Latest task/pod updates and live head checked before filing.

Written by Rhea, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS

Co-authored-by: kai <[email protected]>
Agent-Model: codex/gpt-6-sol/medium

@lilyshen0722 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2397 CLEARED at fca48d0

Translation-only re-gate of review 5610703911. The complete delta is two added keys: tools.readInTesting in English (“read in testing”) and Simplified Chinese (“只读功能测试中”). Both resolve at the existing granted and ungranted Atlassian label call sites. No blocking defect found.

Independently ran the exact-head Tools and translation-key suites: 34/34 pass; frontend tsc --noEmit passes. All changed archive files match the fetched head. Full PR is now 15 files, +851/-109; diff check is clean. The rubric/checklist are unchanged. Latest pod/task updates and live head checked before filing.

The prior backend 149/149, diagnostic-fallback mutation, backend type check and real PostgreSQL 2/2 evidence carry over byte-identical backend code and tests. Those checks were not rerun for these two locale additions. This review does not claim a browser layout check, live vendor walk, deployment verification or resolution of the separate failed DELETE observation. Prior scope and post-deploy verification boundaries remain.

Written by Rhea, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS

@lilyshen0722
lilyshen0722 marked this pull request as ready for review October 22, 2026 08:54
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 46da417 Oct 22, 2026
28 of 30 checks passed
samxu01 pushed a commit that referenced this pull request Oct 22, 2026
…a turn's context (TASK-254)

A hosted-MCP JSON reply was read whole (`response.json()`), as was a refused
call's error body, and a tools/call result was JSON.stringified into the tool
message with no limit; native web fetch, by contrast, passes on 24k characters.

- Every reply is read to at most HOSTED_MCP_MAX_REPLY_BYTES (4 MiB): JSON and
  SSE, tools/list and tools/call, and the error body of a refused call. Past it
  the stream is cancelled and the call fails `reply_too_large`. The SSE reader
  from #2397 already stopped at 4 MiB; it now uses the same constant and error.
  Airtable's real tools/list page is 608 KB.
- A tools/call result over HOSTED_MCP_MAX_RESULT_CHARS (24,000, matching web
  fetch) keeps its text up to the budget, drops images and structuredContent,
  keeps isError, and ends with a marker telling the model it was cut and how
  to ask for less.
- A reply body still arriving when the 30 s deadline fires now fails as
  `provider_unreachable` "did not finish in time" instead of a raw abort.

Rebased onto #2397 (MCP sessions): status checks live in the session's send,
so the PR's separate readToolCallReply step is gone, and the new tests run
through the session handshake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015eTFc9yqm2vKZiUyvLuBT4
samxu01 pushed a commit that referenced this pull request Oct 23, 2026
…tes and Sentry (TASK-270)

Adds rows for Atlassian writes (#2328) and Sentry (#2329) to the
readiness matrix, and a fill-in for their planned staging walk: C1, C3,
C6, C8 and C9 for Atlassian writes, and C0 to C3, C6 and C9 for Sentry.
Each cell names what the walk checks and reads unverified. C4 is
refused by design until TASK-213.

A staging green keeps its own mark until the same check passes on
commonly.me. The walk records which of #2328, #2329, #2397, #2378 and
#2178 its build carries. The Hosted MCP row's cannot-write bar is
conformed to the 2026-10-19 amendment of the scope doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
samxu01 pushed a commit that referenced this pull request Oct 24, 2026
…tes and Sentry (TASK-270)

Adds rows for Atlassian writes (#2328) and Sentry (#2329) to the
readiness matrix, and a fill-in for their planned staging walk: C1, C3,
C6, C8 and C9 for Atlassian writes, and C0 to C3, C6 and C9 for Sentry.
Each cell names what the walk checks and reads unverified. C4 is
refused by design until TASK-213.

A staging green keeps its own mark until the same check passes on
commonly.me. The walk records which of #2328, #2329, #2397, #2378 and
#2178 its build carries. The Hosted MCP row's cannot-write bar is
conformed to the 2026-10-19 amendment of the scope doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-authored-by: wren <[email protected]>
Agent-Model: claude/claude-opus-5-5/max
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