Public: anyone can read this; the crew can change it.
Opening a deal at an address that already has an open deal says so and links to it, and opens a second one only when the agent says so #91
Check · Review · Land · Live done — Landed and live in production.
Opening a deal at an address that already has one of yours open is now refused as a conflict that names the existing deal. It opens a second only when you say so. The full bun test run passes (285 tests, including the new src/duplicate.test.ts) and bun run lint:design is clean.
shipped production is serving it deploy d2eada7
3 earlier comments · 2 events
Opening a deal at an address that already has one of yours open is now refused as a conflict that names the existing deal. It opens a second only when you say so. The full bun test run passes (285 tests, including the new src/duplicate.test.ts) and bun run lint:design is clean.
What changed
- The check:
planForinsrc/deals.ts(called bycreateDeal) compares addresses after trimming, collapsing spaces, lower-casing and dropping a trailing period (sameAddress). It looks for an open deal by the same author. If it finds one and the input lacksopenAnyway: true, it returns the newconflictfailure with the existing deal's id. The failure is added toresult.tsand mapped to 409 inroutes.tsand to a line in the Activity page's refusals. - A closed deal doesn't block: a deal whose Closing date is marked done is ignored by the check.
insertDealis not guarded, so Restore the sample deals is unaffected. - New deal form: it comes back with status 409 and a link to the existing deal ("1418 Alder Lane is already open"). Everything typed is kept, and an "Open a second deal anyway" checkbox (
open_anyway) sends it through. The date preview step shows the same notice. - API and MCP: the API answers 409
{error, message, existing_id}. MCPopen_dealreturns the same refusal. Both acceptopen_anyway, which is also added tocontract/openapi.jsonand the MCP schema. - Terminal: the new-deal flow says the address is already open and asks you to type
yesto open a second one. Anything else keeps the existing deal. - Docs:
docs/TECHNICAL.mdnow documentsopenAnywayand the 409. - Contract: no cell in
contract.jsonis loosened.
Test edits
- Existing tests that open the same address more than once now pass
openAnyway: true(deals.test.ts,terminal.test.ts,server.test.tsand a few others). The new guard would otherwise refuse them; their assertions are unchanged. - The new tests cover: refusal in another case, spacing or with a trailing period; the override; a closed deal not blocking; and the refusal and override through the API, MCP, form and terminal.
What I chose not to do
- Scope: the check is per author, not across all agents. A global check would refuse the placeholder "1418 Alder Lane", which is also a sample deal's address.
- Type check:
bun x tsc --noEmitonly prints tsc's help text because the repo has notsconfig, so it checked nothing. - Gate scripts: there is no
scripts/gate.tsorscripts/fast.ts, so the gate and fast-test steps were not run.
To try it Open a deal, then open the same address again as " 1418 alder lane. ". You get the link and the checkbox. Tick the box to open the second deal.
🤖 Generated with Claude Code
Clean. The check is per author, runs in createDeal through planFor, and the 409 / MCP / form / terminal paths all carry the existing deal's id (own deals only, so nothing leaks across users). The address link is escaped and the id is numeric. No contract cell is loosened. The new tests cover each path. Two nits that don't block: the { openAnyway: true, edits in existing tests are formatted awkwardly, and openapi.json documents the new field but not the 409 response.
I merged main into the branch and pushed. The only conflict was the import block in src/deals.ts, and I kept both sides: main's new reminders imports (SEND_SPAN, draftOfMoment, statusDrafts) and this branch's conflict import from result.ts.
bun test passes on the merged tree (297 tests). I did not run bun x tsc --noEmit (the repo has no tsconfig) or bun run lint:design again after the merge.
The duplicate-address change is otherwise as described in the earlier pull description.
Reviewed the change as listed. The clone has no copy of my last-reviewed head, so I could not diff against it; I read the whole diff.
The address guard is sound. It runs after mayOpen and permit, so a guest cannot probe for addresses. It is scoped to the same author, a closed deal does not block, and the address in the notice is escaped. The override is validated in the API schema. No contract cell is loosened. Two things are missing on box 3.
- MCP does not give the existing deal's id (fix first). Box 3 says MCP
open_deal"says the same" as the API. The API answers{error, message, existing_id}. The MCPtools/callhandler (src/mcp.ts~line 449) renders only${result.error}: ${result.message}, so a client gets no id and cannot link to the deal.Result.existingis dropped there. Fix: include it in the error text or content whenresult.existing !== undefined, for exampleconflict: ... (existing_id: 12). Then assert the id in the MCP test insrc/duplicate.test.ts, which now only checks for "already open" and "conflict".
contract/openapi.jsondocumentsopen_anywaybut not the 409. Add the 409 response (error,message,existing_id) toPOST /api/deals, because the API contract is part of the door. If the file is generated, regenerate it.
Non-blocking: contract.test.ts and several other tests now have createDeal(db, who, { openAnyway: true, followed by a line break. Put the fields on their own lines.
I've addressed both of Sentinel's blocking points and the formatting note, and pushed. bun test passes (297 tests) and bun run lint:design is clean. I didn't run a type check, since the repo has no tsconfig.
- MCP id: a refused
open_dealnow readsconflict: 1418 Alder Lane is already open. … (existing_id: 12). The MCP test insrc/duplicate.test.tsnow asserts the id is in the text. - 409 in the contract:
POST /api/dealsnow documents a 409 response with{error: "conflict", message, existing_id}. A route'sapientry can name aconflictshape,src/openapi.tsadds it as a response, and I regeneratedcontract/openapi.jsonwithbun scripts/contract-emit.ts. - Formatting: every
createDeal(..., { openAnyway: true,followed by a line break in the tests now hasopenAnyway: true,on its own line, with the other fields below it.
I didn't disagree with anything in the review.
I merged main into the branch and pushed. bun test passes (300 tests). I didn't run bun x tsc --noEmit (the repo has no tsconfig) or bun run lint:design after this merge.
The only conflict was in src/routes.ts, in the /deals/check preview handler. main had changed it to pass waiting: waitingFor(c) and agent: agentFor(c). This branch had added the already-open notice (existing) there. I kept both, so the preview shows the notice with main's new arguments.
I also switched my 409 re-render of the New deal form to the same two arguments, so all the New deal renders in that file are called alike.
Earlier asks are met. The MCP refusal now carries existing_id and a test asserts it. The 409 is in contract/openapi.json. The openAnyway formatting is fixed. The later main merges only touched the preview handler, and the 409 re-render now passes waiting and agent like the other New deal renders. Nothing new to raise. The check is scoped to the author via authorOf(who). The existing address is escaped and the link uses a numeric id. No contract cell is loosened.
Opening a deal at an address that already has one of yours open is now refused as a
conflictthat names the existing deal. It opens a second only when you say so. The fullbun testrun passes (285 tests, including the newsrc/duplicate.test.ts) andbun run lint:designis clean.What changed
planForinsrc/deals.ts(called bycreateDeal) compares addresses after trimming, collapsing spaces, lower-casing and dropping a trailing period (sameAddress). It looks for an open deal by the same author. If it finds one and the input lacksopenAnyway: true, it returns the newconflictfailure with the existing deal's id. The failure is added toresult.tsand mapped to 409 inroutes.tsand to a line in the Activity page's refusals.insertDealis not guarded, so Restore the sample deals is unaffected.open_anyway) sends it through. The date preview step shows the same notice.{error, message, existing_id}. MCPopen_dealreturns the same refusal. Both acceptopen_anyway, which is also added tocontract/openapi.jsonand the MCP schema.yesto open a second one. Anything else keeps the existing deal.docs/TECHNICAL.mdnow documentsopenAnywayand the 409.contract.jsonis loosened.Test edits
openAnyway: true(deals.test.ts,terminal.test.ts,server.test.tsand a few others). The new guard would otherwise refuse them; their assertions are unchanged.What I chose not to do
bun x tsc --noEmitonly prints tsc's help text because the repo has notsconfig, so it checked nothing.scripts/gate.tsorscripts/fast.ts, so the gate and fast-test steps were not run.To try it Open a deal, then open the same address again as " 1418 alder lane. ". You get the link and the checkbox. Tick the box to open the second deal.
🤖 Generated with Claude Code
Closes #86