Repository navigation
Call back a delayed send and restore a trashed entry - #312
Conversation
Model HEY's Undo Send for a topic (POST /topics/{topicId}/undo_send) and
an entry's restore from the trash (PUT /entries/{entryId}/status/active),
both of which HEY answers with a 303 rather than a body.
Go's Topics().UndoSend takes the redirect as the answer and reads the
entry HEY called back out of its Location, since HEY undoes the caller's
last delayed entry on the topic, which need not be the one meant. A 400
is too late: nothing was held. Entries().Restore takes its redirect the
same way, so a failed read of the thread can't report a restore that went
through as one that didn't. PutForm completes the form family for a
caller driving the path itself.
Rust's Topics::undo_topic_send and Kotlin's and Swift's undoTopicSend send UndoTopicSend from its generated route without following HEY's 303, and answer the entry its Location names: Go's Topics().UndoSend, ported. HEY undoes the caller's last delayed entry on the topic, which need not be the one meant, and the Location is the only place it says which. A 400 is reworded inside the operation as Go words it, nothing to undo, with HEY's status and request id kept, so the hooks hear the error the caller gets. undone_entry_id and undoneEntryId read the entry out of a Location for a caller holding one, against Go's table of what is and is not an undo's redirect. The generated undo_send and undoSend still follow the redirect. PARITY.md gains the rows for the undo and for the entry restore, which Rust leaves to the generated method. Kotlin's and Swift's route counts move to 141 for the two operations the last commit modelled.
The path cases for UndoTopicSend and RestoreEntry answer what HEY answers,
a 303 and then the read a generated client follows it to. undo-restore.json
holds the behaviour. The hand-written Undo Send takes the redirect for its
answer in one request and reads the entry out of either Location shape. A
400 is an error with that status, asked once. A 503 is not answered with a
resend, by the convenience or the generated operation, under a client that
allows three. RestoreEntry is resent once and stops at its two attempts.
Each runner dispatches UndoTopicSend and RestoreEntry to the generated
operation and UndoSend to its convenience, answering {"entry_id"} for
responseBody to read. Go's HEY layer sends RestoreEntry through
Entries().Restore.
TypeScript follows no redirect, so the four cases a 303 succeeds in are
not applicable there: its client reports the 303 as an error with that
status, which its README now says of these two writes. Its own tests hold
that, the single send of an undo and the resend of a restore, and its
runner sends the undo's error cases through the generated operation.
The spec said a generated client follows the 303 UndoTopicSend and RestoreEntry answer with. TypeScript's follows none: there a HeyError whose httpStatus is 303 is the write having gone through, and it carries no Location, so it cannot say which entry an undo called back. The comment is printed on TypeScript's own methods, so it says so there. Every generated tree is regenerated for the comment.
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues can falsely report successful writes without delivering mutations and misclassify a delivery-capable restore operation as mailbox-only for downstream policy consumers.
2 open issues
What changed in this PR
Adds modeled Undo Send and single-entry restore operations across the five HEY SDKs, enabling callers such as the hosted MCP server to use generated APIs rather than construct paths manually.
Changes:
- Models both routes and generates client methods, route metadata, and coverage records.
- Adds undo conveniences that capture the redirect and return the recalled entry ID, plus Go restore and
PutFormsupport. - Adds redirect, error, and retry tests; documents TypeScript’s existing treatment of successful redirects as errors.
[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
| File | Description |
|---|---|
typescript/tests/client.test.ts |
Tests redirect errors and retry limits. |
typescript/src/generated/schema.ts |
Adds operation types and updates scope documentation. |
typescript/src/generated/operations.ts |
Adds methods and retry metadata. |
typescript/src/generated/coverage.json |
Registers both operations. |
typescript/README.md |
Documents redirect behavior and conformance exclusions. |
swift/Tests/HeyTests/TopicsTests.swift |
Tests undo results, errors, and Location parsing. |
swift/Tests/HeyTests/RouteTests.swift |
Updates the expected route count. |
swift/Sources/Hey/Services/TopicsService+Conveniences.swift |
Adds redirect-capturing undo and entry-ID parsing. |
swift/Sources/Hey/Generated/Services/TopicsService.swift |
Adds generated undo method. |
swift/Sources/Hey/Generated/Services/EntriesService.swift |
Adds generated restore method. |
swift/Sources/Hey/Generated/Routes.swift |
Adds routes and retry policies. |
swift/Sources/Hey/Generated/Models/SentMessage.swift |
Corrects undo-action scope documentation. |
spec/route-coverage.json |
Records both modeled routes. |
spec/hey.smithy |
Defines operations, behavior traits, and documentation. |
spec/excluded-routes.json |
Removes the newly modeled routes. |
rust/hey-sdk/tests/services_topics.rs |
Tests undo behavior and Location parsing. |
rust/hey-sdk/src/services/topics.rs |
Adds redirect-capturing undo and entry-ID parsing. |
rust/hey-sdk/src/services/mod.rs |
Exports the parser and updates convenience documentation. |
rust/hey-sdk/src/generated/types.rs |
Corrects undo-action scope documentation. |
rust/hey-sdk/src/generated/services/topics.rs |
Adds generated undo method. |
rust/hey-sdk/src/generated/services/entries.rs |
Adds generated restore method. |
rust/hey-sdk/src/generated/routes.rs |
Adds routes and retry policies. |
rust/hey-sdk/PARITY.md |
Documents Go/Rust undo and restore differences. |
openapi.json |
Adds generated operation contracts and metadata. |
kotlin/sdk/src/commonTest/kotlin/com/basecamp/hey/TopicsServiceTest.kt |
Tests undo behavior and Location parsing. |
kotlin/sdk/src/commonTest/kotlin/com/basecamp/hey/RouteTest.kt |
Updates the expected route count. |
kotlin/sdk/src/commonMain/kotlin/com/basecamp/hey/services/TopicsService.kt |
Adds redirect-capturing undo and entry-ID parsing. |
kotlin/sdk/src/commonMain/kotlin/com/basecamp/hey/generated/services/TopicsService.kt |
Adds generated undo method. |
kotlin/sdk/src/commonMain/kotlin/com/basecamp/hey/generated/services/EntriesService.kt |
Adds generated restore method. |
kotlin/sdk/src/commonMain/kotlin/com/basecamp/hey/generated/Routes.kt |
Adds routes and retry policies. |
kotlin/sdk/src/commonMain/kotlin/com/basecamp/hey/generated/models/SentMessage.kt |
Corrects undo-action scope documentation. |
go/pkg/hey/url-routes.json |
Registers both URL patterns. |
go/pkg/hey/undo_restore_test.go |
Tests undo, restore, parsing, and PUT forms. |
go/pkg/hey/topics.go |
Adds undo wrapper and entry-ID parser. |
go/pkg/hey/entries.go |
Adds redirect-capturing restore wrapper. |
go/pkg/hey/client.go |
Adds redirect capture support and PutForm. |
go/pkg/generated/client.gen.go |
Generates operations, response parsers, and metadata. |
conformance/tests/undo-restore.json |
Adds shared undo and restore behavior cases. |
conformance/tests/paths.json |
Adds route and redirect-following cases. |
conformance/runner/typescript/runner.ts |
Maps the undo alias and updates exclusion count. |
conformance/runner/typescript/README.md |
Updates coverage totals and redirect limitations. |
conformance/runner/typescript/not-applicable.json |
Excludes four unsupported redirect cases. |
conformance/runner/typescript/fixture-inventory.json |
Registers the new conformance cases. |
conformance/runner/swift/Sources/ConformanceRunner/Operations.swift |
Dispatches new operations and undo convenience. |
conformance/runner/rust/src/operations.rs |
Dispatches new operations and undo convenience. |
conformance/runner/kotlin/src/main/kotlin/com/basecamp/hey/conformance/Operations.kt |
Dispatches new operations and undo convenience. |
conformance/runner/go/main.go |
Dispatches generated operations and Go wrappers. |
behavior-model.json |
Adds operation effects and retry policies. |
Review effort: Balanced
Go's Topics().UndoSend and Entries().Restore took any 3xx as the write having gone through. A 307 or 308 asks for the write to be sent again somewhere else, and a 301 is no answer to a write either: the hop is not taken, so the write reached nowhere and was reported as done. For an undo that is a message said to be called back that goes out. Only a 302 or a 303 is the answer now, as Go's form transport and the Rust, Kotlin and Swift redirect capture already have it. Any other redirect is still not followed, and is an API error with its status.
|
Review summary for head 4c7f19e. State. Every check has finished on 4c7f19e: 35 pass, and the one neutral is cubic, which reviewed nothing here because the team's monthly line limit is used up (it resumes 1 December). Copilot reviewed 7a2cda2 with two findings and approved 4c7f19e. Both threads are resolved, and the branch merges cleanly into Fixed (1 of 2). Go took any 3xx as a completed write. Declined (1 of 2). Mark Left as documented, for a person to decide. TypeScript's client follows no redirect and reports a non-2xx as an error, so a successful No release, tag or version bump is part of this. Not merged: that is a person's call. |

HEY's Undo Send and its restore-from-Trash for a single entry were the two routes a caller needed to take back a send or a deleted draft, and both sat in
spec/excluded-routes.json. This models them, so the hosted HEY MCP server can offer "undo that send" and "bring that draft back" without driving the paths by hand.What it adds
UndoTopicSend:POST /topics/{topicId}/undo_send.json. Calls back the last message the caller sent on a topic while Undo Send still holds it. The message is a draft again, unsent.RestoreEntry:PUT /entries/{entryId}/status/active.json. Takes one entry out of the Trash. Idempotent: an entry that isn't in the Trash is left as it is.Both leave
excluded-routes.jsonforroute-coverage.json, and every generated client gains the two operations.HEY answers both with a
303and no body, and for the undo that redirect'sLocationis the only place HEY names the entry it called back (/messages/{id}/editfor a message on its own thread,/topics/{topicId}?expanded_draft={id}for a reply). HEY picks the entry, the caller's last delayed one on the topic, so it need not be the one the caller meant. The hand-written layer therefore takes the redirect as the answer rather than follow it:LocationTopics().UndoSend(ctx, topicID) (entryID int64, err error)UndoneEntryID(location) (int64, bool)Topics::undo_topic_send(topic_id) -> Result<Option<i64>, Error>services::undone_entry_id(&str) -> Option<i64>TopicsService.undoTopicSend(topicId): Long?undoneEntryId(String): Long?TopicsService.undoTopicSend(topicId:) -> Int?undoneEntryId(_:) -> Int?Go also gains
Entries().Restore(ctx, entryID) error, which takes its redirect the same way, so a failed read of the thread can't report a restore that went through as one that didn't, andClient.PutForm, which completes the form family besidePostFormandDeleteForm.Too late is told from undone. With nothing left to call back (the delay ran out and the message went, or none was held) HEY answers
400and changes nothing. Every SDK surfaces that as an API error whose HTTP status is 400. A success is a nil error and, from the conveniences, the entry.The undo is never resent. A second undo would call back the next delayed entry on the thread, so
UndoTopicSendis one attempt, whatever the client's retry settings.RestoreEntryis idempotent and retries a 429 or 503 once.SentMessage.undo_action's comment said HEY offers a scoped token no Undo Send. It does now, to a token holdingwriteapproved since HEY widened that scope, and the comment says so.How it was checked against HEY
Read from haystack's
master, and exercised there with controller tests against a local build (not against production):Topics::UndoSendsController#createundoestopic.last_delayed_entry_for(user:)and redirects to the draft, or answers 400 when there is none.Entry::Delayableholds a send for 15 seconds and offers the undo for 12.Entries::StatusController#activerestores the entry alone. A draft that was its topic's only entry took the topic to the Trash with it, and restoring just the entry leaves a draft on a trashed topic.RestoreTopicis the call for that one, and the operation's comment says which to use when.write(approved since the widening). Restoring a draft that is scheduled to send needssendas well, since a draft keeps its schedule in the Trash.Nothing in haystack changes for this, and no existing caller of either route sees a difference.
TypeScript
The TypeScript client follows no redirect and reports any non-2xx as an error, so there a successful
undoTopicSendorrestoreEntrythrows aHeyErrorwhosehttpStatusis 303, with noLocation. That is documented on the two methods and intypescript/README.md, and held bytypescript/tests/client.test.ts, rather than changed here: making a redirect an answer in TypeScript is a transport change that deserves its own PR (a model-level "the redirect is the answer" trait would also let the other generated clients stop following). Four conformance cases that need a followed or captured redirect are marked not applicable for TypeScript for the same reason.Tests
Locationshapes, a bare/topics/{id}not read as an undo, non-positive ids refused, the 400, one request after a 503.conformance/tests/undo-restore.json(the entry out of eachLocationshape, the 400, no resend of an undo after a 503 from either layer, one resend of a restore). Go, Rust, Kotlin and Swift run 237 of 237; TypeScript runs 228 with 9 not applicable.make checkpasses on the head.Locationshape unread, non-positive ids accepted, a bare topic read as an undo, the 400 swallowed or unworded, a resend after 503).Additive. No release, tag or version bump here.