There is a race condition that can cause a partitioned state store to be missing records up to an offset when using standby tasks.
When a reassignment occurs and a task is migrated to a StandbyTask in another StreamThread/TaskManager on the same JVM, there can be lock contention that prevents the StandbyTask on the currently assigned StreamThread from acquiring the lock and to not retry acquiring the lock because all of the active StreamTasks are running for that StreamThread. If the StandbyTask does not acquire the lock before the StreamThread enters into the RUNNING state, then the StandbyTask will not consume any records. If there is no subsequent reassignment before the second execution of the stateDirCleaner Thread, then the task directory for the StandbyTask will be deleted. When the next reassignment occurs the offset that was read by the StandbyTask at creation time before acquiring the lock will be written back to the state store directory, this re-creates the state store directory.
StreamThread(A) and StreamThread(B) are running on the same JVM in the same streams application.
StreamThread(A) has StandbyTask 1_0
StreamThread(B) has no tasks
A reassignment is triggered by another host in the streams application fleet.
StreamThread(A) is notified with a PARTITIONS_REVOKED event of the threads one task
StreamThread(B) is notified with a PARTITIONS_ASSIGNED event of a standby task for 1_0
Here begins the race condition.
StreamThread(B) creates the StandbyTask which reads the current checkpoint from disk.
StreamThread(B) then attempts to updateNewAndRestoringTasks() for it's assigned tasks. 
StreamThread(B) initializes the new tasks for the active and standby tasks.  
StreamThread(B) attempts to lock the state directory for task 1_0 but fails with a LockException , since StreamThread(A) still holds the lock.
StreamThread(B) returns true from updateNewAndRestoringTasks() due to the check at  which only checks that the active assigned tasks are running.
StreamThread(B) state is set to RUNNING
StreamThread(A) closes the previous StandbyTask specifically calling closeStateManager() 
StreamThread(A) state is set to RUNNING
Streams application for this host has completed re-balancing and is now in the RUNNING state.
State at this point is the following: State directory exists for 1_0 and all data is present.
Then at a period that is 1 to 2 intervals of (which is default of 10 minutes) after the reassignment had completed the stateDirCleaner thread will execute .
The stateDirCleaner will then do , which finds the directory 1_0, finds that there isn't an active lock for that directory, acquire the lock, and deletes the directory.
State at this point is the following: State directory does not exist for 1_0.
When the next reassignment occurs. The offset that was read by StreamThread(B) during construction of the StandbyTask for 1_0 will be written back to disk. This write re-creates the state store directory and writes the .checkpoint file with the old offset.
State at this point is the following: State directory exists for 1_0 with a '.checkpoint' file in it, but there is no other state store data in the directory.
If this host is assigned the active task for 1_0 then all the history in the state store will be missing from before the offset that was read at the previous reassignment.
If this host is assigned the standby task for 1_0 then the lock will be acquired and the standby will start to consume records, but it will still be missing all records from before the offset that was read at the previous reassignment.
If this host is not assigned 1_0, then the state directory will get cleaned up by the stateDirCleaner thread 10 to 20 minutes later and the record loss issue will be hidden.
How we recovered from the record loss:
1. Stop the streams application
2. Delete the impacted task directory to remove the .checkpoint file
3. Restart the streams application
Some possible ways of addressing this issue could be the following:
1. Check that the assigned standbys are running in addition to the assigned active tasks before returning in this method 
2. Only write the checkpoint file for a task if the thread still has the state directory lock for the task , on close StandbyTasks commit the offsets they have in memory. 
3. Read the checkpoint file after acquiring the locks for a task in the StreamThread.