Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(target_dir):
$(exe): $(shell find . unison -type f -name '*.hs') $(shell find . unison -type f -name '*.yaml')
@echo $(exe)
@echo $@
stack build $(STACK_FLAGS) share-api:share-api
stack build $(STACK_FLAGS)

$(installed_share): $(exe) $(target_dir)
cp $(exe) $(installed_share)
Expand Down Expand Up @@ -109,3 +109,24 @@ transcripts: $(installed_share)
kill $$SERVER_PID 2>/dev/null || true; \
)
@echo "Transcripts complete!";

task-runner: $(installed_share)
@echo "Taking down any existing docker dependencies"
@docker compose -f docker/docker-compose.base.yml down || true
@trap 'docker compose -f docker/docker-compose.base.yml down' EXIT INT TERM
@echo "Booting up task docker dependencies..."
docker compose -f docker/docker-compose.base.yml up --remove-orphans --detach
@while ! ( pg_isready --host localhost -U postgres -p 5432 >/dev/null 2>&1 && redis-cli -p 6379 ping >/dev/null 2>&1 && VAULT_ADDR=http://localhost:8200 vault status >/dev/null 2>&1 ) do \
sleep 1; \
done;
./transcripts/configure_transcript_database.zsh
@echo "Booting up share";
( . ./local.env ; \
$(exe) & \
SERVER_PID=$$!; \
trap "kill $$SERVER_PID 2>/dev/null || true" EXIT INT TERM; \
echo "Running task"; \
stack exec share-task-runner; \
kill $$SERVER_PID 2>/dev/null || true; \
)
@echo "Task complete!";
6 changes: 0 additions & 6 deletions docker/share-task-runner-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

set -ex

echo SHARE_REDIS: "$SHARE_REDIS"

if [ -n "$NOMAD_PORT_enlil_http" ]; then
export SHARE_SERVER_PORT="$NOMAD_PORT_enlil_http"
fi

export SHARE_IP=0.0.0.0

exec 2>&1
Expand Down
19 changes: 12 additions & 7 deletions share-api/src/Share/Web/UCM/Sync/Impl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import Share.Web.Errors
import Share.Web.UCM.Sync.HashJWT qualified as HashJWT
import Share.Web.UCM.Sync.Types (EntityBunch (..), RepoInfoKind (..), entityKind)
import U.Codebase.Causal qualified as Causal
import U.Codebase.Sqlite.HashHandle qualified as HH
import U.Codebase.Sqlite.Orphans ()
import Unison.Codebase.Path qualified as Path
import Unison.Hash32 (Hash32)
Expand Down Expand Up @@ -259,7 +260,11 @@ insertEntitiesToCodebase codebase entities = do
mayErrs <- PG.transactionUnsafeIO $ batchValidateEntities maxParallelismPerUploadRequest isComponentHashMismatchAllowedIO isCausalHashMismatchAllowedIO unsavedEntities
case mayErrs of
Nothing -> pure ()
Just (err :| _errs) -> throwError err
Just (err :| _errs) ->
case err of
Right e -> throwError e
Left (HH.IncompleteElementOrderingError (ComponentHash hash)) ->
throwError $ Sync.InvalidByteEncoding (Hash32.fromHash hash) Sync.TermComponentType "Incomplete element ordering in term components"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we don't have a more generic spot for this failure so it goes here.

SyncQ.saveTempEntities codebase unsavedEntities
let hashesNowInTemp = Set.fromList (fst <$> Foldable.toList unsavedEntities) <> (Set.fromList . Foldable.toList $ hashesAlreadyInTemp)
pure hashesNowInTemp
Expand Down Expand Up @@ -393,7 +398,7 @@ batchValidateEntities ::
(ComponentHash -> ComponentHash -> IO Bool) ->
(CausalHash -> CausalHash -> IO Bool) ->
f (Hash32, Sync.Entity Text Hash32 Hash32) ->
IO (Maybe (NonEmpty (Sync.EntityValidationError)))
IO (Maybe (NonEmpty (Either HH.HashingFailure Sync.EntityValidationError)))
batchValidateEntities maxParallelism checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed entities = do
errs <- UnliftIO.pooledForConcurrentlyN maxParallelism entities \(hash, entity) ->
validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity
Expand All @@ -405,16 +410,16 @@ validateEntity ::
(CausalHash -> CausalHash -> m Bool) ->
Hash32 ->
Share.Entity Text Hash32 Hash32 ->
m (Maybe Sync.EntityValidationError)
m (Maybe (Either HH.HashingFailure Sync.EntityValidationError))
validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity = do
case (Sync.validateEntity hash entity) of
Just err@(Sync.EntityHashMismatch Sync.TermComponentType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) ->
Just (Right (err@(Sync.EntityHashMismatch Sync.TermComponentType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})))) ->
checkIfComponentHashMismatchIsAllowed (ComponentHash . Hash32.toHash $ expectedHash) (ComponentHash . Hash32.toHash $ actualHash) >>= \case
False -> pure (Just err)
False -> pure (Just $ Right err)
True -> pure Nothing
Just err@(Sync.EntityHashMismatch Sync.CausalType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) ->
Just (Right (err@(Sync.EntityHashMismatch Sync.CausalType (Sync.HashMismatchForEntity {supplied = expectedHash, computed = actualHash})))) ->
checkIfCausalHashMismatchIsAllowed (CausalHash . Hash32.toHash $ expectedHash) (CausalHash . Hash32.toHash $ actualHash) >>= \case
False -> pure (Just err)
False -> pure (Just $ Right err)
True -> pure Nothing
Just err ->
-- This shouldn't happen unless the ucm client is buggy or malicious
Expand Down
18 changes: 11 additions & 7 deletions share-task-runner/src/Share/Tasks/AmbiguousComponentCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Share.Postgres.Cursors qualified as PG
import Share.Prelude
import Share.Utils.Logging (Loggable (..))
import Share.Utils.Logging qualified as Logging
import U.Codebase.Sqlite.HashHandle qualified as HH
import U.Codebase.Sqlite.TempEntity
import Unison.Hash32
import Unison.Sync.EntityValidation qualified as EV
Expand All @@ -17,7 +18,7 @@ import Unison.Util.Servant.CBOR qualified as CBOR

