Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ae2641c
fix(agent): keep op sender stamps and displaced admissions
christian-byrne Oct 2, 2026
a6d25af
fix(agent): retain every workflow mint cursor
christian-byrne Oct 2, 2026
ec6e0b1
fix(agent): reset only the document whose lineage broke
christian-byrne Oct 2, 2026
df1de6c
docs: shorten admission contract
christian-byrne Oct 2, 2026
d7c4173
docs: clarify workflow cursor retention
christian-byrne Oct 2, 2026
4038bdd
docs: remove redundant mint version comment
christian-byrne Oct 2, 2026
151fedf
refactor: write minted version directly
christian-byrne Oct 2, 2026
26964d7
refactor: remove minted version alias
christian-byrne Oct 2, 2026
b6d2009
docs: shorten displaced admission comment
christian-byrne Oct 2, 2026
88a211f
docs: remove duplicate pump deferral comment
christian-byrne Oct 2, 2026
2c37e41
docs: trim seal group comment
christian-byrne Oct 2, 2026
9975288
refactor: name admission group shape
christian-byrne Oct 2, 2026
467176d
docs: shorten reset cursor comment
christian-byrne Oct 2, 2026
d2d25a7
test: trim reset isolation narration
christian-byrne Oct 2, 2026
0e1067c
test: remove redundant unbound cursor comment
christian-byrne Oct 2, 2026
bdb9d32
test: remove redundant resubscribe comment
christian-byrne Oct 2, 2026
3ccaf82
test: remove redundant abort comments
christian-byrne Oct 2, 2026
51c3a3e
test: remove redundant admission ordering comments
christian-byrne Oct 2, 2026
0a05957
Merge branch 'main' into op269-opsender-mint-cursor-and-displaced-adm…
christian-byrne Oct 2, 2026
1055431
docs: drop the duplicate blank line in the admit contract
christian-byrne Oct 2, 2026
2b89b57
test: pin the mint cursor against two surviving mutants
christian-byrne Oct 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 163 additions & 9 deletions src/workbench/extensions/agent/crdt/opSender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe('createOpSender', () => {
let transportUp: boolean
let transportThrows: boolean
let boundWorkflow: string | null
let observedSequence: number
let sender: ReturnType<typeof createOpSender>
const unsubscribe = vi.fn(() => {
resultListener = null
Expand All @@ -144,6 +145,7 @@ describe('createOpSender', () => {
transportUp = true
transportThrows = false
boundWorkflow = WORKFLOW
observedSequence = 41
sender = createOpSender({
sendOps: (workflowId, tab, ops) => {
if (transportThrows) throw new Error('frame serialization failed')
Expand All @@ -158,7 +160,7 @@ describe('createOpSender', () => {
workflowId: () => boundWorkflow,
tab: TAB,
actor: () => ACTOR,
baseVersion: () => 41,
baseVersion: () => observedSequence,
onBatchSettled: (outcome) => settled.push(outcome)
})
})
Expand Down Expand Up @@ -198,6 +200,110 @@ describe('createOpSender', () => {
expect(sent[1].ops[0].base_version).toBe(41)
})

it('a document reset restarts only the reset document, not every workflow visited', () => {
sender.admit([addNode(1)])
sender.admit([addNode(2)])
sender.flush()
boundWorkflow = 'wf-2'
sender.admit([addNode(3)])
sender.abortAll()
sender.admit([addNode(4)])
// Back on wf-1 before its re-subscribe is acknowledged.
boundWorkflow = WORKFLOW
observedSequence = 0
sender.admit([addNode(5)])

expect(
sender.pendingOps().map(({ workflowId, ops }) => ({
workflowId,
versions: ops.map((op) => op.base_version)
}))
).toEqual([
{ workflowId: 'wf-2', versions: [41] },
{ workflowId: WORKFLOW, versions: [43] }
])
})

it('an admission taken while unbound leaves the bound workflow its own counter', () => {
sender.admit([addNode(1)])
boundWorkflow = null

sender.admit([addNode(2)])

boundWorkflow = WORKFLOW
sender.admit([addNode(3)])
sender.flush()

expect(
sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version))
).toEqual([41, 42])
expect(settled.map(summarizeSettlement)).toEqual([
{ state: 'undeliverable', nodeIds: [2] }
])
})

it('keeps one Lamport counter per workflow across a switch away and back', () => {
sender.admit([addNode(1)])
boundWorkflow = 'wf-2'
sender.admit([addNode(2)])
boundWorkflow = WORKFLOW
sender.admit([addNode(3)])
sender.flush()

const minted = sender.pendingOps().map(({ workflowId, ops }) => ({
workflowId,
versions: ops.map((op) => op.base_version)
}))
expect(minted).toEqual([
{ workflowId: WORKFLOW, versions: [41] },
{ workflowId: 'wf-2', versions: [41] },
{ workflowId: WORKFLOW, versions: [42] }
])
})

it('keeps a workflow its counter while a re-subscribe has not been acknowledged', () => {
sender.admit([addNode(1)])
sender.admit([addNode(2)])
boundWorkflow = 'wf-2'
observedSequence = 0
sender.admit([addNode(3)])
boundWorkflow = WORKFLOW
sender.admit([addNode(4)])
sender.flush()

expect(
sender.pendingOps().map(({ workflowId, ops }) => ({
workflowId,
versions: ops.map((op) => op.base_version)
}))
).toEqual([
{ workflowId: WORKFLOW, versions: [41, 42] },
{ workflowId: 'wf-2', versions: [0] },
{ workflowId: WORKFLOW, versions: [43] }
])
})

it('mints past every stamp in a multi-operation admission', () => {
sender.admit([addNode(1), addNode(2), addNode(3)])
sender.admit([addNode(4)])
sender.flush()

expect(
sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version))
).toEqual([41, 42, 43, 44])
})

it('mints from the observed sequence once the document advances past this actor', () => {
sender.admit([addNode(1)])
observedSequence = 90
sender.admit([addNode(2)])
sender.flush()

expect(
sender.pendingOps().flatMap(({ ops }) => ops.map((op) => op.base_version))
).toEqual([41, 90])
})

it('serializes batches: the next sends only after the result settles the first', () => {
sender.enqueue([addNode(1)])
sender.enqueue([addNode(2)])
Expand Down Expand Up @@ -1375,6 +1481,18 @@ describe('createOpSender', () => {
expect(localSettled.map(summarizeSettlement)).toEqual([
{ state: 'undeliverable', nodeIds: [1, 2] }
])
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({
errorType: 'failure_chunking_agent_op_sender_abort'
})
)
expect(reportError).not.toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({
errorType: 'failure_chunking_agent_op_sender'
})
)
expect(localSender.pending()).toBe(0)
localSender.detach()
})
Expand Down Expand Up @@ -1429,13 +1547,17 @@ describe('createOpSender', () => {
it('resumes a pump requested during workflow-change sealing', () => {
const localSent: Array<{ workflowId: string; ops: Op[] }> = []
const localSettled: BatchOutcome[] = []
let localResultListener!: (result: OpsResultView) => void
let workflow = 'wf-old'
const localSender = createOpSender({
sendOps: (workflowId, _tab, ops) => {
localSent.push({ workflowId, ops })
return true
},
onOpsResult: () => vi.fn(),
onOpsResult: (listener) => {
localResultListener = listener
return vi.fn()
},
workflowId: () => workflow,
tab: TAB,
actor: () => ACTOR,
Expand All @@ -1459,13 +1581,45 @@ describe('createOpSender', () => {

localSender.admit([addNode(2)])

expect(localSent).toHaveLength(1)
expect(localSent[0].workflowId).toBe('wf-new')
expect(nodeIdsOf(localSent[0].ops)).toEqual([3])
expect(localSettled.map(summarizeSettlement)).toContainEqual({
state: 'undeliverable',
nodeIds: [1]
})
expect(
localSent.map(({ workflowId, ops }) => ({
workflowId,
nodeIds: nodeIdsOf(ops)
}))
).toEqual([{ workflowId: 'wf-new', nodeIds: [2] }])
expect(
localSender.pendingOps().map(({ workflowId, ops }) => ({
workflowId,
nodeIds: nodeIdsOf(ops),
versions: ops.map((op) => op.base_version)
}))
).toEqual([
{ workflowId: 'wf-new', nodeIds: [2], versions: [41] },
{ workflowId: 'wf-old', nodeIds: [1], versions: [41] },
{ workflowId: 'wf-new', nodeIds: [3], versions: [42] }
])
const deliveredIds = localSent[0].ops.map((op) => op.op_id)

localResultListener({ ok: true, applied: deliveredIds, skipped: [] })

expect(
localSent.map(({ workflowId, ops }) => ({
workflowId,
nodeIds: nodeIdsOf(ops),
opIds: ops.map((op) => op.op_id)
}))
).toEqual([
{ workflowId: 'wf-new', nodeIds: [2], opIds: deliveredIds },
{
workflowId: 'wf-new',
nodeIds: [3],
opIds: [expect.stringMatching(/^[0-9a-f]{32}$/)]
}
])
expect(localSettled.map(summarizeSettlement)).toEqual([
{ state: 'acknowledged', nodeIds: [2] },
{ state: 'undeliverable', nodeIds: [1] }
])
localSender.detach()
})

Expand Down
Loading
Loading