{"record":{"id":"2f77dca2dac8f3a5","repo":"Tencent/WeKnora","slug":"validate-sandbox-binding-w-2f77dc","errorCode":null,"errorMessage":"validate sandbox binding: %w","messagePattern":"validate sandbox binding: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_lifecycle.go","lineNumber":525,"sourceCode":"\tif current == nil {\n\t\treturn nil\n\t}\n\treturn errors.New(\"sandbox binding changed during destroy\")\n}\n\nfunc (l *remoteSessionLifecycle) readBinding(\n\tctx context.Context,\n\tkey SessionSandboxKey,\n) (*SessionSandboxBinding, error) {\n\tbinding, err := l.bindings.Get(ctx, key)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get sandbox binding: %w\", err)\n\t}\n\tif binding == nil {\n\t\treturn nil, nil\n\t}\n\tif err := binding.Validate(key); err != nil {\n\t\treturn nil, fmt.Errorf(\"validate sandbox binding: %w\", err)\n\t}\n\treturn binding, nil\n}\n\nfunc (l *remoteSessionLifecycle) cleanupCreated(\n\tparent context.Context,\n\thandle RemoteSandboxHandle,\n) error {\n\tif handle == nil || handle.ID() == \"\" {\n\t\treturn errors.New(\"cannot clean up remote sandbox without an ID\")\n\t}\n\treturn l.cleanupSandboxID(parent, handle.ID())\n}\n\nfunc (l *remoteSessionLifecycle) cleanupSandboxID(\n\tparent context.Context,\n\tsandboxID string,\n) error {","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_lifecycle.go#L507-L543","documentation":"After a successful Get, readBinding validates that the returned SessionSandboxBinding actually matches the requested session key (binding.Validate). A mismatch means the store returned corrupt or cross-key data, so the library refuses to trust it. This indicates data corruption or a misbehaving store, not a transient failure.","triggerScenarios":"The binding store returns a non-nil binding whose provider/sandbox/session fields do not match the requested SessionSandboxKey — typically from store corruption, a bug in a custom SessionSandboxBindingStore implementation, or key collisions from bad key encoding.","commonSituations":"Custom/in-memory store implementations returning wrong records; key serialization bugs after upgrades; manual edits or migrations corrupting binding records.","solutions":["Inspect the Validate error in the %w chain to see which field mismatched","Audit/fix the SessionSandboxBindingStore implementation for key encoding or retrieval bugs","Delete the corrupt binding record so the next resolve recreates it cleanly","Check for recent migrations or version changes that altered key formats"],"exampleFix":"// before (custom store)\nfunc (s *memStore) Get(ctx context.Context, key SessionSandboxKey) (*SessionSandboxBinding, error) {\n    return s.m[s.keyString(key)], nil // may return wrong record\n}\n// after\nfunc (s *memStore) Get(ctx context.Context, key SessionSandboxKey) (*SessionSandboxBinding, error) {\n    b, ok := s.m[s.keyString(key)]\n    if !ok { return nil, nil }\n    if b.SessionID != key.SessionID { return nil, fmt.Errorf(\"key mismatch: stored %q want %q\", b.SessionID, key.SessionID) }\n    return b, nil\n}","handlingStrategy":"validation","validationCode":"// Guard custom store implementations against key/record mismatch\nfunc (s *memStore) Get(ctx context.Context, key SessionSandboxKey) (*SessionSandboxBinding, error) {\n    b := s.m[s.encode(key)]\n    if b != nil && b.SessionID != key.SessionID {\n        return nil, fmt.Errorf(\"corrupt record for key %v\", key)\n    }\n    return b, nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"validate sandbox binding\") {\n    // store returned data inconsistent with the key: purge record, do not retry blindly\n    log.Printf(\"corrupt binding: %v\", err)\n}","preventionTips":["Unit-test custom SessionSandboxBindingStore implementations for key fidelity","Avoid hand-editing or migrating binding records without schema checks","Log binding records on validation failure to diagnose corruption quickly"],"tags":["go","data-corruption","binding-store","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}