data AmbiguousComponentCheckError
= TaskAmbiguousComponentCheckError Hash32
| TaskEntityValidationError Hash32 Sync.EntityValidationError
| TaskEntityValidationError Hash32 (Either HH.HashingFailure Sync.EntityValidationError)
| TaskEntityDecodingError Hash32 CBOR.DeserialiseFailure
deriving (Show, Eq)

Expand Down Expand Up @@ -51,12 +52,15 @@ run = withWorkerName "ambiguous-component-task" do
PG.newRowCursor @(CBORBytes TempEntity, Hash32)
"component_cursor"
[PG.sql|
(SELECT DISTINCT ON (t.component_hash_id) bytes.bytes, ch.base32
FROM terms t
JOIN serialized_components sc ON t.component_hash_id = sc.component_hash_id
JOIN bytes ON sc.bytes_id = bytes.id
JOIN component_hashes ch ON t.component_hash_id = ch.id
)
WITH component_hash_ids(component_hash_id) AS (
SELECT DISTINCT component_hash_id
FROM terms t
WHERE t.component_index = 1
) SELECT DISTINCT ON (bytes.id) bytes.bytes, ch.base32
FROM component_hash_ids chi
JOIN serialized_components sc ON chi.component_hash_id = sc.component_hash_id
JOIN bytes ON sc.bytes_id = bytes.id
JOIN component_hashes ch ON chi.component_hash_id = ch.id
|]
PG.foldBatched cursor 100 \rows -> do
rows
Expand Down
2 changes: 1 addition & 1 deletion unison
Submodule unison updated 32 files
+22 −16 codebase2/codebase-sqlite-hashing-v2/src/U/Codebase/Term/Hashing.hs
+36 −1 codebase2/codebase-sqlite/U/Codebase/Sqlite/HashHandle.hs
+2 −2 parser-typechecker/src/Unison/Builtin/Terms.hs
+1 −0 parser-typechecker/src/Unison/Codebase/SqliteCodebase/Migrations/MigrateSchema1To2.hs
+1 −0 parser-typechecker/src/Unison/DataDeclaration/Dependencies.hs
+6 −2 parser-typechecker/src/Unison/Hashing/V2/Convert.hs
+24 −14 parser-typechecker/src/Unison/UnisonFile.hs
+3 −5 unison-cli/src/Unison/Codebase/Editor/AuthorInfo.hs
+9 −5 unison-cli/src/Unison/Codebase/Editor/HandleInput/Run.hs
+1 −1 unison-cli/src/Unison/Codebase/Editor/Output.hs
+7 −0 unison-cli/src/Unison/Codebase/Transcript/Runner.hs
+43 −15 unison-cli/src/Unison/CommandLine/OutputMessages.hs
+7 −0 unison-cli/src/Unison/Main.hs
+5 −2 unison-cli/src/Unison/Share/Sync.hs
+5 −2 unison-cli/src/Unison/Share/SyncV2.hs
+7 −4 unison-cli/transcripts/Transcripts.hs
+3 −0 unison-hashing-v2/src/Unison/Hashing/V2.hs
+70 −27 unison-hashing-v2/src/Unison/Hashing/V2/ABT.hs
+1 −1 unison-hashing-v2/src/Unison/Hashing/V2/DataDeclaration.hs
+4 −4 unison-hashing-v2/src/Unison/Hashing/V2/Reference/Util.hs
+7 −4 unison-hashing-v2/src/Unison/Hashing/V2/Term.hs
+12 −11 unison-share-api/src/Unison/Sync/EntityValidation.hs
+7 −0 unison-src/transcripts/errors/incomplete-element-ordering-error.md
+25 −0 unison-src/transcripts/errors/incomplete-element-ordering-error.output.md
+29 −13 unison-src/transcripts/idempotent/run.md
+0 −41 unison-src/transcripts/project-outputs/.github/ISSUE_TEMPLATE/bug_report.output.md
+0 −37 unison-src/transcripts/project-outputs/.github/pull_request_template.output.md
+0 −226 unison-src/transcripts/project-outputs/comments-and-docs.output.md
+0 −389 unison-src/transcripts/project-outputs/publishing-library1.output.md
+0 −57 unison-src/transcripts/project-outputs/testing.output.md
+0 −150 unison-src/transcripts/project-outputs/type-declarations.output.md
+9 −7 weeder.toml
Loading