-
Notifications
You must be signed in to change notification settings - Fork 74
fix(claude-sdk-oauth): ignore volatile top hooks in continuity hashes #1085
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
Open
codeg-dev
wants to merge
3
commits into
code-yeongyu:main
Choose a base branch
from
codeg-dev:fix/session-sync-volatile-hook-hashes
base: main
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.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9aab008
fix(claude-sdk-oauth): ignore volatile top hooks in continuity hashes
codeg-dev 3fd8bde
fix(claude-sdk-oauth): hash volatile hooks by kind, keep them on the …
codeg-dev cf0e5d8
fix(claude-sdk-oauth): add monitor notification and wake hook to vola…
codeg-dev 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
20 changes: 20 additions & 0 deletions
20
packages/coding-agent/src/core/extensions/builtin/claude-sdk-oauth/changes.md
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
158 changes: 158 additions & 0 deletions
158
...ges/coding-agent/test/suite/regressions/claude-sdk-oauth-volatile-hook-continuity.test.ts
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,158 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { | ||
| type ContinuityBindingSnapshot, | ||
| type ContinuityEntrySnapshot, | ||
| decideNativeContinuity, | ||
| } from "../../../src/core/extensions/builtin/claude-sdk-oauth/session-continuity.ts"; | ||
| import { | ||
| isTransmittedMessage, | ||
| sentHashPrefixDigest, | ||
| sentMessageHashes, | ||
| } from "../../../src/core/extensions/builtin/claude-sdk-oauth/session-sync.ts"; | ||
|
|
||
| const ACCOUNT = "default"; | ||
| const MODEL = "claude-opus-5"; | ||
| const SYSTEM_PROMPT_HASH = "system-prompt-hash"; | ||
| const TOOLSET_HASH = "toolset-hash"; | ||
|
|
||
| function userMessage(text: string) { | ||
| return { role: "user" as const, content: [{ type: "text" as const, text }], timestamp: 1 }; | ||
| } | ||
|
|
||
| function notice(n: number) { | ||
| return userMessage( | ||
| `<memory_notice>\n- ${n} previous messages between you and the user are stored in recall memory\n</memory_notice>`, | ||
| ); | ||
| } | ||
|
|
||
| function goalContinuation(tokens: number) { | ||
| return userMessage( | ||
| `Continue working toward the active thread goal.\n\n<untrusted_objective>\nship it\n</untrusted_objective>\n\nUsage so far:\n- Tokens used: ${tokens}`, | ||
| ); | ||
| } | ||
|
|
||
| function toolResult(id: string) { | ||
| return { | ||
| role: "toolResult" as const, | ||
| toolCallId: id, | ||
| toolName: "bash", | ||
| content: [{ type: "text" as const, text: "ok" }], | ||
| timestamp: 1, | ||
| }; | ||
| } | ||
|
|
||
| function hashesOf(messages: ReadonlyArray<{ role: string }>): string[] { | ||
| return sentMessageHashes(messages.filter(isTransmittedMessage)); | ||
| } | ||
|
|
||
| function bindingFrom(messages: ReadonlyArray<{ role: string }>): ContinuityBindingSnapshot { | ||
| const hashes = hashesOf(messages); | ||
| return { | ||
| sdkSessionId: "sdk-1", | ||
| accountName: ACCOUNT, | ||
| modelId: MODEL, | ||
| systemPromptHash: SYSTEM_PROMPT_HASH, | ||
| toolsetHash: TOOLSET_HASH, | ||
| sentCount: hashes.length, | ||
| sentHashes: hashes, | ||
| sentPrefixHash: sentHashPrefixDigest(hashes), | ||
| lastAssistantUuid: null, | ||
| }; | ||
| } | ||
|
|
||
| function entryFrom(messages: ReadonlyArray<{ role: string }>): ContinuityEntrySnapshot { | ||
| const sentHashes = hashesOf(messages); | ||
| return { | ||
| sdkSessionId: "sdk-1", | ||
| accountName: ACCOUNT, | ||
| modelId: MODEL, | ||
| systemPromptHash: SYSTEM_PROMPT_HASH, | ||
| toolsetHash: TOOLSET_HASH, | ||
| sentCount: sentHashes.length, | ||
| sentHashes, | ||
| lastAssistantUuid: "assistant-uuid", | ||
| assistantUuidByIndex: new Map([[1, "assistant-uuid"]]), | ||
| pendingForkReason: null, | ||
| taintedReason: null, | ||
| }; | ||
| } | ||
|
|
||
| const fingerprint = { systemPromptHash: SYSTEM_PROMPT_HASH, toolsetHash: TOOLSET_HASH }; | ||
|
|
||
| describe("volatile hook continuity", () => { | ||
| const prior = [userMessage("task1"), notice(8), toolResult("t1")]; | ||
| const rewrittenNotice = [userMessage("task1"), notice(186), toolResult("t1")]; | ||
| const prependedNotice = [notice(280), userMessage("task1"), notice(8), toolResult("t1")]; | ||
| const appended = [ | ||
| userMessage("task1"), | ||
| notice(8), | ||
| toolResult("t1"), | ||
| userMessage("task2"), | ||
| notice(999), | ||
| goalContinuation(12), | ||
| ]; | ||
| const realEdit = [userMessage("task1-edited"), notice(8), toolResult("t1")]; | ||
|
|
||
| it("does not treat converted hook signatures as transmitted", () => { | ||
| expect(isTransmittedMessage(notice(8))).toBe(false); | ||
| expect(isTransmittedMessage(goalContinuation(1))).toBe(false); | ||
| expect(isTransmittedMessage(userMessage("task1"))).toBe(true); | ||
| expect(isTransmittedMessage(toolResult("t1"))).toBe(true); | ||
| expect(isTransmittedMessage(userMessage("Continue working toward the active thread goal"))).toBe(true); | ||
| }); | ||
|
|
||
| it("reattaches after a hook rewrite or prepend, but still diverges on a real user rewrite", () => { | ||
| const binding = bindingFrom(prior); | ||
| const input = { | ||
| entry: undefined, | ||
| binding, | ||
| accountName: ACCOUNT, | ||
| modelId: MODEL, | ||
| fingerprint, | ||
| transcriptAvailable: true, | ||
| idleExpired: false, | ||
| }; | ||
| expect(decideNativeContinuity({ ...input, currentHashes: hashesOf(rewrittenNotice) })).toEqual({ | ||
| kind: "reattach", | ||
| sdkSessionId: "sdk-1", | ||
| from: 2, | ||
| reason: "registry_miss", | ||
| }); | ||
| expect(decideNativeContinuity({ ...input, currentHashes: hashesOf(prependedNotice) })).toEqual({ | ||
| kind: "reattach", | ||
| sdkSessionId: "sdk-1", | ||
| from: 2, | ||
| reason: "registry_miss", | ||
| }); | ||
| expect(decideNativeContinuity({ ...input, currentHashes: hashesOf(appended) })).toEqual({ | ||
| kind: "reattach", | ||
| sdkSessionId: "sdk-1", | ||
| from: 2, | ||
| reason: "registry_miss", | ||
| }); | ||
| expect(decideNativeContinuity({ ...input, currentHashes: hashesOf(realEdit) })).toEqual({ | ||
| kind: "flatten", | ||
| reason: "sent_stream_diverged", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps an in-process hook rewrite as a delta", () => { | ||
| const entry = entryFrom(prior); | ||
| const input = { | ||
| entry, | ||
| binding: undefined, | ||
| accountName: ACCOUNT, | ||
| modelId: MODEL, | ||
| fingerprint, | ||
| transcriptAvailable: true, | ||
| idleExpired: false, | ||
| }; | ||
| expect(decideNativeContinuity({ ...input, currentHashes: hashesOf(rewrittenNotice) })).toEqual({ | ||
| kind: "delta", | ||
| from: 2, | ||
| }); | ||
| const edit = decideNativeContinuity({ ...input, currentHashes: hashesOf(realEdit) }); | ||
| expect(edit.kind === "flatten" || edit.kind === "fork").toBe(true); | ||
| expect("reason" in edit ? edit.reason : undefined).toBe("sent_stream_diverged"); | ||
| }); | ||
| }); |
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.
On any non-flatten resident turn containing one of these hooks—especially an automatic
goal-continuationturn—this filter removes the hook fromsentMessages(), andsession-stream.tslater builds the actual delta payload from that same filtered array viabuildDeltaPromptBlocks(messages.slice(from)). The SDK therefore never receives the continuation or updated memory/team/task context (and a hook-only turn can submit an empty user payload), even though the turn may be recorded as synchronized; exclude these messages only from continuity hashing, not from the transport message list.Useful? React with 👍 / 👎.