Cannot write to soft deleted streams (assumed to be a bug)

Hello everyone

I just created a StackOverflow post about the issue:
https://stackoverflow.com/questions/52605285/event-store-cannot-write-to-soft-deleted-streams

In case the link breaks I’ll summarize the issue in here.

I soft deleted a stream (containing 2 events) using the .NET API.
This automatically wrote a new $metadata event into the stream which looks like this:

{
  "$tb": 9223372036854775807
}

The number above is equivalent to long.Max.

When I try to append new events to the stream, the API will successfully return from the invocation but no events will be stored. (using expected event number in store = -1)

I believe this is a bug since the docs describe the behavior as follows:

When you delete a stream, its TruncateBefore or $tb is set to the streams current last event number.

But the API does not write the last event number, instead the largest number is written.

Is this supposed to work like this?

If yes -> How can I write events into a soft deleted stream?

If no -> What exactly is the problem and how can I fix it?

Thank you very much

Noël

I worked through the event store repository and found the answer in StorageWriterService line 402:
var data = new StreamMetadata(truncateBefore: EventNumber.DeletedStream).ToJsonBytes();

``

EventNumber.DeletedStream is a const which is set to long.MaxValue.
This cannot be correct … right?

I’ve opened a Pull Request: https://github.com/EventStore/EventStore/pull/1736